diff options
author | Thanh Liem PHAN | 2017-08-11 13:18:56 +0000 |
---|---|---|
committer | vincent lorenzo | 2017-09-06 15:27:59 +0000 |
commit | 94a0ec0473fe4e58e47df99236c6df45cb388c85 (patch) | |
tree | 111356124c24b7393e49adc59f0b37c4a9f6a230 | |
parent | bd7cc54920a37a1a35f8113921f4a2008033b74a (diff) | |
download | org.eclipse.papyrus-94a0ec0473fe4e58e47df99236c6df45cb388c85.tar.gz org.eclipse.papyrus-94a0ec0473fe4e58e47df99236c6df45cb388c85.tar.xz org.eclipse.papyrus-94a0ec0473fe4e58e47df99236c6df45cb388c85.zip |
Bug 520188: [Matrix][TreeTable][Table] sometimes, the icon for
collapse/expand is missing
https://bugs.eclipse.org/bugs/show_bug.cgi?id=520188
- Prevent the creation of new NattableModelManager in NatTableModel
Element
- Hide Appearance and Paste tab when selecting table in Model Explorer
Change-Id: I5c5f78a087f0139631a960389e1a826e2f80f2d1
Signed-off-by: Thanh Liem PHAN <thanhliem.phan@all4tec.net>
(cherry picked from commit 348f8aa64c70ce745ce35d69b0b55c4ab8f578f0)
6 files changed, 209 insertions, 127 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/model/nattable.ctx b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/model/nattable.ctx index b83c60e1abe..60d577a2625 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/model/nattable.ctx +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/model/nattable.ctx @@ -828,17 +828,29 @@ </constraints> </views> <views xmi:id="_bYg4e5LDEeWbp4A9_-WIrQ" name="SingleTableAppearance" sections="_hIAtIJQtEeWx9KtEop_Tug _bYfDCZLDEeWbp4A9_-WIrQ _bYfDCpLDEeWbp4A9_-WIrQ _bYfDDZLDEeWbp4A9_-WIrQ _bYfDEJLDEeWbp4A9_-WIrQ _bYfDE5LDEeWbp4A9_-WIrQ"> - <constraints xsi:type="constraints:SimpleConstraint" xmi:id="_bYg4fJLDEeWbp4A9_-WIrQ" name="singleTable"> - <constraintType href="ppe:/environment/org.eclipse.papyrus.infra.properties.ui/model/Environment.xmi#//@constraintTypes.0"/> - <properties xsi:type="constraints:ValueProperty" xmi:id="_bYg4fZLDEeWbp4A9_-WIrQ" name="nsUri" value="http://www.eclipse.org/papyrus/nattable/model"/> - <properties xsi:type="constraints:ValueProperty" xmi:id="_bYg4fpLDEeWbp4A9_-WIrQ" name="className" value="Table"/> + <constraints xsi:type="constraints:CompositeConstraint" xmi:id="_SdshkH3lEee6PdP9Dq217g" name="isEObjectInActiveSingleTable"> + <constraints xmi:id="_hmDvMH3iEeeYgItd3wXbFg" name="isEObjectInTable"> + <constraintType href="Environment.xmi#//@constraintTypes.1"/> + <properties xsi:type="constraints:ValueProperty" xmi:id="_TVrScH3lEee6PdP9Dq217g" name="expectedValue" value="true"/> + </constraints> + <constraints xmi:id="_bYg4fJLDEeWbp4A9_-WIrQ" name="singleTable"> + <constraintType href="ppe:/environment/org.eclipse.papyrus.infra.properties.ui/model/Environment.xmi#//@constraintTypes.0"/> + <properties xsi:type="constraints:ValueProperty" xmi:id="_bYg4fZLDEeWbp4A9_-WIrQ" name="nsUri" value="http://www.eclipse.org/papyrus/nattable/model"/> + <properties xsi:type="constraints:ValueProperty" xmi:id="_bYg4fpLDEeWbp4A9_-WIrQ" name="className" value="Table"/> + </constraints> </constraints> </views> <views xmi:id="_bYg4f5LDEeWbp4A9_-WIrQ" name="SinglePasteInTable" sections="_bYfDF5LDEeWbp4A9_-WIrQ _bYfDGpLDEeWbp4A9_-WIrQ _bYfDHZLDEeWbp4A9_-WIrQ _bYfDIJLDEeWbp4A9_-WIrQ"> - <constraints xsi:type="constraints:SimpleConstraint" xmi:id="_bYg4gJLDEeWbp4A9_-WIrQ" name="singleTable"> - <constraintType href="ppe:/environment/org.eclipse.papyrus.infra.properties.ui/model/Environment.xmi#//@constraintTypes.0"/> - <properties xsi:type="constraints:ValueProperty" xmi:id="_bYg4gZLDEeWbp4A9_-WIrQ" name="nsUri" value="http://www.eclipse.org/papyrus/nattable/model"/> - <properties xsi:type="constraints:ValueProperty" xmi:id="_bYg4gpLDEeWbp4A9_-WIrQ" name="className" value="Table"/> + <constraints xsi:type="constraints:CompositeConstraint" xmi:id="_fZfpoH3lEee6PdP9Dq217g" name="isEObjectInActiveSingleTable"> + <constraints xmi:id="_f7h_sH3lEee6PdP9Dq217g" name="isEObjectInTable"> + <constraintType href="Environment.xmi#//@constraintTypes.1"/> + <properties xsi:type="constraints:ValueProperty" xmi:id="_f7h_sX3lEee6PdP9Dq217g" name="expectedValue" value="true"/> + </constraints> + <constraints xmi:id="_bYg4gJLDEeWbp4A9_-WIrQ" name="singleTable"> + <constraintType href="ppe:/environment/org.eclipse.papyrus.infra.properties.ui/model/Environment.xmi#//@constraintTypes.0"/> + <properties xsi:type="constraints:ValueProperty" xmi:id="_bYg4gZLDEeWbp4A9_-WIrQ" name="nsUri" value="http://www.eclipse.org/papyrus/nattable/model"/> + <properties xsi:type="constraints:ValueProperty" xmi:id="_bYg4gpLDEeWbp4A9_-WIrQ" name="className" value="Table"/> + </constraints> </constraints> </views> <views xmi:id="_bYfDI5LDEeWbp4A9_-WIrR" name="EObjectInFlatTable" sections="_bYd04pLDEeWbp4A9_-WIrR" automaticContext="true" datacontexts="_bYg4g5LDEeWbp4A9_-WIrR"> diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/Activator.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/Activator.java index e6bc5bbc6b7..e89ce50ae0f 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/Activator.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/Activator.java @@ -1,71 +1,71 @@ -/*****************************************************************************
- * Copyright (c) 2013 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
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.nattable.properties;
-
-import org.eclipse.papyrus.infra.core.log.LogHelper;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class Activator extends AbstractUIPlugin {
-
- // The plug-in ID
- public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.nattable.properties"; //$NON-NLS-1$
-
- // The shared instance
- private static Activator plugin;
-
- public static LogHelper log;
-
- /**
- * The constructor
- */
- public Activator() {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
- */
- @Override
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- log = new LogHelper();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
- */
- @Override
- public void stop(BundleContext context) throws Exception {
- plugin = null;
- super.stop(context);
- }
-
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static Activator getDefault() {
- return plugin;
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2013 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 + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.nattable.properties; + +import org.eclipse.papyrus.infra.core.log.LogHelper; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.nattable.properties"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + public static LogHelper log; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + log = new LogHelper(this); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/EObjectInNatTableFactory.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/EObjectInNatTableFactory.java index da434aa0a3d..702a00a4c84 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/EObjectInNatTableFactory.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/EObjectInNatTableFactory.java @@ -1,6 +1,6 @@ /***************************************************************************** - * Copyright (c) 2016 CEA LIST and others. - * + * Copyright (c) 2016, 2017 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 @@ -8,55 +8,54 @@ * * Contributors: * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation - * + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 520188 *****************************************************************************/ package org.eclipse.papyrus.infra.nattable.properties.modelelement; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.emf.edit.domain.EditingDomain; -import org.eclipse.papyrus.infra.core.sasheditor.editor.IMultiPageEditorPart; +import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.properties.utils.NatTableEditorUtils; +import org.eclipse.papyrus.infra.nattable.utils.TableEditingDomainUtils; import org.eclipse.papyrus.infra.properties.contexts.DataContextElement; import org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElement; -import org.eclipse.papyrus.infra.ui.util.EditorHelper; -import org.eclipse.ui.IEditorPart; /** * The model factory to create {@link NatTableModelElement}s from the current nattable editor. - * + * * @since 2.1 */ public class EObjectInNatTableFactory extends NatTableFactory { /** * {@inheritDoc} - * + * * @see org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElementFactory#doCreateFromSource(java.lang.Object, org.eclipse.papyrus.infra.properties.contexts.DataContextElement) */ @Override protected EMFModelElement doCreateFromSource(final Object sourceElement, final DataContextElement context) { - EMFModelElement result = null; - final NatTableEditor nattableEditor = getCurrentNatTableEditor(); - if (null != nattableEditor) { - final EditingDomain domain = nattableEditor.getTableEditingDomain(); - result = new NatTableModelElement(nattableEditor.getTable(), domain); - } else { - result = super.doCreateFromSource(sourceElement, context); + final INattableModelManager nattableManager = NatTableEditorUtils.getCurrentNatTableModelManager(); + + if (null != nattableManager) { + final TransactionalEditingDomain domain = TableEditingDomainUtils.getTableEditingDomain(nattableManager.getTable()); + if (null != domain) { + return new NatTableModelElement(nattableManager, domain); + } } - return result; + return super.doCreateFromSource(sourceElement, context); } /** * {@inheritDoc} - * + * * @see org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractEMFModelElementFactory#updateModelElement(org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElement, java.lang.Object) */ @Override protected void updateModelElement(final EMFModelElement modelElement, final Object newSourceElement) { - final NatTableEditor nattableEditor = getCurrentNatTableEditor(); + final NatTableEditor nattableEditor = NatTableEditorUtils.getCurrentNatTableEditor(); if (null != nattableEditor) { if (modelElement instanceof NatTableModelElement) { updateTableModelElement((NatTableModelElement) modelElement, nattableEditor.getTable()); @@ -66,22 +65,14 @@ public class EObjectInNatTableFactory extends NatTableFactory { super.updateModelElement(modelElement, newSourceElement); } } - + /** * This allows to get the current nattable editor when this is available. * * @return The current nattable editor if available or <code>null</code>. + * @deprecated since 4.0 */ protected NatTableEditor getCurrentNatTableEditor() { - NatTableEditor result = null; - - final IEditorPart currentEditor = EditorHelper.getCurrentEditor(); - if (currentEditor instanceof IMultiPageEditorPart) { - result = ((IMultiPageEditorPart) currentEditor).getActiveEditor().getAdapter(NatTableEditor.class); - } else if (currentEditor instanceof IAdaptable) { - result = ((IAdaptable) currentEditor).getAdapter(NatTableEditor.class); - } - - return result; + return NatTableEditorUtils.getCurrentNatTableEditor(); } } diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/NatTableFactory.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/NatTableFactory.java index 63dcabcf66c..9deda20705f 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/NatTableFactory.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/NatTableFactory.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2013, 2014 CEA LIST and others. + * Copyright (c) 2013, 2017 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 @@ -10,16 +10,18 @@ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation * Christian W. Damus (CEA) - bug 417409 * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 492891 - * + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 520188 *****************************************************************************/ package org.eclipse.papyrus.infra.nattable.properties.modelelement; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; -import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; import org.eclipse.papyrus.infra.nattable.model.nattable.Table; import org.eclipse.papyrus.infra.nattable.properties.Activator; +import org.eclipse.papyrus.infra.nattable.properties.utils.NatTableEditorUtils; +import org.eclipse.papyrus.infra.nattable.utils.TableEditingDomainUtils; import org.eclipse.papyrus.infra.properties.contexts.DataContextElement; import org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElement; import org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElementFactory; @@ -31,7 +33,7 @@ public class NatTableFactory extends EMFModelElementFactory { /** * {@inheritDoc} - * + * * @see org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElementFactory#doCreateFromSource(java.lang.Object, org.eclipse.papyrus.infra.properties.contexts.DataContextElement) */ @Override @@ -41,17 +43,24 @@ public class NatTableFactory extends EMFModelElementFactory { Activator.log.warn("Unable to resolve the selected element to an EObject"); //$NON-NLS-1$ return null; } + if (source instanceof Table) { - EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(source); - return new NatTableModelElement((Table) source, domain); - } else { - return super.doCreateFromSource(sourceElement, context); + final INattableModelManager nattableManager = NatTableEditorUtils.getCurrentNatTableModelManager(); + + if (null != nattableManager && source == nattableManager.getTable()) { + final TransactionalEditingDomain domain = TableEditingDomainUtils.getTableEditingDomain(nattableManager.getTable()); + if (null != domain) { + return new NatTableModelElement(nattableManager, domain); + } + } } + + return super.doCreateFromSource(sourceElement, context); } /** * {@inheritDoc} - * + * * @see org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractEMFModelElementFactory#updateModelElement(org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElement, java.lang.Object) * * @since 2.1 diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/NatTableModelElement.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/NatTableModelElement.java index 557d5566c25..85098bf3a0f 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/NatTableModelElement.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/NatTableModelElement.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2013, 2014 CEA LIST and others. + * Copyright (c) 2013, 2017 CEA LIST and others. * * * All rights reserved. This program and the accompanying materials @@ -11,7 +11,7 @@ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation * Christian W. Damus (CEA) - bug 323802 * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 476618, 192891, 496905, 508175 - * + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 520188 *****************************************************************************/ package org.eclipse.papyrus.infra.nattable.properties.modelelement; @@ -29,7 +29,6 @@ import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.papyrus.infra.architecture.representation.PapyrusRepresentationKind; -import org.eclipse.papyrus.infra.emf.nattable.selection.EObjectSelectionExtractor; import org.eclipse.papyrus.infra.nattable.contentprovider.ColumnAxisIdentifierContentProvider; import org.eclipse.papyrus.infra.nattable.contentprovider.ColumnContainmentFeatureContentProvider; import org.eclipse.papyrus.infra.nattable.contentprovider.ColumnElementTypeIdContentProvider; @@ -83,7 +82,6 @@ import org.eclipse.papyrus.infra.nattable.properties.provider.ColumnPostActionId import org.eclipse.papyrus.infra.nattable.properties.provider.RowPostActionIdsProvider; import org.eclipse.papyrus.infra.nattable.properties.utils.Constants; import org.eclipse.papyrus.infra.nattable.utils.HeaderAxisConfigurationManagementUtils; -import org.eclipse.papyrus.infra.nattable.utils.NattableModelManagerFactory; import org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElement; import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype; import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider; @@ -142,10 +140,27 @@ public class NatTableModelElement extends EMFModelElement { * * Constructor. * + * @param tableManager + * the table manager, must not be <code>null</code> + * @param domain + * the editing domain, must not be <code>null</code> + */ + public NatTableModelElement(final INattableModelManager tableManager, final EditingDomain domain) { + super(tableManager.getTable(), domain); + this.tableModelManager = tableManager; + this.table = tableManager.getTable(); + init(); + } + + /** + * + * Constructor. + * * @param source * the table * @param domain * the editing domain + * @deprecated since 4.0 */ public NatTableModelElement(final Table source, final EditingDomain domain) { super(source, domain); @@ -157,8 +172,6 @@ public class NatTableModelElement extends EMFModelElement { * Add the listener */ private void init() { - // The create nattable model manager for the properties view doesn't need some listeners of the table (invert axis and update cells map listener) - tableModelManager = NattableModelManagerFactory.INSTANCE.createNatTableModelManager(getEditedTable(), new EObjectSelectionExtractor(), false); this.interestingFeatures = new ArrayList<EStructuralFeature>(); interestingFeatures.add(NattablePackage.eINSTANCE.getTable_TableKindId()); interestingFeatures.add(NattablePackage.eINSTANCE.getTable_Owner()); @@ -322,7 +335,6 @@ public class NatTableModelElement extends EMFModelElement { } columnLabelProviderConfigurations = null; rowLabelProviderConfigurations = null; - tableModelManager.dispose(); tableModelManager = null; } diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/utils/NatTableEditorUtils.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/utils/NatTableEditorUtils.java new file mode 100644 index 00000000000..5b9c0b7c9b9 --- /dev/null +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/utils/NatTableEditorUtils.java @@ -0,0 +1,58 @@ +/***************************************************************************** + * Copyright (c) 2017 CEA LIST, ALL4TEC 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: + * Thanh Liem PHAN (ALL4TEC) - thanhliem.phan@all4tec.net - Bug 520188 + *****************************************************************************/ + +package org.eclipse.papyrus.infra.nattable.properties.utils; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.papyrus.infra.core.sasheditor.editor.IMultiPageEditorPart; +import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.ui.util.EditorHelper; +import org.eclipse.ui.IEditorPart; + +/** + * Utility class for NatTable Editor. + * + * @since 4.0 + */ +public class NatTableEditorUtils { + + /** + * @return The current nattable editor if it is available or <code>null</code> if not found + */ + public static NatTableEditor getCurrentNatTableEditor() { + NatTableEditor result = null; + + final IEditorPart currentEditor = EditorHelper.getCurrentEditor(); + if (currentEditor instanceof IMultiPageEditorPart && null != ((IMultiPageEditorPart) currentEditor).getActiveEditor()) { + result = ((IMultiPageEditorPart) currentEditor).getActiveEditor().getAdapter(NatTableEditor.class); + } else if (currentEditor instanceof IAdaptable) { + result = ((IAdaptable) currentEditor).getAdapter(NatTableEditor.class); + } + + return result; + } + + /** + * @return The current nattable model manager if it is available or <code>null</code> if not found + */ + public static INattableModelManager getCurrentNatTableModelManager() { + NatTableEditor nattableEditor = getCurrentNatTableEditor(); + INattableModelManager currentNattableManager = null; + + if (null != nattableEditor) { + currentNattableManager = (INattableModelManager) nattableEditor.getAdapter(INattableModelManager.class); + } + + return currentNattableManager; + } +} |