Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2017-01-16 08:21:14 +0000
committerGerrit Code Review @ Eclipse.org2017-03-03 09:07:03 +0000
commitc17bf6e6525851a6fdecee41c7e3a8b9dec59f86 (patch)
treec0d931deef732fdff99b94702f14f598da070126 /plugins/infra
parentdd8229e833e31ee60aa4219b8fa56b3a43b31311 (diff)
downloadorg.eclipse.papyrus-c17bf6e6525851a6fdecee41c7e3a8b9dec59f86.tar.gz
org.eclipse.papyrus-c17bf6e6525851a6fdecee41c7e3a8b9dec59f86.tar.xz
org.eclipse.papyrus-c17bf6e6525851a6fdecee41c7e3a8b9dec59f86.zip
Bug 494531: [Property][Table] Editor is dirty after the creation of the
table in the Property View https://bugs.eclipse.org/bugs/show_bug.cgi?id=494531 - The used command need to be execute with a GMFUnsafe because this don't need to be in the command stack - Manage the table as a proper Resource. Change-Id: I4a3d418467516f9a4b4aea37d8eaa05c81e59dbb Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF1
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/resource/TableResource.java124
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/resource/TableResourceFactory.java66
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/resource/TableResourceHelper.java36
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/TableResourceConstants.java26
5 files changed, 253 insertions, 0 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF
index 5516bc6d1f7..ce9f44af5fc 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF
@@ -40,6 +40,7 @@ Export-Package: org.eclipse.papyrus.infra.nattable,
org.eclipse.papyrus.infra.nattable.preferences,
org.eclipse.papyrus.infra.nattable.provider,
org.eclipse.papyrus.infra.nattable.reorder,
+ org.eclipse.papyrus.infra.nattable.resource,
org.eclipse.papyrus.infra.nattable.selection,
org.eclipse.papyrus.infra.nattable.sort,
org.eclipse.papyrus.infra.nattable.style.configattribute,
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/resource/TableResource.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/resource/TableResource.java
new file mode 100644
index 00000000000..8aed2b487c0
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/resource/TableResource.java
@@ -0,0 +1,124 @@
+/*****************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.resource;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
+
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.emf.transaction.RollbackException;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.emf.gmf.util.GMFUnsafe;
+import org.eclipse.papyrus.infra.nattable.Activator;
+import org.eclipse.papyrus.infra.nattable.model.nattable.NattablePackage;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage;
+
+/**
+ * The resource corresponding to the properties files.
+ *
+ * @since 3.0
+ */
+public class TableResource extends XMIResourceImpl {
+
+ /**
+ * Constructor.
+ *
+ * @param uri
+ * The uri of the resource.
+ */
+ public TableResource(final URI uri) {
+ super(uri);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.ecore.resource.impl.ResourceImpl#save(java.util.Map)
+ */
+ @Override
+ public void save(final Map<?, ?> options) throws IOException {
+
+ final TransactionalEditingDomain domain = ((ModelSet) getResourceSet()).getTransactionalEditingDomain();
+
+ final CompoundCommand compoundCommand = new CompoundCommand("Modify top tables"); //$NON-NLS-1$
+ for (final EObject top : getContents()) {
+ if (top instanceof Table) {
+ compoundCommand.append(getDisposeTableCommand(domain, (Table) top));
+ }
+ }
+
+ try {
+ GMFUnsafe.write(domain, compoundCommand);
+ } catch (InterruptedException e) {
+ Activator.log.error(e);
+ } catch (RollbackException e) {
+ Activator.log.error(e);
+ } finally {
+ super.save(options);
+ }
+ }
+
+ /**
+ * @see org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl#useUUIDs()
+ *
+ * @return
+ */
+ @Override
+ protected boolean useUUIDs() {
+ return true;
+ }
+
+ /**
+ *
+ * @param domain
+ * the editing domain
+ * @param table
+ * the table to clean before dispose
+ * @return
+ * the command to use to clean the table before disposing it
+ */
+ protected void disposeTableCommand(final Table table) {
+ table.setContext(null);
+ table.setOwner(null);
+ table.getCurrentRowAxisProvider().eSet(NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), Collections.emptyList());
+ }
+
+ /**
+ * This allows to delete the possible project dependencies.
+ *
+ * @param domain
+ * the editing domain.
+ * @param table
+ * the table to clean before dispose.
+ * @return
+ * the command to use to clean the table before disposing it.
+ * @since 2.0
+ */
+ protected CompoundCommand getDisposeTableCommand(final TransactionalEditingDomain domain, final Table table) {
+ final CompoundCommand disposeCommand = new CompoundCommand("Command used to clean the table before disposing it"); //$NON-NLS-1$
+ disposeCommand.append(SetCommand.create(domain, table, NattablePackage.eINSTANCE.getTable_Context(), null));
+ disposeCommand.append(SetCommand.create(domain, table, NattablePackage.eINSTANCE.getTable_Owner(), null));
+ // assuming the table is synchronized and not inverted :
+ disposeCommand.append(SetCommand.create(domain, table.getCurrentRowAxisProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), Collections.emptyList()));
+
+ return disposeCommand;
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/resource/TableResourceFactory.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/resource/TableResourceFactory.java
new file mode 100644
index 00000000000..0777c8a5fc7
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/resource/TableResourceFactory.java
@@ -0,0 +1,66 @@
+/*****************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.resource;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xmi.XMIResource;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
+
+/**
+ * The resource factory for the properties files.
+ *
+ * @since 3.0
+ */
+@SuppressWarnings("restriction")
+public class TableResourceFactory extends XMIResourceFactoryImpl {
+
+ /** The save options. */
+ private static final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
+
+ static {
+ saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
+ saveOptions.put(Resource.OPTION_LINE_DELIMITER, Resource.OPTION_LINE_DELIMITER_UNSPECIFIED);
+ saveOptions.put(XMLResource.OPTION_SAVE_TYPE_INFORMATION, true);
+ saveOptions.put(XMIResource.OPTION_ENCODING,"UTF-8"); //$NON-NLS-1$
+ saveOptions.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.TRUE);
+ saveOptions.put(XMLResource.OPTION_PROCESS_DANGLING_HREF, XMLResource.OPTION_PROCESS_DANGLING_HREF_DISCARD);
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl#createResource(org.eclipse.emf.common.util.URI)
+ */
+ @Override
+ public Resource createResource(final URI uri) {
+
+ final XMIResource resource = new TableResource(uri);
+
+ if (!resource.getEncoding().equals(EMFCoreConstants.XMI_ENCODING)) {
+ resource.setEncoding(EMFCoreConstants.XMI_ENCODING);
+ }
+
+ resource.getDefaultSaveOptions().putAll(saveOptions);
+
+ return resource;
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/resource/TableResourceHelper.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/resource/TableResourceHelper.java
new file mode 100644
index 00000000000..a09f26fef4a
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/resource/TableResourceHelper.java
@@ -0,0 +1,36 @@
+/*****************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.resource;
+
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.papyrus.infra.nattable.utils.TableResourceConstants;
+
+/**
+ * The table resource helper needed to install the table support for the '*.table' files resources.
+ */
+public class TableResourceHelper {
+
+ /**
+ * This allows to install the correct resource factory corresponding to the table files.
+ *
+ * @param resourceSet
+ * The current resource set.
+ */
+ public static void installTableSupport(final ResourceSet resourceSet) {
+ final TableResourceFactory factory = new TableResourceFactory();
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
+ .put(TableResourceConstants.TABLE_FILE_EXTENSION, factory);
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/TableResourceConstants.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/TableResourceConstants.java
new file mode 100644
index 00000000000..bb4d436d01f
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/TableResourceConstants.java
@@ -0,0 +1,26 @@
+/*****************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.utils;
+
+/**
+ * This allows to define the table resource constants needed.
+ */
+public class TableResourceConstants {
+
+ /**
+ * The file extension for the table.
+ */
+ public static final String TABLE_FILE_EXTENSION = "table"; //$NON-NLS-1$
+
+}

Back to the top