diff options
author | vlorenzo | 2012-08-20 13:57:42 +0000 |
---|---|---|
committer | vlorenzo | 2012-08-20 13:57:42 +0000 |
commit | 7ffd4856375624197517bb9f8f68c6d02393c0fb (patch) | |
tree | 26078be8e5942268faf323b77bf9ba0fa7ab1f18 /incoming | |
parent | a05eaed2a52810c733568defe992d57c5a9868a7 (diff) | |
download | org.eclipse.papyrus-7ffd4856375624197517bb9f8f68c6d02393c0fb.tar.gz org.eclipse.papyrus-7ffd4856375624197517bb9f8f68c6d02393c0fb.tar.xz org.eclipse.papyrus-7ffd4856375624197517bb9f8f68c6d02393c0fb.zip |
A save of my work on the new tables
Manage the synchronization of the table (first part of this development)
Diffstat (limited to 'incoming')
20 files changed, 1481 insertions, 244 deletions
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/.classpath b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/.classpath index 51a56a9b454..a442cf10ed3 100644 --- a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/.classpath +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/.classpath @@ -2,6 +2,6 @@ <classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry excluding="org/eclipse/papyrus/infra/table/efacet/common/modelresource/EMFFacetTableModelResource.java" kind="src" path="src"/>
+ <classpathentry excluding="org/eclipse/papyrus/infra/table/efacet/common/modelresource/EMFFacetTableModelResource.java|org/eclipse/papyrus/infra/table/efacet/common/copy/CustomizationUtils.java|org/eclipse/papyrus/infra/table/efacet/common/copy/TableInstanceUtils.java" kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/META-INF/MANIFEST.MF b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/META-INF/MANIFEST.MF index 9305fb9e9f7..2939b0a3287 100644 --- a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/META-INF/MANIFEST.MF +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/META-INF/MANIFEST.MF @@ -20,7 +20,16 @@ Require-Bundle: org.eclipse.ui, org.eclipse.uml2.uml, org.eclipse.emf.facet.widgets.nattable.instance, org.eclipse.papyrus.infra.table.efacet.papyrustableconfiguration.metamodel;bundle-version="0.9.0", - org.eclipse.papyrus.infra.table.efacet.metamodel.edit;bundle-version="1.0.0" + org.eclipse.papyrus.infra.table.efacet.metamodel.edit;bundle-version="1.0.0", + org.eclipse.gmf.runtime.emf.commands.core, + org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.6.0", + net.sourceforge.nattable.core;bundle-version="2.1.0", + org.eclipse.core.expressions, + org.eclipse.papyrus.infra.services.edit, + org.eclipse.emf.facet.widgets.celleditors.editor;bundle-version="0.2.0", + org.eclipse.emf.facet.widgets.celleditors.ecore;bundle-version="0.2.0", + org.eclipse.emf.facet.efacet.core, + org.eclipse.emf.facet.util.core Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.papyrus.infra.table.efacet.common.editor, diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/icons/down.gif b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/icons/down.gif Binary files differnew file mode 100644 index 00000000000..47b36723730 --- /dev/null +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/icons/down.gif diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/icons/up.gif b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/icons/up.gif Binary files differnew file mode 100644 index 00000000000..2dd3d81fe53 --- /dev/null +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/icons/up.gif diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/plugin.xml b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/plugin.xml index a9ad19f2f90..467a5c5e259 100644 --- a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/plugin.xml +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/plugin.xml @@ -22,5 +22,125 @@ </toolbar>
</menuContribution>
</extension>
-
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.emf.facet.widgets.table.command.category"
+ description="Move the line up"
+ id="org.eclipse.papyrus.infra.table.efacet.common.command.moveuprow"
+ name="Move Line Up">
+ </command>
+ <command
+ categoryId="org.eclipse.emf.facet.widgets.table.command.category"
+ description="Move the line down"
+ id="org.eclipse.papyrus.infra.table.efacet.common.command.movedownrow"
+ name="Move Line Down">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.ui.popup.any">
+ <command
+ commandId="org.eclipse.papyrus.infra.table.efacet.common.command.moveuprow"
+ icon="icons/up.gif"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <and>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.infra.core.papyrusEditor">
+ </equals>
+ </with>
+ <with
+ variable="activePart">
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.infra.table.efacet.common.propertyTester.isPapyrusTableEfacet"
+ value="true">
+ </test>
+ </with>
+ </and>
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.infra.table.efacet.common.command.movedownrow"
+ icon="icons/down.gif"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <and>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.infra.core.papyrusEditor">
+ </equals>
+ </with>
+ <with
+ variable="activePart">
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.infra.table.efacet.common.propertyTester.isPapyrusTableEfacet"
+ value="true">
+ </test>
+ </with>
+ </and>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.infra.table.efacet.common.handlers.DownRowHandler"
+ commandId="org.eclipse.papyrus.infra.table.efacet.common.command.movedownrow">
+ </handler>
+ <handler
+ class="org.eclipse.papyrus.infra.table.efacet.common.handlers.UpRowHandler"
+ commandId="org.eclipse.papyrus.infra.table.efacet.common.command.moveuprow">
+ </handler>
+ </extension>
+ <extension
+ point="org.eclipse.ui.bindings">
+ <key
+ commandId="org.eclipse.papyrus.infra.table.efacet.common.command.moveuprow"
+ contextId="org.eclipse.papyrus.infra.table.efacet.common.context"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="ALT+ARROW_UP">
+ </key>
+ <key
+ commandId="org.eclipse.papyrus.infra.table.efacet.common.command.movedownrow"
+ contextId="org.eclipse.papyrus.infra.table.efacet.common.context"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="ALT+ARROW_DOWN">
+ </key>
+ </extension>
+ <extension
+ point="org.eclipse.ui.contexts">
+ <context
+ description="Papyrus Table Context"
+ id="org.eclipse.papyrus.infra.table.efacet.common.context"
+ name="Papyrus Table Context"
+ parentId="org.eclipse.ui.contexts.window">
+ </context>
+ </extension>
+ <extension
+ point="org.eclipse.core.expressions.propertyTesters">
+ <propertyTester
+ class="org.eclipse.papyrus.infra.table.efacet.common.tester.TablePropertyTester"
+ id="org.eclipse.papyrus.infra.table.efacet.common.propertyTester"
+ namespace="org.eclipse.papyrus.infra.table.efacet.common.propertyTester"
+ properties="isPapyrusTableEfacet"
+ type="org.eclipse.ui.IWorkbenchPart">
+ </propertyTester>
+ </extension>
+ <extension
+ point="org.eclipse.emf.facet.widgets.celleditors.commandFactories">
+ <commandFactory
+ class="org.eclipse.papyrus.infra.table.efacet.common.factory.PapyrusCommandFactory">
+ </commandFactory>
+ </extension>
</plugin>
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/Activator.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/Activator.java index fd6dfd2f990..695bdeb5b78 100644 --- a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/Activator.java +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/Activator.java @@ -1,3 +1,15 @@ +/**
+ * Copyright (c) 2012 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.table.efacet.common;
import org.eclipse.papyrus.infra.core.log.LogHelper;
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/copy/PapyrusTableEfacetCommandFactory.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/copy/PapyrusTableEfacetCommandFactory.java new file mode 100644 index 00000000000..3a053bbfc16 --- /dev/null +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/copy/PapyrusTableEfacetCommandFactory.java @@ -0,0 +1,120 @@ +/**
+ * Copyright (c) 2012 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.table.efacet.common.copy;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.edit.command.MoveCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Row;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Table;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.TablePackage;
+import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTable;
+
+/**
+ *
+ * This factory provides commands for the PapyrusTable
+ *
+ */
+public class PapyrusTableEfacetCommandFactory {
+
+ private PapyrusTableEfacetCommandFactory() {
+ //to prevent instanciation
+ }
+
+ /**
+ *
+ * @param domain
+ * the editing domain
+ * @param table
+ * the table
+ * @param rowToMove
+ * the row to move
+ * @return
+ * the command to move the row
+ */
+ public static final Command getMoveLineUpCommand(final EditingDomain domain, final Table table, final Row rowToMove) {
+ if(domain != null && table != null && rowToMove != null) {
+ final EList<Row> allRows = table.getRows();
+ final int currentIndex = allRows.indexOf(rowToMove);
+ if(currentIndex != -1) {
+ final int newIndex = currentIndex - 1;
+ if(newIndex >= 0) {
+ final MoveCommand cmd = new MoveCommand(domain, table, TablePackage.eINSTANCE.getTable_Rows(), rowToMove, newIndex);
+ cmd.setLabel("Move Line Up"); //$NON-NLS-1$
+ return cmd;
+ }
+ }
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ /**
+ *
+ * @param domain
+ * the editing domain
+ * @param table
+ * the table
+ * @param rowToMove
+ * the row to move
+ * @return
+ * the command to move the row
+ */
+ public static final Command getMoveLineDownCommand(final EditingDomain domain, final Table table, final Row rowToMove) {
+ if(domain != null && table != null && rowToMove != null) {
+ final EList<Row> allRows = table.getRows();
+ final int currentIndex = allRows.indexOf(rowToMove);
+ if(currentIndex != -1) {
+ final int newIndex = currentIndex + 1;
+ if(newIndex <= allRows.size() - 1) {
+ final MoveCommand cmd = new MoveCommand(domain, table, TablePackage.eINSTANCE.getTable_Rows(), rowToMove, newIndex);
+ cmd.setLabel("Move Line Down"); //$NON-NLS-1$
+ return cmd;
+ }
+ }
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ /**
+ *
+ * @param domain
+ * the editing domain
+ * @param table
+ * the table
+ * @param rowToMove
+ * the row to move
+ * @return
+ * the command to move the row
+ */
+ public static final Command getMoveLineUpCommand(final EditingDomain domain, final PapyrusTable table, final Row rowToMove) {
+ return getMoveLineUpCommand(domain, table.getTable(), rowToMove);
+ }
+
+ /**
+ *
+ * @param domain
+ * the editing domain
+ * @param table
+ * the table
+ * @param rowToMove
+ * the row to move
+ * @return
+ * the command to move the row
+ */
+ public static final Command getMoveLineDownCommand(final EditingDomain domain, final PapyrusTable table, final Row rowToMove) {
+ return getMoveLineDownCommand(domain, table.getTable(), rowToMove);
+ }
+
+}
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/AbstractTableEditor.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/AbstractTableEditor.java index 7126044b88c..6fc3df0cbd4 100644 --- a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/AbstractTableEditor.java +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/AbstractTableEditor.java @@ -1,20 +1,39 @@ +/**
+ * Copyright (c) 2012 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.table.efacet.common.editor;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.TriggerListener;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
import org.eclipse.papyrus.infra.table.efacet.common.Activator;
import org.eclipse.papyrus.infra.table.efacet.common.input.PapyrusTableEditorInput;
+import org.eclipse.papyrus.infra.table.efacet.common.listener.FillingListener;
+import org.eclipse.papyrus.infra.table.efacet.common.listener.MoveTableLineListener;
+import org.eclipse.papyrus.infra.table.efacet.common.listener.TableFillingModeListener;
import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTable;
import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrustablePackage;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.contexts.IContextService;
public abstract class AbstractTableEditor extends NatTableEditor2 {
@@ -25,21 +44,27 @@ public abstract class AbstractTableEditor extends NatTableEditor2 { protected PapyrusTable rawModel;
/** listener on the model for synchronized table */
- private TriggerListener modelTriggerListener;
+ private TriggerListener fillingListener;
- /** listener on the table for synchronized table : listen the properties "isSynchronized" and "fillingQueries" */
- private TriggerListener tableTriggerListener;
+ /** listener on the filling mode */
+ private TriggerListener fillingModeListener;
+
+ /** to listen moving lines in the table */
+ private TriggerListener moveLineListener;
/**
- * the part name synchronizer
+ *
+ * Constructor.
+ *
+ * @param servicesRegistry
+ * the service registry
+ * @param rawModel
+ * the raw model
*/
- private final PartNameSynchronizer synchronizer;
-
-
public AbstractTableEditor(final ServicesRegistry servicesRegistry, final PapyrusTable rawModel) {
this.servicesRegistry = servicesRegistry;
this.rawModel = rawModel;
- this.synchronizer = new PartNameSynchronizer(rawModel);
+ new PartNameSynchronizer(rawModel);
}
@@ -61,54 +86,48 @@ public abstract class AbstractTableEditor extends NatTableEditor2 { super.init(site, tableEditorInput);
}
- // /**
- // * add listeners on the context of the table and on the table itself
- // */
- // protected void addListeners() {
- // EditingDomain editingDomain = getEditingDomain();
- // Assert.isTrue(editingDomain instanceof TransactionalEditingDomain);
- // this.modelTriggerListener = new ModelTriggerListener(this.rawModel, (INatTableWidgetProvider)getAdapter(INatTableWidgetProvider.class));
- // ((TransactionalEditingDomain)editingDomain).addResourceSetListener(this.modelTriggerListener);
- // this.tableTriggerListener = new TableTriggerListener(this.rawModel, (INatTableWidgetProvider)getAdapter(INatTableWidgetProvider.class));
- // ((TransactionalEditingDomain)editingDomain).addResourceSetListener(this.tableTriggerListener);
- // }
- // /**
- // *
- // * @see org.eclipse.papyrus.infra.table.common.internal.NatTableEditor#dispose()
- // *
- // * {@inheritDoc}
- // */
- // @Override
- // public void dispose() {
- // ((TransactionalEditingDomain)getEditingDomain()).removeResourceSetListener(this.modelTriggerListener);
- // ((TransactionalEditingDomain)getEditingDomain()).removeResourceSetListener(this.tableTriggerListener);
- // super.dispose();
- // }
+ /**
+ * add listeners on the context of the table and on the table itself
+ */
+ protected void addListeners() {
+ final EditingDomain editingDomain = getEditingDomain();
+ Assert.isTrue(editingDomain instanceof TransactionalEditingDomain);
+
+ this.fillingListener = new FillingListener(this.rawModel);
+ ((TransactionalEditingDomain)editingDomain).addResourceSetListener(this.fillingListener);
- // /**
- // *
- // * @param rawModel2
- // */
- // private void initHiddenColumn(final PapyrusTableInstance rawModel2) {
- // for(Column current : rawModel2.getTable().getColumns()) {
- // if(current instanceof DefaultLabelColumn || current instanceof MetaClassColumn || current instanceof EContainerColumn){
- // String name = NatTableWidgetInternalUtils.getColumnName(current);
- // if(getInitialHiddenColumns().contains(name)) {
- // current.setIsHidden(true);
- // }
- // }
- // }
- // }
+ this.fillingModeListener = new TableFillingModeListener(this.rawModel);
+ ((TransactionalEditingDomain)editingDomain).addResourceSetListener(this.fillingModeListener);
+
+ this.moveLineListener = new MoveTableLineListener(this.rawModel);
+ ((TransactionalEditingDomain)editingDomain).addResourceSetListener(this.moveLineListener);
+ }
+
+ @Override
+ public void createPartControl(final Composite parent) {
+ final IContextService contextService = (IContextService)getSite().getService(IContextService.class);
+ //FIXME : before Eclipse Juno, this line was not necessary
+ //see bug 367816 and bug 382218
+ contextService.activateContext("org.eclipse.papyrus.infra.table.efacet.common.context"); //$NON-NLS-1$
+ super.createPartControl(parent);
+ addListeners();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.table.common.internal.NatTableEditor#dispose()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void dispose() {
+ ((TransactionalEditingDomain)getEditingDomain()).removeResourceSetListener(this.fillingListener);
+ ((TransactionalEditingDomain)getEditingDomain()).removeResourceSetListener(this.fillingModeListener);
+ ((TransactionalEditingDomain)getEditingDomain()).removeResourceSetListener(this.moveLineListener);
+ super.dispose();
+ }
- // /**
- // *
- // * @return
- // * a list of the names of the columns to hide by default
- // */
- // protected List<String> getInitialHiddenColumns() {
- // return Collections.emptyList();
- // }
/**
*
@@ -127,48 +146,6 @@ public abstract class AbstractTableEditor extends NatTableEditor2 { }
- // /**
- // * This method execute the filling queries
- // */
- // @Deprecated
- // protected void executeQueries() {
- // if(this.rawModel.isIsSynchronized()) {
- // TableInstance table = this.rawModel.getTable();
- // EObject context = table.getContext();
- // List<EObject> elementsToAdd = new ArrayList<EObject>();
- // for(ModelQuery query : this.rawModel.getFillingQueries()) {
- // ModelQuerySetCatalog catalog = ModelQuerySetCatalog.getSingleton();
- // AbstractModelQuery impl = null;
- // try {
- // impl = catalog.getModelQueryImpl(query);
- // } catch (ModelQueryException e) {
- // e.printStackTrace();
- // }
- // if(impl != null) {
- // ModelQueryResult result = impl.evaluate(context);
- // Object value = result.getValue();
- // if(value instanceof Collection<?>) {
- // for(Object currentObject : (Collection<?>)value) {
- // if(currentObject instanceof EObject && !table.getElements().contains(currentObject)) {
- // elementsToAdd.add((EObject)currentObject);
- // }
- // }
- //
- // } else {
- // //nothing to do for the moment
- // }
- // }
- // }
- // if(!elementsToAdd.isEmpty()) {
- // // this.natTableWidget.addRows(elementsToAdd);
- // if(this.natTableWidget instanceof IPapyrusNatTableWidget) {
- // ((IPapyrusNatTableWidget)this.natTableWidget).addRowsOutOfCommandStack(elementsToAdd);
- // }
- // }
- // }
- //
- // }
-
/**
* A class taking in charge the synchronization of the partName and the diagram name.
* When diagram name change, the other is automatically updated.
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/NatTableEditor2.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/NatTableEditor2.java index eea53f040f3..5f2cf45e1e9 100644 --- a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/NatTableEditor2.java +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/NatTableEditor2.java @@ -27,6 +27,7 @@ import java.util.HashMap; import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.command.BasicCommandStack;
+import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandStackListener;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
@@ -44,6 +45,8 @@ import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Table; import org.eclipse.emf.facet.widgets.table.ui.internal.exported.ITableWidget;
import org.eclipse.emf.facet.widgets.table.ui.internal.exported.ITableWidgetFactory;
import org.eclipse.emf.facet.widgets.table.ui.internal.exported.ITableWidgetProvider;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.TriggerListener;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.ISelection;
@@ -132,6 +135,11 @@ public class NatTableEditor2 extends EditorPart implements ISelectionProvider, I }
};
}
+ if(adapter == PapyrusTable.class) {
+ this.natTableWidget.getTable().eContainer();
+ } else if(adapter == Table.class) {
+ return this.natTableWidget.getTable();
+ }
return null;
}
@@ -225,7 +233,6 @@ public class NatTableEditor2 extends EditorPart implements ISelectionProvider, I tableGridData.horizontalAlignment = SWT.FILL;
tableGridData.verticalAlignment = SWT.FILL;
this.natTableWidget.getComposite().setLayoutData(tableGridData);
-
return this.natTableWidget;
}
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/factory/AbstractTableEditorFactory.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/factory/AbstractTableEditorFactory.java index 381d1d313a4..e5808754de8 100644 --- a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/factory/AbstractTableEditorFactory.java +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/factory/AbstractTableEditorFactory.java @@ -1,3 +1,15 @@ +/**
+ * Copyright (c) 2012 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.table.efacet.common.factory;
import java.lang.reflect.Constructor;
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/factory/PapyrusCommandFactory.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/factory/PapyrusCommandFactory.java new file mode 100644 index 00000000000..ddaf5280198 --- /dev/null +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/factory/PapyrusCommandFactory.java @@ -0,0 +1,302 @@ +/*****************************************************************************
+ * Copyright (c) 2011 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.table.efacet.common.factory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.facet.infra.browser.custom.AttributeView;
+import org.eclipse.emf.facet.infra.browser.custom.CustomViewFeature;
+import org.eclipse.emf.facet.infra.browser.custom.MetamodelView;
+import org.eclipse.emf.facet.infra.browser.custom.ReferenceView;
+import org.eclipse.emf.facet.infra.browser.custom.StaticFeatureValue;
+import org.eclipse.emf.facet.infra.browser.custom.TypeView;
+import org.eclipse.emf.facet.infra.facet.Facet;
+import org.eclipse.emf.facet.widgets.celleditors.internal.DefaultCommandFactory;
+import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.Column;
+import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.Row;
+import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.TableInstance;
+import org.eclipse.emf.facet.widgets.nattable.internal.painter.Customization;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrus.infra.table.efacet.common.Activator;
+
+/**
+ *
+ * This factory is used by the Papyrus Table when the editing domain is an instanceof TransactionalEditingDomain
+ *
+ */
+@SuppressWarnings("restriction")
+public class PapyrusCommandFactory extends DefaultCommandFactory {
+
+ /**
+ *
+ * @see org.eclipse.emf.facet.widgets.celleditors.internal.DefaultCommandFactory#handles(org.eclipse.emf.edit.domain.EditingDomain)
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean handles(final EditingDomain editingDomain) {
+ return editingDomain instanceof TransactionalEditingDomain;
+ }
+
+ /**
+ *
+ * @param owner
+ * the owner object
+ * @param feature
+ * the feature to edit
+ * @return <code>true</code> if object is an {@link EObject} and feature a {@link EStructuralFeature}
+ */
+ protected boolean testArgs(final Object owner, final Object feature) {
+ if(feature != null) {
+ if(feature instanceof EStructuralFeature) {
+ /*
+ * The ElementEditService can be used for UML Element and for view and for... others things,
+ * but it doesn't work correctly with the nattable widget elements
+ */
+ if(isEMFFacetElement(owner)) {
+ return false;
+ } else if(owner instanceof EObject) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * The ElementEditService can be used for UML Element and for view and for... others things, but it doesn't work correctly with the nattable
+ * widget
+ * elements
+ *
+ * @param owner
+ * an object
+ * @return
+ * <code>true</code> if the object is an EMF-Facet object
+ */
+ private boolean isEMFFacetElement(final Object owner) {
+ if(owner instanceof TableInstance) {
+ return true;
+ } else if(owner instanceof MetamodelView) {
+ return true;
+ } else if(owner instanceof Row) {
+ return true;
+ } else if(owner instanceof Column) {
+ return true;
+ } else if(owner instanceof Facet) {
+ return true;
+ } else if(owner instanceof Customization) {
+ return true;
+ } else if(owner instanceof TypeView) {
+ return true;
+ } else if(owner instanceof ReferenceView) {
+ return true;
+ } else if(owner instanceof AttributeView) {
+ return true;
+ } else if(owner instanceof CustomViewFeature) {
+ return true;
+ } else if(owner instanceof StaticFeatureValue) {
+ return true;
+ }
+ //we add this test,because, it is possible that we forget some emf-facet elements
+ String className = owner.getClass().getCanonicalName();
+ if(className.contains("org.eclipse.emf.facet")) { //$NON-NLS-1$
+ String message = "the type " + className + " should be included in the test"; //$NON-NLS-1$ //$NON-NLS-2$
+ Activator.getDefault().log.info(message);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.facet.widgets.celleditors.internal.DefaultCommandFactory#createAddCommand(org.eclipse.emf.edit.domain.EditingDomain,
+ * java.lang.Object, java.lang.Object, java.lang.Object)
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Command createAddCommand(final EditingDomain editingDomain, final Object owner, final Object feature, final Object value) {
+ //the ElementEditService doesn't work correctly with nattable elements, so we test the edited element
+ if(isEMFFacetElement(owner)) {
+ return super.createAddCommand(editingDomain, owner, feature, value);
+ }
+ IElementEditService elementEditService = ElementEditServiceUtils.getCommandProvider(owner);
+ if(testArgs(owner, feature) && elementEditService != null) {
+ EObject current = (EObject)owner;
+ Object values = current.eGet((EStructuralFeature)feature);
+ if(values instanceof List<?>) {
+ ArrayList<Object> newList = new ArrayList<Object>();
+ newList.addAll((List<?>)values);
+ newList.add(value);
+ SetRequest request = new SetRequest((TransactionalEditingDomain)editingDomain, current, (EStructuralFeature)feature, newList);
+ ICommand command = elementEditService.getEditCommand(request);
+ if(command.canExecute()) {
+ return new GMFtoEMFCommandWrapper(command);
+ }
+ }
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.facet.widgets.celleditors.internal.DefaultCommandFactory#createDeleteCommand(org.eclipse.emf.edit.domain.EditingDomain,
+ * java.lang.Object)
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Command createDeleteCommand(final EditingDomain editingDomain, final Object elementToDestroy) {
+ //the ElementEditService doesn't work correctly with nattable elements, so we test the edited element
+ if(isEMFFacetElement(elementToDestroy)) {
+ return super.createDeleteCommand(editingDomain, elementToDestroy);
+ }
+ IElementEditService elementEditService = ElementEditServiceUtils.getCommandProvider(elementToDestroy);
+ if(testArgs(elementToDestroy, null) && elementEditService != null) {
+ DestroyElementRequest request = new DestroyElementRequest((TransactionalEditingDomain)editingDomain, (EObject)elementToDestroy, false);
+ ICommand command = elementEditService.getEditCommand(request);
+ if(command.canExecute()) {
+ return new GMFtoEMFCommandWrapper(command);
+ }
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.facet.widgets.celleditors.internal.DefaultCommandFactory#createMoveCommand(org.eclipse.emf.edit.domain.EditingDomain,
+ * java.lang.Object, java.lang.Object, java.lang.Object, int)
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Command createMoveCommand(final EditingDomain editingDomain, final Object owner, final Object feature, final Object value, final int index) {
+ //the ElementEditService doesn't work correctly with nattable elements, so we test the edited element
+ if(isEMFFacetElement(owner)) {
+ return super.createMoveCommand(editingDomain, owner, feature, value, index);
+ }
+
+ IElementEditService elementEditService = ElementEditServiceUtils.getCommandProvider(owner);
+ if(testArgs(owner, feature) && elementEditService != null) {
+ EObject current = (EObject)owner;
+ Object values = current.eGet((EStructuralFeature)feature);
+ if(values instanceof List<?>) {
+ ArrayList<Object> newList = new ArrayList<Object>();
+ newList.addAll((List<?>)values);
+ int currentIndex = ((List<?>)values).indexOf(value);
+ newList.remove(currentIndex);
+ newList.add(index, value);
+ SetRequest request = new SetRequest((TransactionalEditingDomain)editingDomain, (EObject)owner, (EStructuralFeature)feature, newList);
+ ICommand command = elementEditService.getEditCommand(request);
+ if(command.canExecute()) {
+ return new GMFtoEMFCommandWrapper(command);
+ }
+ }
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.facet.widgets.celleditors.internal.DefaultCommandFactory#createRemoveCommand(org.eclipse.emf.edit.domain.EditingDomain,
+ * java.lang.Object, java.lang.Object, java.lang.Object)
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Command createRemoveCommand(final EditingDomain editingDomain, final Object owner, final Object feature, final Object value) {
+ //the ElementEditService doesn't work correctly with nattable elements, so we test the edited element
+ if(isEMFFacetElement(owner)) {
+ return super.createRemoveCommand(editingDomain, owner, feature, value);
+ }
+ IElementEditService elementEditService = ElementEditServiceUtils.getCommandProvider(owner);
+ if(testArgs(owner, feature) && elementEditService != null) {
+ DestroyReferenceRequest request = new DestroyReferenceRequest((TransactionalEditingDomain)editingDomain, (EObject)owner, (EReference)feature, (EObject)value, false);
+ ICommand command = elementEditService.getEditCommand(request);
+ if(command.canExecute()) {
+ return new GMFtoEMFCommandWrapper(command);
+ }
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.facet.widgets.celleditors.internal.DefaultCommandFactory#createSetCommand(org.eclipse.emf.edit.domain.EditingDomain,
+ * java.lang.Object, java.lang.Object, java.lang.Object)
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Command createSetCommand(final EditingDomain editingDomain, final Object owner, final Object feature, final Object value) {
+ //the ElementEditService doesn't work correctly with nattable elements, so we test the edited element
+ if(isEMFFacetElement(owner)) {
+ return super.createSetCommand(editingDomain, owner, feature, value);
+ }
+ IElementEditService elementEditService = ElementEditServiceUtils.getCommandProvider(owner);
+ if(testArgs(owner, feature) && elementEditService != null) {
+ SetRequest request = new SetRequest((TransactionalEditingDomain)editingDomain, (EObject)owner, (EStructuralFeature)feature, value);
+ ICommand command = elementEditService.getEditCommand(request);
+ if(command.canExecute()) {
+ return new GMFtoEMFCommandWrapper(command);
+ }
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.facet.widgets.celleditors.internal.DefaultCommandFactory#createSetCommand(org.eclipse.emf.edit.domain.EditingDomain,
+ * java.lang.Object, java.lang.Object, java.lang.Object, int)
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Command createSetCommand(final EditingDomain editingDomain, final Object owner, final Object feature, final Object value, final int index) {
+ //the ElementEditService doesn't work correctly with nattable elements, so we test the edited element
+ if(isEMFFacetElement(owner)) {
+ return super.createSetCommand(null, owner, feature, value, index);
+ }
+ IElementEditService elementEditService = ElementEditServiceUtils.getCommandProvider(owner);
+ if(testArgs(owner, feature) && elementEditService != null) {
+ EObject current = (EObject)owner;
+ Object values = current.eGet((EStructuralFeature)feature);
+ if(values instanceof List<?>) {
+ ArrayList<Object> newList = new ArrayList<Object>();
+ newList.addAll((List<?>)values);
+ newList.set(index, value);
+ SetRequest request = new SetRequest((TransactionalEditingDomain)editingDomain, (EObject)owner, (EStructuralFeature)feature, newList);
+ ICommand command = elementEditService.getEditCommand(request);
+ if(command.canExecute()) {
+ return new GMFtoEMFCommandWrapper(command);
+ }
+ }
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+}
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/handlers/AbstractCreateTableEditorHandler.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/handlers/AbstractCreateTableEditorHandler.java index 61c13559335..c73484e2ca9 100644 --- a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/handlers/AbstractCreateTableEditorHandler.java +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/handlers/AbstractCreateTableEditorHandler.java @@ -1,6 +1,19 @@ +/**
+ * Copyright (c) 2012 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.table.efacet.common.handlers;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -13,11 +26,13 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EGenericType;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
@@ -109,6 +124,15 @@ public abstract class AbstractCreateTableEditorHandler extends AbstractHandler { }
/**
+ *
+ * @return
+ * <code>true</code> to open the name dialog
+ */
+ protected boolean shouldOpenNameDialog() {
+ return true;
+ }
+
+ /**
* Run the command as a transaction.
* Create a Transaction and delegate the command to {@link #doExecute(ServicesRegistry)}.
*
@@ -118,38 +142,42 @@ public abstract class AbstractCreateTableEditorHandler extends AbstractHandler { public void runAsTransaction() throws ServiceException {
//default Value
this.name = this.defaultName;
- final InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), "Create new table", "Table Name", this.name, null);//TODO improve it
- if(dialog.open() == Dialog.OK) {
- //get the name and the description for the table
- this.name = dialog.getValue();
-
- final ServicesRegistry serviceRegistry = ServiceUtilsForActionHandlers.getInstance().getServiceRegistry();
- final TransactionalEditingDomain domain = ServiceUtils.getInstance().getTransactionalEditingDomain(serviceRegistry);
- //Create the transactional command
- final AbstractEMFOperation command = new AbstractEMFOperation(domain, "Create Table Editor") { //$NON-NLS-1$ //TODO add the type of the table in the command name
-
- @Override
- protected IStatus doExecute(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
- try {
- AbstractCreateTableEditorHandler.this.doExecute(serviceRegistry);
- } catch (final ServiceException e) {
- Activator.log.error(e);
- return Status.CANCEL_STATUS;
- } catch (final NotFoundException e) {
- Activator.log.error(e);
- return Status.CANCEL_STATUS;
- }
- return Status.OK_STATUS;
+ if(shouldOpenNameDialog()) {//this test is used to allow the JUnit test without ui!
+ final InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), "Create new table", "Table Name", this.name, null);//TODO improve it //$NON-NLS-1$ //$NON-NLS-2$
+ if(dialog.open() == Dialog.OK) {
+ //get the name and the description for the table
+ this.name = dialog.getValue();
+ } else {
+ return;
+ }
+ }
+ final ServicesRegistry serviceRegistry = ServiceUtilsForActionHandlers.getInstance().getServiceRegistry();
+ final TransactionalEditingDomain domain = ServiceUtils.getInstance().getTransactionalEditingDomain(serviceRegistry);
+
+ //Create the transactional command
+ final AbstractEMFOperation command = new AbstractEMFOperation(domain, "Create Table Editor") { //$NON-NLS-1$ //TODO add the type of the table in the command name
+
+ @Override
+ protected IStatus doExecute(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ try {
+ AbstractCreateTableEditorHandler.this.doExecute(serviceRegistry);
+ } catch (final ServiceException e) {
+ Activator.log.error(e);
+ return Status.CANCEL_STATUS;
+ } catch (final NotFoundException e) {
+ Activator.log.error(e);
+ return Status.CANCEL_STATUS;
}
- };
-
- // Execute the command
- try {
- CheckedOperationHistory.getInstance().execute(command, new NullProgressMonitor(), null); //TODO : best way?
- } catch (final ExecutionException e) {
- Activator.log.error("Can't create Table Editor", e); //$NON-NLS-1$
+ return Status.OK_STATUS;
}
+ };
+
+ // Execute the command
+ try {
+ CheckedOperationHistory.getInstance().execute(command, new NullProgressMonitor(), null); //TODO : best way?
+ } catch (final ExecutionException e) {
+ Activator.log.error("Can't create Table Editor", e); //$NON-NLS-1$
}
}
@@ -198,8 +226,9 @@ public abstract class AbstractCreateTableEditorHandler extends AbstractHandler { Assert.isNotNull(context);
// List<EObject> elements = getInitialElement(papyrusTable, context);
- //TODO initialize these elements if necessary...
- final List<EObject> elements = new ArrayList<EObject>();
+
+ // final List<EObject> elements = TableContentsUtils.getTableContents(papyrusTable, context, true);
+ final List<EObject> elements = Collections.EMPTY_LIST;
// elements.add(getTableContext());
final String description = null;
TableConfiguration tableConfiguration = null;
@@ -227,132 +256,29 @@ public abstract class AbstractCreateTableEditorHandler extends AbstractHandler { System.out.println(labelProvider.getText(papyrusTable));;
if(papyrusTable.isUsingContextFeature() && papyrusTable.getContextFeature() != null) { //TODO : verify that the context owns the wanted feature
- getTableContext().eAdapters().add(new Adapter() {
+ final boolean isDerived = papyrusTable.getContextFeature().isDerived();
+ final EReference ref = papyrusTable.getContextFeature();
+ final EGenericType genericTtype = ref.getEGenericType();
+ final EList<EObject> cross = ref.eCrossReferences();
+ System.out.println(isDerived);
- public void setTarget(final Notifier newTarget) {
- int i = 0;
- i++;
+ getTableContext().eAdapters().add(new AdapterImpl() {
- }
+
+ @Override
public void notifyChanged(final Notification notification) {
+ final Object feature = notification.getFeature();
int i = 0;
i++;
}
- public boolean isAdapterForType(final Object type) {
- // TODO Auto-generated method stub
- return false;
- }
-
- public Notifier getTarget() {
- // TODO Auto-generated method stub
- return null;
- }
});
}
return papyrusTable;
}
- // /**
- // *
- // * @param papyrusTable
- // * the papyrus table
- // * @param context
- // * @return the list of the initial element for the table
- // */
- // private List<EObject> getInitialElement(PapyrusTableInstance papyrusTable, EObject context) {
- // if(papyrusTable.isIsSynchronized() && !papyrusTable.getFillingQueries().isEmpty()) {
- // List<EObject> elements = new ArrayList<EObject>();
- //
- // for(ModelQuery query : papyrusTable.getFillingQueries()) {
- // ModelQuerySetCatalog catalog = ModelQuerySetCatalog.getSingleton();
- // AbstractModelQuery impl = null;
- // try {
- // impl = catalog.getModelQueryImpl(query);
- // } catch (ModelQueryException e) {
- // Activator.getDefault().log.error(e);
- // }
- // if(impl != null) {
- // ModelQueryResult result = impl.evaluate(context);
- // Object value = result.getValue();
- // if(value instanceof Collection<?>) {
- // // the build the list of the elements to add in the
- // // table
- // for(Object currentObject : (Collection<?>)value) {
- // if(currentObject instanceof EObject) {
- // elements.add((EObject)currentObject);
- // }
- // }
- //
- // }
- // }
- // }
- // return elements;
- // }
- // return Collections.emptyList();
- // }
- //
- // /**
- // * Allows to hide the columns created by default
- // *
- // * @param papyrusTable
- // */
- // private void setHiddenColumns(final PapyrusTableInstance papyrusTable) {
- // List<String> hiddenColumnsName = getHiddenColumnName();
- // if(!hiddenColumnsName.isEmpty()) {
- // for(Column column : papyrusTable.getTable().getColumns()) {
- // String name = NatTableWidgetInternalUtils.getColumnName(column);
- // if(hiddenColumnsName.contains(name)) {
- // column.setIsHidden(true);
- // }
- // }
- // }
- // }
-
- // /**
- // * Returns the list of the columns to hide. Currently, the name can be :
- // * <ul>
- // * <li>[Label]</li>
- // * <li>[Metaclass]</li>
- // * <li>/eContainer</li>
- // * </ul>
- // *
- // * @return
- // * the list of the columns to hide
- // */
- // protected List<String> getHiddenColumnName() {
- // return Collections.emptyList();
- // }
- //
- // /**
- // * Returns the table configuration for the table
- // *
- // * {@link Deprecated} // use getTableConfiguration2
- // *
- // * @return
- // * the table configuration of the table
- // * FIXME should be removed in Papyrus 0.9.0
- // *
- // */
- // @Deprecated
- // protected TableConfiguration getTableConfiguration() {
- // return getTableConfiguration2();
- // }
- //
- // /**
- // * Returns the table configuration for the table
- // *
- // * @return
- // * the table configuration of the table
- // *
- // */
- // protected TableConfiguration2 getTableConfiguration2() {
- // return null;
- // }
- //
-
/**
*
* @return
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/handlers/AbstractMoveRowHandler.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/handlers/AbstractMoveRowHandler.java new file mode 100644 index 00000000000..ebfc76a2aae --- /dev/null +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/handlers/AbstractMoveRowHandler.java @@ -0,0 +1,149 @@ +/**
+ * Copyright (c) 2012 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.table.efacet.common.handlers;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Row;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Table;
+import org.eclipse.emf.facet.widgets.table.ui.internal.exported.ITableWidget;
+import org.eclipse.emf.facet.widgets.table.ui.internal.exported.ITableWidgetProvider;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.infra.table.efacet.common.editor.AbstractTableEditor;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ *
+ * the abstract class for the move line handler
+ *
+ */
+public abstract class AbstractMoveRowHandler extends AbstractHandler {
+
+ /**
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ *
+ * @param event
+ * @return
+ * @throws ExecutionException
+ */
+ public final Object execute(final ExecutionEvent event) throws ExecutionException {
+ final Command cmd = getMoveRowCommand();
+ if(cmd != null && cmd.canExecute()) {
+ //we save the current row selection
+ final List<EObject> selectedRows = getSelectedRowEObject();
+ getEditingDomain().getCommandStack().execute(cmd);
+
+ //we set the old row selection
+ final ITableWidget widget = getTableWidget();
+
+ final List<EObject> toSelect = new ArrayList<EObject>();
+
+ widget.selectRows(selectedRows, true);
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
+ *
+ * @return
+ */
+ @Override
+ public boolean isEnabled() {
+ return (getSelectedRowEObject().size() == 1) && getMoveRowCommand().canExecute();
+
+ }
+
+ /**
+ *
+ * @return
+ * a list of the selected rows
+ */
+ protected List<EObject> getSelectedRowEObject() {
+ final List<Row> rows = new ArrayList<Row>();
+ final ITableWidget widget = getTableWidget();
+ if(widget instanceof org.eclipse.emf.facet.widgets.table.ui.ITableWidget) {
+ return ((org.eclipse.emf.facet.widgets.table.ui.ITableWidget)widget).getSelectedRowEObjects();
+ }
+ return Collections.EMPTY_LIST;
+ }
+
+ /**
+ *
+ * @return
+ * the current table editor
+ */
+ protected AbstractTableEditor getCurrentTableEditor() {
+ final IWorkbenchPart page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
+ if(page instanceof CoreMultiDiagramEditor) {
+ final IEditorPart activeEditor = ((CoreMultiDiagramEditor)page).getActiveEditor();
+ if(activeEditor instanceof AbstractTableEditor) {
+ return (AbstractTableEditor)activeEditor;
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ *
+ * @return
+ * the current nattable widget
+ */
+ protected ITableWidget getTableWidget() {
+ final AbstractTableEditor editor = getCurrentTableEditor();
+ if(editor != null) {
+ final ITableWidgetProvider provider = (ITableWidgetProvider)editor.getAdapter(ITableWidgetProvider.class);
+ if(provider != null) {
+ return provider.getTableWidget();
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @return the editing domain to use for the command
+ */
+ protected TransactionalEditingDomain getEditingDomain() {
+ return (TransactionalEditingDomain)getCurrentTableEditor().getEditingDomain();
+ }
+
+ /**
+ *
+ * @return
+ * the current table
+ */
+ protected Table getTable() {
+ return (Table)getCurrentTableEditor().getAdapter(Table.class);
+ }
+
+ /**
+ *
+ * @return
+ * the command to move the lines
+ */
+ protected abstract Command getMoveRowCommand();
+}
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/handlers/DownRowHandler.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/handlers/DownRowHandler.java new file mode 100644 index 00000000000..efc320f574b --- /dev/null +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/handlers/DownRowHandler.java @@ -0,0 +1,43 @@ +/**
+ * Copyright (c) 2012 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.table.efacet.common.handlers;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Row;
+import org.eclipse.papyrus.infra.table.efacet.common.copy.PapyrusTableEfacetCommandFactory;
+
+/**
+ *
+ * This handler allows to move a line down
+ *
+ */
+public class DownRowHandler extends AbstractMoveRowHandler {
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.table.efacet.common.handlers.AbstractMoveRowHandler#getMoveRowCommand()
+ *
+ * @return
+ */
+ @Override
+ protected Command getMoveRowCommand() {
+ final EObject element = getSelectedRowEObject().get(0);
+ for(final Row row : getTable().getRows()) {
+ if(row.getElement() == element) {
+ return PapyrusTableEfacetCommandFactory.getMoveLineDownCommand(getEditingDomain(), getTable(), row);
+ }
+ }
+ return null;
+ }
+}
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/handlers/UpRowHandler.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/handlers/UpRowHandler.java new file mode 100644 index 00000000000..d1272feed97 --- /dev/null +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/handlers/UpRowHandler.java @@ -0,0 +1,43 @@ +/**
+ * Copyright (c) 2012 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.table.efacet.common.handlers;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Row;
+import org.eclipse.papyrus.infra.table.efacet.common.copy.PapyrusTableEfacetCommandFactory;
+
+/**
+ *
+ * This handler allows to move a line up
+ *
+ */
+public class UpRowHandler extends AbstractMoveRowHandler {
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.table.efacet.common.handlers.AbstractMoveRowHandler#getMoveRowCommand()
+ *
+ * @return
+ */
+ @Override
+ protected Command getMoveRowCommand() {
+ final EObject element = getSelectedRowEObject().get(0);
+ for(final Row row : getTable().getRows()) {
+ if(row.getElement() == element) {
+ return PapyrusTableEfacetCommandFactory.getMoveLineUpCommand(getEditingDomain(), getTable(), row);
+ }
+ }
+ return null;
+ }
+}
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/AbstractSynchronizedTableListener.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/AbstractSynchronizedTableListener.java new file mode 100644 index 00000000000..0e5d7964456 --- /dev/null +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/AbstractSynchronizedTableListener.java @@ -0,0 +1,263 @@ +/**
+ * Copyright (c) 2012 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.table.efacet.common.listener;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.facet.efacet.core.IFacetManager;
+import org.eclipse.emf.facet.efacet.core.IFacetManagerFactory;
+import org.eclipse.emf.facet.widgets.celleditors.ICommandFactoriesRegistry;
+import org.eclipse.emf.facet.widgets.celleditors.ICommandFactory;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Table;
+import org.eclipse.emf.facet.widgets.table.ui.command.ITableCommandFactory;
+import org.eclipse.emf.facet.widgets.table.ui.command.ITableCommandFactoryFactory;
+import org.eclipse.emf.facet.widgets.table.ui.internal.exported.TableWidgetUtils;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.TriggerListener;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTable;
+
+/**
+ *
+ * This abstract classes provides the commands to synchronize the tables
+ *
+ */
+public abstract class AbstractSynchronizedTableListener extends TriggerListener {
+
+ /**
+ * the table on which we are working
+ */
+ protected PapyrusTable table;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param table
+ */
+ public AbstractSynchronizedTableListener(final PapyrusTable table) {
+ this.table = table;
+ }
+
+ @Override
+ protected final Command trigger(final TransactionalEditingDomain domain, final Notification notification) {
+ System.out.println(notification);
+ if(isManagedNotification(notification)) {
+ return getSynchronizationCommand(domain, notification);
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param domain
+ * the editing domain used for the command
+ * @return
+ */
+ public Command getSynchronizationCommand(final TransactionalEditingDomain domain, final Notification notification) {
+ List<EObject> toAdd = null;
+ List<EObject> toRemove = null;
+ if(this.table.isUsingContextFeature()) {
+ final EReference ref = this.table.getContextFeature();
+ if(!ref.isDerived()) {
+ //TODO verify that the query to define accepted elements in a table is already called
+ final List<EObject>[] addRemove = getElementToAddRemoveUsingContextFeature(this.table);
+ toAdd = addRemove[0];
+ toRemove = addRemove[1];
+ } else {
+ //TODO verify that the query to define accepted elements in a table is already called
+ final List<EObject>[] addRemove = getElementToAddRemoveUsingContextFeature(this.table);
+ toAdd = addRemove[0];
+ toRemove = addRemove[1];
+ }
+ } else if(this.table.isUsingQueries()) {
+ final List<EObject>[] addRemove = getElementToAddRemoveUsingQueries();
+ toAdd = addRemove[0];
+ toRemove = addRemove[1];
+ }
+
+ if(!toAdd.isEmpty() || !toRemove.isEmpty()) {
+ final ITableCommandFactory factory = getTableCmdFactory(domain, AbstractSynchronizedTableListener.this.table.getTable().eResource().getResourceSet(), AbstractSynchronizedTableListener.this.table.getTable());
+ final CompoundCommand cmd = new CompoundCommand("Table Synchronization Command"); //$NON-NLS-1$
+
+ if(!toRemove.isEmpty()) {//it is better to do the remove before the add, because the remove use the position of the row!
+ // final ITableCommandFactory factory = getTableCmdFactory(domain, AbstractSynchronizedTableListener.this.table.getTable().eResource().getResourceSet(), AbstractSynchronizedTableListener.this.table.getTable());
+ // final Command cmd2 = factory.createRemoveRowByEObjectCommand(toRemove);
+ // System.out.println("--------------------------------------------------------------canExecute : " + cmd2.canExecute());
+ // cmd.append(cmd2);
+ final List<EObject> elementsToRemove = new ArrayList<EObject>(toRemove);
+ //TODO try to remove this GMF command (keep a trace of the already deleted rows?)
+ final ICommand tmp = new AbstractTransactionalCommand(domain, "Remove elements of the table", null) { //$NON-NLS-1$
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+
+ final Command cmd2 = factory.createRemoveRowByEObjectCommand(elementsToRemove);
+ cmd2.execute();
+ return CommandResult.newOKCommandResult();
+ }
+ };
+ cmd.append(new GMFtoEMFCommandWrapper(tmp));
+ }
+
+ if(!toAdd.isEmpty()) {
+ final List<EObject> elementsToAdd = new ArrayList<EObject>(toAdd);
+ final ICommand tmp = new AbstractTransactionalCommand(domain, "Add elements of the table", null) { //$NON-NLS-1$
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ final List<EObject> currentContent = TableWidgetUtils.getElements(AbstractSynchronizedTableListener.this.table.getTable());
+ if(!currentContent.containsAll(elementsToAdd)) {
+ final List<EObject> elToAdd = new ArrayList<EObject>();
+ //we redo the calculus of the elements to add, because we can catch several notification for the "same" event
+ for(final EObject current : elementsToAdd) {
+ if(!currentContent.contains(current)) {
+ elToAdd.add(current);
+ }
+ }
+
+ //duplicated code of the widget
+ //CompoundCommand addRowCommand = TableInstanceCommandFactory.createAddRowsCommand(elToAdd, controller);
+ // final CompoundCommand addRowCommand = PapyrusTableEfacetCommandFactory.createAddRowsCommand(domain, AbstractSynchronizedTableListener.this.table.getTable(), elToAdd);
+ // try {
+ // final Command setFacetsCommand = PapyrusTableEfacetCommandFactory.createSetFacetsCommand(domain, AbstractSynchronizedTableListener.this.table.getTable(), AbstractSynchronizedTableListener.this.table.getTable().getFacetSets(), elementsToAdd);
+ // if(setFacetsCommand != null && setFacetsCommand.canExecute()) {
+ // addRowCommand.append(setFacetsCommand);
+ // }
+ // } catch (final CoreException e) {
+ // Activator.log.error(e);
+ // }
+ //
+ // if(addRowCommand.canExecute()) {
+ // addRowCommand.execute();
+ // }
+
+ final CompoundCommand addRows = new CompoundCommand("Add rows");
+ addRows.append(factory.createAddRowsCommand(elToAdd));
+ addRows.append(factory.createSetFacetSetsCommand(AbstractSynchronizedTableListener.this.table.getTable().getFacetSets()));
+ // final CompoundCommand addRowCommand = PapyrusTableEfacetCommandFactory.createAddRowsCommand(domain, AbstractSynchronizedTableListener.this.table.getTable(), elToAdd);
+ // try {
+ // final Command setFacetsCommand = PapyrusTableEfacetCommandFactory.createSetFacetsCommand(domain, AbstractSynchronizedTableListener.this.table.getTable(), AbstractSynchronizedTableListener.this.table.getTable().getFacetSets(), elementsToAdd);
+ // if(setFacetsCommand != null && setFacetsCommand.canExecute()) {
+ // addRowCommand.append(setFacetsCommand);
+ // }
+ // } catch (final CoreException e) {
+ // Activator.log.error(e);
+ // }
+ //
+ // if(addRowCommand.canExecute()) {
+ // addRowCommand.execute();
+ // }
+
+ if(addRows.canExecute()) {
+ addRows.execute();
+ }
+ }
+ return CommandResult.newOKCommandResult();
+ }
+
+ };
+
+ cmd.append(new GMFtoEMFCommandWrapper(tmp));
+ }
+ // if(cmd.canExecute()) {
+ return cmd;
+ // } else {
+ // Activator.log.warn("The command to add/remove elements to the table is not executable"); //$NON-NLS-1$
+ // }
+ }
+ return null;
+ }
+
+
+ private static ITableCommandFactory getTableCmdFactory(final TransactionalEditingDomain editingDomain, final ResourceSet resourceSet, final Table table) {
+ final IFacetManager facetManager = IFacetManagerFactory.DEFAULT.getOrCreateFacetManager(resourceSet);
+ final ICommandFactory commandFactory = ICommandFactoriesRegistry.INSTANCE.getCommandFactoryFor(editingDomain);
+ final ITableCommandFactory tableCmdFactory = ITableCommandFactoryFactory.DEFAULT.createTableCommandFactory(table, editingDomain, commandFactory, facetManager);
+ return tableCmdFactory;
+ }
+
+ /**
+ *
+ *
+ *
+ * @param notification
+ * the notification
+ * @return
+ * <code>true</code> if we should do something with this notification
+ */
+ protected abstract boolean isManagedNotification(final Notification notification);
+
+
+ /**
+ *
+ * @return
+ * an array of lists. the first list contains the elements to add and the second list contains the elements to remove
+ */
+ @SuppressWarnings("unchecked")
+ private final List<EObject>[] getElementToAddRemoveUsingQueries() {
+ final List<?>[] addRemove = new List<?>[2];
+ final List<EObject> toAdd = new ArrayList<EObject>();
+ final List<EObject> toRemove = new ArrayList<EObject>();
+ addRemove[0] = toAdd;
+ addRemove[1] = toRemove;
+ //TODO
+ return (List<EObject>[])addRemove;
+ }
+
+
+ /**
+ *
+ * @return
+ * an array of lists. the first list contains the elements to add and the second list contains the elements to remove
+ */
+ @SuppressWarnings("unchecked")
+ private final List<EObject>[] getElementToAddRemoveUsingContextFeature(final PapyrusTable papyrusTable) {
+ final List<?>[] addRemove = new List<?>[2];
+ final List<EObject> toAdd = new ArrayList<EObject>();
+ final List<EObject> toRemove = new ArrayList<EObject>();
+ addRemove[0] = toAdd;
+ addRemove[1] = toRemove;
+
+
+ final List<EObject> currentContent = TableWidgetUtils.getElements(papyrusTable.getTable());
+ final Object value = papyrusTable.getTable().getContext().eGet(papyrusTable.getContextFeature());
+ if(value instanceof List<?>) {
+ final ArrayList<EObject> newValue = new ArrayList<EObject>((List<EObject>)value);
+ //fill the add list
+ // newValue.removeAll(currentContent);
+ toAdd.addAll(newValue);
+ toAdd.removeAll(currentContent);
+ //fill the removeList
+ currentContent.removeAll(newValue);
+ toRemove.addAll(currentContent);
+ } else {
+ //we do nothing
+ }
+ return (List<EObject>[])addRemove;
+ }
+
+}
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/FillingListener.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/FillingListener.java new file mode 100644 index 00000000000..92a06e83d2d --- /dev/null +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/FillingListener.java @@ -0,0 +1,68 @@ +/**
+ * Copyright (c) 2012 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.table.efacet.common.listener;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.core.sashwindows.di.PageRef;
+import org.eclipse.papyrus.infra.core.sashwindows.di.TabFolder;
+import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTable;
+
+/**
+ *
+ * This listener provides the command to synchronize the table when something changes in the uml file OR when the table is opened
+ *
+ */
+public class FillingListener extends AbstractSynchronizedTableListener {
+
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param table
+ * the table to fill
+ * @param natTableWidget
+ */
+ public FillingListener(final PapyrusTable table) {
+ super(table);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.table.efacet.common.listener.AbstractSynchronizedTableListener#isManagedNotification(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ * @return
+ */
+ @Override
+ protected boolean isManagedNotification(final Notification notification) {
+ final Object notifier = notification.getNotifier();
+ if(!this.table.isUsingUser() && notifier instanceof EObject) {
+ final EObject eobject = (EObject)notifier;
+ if(notifier instanceof TabFolder) {//to synchronized an opening table
+ final Object newValue = notification.getNewValue();
+ PageRef ref = null;
+ if(newValue instanceof PageRef) {
+ ref = (PageRef)newValue;
+ }
+ if(ref != null && ref.getEmfPageIdentifier() == this.table) {
+ return true;
+ }
+ } else if(eobject.eResource() != null && eobject.eResource().getURI().fileExtension().equals("uml")) { //$NON-NLS-1$
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/MoveTableLineListener.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/MoveTableLineListener.java new file mode 100644 index 00000000000..0113b5a6ba0 --- /dev/null +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/MoveTableLineListener.java @@ -0,0 +1,85 @@ +/**
+ * Copyright (c) 2012 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.table.efacet.common.listener;
+
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.command.MoveCommand;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Row;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.TablePackage;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTable;
+
+/**
+ *
+ * This listener allows to know when a line has been moved in the table
+ *
+ */
+public class MoveTableLineListener extends AbstractSynchronizedTableListener {
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param table
+ */
+ public MoveTableLineListener(final PapyrusTable table) {
+ super(table);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.table.efacet.common.listener.AbstractSynchronizedTableListener#isManagedNotification(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ * @return
+ */
+ @Override
+ protected boolean isManagedNotification(final Notification notification) {
+ if(notification.getEventType() == Notification.MOVE && notification.getNotifier() == this.table.getTable() && notification.getFeature() == TablePackage.eINSTANCE.getTable_Rows()) {
+ if(this.table.isUsingContextFeature()) {
+ final EStructuralFeature feature = this.table.getContextFeature();
+ if(feature != null && feature.isOrdered()) {
+ return true;
+ }
+
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.table.efacet.common.listener.AbstractSynchronizedTableListener#getSynchronizationCommand(org.eclipse.emf.transaction.TransactionalEditingDomain,
+ * org.eclipse.emf.common.notify.Notification)
+ *
+ * @param domain
+ * @param notification
+ * @return
+ */
+ @Override
+ public Command getSynchronizationCommand(final TransactionalEditingDomain domain, final Notification notification) {
+ final EObject tableContext = this.table.getTable().getContext();
+ final Object currentValue = tableContext.eGet(this.table.getContextFeature());
+ final EObject movedValue = ((Row)notification.getNewValue()).getElement();
+ if(currentValue instanceof List<?>) {
+ final MoveCommand cmd = new MoveCommand(domain, tableContext, this.table.getContextFeature(), movedValue, notification.getPosition());
+ return cmd;
+ }
+ return super.getSynchronizationCommand(domain, notification);
+ }
+}
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/TableFillingModeListener.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/TableFillingModeListener.java new file mode 100644 index 00000000000..cce7e2adfad --- /dev/null +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/TableFillingModeListener.java @@ -0,0 +1,55 @@ +/**
+ * Copyright (c) 2012 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.table.efacet.common.listener;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.FillingMode;
+import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTable;
+import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrustablePackage;
+
+/**
+ *
+ * this listener provides the command to synchronized the table when the filling mode used to fill the table change
+ *
+ */
+public class TableFillingModeListener extends AbstractSynchronizedTableListener {
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param table
+ * the table on which we are working
+ * @param controller
+ */
+ public TableFillingModeListener(final PapyrusTable table) {
+ super(table);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.table.efacet.common.listener.AbstractSynchronizedTableListener#isManagedNotification(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ * @return
+ */
+ @Override
+ protected boolean isManagedNotification(final Notification notification) {
+ if(notification.getNotifier() == this.table && notification.getFeature() == PapyrustablePackage.eINSTANCE.getPapyrusTable_FillingMode() && !(notification.getNewValue() == FillingMode.USER)) {
+ return false;
+ //TODO
+ // return true;
+ }
+ return false;
+ }
+}
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/tester/TablePropertyTester.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/tester/TablePropertyTester.java new file mode 100644 index 00000000000..010c059f1e4 --- /dev/null +++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/tester/TablePropertyTester.java @@ -0,0 +1,46 @@ +/**
+ * Copyright (c) 2012 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.table.efacet.common.tester;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.infra.table.efacet.common.editor.AbstractTableEditor;
+
+/**
+ *
+ * This class provides tests to define the enablement of the actions
+ *
+ */
+public class TablePropertyTester extends PropertyTester {
+
+ /** this property is used to know if the current editor is a PapyrusTableEditor */
+ final String IS_PAPYRUS_TABLE_EFACET = "isPapyrusTableEfacet"; //$NON-NLS-1$
+
+ /**
+ *
+ * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
+ *
+ * @param receiver
+ * @param property
+ * @param args
+ * @param expectedValue
+ * @return
+ */
+ public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
+ if(this.IS_PAPYRUS_TABLE_EFACET.equals(property) && receiver instanceof CoreMultiDiagramEditor) {
+ return expectedValue.equals((((CoreMultiDiagramEditor)receiver).getActiveEditor() instanceof AbstractTableEditor));
+ }
+ return false;
+ }
+
+}
|