Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2012-08-24 11:17:53 +0000
committervlorenzo2012-08-24 11:17:53 +0000
commit470ca51274036d548585bbed0bd37c207aaa219a (patch)
tree6b2243899290acfac2532a534c5d6756ef86a592
parent37661e2d0b4826153b874af03a17675a85ac069b (diff)
downloadorg.eclipse.papyrus-470ca51274036d548585bbed0bd37c207aaa219a.tar.gz
org.eclipse.papyrus-470ca51274036d548585bbed0bd37c207aaa219a.tar.xz
org.eclipse.papyrus-470ca51274036d548585bbed0bd37c207aaa219a.zip
Save my work on the table :
- improve the common table plugin - rename the abstract class used for table editors
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/.classpath2
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/META-INF/MANIFEST.MF1
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/build.properties3
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/AbstractPapyrusNestedEditor.java407
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/AbstractSynchronizedTableEditor.java110
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/AbstractTableEditor.java427
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/NatTableEditor2.java476
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/factory/AbstractTableEditorFactory.java4
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/factory/PapyrusCommandFactory.java1
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/handlers/AbstractCreateTableEditorHandler.java107
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/handlers/AbstractMoveRowHandler.java10
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/AbstractSynchronizedTableListener.java263
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/AbstractTableTriggerListener.java85
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/FillingListener.java302
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/MoveTableLineListener.java10
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/TableFillingModeListener.java55
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/tester/TablePropertyTester.java4
-rw-r--r--incoming/TableEFacet/org.eclipse.papyrus.table.efacet.uml.generic/src/org/eclipse/papyrus/uml/table/efacet/generic/editor/GenericTableEditor.java4
18 files changed, 1302 insertions, 969 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 a442cf10ed3..55b6205754a 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|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 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|org/eclipse/papyrus/infra/table/efacet/common/listener/TableFillingModeListener.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 2939b0a3287..2fb0f6a76e7 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
@@ -17,7 +17,6 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.databinding,
org.eclipse.emf.facet.widgets.nattable,
org.eclipse.papyrus.infra.widgets,
- 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",
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/build.properties b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/build.properties
index 6f20375d6c7..259d16dfc42 100644
--- a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/build.properties
+++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/build.properties
@@ -2,4 +2,5 @@ source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
- plugin.xml
+ plugin.xml,\
+ build.properties
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/AbstractPapyrusNestedEditor.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/AbstractPapyrusNestedEditor.java
new file mode 100644
index 00000000000..2b7b819fd9b
--- /dev/null
+++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/AbstractPapyrusNestedEditor.java
@@ -0,0 +1,407 @@
+/*****************************************************************************
+ * 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 java.util.EventObject;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.emf.common.command.CommandStackListener;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.domain.IEditingDomainProvider;
+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.swt.widgets.Display;
+import org.eclipse.ui.part.EditorPart;
+
+//TODO : we should continue to develp this class in order it looks like to the abstract class of GMFDiagramEditor in Papyrus then move it in an upper plugin
+public abstract class AbstractPapyrusNestedEditor extends EditorPart implements IEditingDomainProvider {
+
+ protected final ServicesRegistry servicesRegistry;
+
+ private final CommandStackListener commandListener = new CommandStackListener() {
+
+ public void commandStackChanged(final EventObject event) {
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ public void run() {
+ firePropertyChange(PROP_DIRTY);
+ }
+ });
+ }
+ };
+
+ public AbstractPapyrusNestedEditor(final ServicesRegistry registry) {
+ this.servicesRegistry = registry;
+ }
+
+ public final EditingDomain getEditingDomain() {
+ try {
+ return ServiceUtils.getInstance().getTransactionalEditingDomain(this.servicesRegistry);
+ } catch (final ServiceException e) {
+ Activator.log.error(e);
+ }
+ return null;
+ }
+
+ /**
+ * @generated
+ */
+ @Override
+ public boolean isSaveAsAllowed() {
+ return true;
+ }
+
+ /**
+ * This sets up the editing domain for the model editor
+ */
+ protected void configureEditorEditingDomain() {
+ Assert.isNotNull(getEditingDomain());
+ getEditingDomain().getCommandStack().removeCommandStackListener(this.commandListener);
+ getEditingDomain().getCommandStack().addCommandStackListener(this.commandListener);
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ getEditingDomain().getCommandStack().removeCommandStackListener(this.commandListener);
+ }
+
+ // /**
+ // * The location of diagram icon in the plug-in
+ // */
+ // private static final String DIAG_IMG_PATH =
+ // "icons/obj16/Diagram_Class.gif";
+ //
+ // /**
+ // * The image descriptor of the diagram icon
+ // */
+ // private static final ImageDescriptor DIAG_IMG_DESC =
+ // UMLDiagramEditorPlugin.getBundledImageDescriptor(UmlClassDiagramForMultiEditor.DIAG_IMG_PATH);
+ //
+ //
+ // /**
+ // * @generated
+ // */
+ // public static final String ID = "org.eclipse.papyrus.uml.diagram.clazz.part.UMLDiagramEditorID"; //$NON-NLS-1$
+ //
+ // /**
+ // * @generated
+ // */
+ // public static final String CONTEXT_ID = "org.eclipse.papyrus.uml.diagram.clazz.ui.diagramContext"; //$NON-NLS-1$
+ //
+ // @Override
+ // public void doSave(final IProgressMonitor monitor) {
+ // // TODO Auto-generated method stub
+ //
+ // }
+ //
+ // @Override
+ // public void doSaveAs() {
+ // // TODO Auto-generated method stub
+ //
+ // }
+ //
+ // @Override
+ // public void init(final IEditorSite site, final IEditorInput input) throws
+ // PartInitException {
+ // // TODO Auto-generated method stub
+ //
+ // }
+ //
+ // @Override
+ // public boolean isDirty() {
+ // // TODO Auto-generated method stub
+ // return false;
+ // }
+ //
+ // @Override
+ // public boolean isSaveAsAllowed() {
+ // // TODO Auto-generated method stub
+ // return false;
+ // }
+ //
+ // @Override
+ // public void createPartControl(final Composite parent) {
+ // // TODO Auto-generated method stub
+ //
+ // }
+ //
+ // @Override
+ // public void setFocus() {
+ // // TODO Auto-generated method stub
+ //
+ // }
+ //
+ // /**
+ // * @generated
+ // */
+ // @Override
+ // protected PreferencesHint getPreferencesHint() {
+ // return UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT;
+ // }
+ //
+ // /**
+ // * @generated
+ // */
+ // public void gotoMarker(final IMarker marker) {
+ // MarkerNavigationService.getInstance().gotoMarker(this, marker);
+ // }
+ //
+ // /**
+ // * @generated
+ // */
+ // @Override
+ // public boolean isSaveAsAllowed() {
+ // return true;
+ // }
+ //
+ // /**
+ // * @generated
+ // */
+ // @Override
+ // protected String getContextID() {
+ // return CONTEXT_ID;
+ // }
+ //
+ // /**
+ // * @generated
+ // */
+ // @Override
+ // public TransactionalEditingDomain getEditingDomain() {
+ // return editingDomain;
+ // }
+ //
+ // //------------------------//from UMLDiagramEditor (in class diagram
+ // plugin
+ // /**
+ // * @generated
+ // */
+ // @Override
+ // public void doSaveAs() {
+ // performSaveAs(new NullProgressMonitor());
+ // }
+ //
+ // //------------------------//from UMLDiagramEditor (in class diagram
+ // plugin
+ // /**
+ // * @generated
+ // */
+ // @Override
+ // protected void performSaveAs(final IProgressMonitor progressMonitor) {
+ // // Nothing
+ // }
+ //
+ // //------------------------//from UMLDiagramEditor (in class diagram
+ // plugin
+ // /**
+ // * @generated
+ // */
+ // @Override
+ // protected TransactionalEditingDomain createEditingDomain() {
+ // // Already configured
+ // return editingDomain;
+ // }
+ //
+ // //------------------------//from UMLDiagramEditor (in class diagram
+ // plugin
+ // /**
+ // * @generated
+ // */
+ // @Override
+ // protected void configureDiagramEditDomain() {
+ // super.configureDiagramEditDomain();
+ // getDiagramEditDomain().getDiagramCommandStack().addCommandStackListener(new
+ // CommandStackListener() {
+ //
+ // public void commandStackChanged(final EventObject event) {
+ // firePropertyChange(IEditorPart.PROP_DIRTY);
+ // }
+ // });
+ // }
+ //
+ // //------------------------//from UMLDiagramEditor (in class diagram
+ // plugin
+ // /**
+ // * @generated
+ // */
+ // @Override
+ // public void doSave(final IProgressMonitor progressMonitor) {
+ // // The saving of the resource is done by the CoreMultiDiagramEditor
+ // lastSavdeOperation = getOperationHistory().getUndoOperation(getUndoContext());
+ // }
+ //
+ // //------------------------//from UMLDiagramEditor (in class diagram
+ // plugin
+
+ //
+ // //---------fro mUMLGrmfDiagramEditor
+ // /**
+ // * The associated Diagram.
+ // */
+ // private Diagram diagram;
+ //
+ // //---------fro mUMLGrmfDiagramEditor
+ // /**
+ // * Object used to synchronize the name of the editor with the name of the
+ // * diagram.
+ // */
+ // private PartNameSynchronizer partNameSynchronizer;
+ //
+ // //---------fro mUMLGrmfDiagramEditor
+ // /**
+ // * service serviceRegistry of the backbone
+ // */
+ // private ServicesRegistry servicesRegistry;
+ //
+ // //---------fro mUMLGrmfDiagramEditor
+ // /**
+ // * Constructor.
+ // *
+ // * @param servicesRegistry
+ // * @param diagram
+ // * @throws ServiceException
+ // */
+ // public UmlGmfDiagramEditor(final ServicesRegistry servicesRegistry, final
+ // Diagram diagram) throws ServiceException {
+ // super(true);
+ // this.diagram = diagram;
+ // this.servicesRegistry = servicesRegistry;
+ // // Install synchronizer
+ // this.partNameSynchronizer = new PartNameSynchronizer(diagram);
+ //
+ // // Register this part to the ISaveAndDirtyService.
+ // // This will allows to be notified of saveAs events, and the isDirty
+ // // flag will be taken into
+ // // account.
+ // final ISaveAndDirtyService saveAndDirtyService =
+ // servicesRegistry.getService(ISaveAndDirtyService.class);
+ // saveAndDirtyService.registerIsaveablePart(this);
+ //
+ // // TODO: unregister when editor is disposed !
+ // }
+ //
+ // //---------fro mUMLGrmfDiagramEditor
+ // /**
+ // * Dispose services used in this part.
+ // *
+ // * @see
+ // org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor#dispose()
+ // *
+ // */
+ // @Override
+ // public void dispose() {
+ // super.dispose();
+ //
+ // ISaveAndDirtyService saveAndDirtyService;
+ // try {
+ // saveAndDirtyService =
+ // this.servicesRegistry.getService(ISaveAndDirtyService.class);
+ // saveAndDirtyService.removeIsaveablePart(this);
+ //
+ // } catch (final ServiceException e) {
+ // // the service can't be found. Maybe it is already disposed.
+ // // Do nothing
+ // }
+ //
+ // }
+ //
+ // //---------fro mUMLGrmfDiagramEditor
+ // /**
+ // *
+ // * @return the backbone service serviceRegistry. it cannot return null.
+ // */
+ // public ServicesRegistry getServicesRegistry() {
+ // return this.servicesRegistry;
+ // }
+ //
+ // public class SynchronizableGmfDiagramEditor extends DiagramDocumentEditor
+ // implements IRevealSemanticElement {
+ //
+ // public SynchronizableGmfDiagramEditor(final boolean hasFlyoutPalette) {
+ // super(hasFlyoutPalette);
+ // }
+ //
+ //
+ // /**
+ // * reveal all editpart that represent an element in the given list.
+ // *
+ // * @see
+ // org.eclipse.papyrus.infra.core.ui.IRevealSemanticElement#revealSemanticElement(java.util.List)
+ // *
+ // */
+ // public void revealSemanticElement(final List<?> elementList) {
+ // //create an instance that can get semantic element from gmf
+ // final SemanticFromGMFElement semanticFromGMFElement = new
+ // SemanticFromGMFElement();
+ //
+ // // get the graphical viewer
+ // final GraphicalViewer graphicalViewer = getGraphicalViewer();
+ // if(graphicalViewer != null) {
+ //
+ // //look for among all edit part if the semantic is contained in the list
+ // final Iterator<?> iter =
+ // graphicalViewer.getEditPartRegistry().values().iterator();
+ // IGraphicalEditPart researchedEditPart = null;
+ // while(iter.hasNext() && researchedEditPart == null) {
+ // final Object currentEditPart = iter.next();
+ // //look for only among IPrimary editpart to avoid compartment and labels
+ // of links
+ // if(currentEditPart instanceof IPrimaryEditPart) {
+ // if(elementList.contains(semanticFromGMFElement.getSemanticElement(currentEditPart)))
+ // {
+ // researchedEditPart = ((IGraphicalEditPart)currentEditPart);
+ // }
+ // }
+ //
+ // }
+ // //an editpart has been found so put selection on it.
+ // if(researchedEditPart != null) {
+ // graphicalViewer.select(researchedEditPart);
+ // }
+ // }
+ // }
+ //
+ // /**
+ // * Configures my diagram edit domain with its command stack.
+ // * This method has been completely overridden in order to use a proxy
+ // stack.
+ // */
+ // @Override
+ // protected void configureDiagramEditDomain() {
+ //
+ // final DefaultEditDomain editDomain = getEditDomain();
+ //
+ // if(editDomain != null) {
+ // final CommandStack stack = editDomain.getCommandStack();
+ // if(stack != null) {
+ // // dispose the old stack
+ // stack.dispose();
+ // }
+ //
+ // // create and assign the new stack
+ // final CheckedDiagramCommandStack diagramStack = new
+ // CheckedDiagramCommandStack(getDiagramEditDomain());
+ //
+ // editDomain.setCommandStack(diagramStack);
+ // }
+ //
+ // final DiagramEditDomain diagEditDomain =
+ // (DiagramEditDomain)getDiagramEditDomain();
+ // diagEditDomain.setActionManager(createActionManager());
+ // }
+ // }
+ //
+}
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/AbstractSynchronizedTableEditor.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/AbstractSynchronizedTableEditor.java
new file mode 100644
index 00000000000..db69e8a6839
--- /dev/null
+++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/AbstractSynchronizedTableEditor.java
@@ -0,0 +1,110 @@
+/**
+ * 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.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.TriggerListener;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+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.metamodel.papyrustable.PapyrusTable;
+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 AbstractSynchronizedTableEditor extends AbstractTableEditor {
+
+
+
+ /** listener on the model for synchronized table */
+ private TriggerListener fillingListener;
+
+ /** to listen moving lines in the table */
+ private TriggerListener moveLineListener;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param servicesRegistry
+ * the service serviceRegistry
+ * @param rawModel
+ * the raw model
+ */
+ public AbstractSynchronizedTableEditor(final ServicesRegistry servicesRegistry, final PapyrusTable rawModel) {
+ super(servicesRegistry, rawModel);
+ }
+
+
+
+ /**
+ *
+ * @see org.eclipse.emf.facet.widgets.nattable.workbench.editor.NatTableEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
+ *
+ * @param site
+ * @param input
+ * @throws PartInitException
+ */
+ @Override
+ public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
+ final PapyrusTableEditorInput tableEditorInput = new PapyrusTableEditorInput(this.rawModel, getEditingDomain());
+ super.init(site, tableEditorInput);
+ }
+
+
+ /**
+ * add listeners on the context of the table and on the table itself
+ */
+ @Override
+ protected void configureEditorEditingDomain() {
+ super.configureEditorEditingDomain();
+ final EditingDomain editingDomain = getEditingDomain();
+ Assert.isTrue(editingDomain instanceof TransactionalEditingDomain);
+
+ this.fillingListener = new FillingListener(this.rawModel);
+ ((TransactionalEditingDomain)editingDomain).addResourceSetListener(this.fillingListener);
+
+ 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);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.table.common.internal.NatTableEditor#dispose()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void dispose() {
+ ((TransactionalEditingDomain)getEditingDomain()).removeResourceSetListener(this.fillingListener);
+ ((TransactionalEditingDomain)getEditingDomain()).removeResourceSetListener(this.moveLineListener);
+ super.dispose();
+ }
+
+
+
+}
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 6fc3df0cbd4..369ae80e867 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
@@ -9,146 +9,423 @@
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Duplicated code from EMF-Facet
*/
+
package org.eclipse.papyrus.infra.table.efacet.common.editor;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.EventObject;
+import java.util.List;
+
import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.command.BasicCommandStack;
+import org.eclipse.emf.common.command.CommandStackListener;
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.emf.edit.domain.IEditingDomainProvider;
+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.ITableWidgetInternal;
+import org.eclipse.emf.facet.widgets.table.ui.internal.exported.ITableWidgetProvider;
+import org.eclipse.emf.facet.widgets.table.ui.internal.exported.ITableWidgetView;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
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.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.contexts.IContextService;
+import org.eclipse.ui.part.EditorPart;
-public abstract class AbstractTableEditor extends NatTableEditor2 {
- /** the service registry */
- protected ServicesRegistry servicesRegistry;
+/**
+ * Adapted code from EMF-Facet
+ *
+ *
+ */
+public class AbstractTableEditor extends AbstractPapyrusNestedEditor implements ISelectionProvider {
- /** the table instance */
- protected PapyrusTable rawModel;
+ /** listener on the selection changes */
+ private final ISelectionChangedListener localSelectionListener = new SelectionChangeListener();
- /** listener on the model for synchronized table */
- private TriggerListener fillingListener;
+ /** the list of the registered selection listeners */
+ private final List<ISelectionChangedListener> registeredSelectionListener = new ArrayList<ISelectionChangedListener>();
- /** listener on the filling mode */
- private TriggerListener fillingModeListener;
+ /** the id for the menu of the editor */
+ private final static String ID = "org.eclipse.papyrus.infra.table.efacet.common.editor";
- /** to listen moving lines in the table */
- private TriggerListener moveLineListener;
+ protected ITableWidget natTableWidget;
+
+ /** the table instance */
+ protected PapyrusTable rawModel;
+
+
- /**
- *
- * Constructor.
- *
- * @param servicesRegistry
- * the service registry
- * @param rawModel
- * the raw model
- */
public AbstractTableEditor(final ServicesRegistry servicesRegistry, final PapyrusTable rawModel) {
- this.servicesRegistry = servicesRegistry;
+ super(servicesRegistry);
this.rawModel = rawModel;
new PartNameSynchronizer(rawModel);
}
+ @SuppressWarnings("rawtypes")
+ // We cannot change the method signature because of the override
+ @Override
+ public Object getAdapter(final Class adapter) {
+ if(adapter == ITableWidgetProvider.class) {
+ return new ITableWidgetProvider() {
+
+ public ITableWidget getTableWidget() {
+ return AbstractTableEditor.this.natTableWidget;
+ }
+ };
+ }
+ if(adapter == PapyrusTable.class) {
+ return this.natTableWidget.getTable().eContainer();
+ } else if(adapter == Table.class) {
+ return this.natTableWidget.getTable();
+ }
+ return null;
+ }
+
+ @Override
+ public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
+ if(input instanceof PapyrusTableEditorInput) {
+ setSite(site);
+ setInput(input);
+ setPartName(this.rawModel.getName());
+ configureEditorEditingDomain();
+ } else {
+ throw new PartInitException("Input should be of type TableEditorInput"); //$NON-NLS-1$
+ }
+ }
+
/**
*
- * @see org.eclipse.emf.facet.widgets.nattable.workbench.editor.NatTableEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
+ * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*
- * @param site
- * @param input
- * @throws PartInitException
+ * @param parent
*/
@Override
- public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
- final PapyrusTableEditorInput tableEditorInput = new PapyrusTableEditorInput(this.rawModel, getEditingDomain());
- setSite(site);
- setInput(tableEditorInput);
- setPartName(this.rawModel.getName());
- super.init(site, tableEditorInput);
- }
+ public void createPartControl(final Composite parent) {
+
+ final Composite editorComposite = createCompositeCompositeWthTableBorder(parent);
+ // the composite owning the table
+ final Composite tableComposite = new Composite(editorComposite, SWT.NONE);
+ final GridLayout tableCompositeGridLayout = new GridLayout(1, true);
+ tableComposite.setLayout(tableCompositeGridLayout);
+
+ final GridData compositeTableGridLayout = new GridData();
+ compositeTableGridLayout.grabExcessHorizontalSpace = true;
+ compositeTableGridLayout.grabExcessVerticalSpace = true;
+ compositeTableGridLayout.horizontalAlignment = SWT.FILL;
+ compositeTableGridLayout.verticalAlignment = SWT.FILL;
+ tableComposite.setLayoutData(compositeTableGridLayout);
+ final FilteredMenuManager menuMgr = new FilteredMenuManager("#PopUp", AbstractTableEditor.ID);
+ this.natTableWidget = createNattableWidget(tableComposite, this, this.rawModel.getTable(), menuMgr);
+ this.natTableWidget.addSelectionChangedListener(new SelectionChangeListener());
+ getSite().setSelectionProvider(this);
+ getSite().registerContextMenu(menuMgr, this.natTableWidget);
+ }
/**
- * add listeners on the context of the table and on the table itself
+ *
+ * @param tableComposite
+ * the composite
+ * @param domainProvider
+ * the editing domain provider
+ * @param table
+ * the table
+ * @param menuMgr2
+ * the menu manager for the widget
+ * @return
*/
- protected void addListeners() {
- final EditingDomain editingDomain = getEditingDomain();
- Assert.isTrue(editingDomain instanceof TransactionalEditingDomain);
+ private ITableWidget createNattableWidget(final Composite tableComposite, final IEditingDomainProvider domainProvider, final Table table, final MenuManager menuMgr) {
+ final ITableWidget widget = ITableWidgetFactory.INSTANCE.createTableWidget(tableComposite, domainProvider, table, menuMgr);
+ final GridData tableGridData = new GridData();
+ tableGridData.grabExcessHorizontalSpace = true;
+ tableGridData.grabExcessVerticalSpace = true;
+ tableGridData.horizontalAlignment = SWT.FILL;
+ tableGridData.verticalAlignment = SWT.FILL;
+ widget.getComposite().setLayoutData(tableGridData);
+ return widget;
+ }
+
+ private Composite createCompositeCompositeWthTableBorder(final Composite parent) {
+ final Composite editorComposite = new Composite(parent, SWT.BORDER);
+ final GridLayout editorGridLayout = new GridLayout(1, true);
+ editorGridLayout.marginHeight = 0;
+ editorGridLayout.marginWidth = 0;
+
+ final GridData data = new GridData();
+ data.grabExcessHorizontalSpace = true;
+ data.horizontalAlignment = SWT.FILL;
+ editorComposite.setLayoutData(data);
+ editorComposite.setLayout(editorGridLayout);
+ return editorComposite;
+ }
- this.fillingListener = new FillingListener(this.rawModel);
- ((TransactionalEditingDomain)editingDomain).addResourceSetListener(this.fillingListener);
+ @Override
+ public void setFocus() {
+ this.natTableWidget.getComposite().setFocus();
+ }
- this.fillingModeListener = new TableFillingModeListener(this.rawModel);
- ((TransactionalEditingDomain)editingDomain).addResourceSetListener(this.fillingModeListener);
+ @Override
+ public boolean isDirty() {
+ return ((BasicCommandStack)getEditingDomain().getCommandStack()).isSaveNeeded();
+ }
- this.moveLineListener = new MoveTableLineListener(this.rawModel);
- ((TransactionalEditingDomain)editingDomain).addResourceSetListener(this.moveLineListener);
+ @Override
+ public void doSave(final IProgressMonitor monitor) {
+ //nothing to do here, the save is done by the CoreMultiDiagramEditor
}
@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();
+ public void doSaveAs() {
+ //nothing to do here, the save is done by the CoreMultiDiagramEditor
}
- /**
- *
- * @see org.eclipse.papyrus.infra.table.common.internal.NatTableEditor#dispose()
- *
- * {@inheritDoc}
- */
+ public void setSelection(final ISelection selection) {
+ this.natTableWidget.setSelection(selection);
+ }
+
+
+
@Override
public void dispose() {
- ((TransactionalEditingDomain)getEditingDomain()).removeResourceSetListener(this.fillingListener);
- ((TransactionalEditingDomain)getEditingDomain()).removeResourceSetListener(this.fillingModeListener);
- ((TransactionalEditingDomain)getEditingDomain()).removeResourceSetListener(this.moveLineListener);
super.dispose();
+ this.natTableWidget.removeSelectionChangedListener(this.localSelectionListener);
+ this.registeredSelectionListener.clear();
}
/**
- *
- * @see org.eclipse.emf.facet.widgets.nattable.workbench.editor.NatTableEditor#getEditingDomain()
+ * Warning, we should avoid to use this method.
+ * It will be better to ask to emffacet to open their API
*
* @return
+ * the grid selection
*/
- @Override
- public EditingDomain getEditingDomain() {
+ //currently never used
+ public List<Object> getGridSelection() {
+ final String errorMessage = "We are using java reflect API to get the Grid Selection of the table";
+ Activator.log.warn(errorMessage);
+ final Class<?> cl = this.natTableWidget.getClass();
+ ITableWidgetView view = null;
+ ITableWidgetInternal nattableWidget = null;
try {
- return ServiceUtils.getInstance().getTransactionalEditingDomain(this.servicesRegistry);
- } catch (final ServiceException e) {
- Activator.log.error(e);
+ Field field = cl.getDeclaredField("nattableWidget");
+ field.setAccessible(true);
+ nattableWidget = (ITableWidgetInternal)field.get(this.natTableWidget);
+ field = nattableWidget.getClass().getDeclaredField("view");
+ field.setAccessible(true);
+ view = (ITableWidgetView)field.get(nattableWidget);
+ } catch (final SecurityException e) {
+ Activator.log.error(errorMessage, e);
+ } catch (final NoSuchFieldException e) {
+ Activator.log.error(errorMessage, e);
+ } catch (final IllegalArgumentException e) {
+ Activator.log.error(errorMessage, e);
+ } catch (final IllegalAccessException e) {
+ Activator.log.error(errorMessage, e);
}
- return null;
+ return view.getGridSelection();
+ }
+
+ public ISelection getSelection() {
+
+ // StructuredSelection selection = null;
+ // final List<EObject> selectedEObject = ((org.eclipse.emf.facet.widgets.table.ui.ITableWidget)this.natTableWidget).getSelectedRowEObjects();
+ // final ITableWidgetView view = getTableWidgetView();
+ //
+ // final List<Object> gridSelection = view.getGridSelection();
+ // final List<Column> selectedColumn = new ArrayList<Column>();
+ // final List<Row> selectedRow = new ArrayList<Row>();
+ // final List<IGridElement> grid = new ArrayList<IGridElement>();
+ // if(gridSelection.isEmpty()) {
+ // return new StructuredSelection(this.tableEditorInput.getPapyrusTable());
+ // }
+ //
+ // for(final Object current : gridSelection) {
+ // if(current instanceof Column) {
+ // selectedColumn.add((Column)current);
+ // } else if(current instanceof IGridElement) {
+ // grid.add((IGridElement)current);
+ // } else if(current instanceof Row) {
+ // selectedRow.add((Row)current);
+ // }
+ // // org.eclipse.emf.facet.widgets.table.ui.nattable.internal.nattable.dataprovider.GridElement
+ // int i = 0;
+ // i++;
+ // }
+ //
+ // //we ignore columns!
+ // if(!selectedRow.isEmpty()) {
+ // selection = new StructuredSelection(((org.eclipse.emf.facet.widgets.table.ui.ITableWidget)this.natTableWidget).getSelectedRowEObjects());
+ // } else if(!gridSelection.isEmpty()) {
+ // final List<Object> eobject = new ArrayList<Object>();
+ // final IFacetManager facetManager = IFacetManagerFactory.DEFAULT.getOrCreateFacetManager(this.tableEditorInput.getPapyrusTable().eResource().getResourceSet());
+ // for(final IGridElement gridElement : grid) {
+ //
+ // try {
+ // eobject.add(TableWidgetUtils.getValueOf(gridElement, facetManager));
+ // } catch (final FacetManagerException e) {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // int i = 0;
+ // i++;
+ // }
+ // return new StructuredSelection(eobject);
+ // }
+ //
+ //
+ //
+ // if(!selectedEObject.isEmpty()) {
+ // //return
+ // selection = new StructuredSelection(selectedEObject);
+ // } else {
+ // // final ISelection tableSelection = this.natTableWidget.getSelection();
+ // // if(tableSelection.isEmpty()) {
+ // selection = new StructuredSelection(this.tableEditorInput.getPapyrusTable());
+ // // }
+ // }
+ StructuredSelection selection = null;
+ selection = (StructuredSelection)this.natTableWidget.getSelection();
+ if(selection.isEmpty()) {
+ selection = new StructuredSelection(this.rawModel);
+ }
+ return selection;
+ }
+
+ public void addSelectionChangedListener(final ISelectionChangedListener listener) {
+ this.registeredSelectionListener.add(listener);
}
+ public void removeSelectionChangedListener(final ISelectionChangedListener listener) {
+ this.registeredSelectionListener.remove(listener);
+ }
+
+ /**
+ *
+ * This listener dispatches the selection change events to the registered listeners
+ *
+ */
+ private class SelectionChangeListener implements ISelectionChangedListener {
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+ * s
+ * @param event
+ */
+ public void selectionChanged(final SelectionChangedEvent event) {
+ ISelection selection = event.getSelection();
+ if(selection.isEmpty()) {
+ selection = new StructuredSelection(AbstractTableEditor.this.rawModel);
+ }
+ for(final ISelectionChangedListener current : AbstractTableEditor.this.registeredSelectionListener) {
+ current.selectionChanged(new SelectionChangedEvent(AbstractTableEditor.this, selection));
+ }
+ }
+ }
+
+ /**
+ *
+ * This menu manager allows to filter the contribution to the menu of the table
+ * FIXME : try to do that with capabilities and activities
+ *
+ */
+ private class FilteredMenuManager extends MenuManager {
+
+
+ /** the qualified name of forbidden contribution */
+ private List<String> forbiddenContributions = null;
+
+ /** the pattern of authorized contribution */
+ private List<String> authorizedPattern = new ArrayList<String>();
+
+ public FilteredMenuManager(final String text, final String id) {
+ super(text, id);
+ this.forbiddenContributions = new ArrayList<String>();
+ this.forbiddenContributions.add("org.eclipse.emf.facet.widgets.nattable.examples.ecore.internal.commands.openEclorTabularEditor");
+ this.forbiddenContributions.add("org.eclipse.emf.facet.widgets.nattable.workbench.action4");
+ this.forbiddenContributions.add("org.eclipse.emf.facet.widgets.nattable.workbench.action3");
+ this.forbiddenContributions.add("org.eclipse.emf.facet.widgets.table.ui.workbench.command1");
+ this.forbiddenContributions.add("org.eclipse.emf.facet.widgets.table.ui.workbench.command2");
+
+ this.authorizedPattern = new ArrayList<String>();
+ this.authorizedPattern.add("papyrus");
+ this.authorizedPattern.add("table");
+ this.authorizedPattern.add("org.eclipse.ui.edit.delete");
+ this.authorizedPattern.add("org.eclipse.ui.edit.copy");
+ this.authorizedPattern.add("org.eclipse.ui.edit.selectAll");
+ }
+
+
+
+ /**
+ * We filter the contribution to the table menu
+ *
+ * @see org.eclipse.jface.action.MenuManager#doItemFill(org.eclipse.jface.action.IContributionItem, int)
+ *
+ * @param ci
+ * @param index
+ */
+ @Override
+ protected void doItemFill(final IContributionItem ci, final int index) {
+ if(isAllowedInTableMenu(ci)) {
+ super.doItemFill(ci, index);
+ }
+ }
+
+ private boolean isAllowedInTableMenu(final IContributionItem ci) {
+ final String contributionId = ci.getId();
+ boolean autorized = true;
+ for(final String current : this.forbiddenContributions) {
+ if(contributionId.contains(current)) {
+ autorized = false;
+ }
+ }
+ if(autorized) {
+ for(final String current : this.authorizedPattern) {
+ if(contributionId.contains(current)) {
+ autorized = true;
+ }
+ }
+ }
+ return autorized;
+ }
+
+ }
/**
- * A class taking in charge the synchronization of the partName and the diagram name.
- * When diagram name change, the other is automatically updated.
+ * A class taking in charge the synchronization of the partName and the table name.
+ * When table name change, the other is automatically updated.
*
* @author vincent lorenzo
* adapted class from UmlGmfDiagramEditor
@@ -223,7 +500,7 @@ public abstract class AbstractTableEditor extends NatTableEditor2 {
* @param papyrusTable
*/
public void setTable(final PapyrusTable papyrusTable) {
- // Remove from old diagram, if any
+ // Remove from old table, if any
if(this.papyrusTable != null) {
papyrusTable.eAdapters().remove(this.tableNameListener);
}
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
deleted file mode 100644
index 6457b205edc..00000000000
--- a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/editor/NatTableEditor2.java
+++ /dev/null
@@ -1,476 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2011 Mia-Software.
- * 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 Bros (Mia-Software) - Bug 331203 - table model editor - initial API and implementation
- * Nicolas Guyomar (Mia-Software) - Bug 331442 - To be able to add and remove lines (model elements) from the table
- * Nicolas Bros (Mia-Software) - Bug 332226 - To be able to create or delete model element from the table
- * Nicolas Guyomar (Mia-Software) - Bug 332226 - To be able to create or delete model element from the table
- * Nicolas Bros (Mia-Software) - Bug 331900 - customizable NatTable
- * Nicolas Guyomar (Mia-Software) - Bug 332924 - To be able to save the table
- * Nicolas Guyomar (Mia-Software) - Bug 332998 - To be able to add a column and fill it with the result of a query
- * Gregoire Dupe (Mia-Software) - Bug 332998 - To be able to add a column and fill it with the result of a query
- * Nicolas Guyomar (Mia-Software) - Bug 333015 - To be able to hide columns
- * Nicolas Guyomar (Mia-Software) - Bug 333029 - To be able to save the size of the lines and the columns
- * Nicolas Guyomar (Mia-Software) - Bug 335154 - Sort Column By Type : Cannot modify resource set without a write transaction
- * Nicolas Guyomar (Mia-Software) - Bug 335020 - Nattable widget should use the Eclipse framework
- *******************************************************************************/
-package org.eclipse.papyrus.infra.table.efacet.common.editor;
-
-import java.util.EventObject;
-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.CommandStackListener;
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.impl.AdapterImpl;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.emf.edit.domain.IEditingDomainProvider;
-import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
-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.jface.action.GroupMarker;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.papyrus.infra.table.efacet.common.input.PapyrusTableEditorInput;
-import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTable;
-import org.eclipse.papyrus.infra.widgets.editors.StringLabel;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.IWorkbenchActionConstants;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.part.EditorPart;
-import org.eclipse.ui.part.FileEditorInput;
-import org.eclipse.uml2.uml.util.UMLUtil;
-
-//TODO : remove the dependency on UML
-/**
- * Comes from org.eclipse.emf.facet.widget.nattable.workbench.
- *
- * This class should not be used by others plugins TODO Should be deleted or
- * merge with an other classe
- */
-public class NatTableEditor2 extends EditorPart implements ISelectionProvider, IEditingDomainProvider {// , IWorkbenchPartProvider { //TODO this
-
- // interface should be useful...
-
- public static final String ID = "org.eclipse.emf.facet.widgets.nattable.workbench.editor.NatTableEditor"; //$NON-NLS-1$
-
- private PapyrusTableEditorInput tableEditorInput;
-
- protected ITableWidget natTableWidget;
-
- private EditingDomain editingDomain;
-
- private MenuManager menuMgr;
-
- private StringLabel contextLabel;
-
- private final CommandStackListener commandListener = new CommandStackListener() {
-
- public void commandStackChanged(final EventObject event) {
- Display.getCurrent().asyncExec(new Runnable() {
-
- public void run() {
- firePropertyChange(PROP_DIRTY);
- }
- });
- }
- };
-
- /**
- * we listen the context to refresh it in the table if the context change
- */
- private final Adapter contextListener = new AdapterImpl() {
-
- /**
- *
- * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification)
- *
- * @param notification
- */
- @Override
- public void notifyChanged(final Notification notification) {
- NatTableEditor2.this.contextLabel.refreshValue();
- super.notifyChanged(notification);
- }
- };
-
- @SuppressWarnings("rawtypes")
- // We cannot change the method signature because of the override
- @Override
- public Object getAdapter(final Class adapter) {
- if(adapter == ITableWidgetProvider.class) {
- return new ITableWidgetProvider() {
-
- public ITableWidget getTableWidget() {
- return NatTableEditor2.this.natTableWidget;
- }
- };
- }
- if(adapter == PapyrusTable.class) {
- return this.natTableWidget.getTable().eContainer();
- } else if(adapter == Table.class) {
- return this.natTableWidget.getTable();
- }
- return null;
- }
-
- @Override
- public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
- if(input instanceof PapyrusTableEditorInput) {
- this.tableEditorInput = (PapyrusTableEditorInput)input;
- this.editingDomain = this.tableEditorInput.getEditingDomain();
- initializeEditingDomain();
- setSite(site);
- setInput(this.tableEditorInput);
- setPartName(this.tableEditorInput.getName());
- } else if(input instanceof FileEditorInput) {
- initializeEditingDomain();
- final FileEditorInput fileEditorInput = (FileEditorInput)input;
- final URI uri = URI.createPlatformResourceURI(fileEditorInput.getFile().getFullPath().toString(), false);
- if(uri != null) {
- Resource resource = null;
- if(getEditingDomain() != null) {
- resource = getEditingDomain().loadResource(uri.toString());
- } else {
- final ResourceSet rSet = new ResourceSetImpl();
- resource = rSet.createResource(uri);
- }
- PapyrusTable tableInstance = null;
- for(final EObject eObject : resource.getContents()) {
- if(eObject instanceof PapyrusTable) {
- tableInstance = (PapyrusTable)eObject;
- // One instance of tableInstance per .table file
- break;
- }
- }
- this.tableEditorInput = new PapyrusTableEditorInput(tableInstance, getEditingDomain());
- setSite(site);
- setInput(this.tableEditorInput);
- setPartName(fileEditorInput.getName());
- }
-
- } else {
- throw new PartInitException("Input should be of type TableEditorInput or a .table file"); //$NON-NLS-1$
- }
- }
-
- /**
- *
- * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
- *
- * @param parent
- */
- @Override
- public void createPartControl(final Composite parent) {
- this.menuMgr = new MenuManager("#PopUp", NatTableEditor2.ID); //$NON-NLS-1$
- this.menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
- this.menuMgr.setRemoveAllWhenShown(true);
-
- final Composite editorComposite = createCompositeCompositeWthTableBorder(parent);
- // createFirstLine(editorComposite);
- // createDescription(editorComposite);
-
- // the composite owning the table
- final Composite tableComposite = new Composite(editorComposite, SWT.NONE);
- final GridLayout tableCompositeGridLayout = new GridLayout(1, true);
- tableComposite.setLayout(tableCompositeGridLayout);
-
- final GridData compositeTableGridLayout = new GridData();
- compositeTableGridLayout.grabExcessHorizontalSpace = true;
- compositeTableGridLayout.grabExcessVerticalSpace = true;
- compositeTableGridLayout.horizontalAlignment = SWT.FILL;
- compositeTableGridLayout.verticalAlignment = SWT.FILL;
- tableComposite.setLayoutData(compositeTableGridLayout);
-
- this.natTableWidget = createNattableWidget(tableComposite, this, this.tableEditorInput.getPapyrusTable().getTable(), this.menuMgr);
-
- getSite().setSelectionProvider(this);
- getSite().registerContextMenu(this.menuMgr, this.natTableWidget);
- }
-
- private ITableWidget createNattableWidget(final Composite tableComposite, final NatTableEditor2 natTableEditor, final Table table, final MenuManager menuMgr2) {
- // the nattable widget itself
- // old instanciation
- // this.natTableWidget =
- // INatTableWidgetFactory.INSTANCE.createNatTableWidget(tableComposite,
- // this, this.tableEditorInput.getPapyrusTableInstance().getTable(),
- // this.menuMgr);
- this.natTableWidget = ITableWidgetFactory.INSTANCE.createTableWidget(tableComposite, this, table, this.menuMgr);
- // new PapyrusNatTableWidget(tableComposite, natTableEditor, table,
- // this.menuMgr);
- final GridData tableGridData = new GridData();
- tableGridData.grabExcessHorizontalSpace = true;
- tableGridData.grabExcessVerticalSpace = true;
- tableGridData.horizontalAlignment = SWT.FILL;
- tableGridData.verticalAlignment = SWT.FILL;
- this.natTableWidget.getComposite().setLayoutData(tableGridData);
- return this.natTableWidget;
- }
-
- private Composite createCompositeCompositeWthTableBorder(final Composite parent) {
- final Composite editorComposite = new Composite(parent, SWT.BORDER);
- final GridLayout editorGridLayout = new GridLayout(1, true);
- editorGridLayout.marginHeight = 0;
- editorGridLayout.marginWidth = 0;
-
- final GridData data = new GridData();
- data.grabExcessHorizontalSpace = true;
- data.horizontalAlignment = SWT.FILL;
- editorComposite.setLayoutData(data);
- editorComposite.setLayout(editorGridLayout);
- return editorComposite;
- }
-
- // /**
- // *
- // * @param parent
- // * the parent composite
- // */
- // protected void createFirstLine(final Composite parent) {
- //
- // final Table table = this.tableEditorInput.getPapyrusTable().getTable();
- // Composite firstLineComposite = new Composite(parent, SWT.NONE);
- // final GridLayout smallGridLayout = new GridLayout(2, true);
- // smallGridLayout.marginHeight = 0;
- // smallGridLayout.marginWidth = 0;
- // smallGridLayout.marginLeft = 0;
- // smallGridLayout.marginRight = 0;
- //
- // firstLineComposite.setLayout(smallGridLayout);
- // GridData lineData = new GridData();
- // lineData.horizontalSpan = 1;
- // lineData.horizontalAlignment = SWT.FILL;
- // firstLineComposite.setLayoutData(lineData);
- //
- // //we display the context of the table
- // this.contextLabel = new StringLabel(firstLineComposite, SWT.LEFT);
- // this.contextLabel.setLabel(Messages.NatTableEditor_TableContextLabel);
- // this.contextLabel.setToolTipText(Messages.NatTableEditor_TableContextTollTip);
- //
- // //we observe the feature context of the table (and not the name of the
- // context, because the context is not a NamedElement, but an EObject
- // final IObservableValue contextObservable = new
- // EObjectObservableValue(table,
- // TableinstancePackage.eINSTANCE.getTableInstance_Context());
- // table.getContext().eAdapters().add(this.contextListener);
- // /*
- // * we should set the converted before the observable!
- // */
- // this.contextLabel.setConverters(null, new ContextLabelConverter());
- // this.contextLabel.setLabelProvider(new UMLLabelProvider());
- // this.contextLabel.setModelObservable(contextObservable);
- //
- // //set the layout for contextLabel
- // GridData contextGridData = new GridData();
- // contextGridData.grabExcessHorizontalSpace = true;
- // contextGridData.horizontalAlignment = SWT.FILL;
- // contextGridData.horizontalSpan = 1;
- // this.contextLabel.setLayoutData(contextGridData);
- //
- // BooleanRadio checkbox = new BooleanRadio(firstLineComposite, SWT.NONE,
- // "IsSynchronized :");
- // checkbox.setToolTipText("Indicates if the table is synchronized with queries");
- // final IObservableValue isSynchronizedObservable = new
- // EMFObservableValue(this.tableEditorInput.getPapyrusTable(),
- // PapyrustableinstancePackage.eINSTANCE.getPapyrusTableInstance_IsSynchronized(),
- // getEditingDomain());
- // checkbox.setModelObservable(isSynchronizedObservable);
- //
- // GridData checkboxGridData = new GridData();
- // checkboxGridData.grabExcessHorizontalSpace = true;
- // checkboxGridData.horizontalAlignment = SWT.FILL;
- // checkbox.setLayoutData(checkboxGridData);
- //
- // }
-
- // protected void createDescription(final Composite parent) {
- // final TableInstance table =
- // this.tableEditorInput.getPapyrusTableInstance().getTable();
- // EClass tableEClass = table.eClass();
- //
- // //we display the description of the table
- // final StringEditor descriptionEditor = new StringEditor(parent,
- // SWT.MULTI);
- // descriptionEditor.setLabel(Messages.NatTableEditor_TaleDescriptionLabel);
- // descriptionEditor.setToolTipText(Messages.NatTableEditor_TableDescriptionToolTip);
- //
- //
- // EStructuralFeature myFeature =
- // tableEClass.getEStructuralFeature(TableinstancePackage.TABLE_INSTANCE__DESCRIPTION);
- // EMFObservableValue observable = new EMFObservableValue(table, myFeature,
- // getEditingDomain());
- // descriptionEditor.setModelObservable(observable);
- //
- // //set the layout for the description editor
- // GridData descriptionGridData = new GridData();
- // descriptionGridData.grabExcessHorizontalSpace = true;
- // descriptionGridData.horizontalAlignment = SWT.FILL;
- // descriptionEditor.setLayoutData(descriptionGridData);
- // }
-
- @Override
- public void dispose() {
- if(this.natTableWidget.getTable().getContext() != null) {// can be null
- // when we
- // are
- // destroying
- // the
- // context
- // (and the
- // table!)
- this.natTableWidget.getTable().getContext().eAdapters().remove(this.contextListener);
- }
- super.dispose();
- }
-
- @Override
- public void setFocus() {
- this.natTableWidget.getComposite().setFocus();
- }
-
- @Override
- public boolean isDirty() {
- return ((BasicCommandStack)this.editingDomain.getCommandStack()).isSaveNeeded();
- }
-
- @Override
- public boolean isSaveAsAllowed() {
- return true;
- }
-
- @Override
- public void doSave(final IProgressMonitor monitor) {
- this.natTableWidget.save();
- firePropertyChange(PROP_DIRTY);
- }
-
- @Override
- public void doSaveAs() {
- this.natTableWidget.saveAs();
- firePropertyChange(PROP_DIRTY);
- }
-
- public void addSelectionChangedListener(final ISelectionChangedListener listener) {
- this.natTableWidget.addSelectionChangedListener(listener);
- }
-
- public ISelection getSelection() {
- /*
- * if nattable has the focus : we retun the nattable selection if not,
- * we return the papyrus table instance
- */
- // TODO
- // Control[] children = ((Composite)this.natTableWidget).getChildren();
- // if(children.length != 0) {
- // boolean focus = children[0].isFocusControl();
- // if(focus) {
- // return this.natTableWidget.getSelection();
- // }
- // }
- int i = 0;
- i++;
- final ISelection tableSelection = this.natTableWidget.getSelection();
- if(tableSelection.isEmpty()) {
- return new StructuredSelection(this.tableEditorInput.getPapyrusTable());
- }
- return tableSelection;
- }
-
- public EditingDomain getEditingDomain() {
- return this.editingDomain;
- }
-
- public void removeSelectionChangedListener(final ISelectionChangedListener listener) {
- this.natTableWidget.removeSelectionChangedListener(listener);
- }
-
- public void setSelection(final ISelection selection) {
- this.natTableWidget.setSelection(selection);
- }
-
- /**
- * This sets up the editing domain for the model editor
- */
- protected void initializeEditingDomain() {
- if(this.editingDomain == null) {
- final ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
- final BasicCommandStack commandStack = new BasicCommandStack();
- this.editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, new HashMap<Resource, Boolean>());
- }
- this.editingDomain.getCommandStack().removeCommandStackListener(this.commandListener);
- this.editingDomain.getCommandStack().addCommandStackListener(this.commandListener);
- }
-
- public IWorkbenchPart getPart() {
- return this;
- }
-
- /**
- * This ocnverter is used by the LabelEditor (used to display the context)
- *
- *
- *
- */
- private class ContextLabelConverter implements IConverter {
-
- /**
- *
- * @see org.eclipse.core.databinding.conversion.IConverter#getToType()
- *
- * @return
- */
- public Object getToType() {
- return String.class;
- }
-
- /**
- *
- * @see org.eclipse.core.databinding.conversion.IConverter#getFromType()
- *
- * @return
- */
- public Object getFromType() {
- return Object.class;
- }
-
- /**
- *
- * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
- *
- * @param fromObject
- * @return
- */
- public Object convert(final Object fromObject) {
- if(fromObject instanceof EObject) {
- return UMLUtil.getQualifiedText((EObject)fromObject);
- }
- return ""; //$NON-NLS-1$
- }
- }
-}
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 e5808754de8..19f87d581f4 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
@@ -108,8 +108,6 @@ public class AbstractTableEditorFactory extends AbstractEditorFactory {
final Constructor<?> c = getDiagramClass().getConstructor(ServicesRegistry.class, PapyrusTable.class);
final IEditorPart newEditor = (IEditorPart)c.newInstance(this.servicesRegistry, this.rawModel);
- // IEditorPart newEditor = new
- // DefaultNattableEditor(getServiceRegistry(), rawModel);
this.editor = newEditor;
return this.editor;
@@ -117,7 +115,7 @@ public class AbstractTableEditorFactory extends AbstractEditorFactory {
// Lets propagate. This is an implementation problem that should
// be solved by
// programmer.
- throw new PartInitException("Can't create TextEditor", e); //$NON-NLS-1$
+ throw new PartInitException("Can't create TableEditor", e); //$NON-NLS-1$
}
}
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
index ddaf5280198..971cf6c1dcb 100644
--- 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
@@ -49,6 +49,7 @@ 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
*
*/
+//TODO we should write a switch for the command factory (one for old tables and another one for new tabels)
@SuppressWarnings("restriction")
public class PapyrusCommandFactory extends DefaultCommandFactory {
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 4db8d7cc129..4d0308854ec 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
@@ -26,19 +26,11 @@ 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.AdapterFactory;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.impl.AdapterImpl;
-import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
-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.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
-import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Table;
import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.tableconfiguration.TableConfiguration;
import org.eclipse.emf.facet.widgets.table.ui.internal.exported.TableWidgetUtils;
@@ -46,7 +38,6 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.workspace.AbstractEMFOperation;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.commands.CheckedOperationHistory;
@@ -128,28 +119,28 @@ public abstract class AbstractCreateTableEditorHandler extends AbstractHandler {
/**
*
- * @return
- * <code>true</code> to open the name dialog
+ * @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)}.
+ * Run the command as a transaction. Create a Transaction and delegate the
+ * command to {@link #doExecute(ServicesRegistry)}.
*
* @throws ServiceException
*
*/
public void runAsTransaction() throws ServiceException {
- //default Value
+ // default Value
this.name = this.defaultName;
- 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(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); //$NON-NLS-1$ //$NON-NLS-2$
if(dialog.open() == Dialog.OK) {
- //get the name and the description for the table
+ // get the name and the description for the table
this.name = dialog.getValue();
} else {
return;
@@ -158,8 +149,8 @@ public abstract class AbstractCreateTableEditorHandler extends AbstractHandler {
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
+ // Create the transactional command
+ final AbstractEMFOperation command = new AbstractEMFOperation(domain, "Create " + this.editorType) { //$NON-NLS-1$
@Override
protected IStatus doExecute(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
@@ -178,7 +169,7 @@ public abstract class AbstractCreateTableEditorHandler extends AbstractHandler {
// Execute the command
try {
- CheckedOperationHistory.getInstance().execute(command, new NullProgressMonitor(), null); //TODO : best way?
+ CheckedOperationHistory.getInstance().execute(command, new NullProgressMonitor(), null);
} catch (final ExecutionException e) {
Activator.log.error("Can't create Table Editor", e); //$NON-NLS-1$
}
@@ -202,7 +193,8 @@ public abstract class AbstractCreateTableEditorHandler extends AbstractHandler {
}
/**
- * Create a model identifying the editor. This model will be saved with the sash
+ * Create a model identifying the editor. This model will be saved with the
+ * sash
*
* @return
* @throws ServiceException
@@ -222,88 +214,45 @@ public abstract class AbstractCreateTableEditorHandler extends AbstractHandler {
papyrusTable.setContextFeature(configuration.getListenContextFeature());
papyrusTable.getQueries().addAll(configuration.getFillingQueries());
}
- //TODO
- // setFillingQueries(papyrusTable); //should be done before the TableInstance creation
- // setSynchronization(papyrusTable); //should be done before the TableInstance creation
+
final EObject context = getTableContext();
Assert.isNotNull(context);
- // List<EObject> elements = getInitialElement(papyrusTable, context);
-
- // 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;
if(configuration != null) {
tableConfiguration = configuration.getTableConfiguration();
}
final Object parameter = null;
- final Table table = TableWidgetUtils.createTableInstance(elements, description, tableConfiguration, context, parameter);
- // TableInstance2 tableInstance = NatTableWidgetUtils.createTableInstance(elements, defaultDescription, getTableConfiguration2(), getTableContext(), null);
- // tableInstance.setDescription(description);
+ final Table table = TableWidgetUtils.createTableInstance(Collections.EMPTY_LIST, description, tableConfiguration, context, parameter);
- // Save the model in the associated resource
- // EMFFacetTableModelResource model = (EMFFacetTableModelResource)ServiceUtils.getInstance().getModelSet(serviceRegistry).getModelChecked(EMFFacetTableModelResource.MODEL_ID);
- // model.addTableInstance(table);
papyrusTable.setTable(table);
- // tableInstance.setContext(context);
-
- // setHiddenColumns(papyrusTable);
- // adapter factory used by EMF objects
- final AdapterFactory factory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
-
- /** label provider for EMF objects */
- final ILabelProvider labelProvider = new AdapterFactoryLabelProvider(factory);
-
- if(papyrusTable.isUsingContextFeature() && papyrusTable.getContextFeature() != null) { //TODO : verify that the context owns the wanted feature
- final boolean isDerived = papyrusTable.getContextFeature().isDerived();
- final EReference ref = papyrusTable.getContextFeature();
- final EGenericType genericTtype = ref.getEGenericType();
- final EList<EObject> cross = ref.eCrossReferences();
-
- getTableContext().eAdapters().add(new AdapterImpl() {
-
-
-
- @Override
- public void notifyChanged(final Notification notification) {
- final Object feature = notification.getFeature();
- int i = 0;
- i++;
- }
-
- });
-
- }
return papyrusTable;
}
/**
*
- * @return
- * the configuration to use for the table. This method can return <code>null</code>
+ * @return the configuration to use for the table. This method can return <code>null</code>
*/
protected final PapyrusTableConfiguration getPapyrusTableConfiguration() {
-
+ PapyrusTableConfiguration configuration = null;
final ResourceSet resourceSet = getTableContext().eResource().getResourceSet();
final URI uri = getPapyrusTableConfigurationURI();
- final Resource resource = resourceSet.getResource(uri, true);
- EcoreUtil.resolveAll(resource);
- PapyrusTableConfiguration configuration = null;
-
- if(resource.getContents().get(0) instanceof PapyrusTableConfiguration) {
- configuration = (PapyrusTableConfiguration)resource.getContents().get(0);
+ if(uri != null) {
+ final Resource resource = resourceSet.getResource(uri, true);
+ EcoreUtil.resolveAll(resource);
+ if(resource.getContents().get(0) instanceof PapyrusTableConfiguration) {
+ configuration = (PapyrusTableConfiguration)resource.getContents().get(0);
+ }
}
return configuration;
}
/**
*
- * @return
- * the URI of the Papyrus Table Configuration
+ * @return the URI of the Papyrus Table Configuration
*/
protected URI getPapyrusTableConfigurationURI() {
return null;
@@ -322,8 +271,8 @@ public abstract class AbstractCreateTableEditorHandler extends AbstractHandler {
/**
* Returns the context used to create the table
*
- * @return
- * the context used to create the table or <code>null</code> if not found
+ * @return the context used to create the table or <code>null</code> if not
+ * found
* @throws ServiceException
*/
protected EObject getTableContext() {
@@ -333,7 +282,8 @@ public abstract class AbstractCreateTableEditorHandler extends AbstractHandler {
return selection.get(0);
}
- //we shouldn't try to find a valid context when the selection is not valid!
+ // we shouldn't try to find a valid context when the selection is not
+ // valid!
ModelSet modelSet = null;
ServicesRegistry serviceRegistry;
try {
@@ -345,7 +295,6 @@ public abstract class AbstractCreateTableEditorHandler extends AbstractHandler {
}
-
if(modelSet != null) {
final IModel model = modelSet.getModel(org.eclipse.papyrus.infra.core.resource.uml.UmlModel.MODEL_ID);
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
index c2278fa7c29..7321629a146 100644
--- 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
@@ -24,7 +24,7 @@ import org.eclipse.emf.facet.widgets.table.ui.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.papyrus.infra.table.efacet.common.editor.AbstractSynchronizedTableEditor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
@@ -87,12 +87,12 @@ public abstract class AbstractMoveRowHandler extends AbstractHandler {
* @return
* the current table editor
*/
- protected AbstractTableEditor getCurrentTableEditor() {
+ protected AbstractSynchronizedTableEditor 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;
+ if(activeEditor instanceof AbstractSynchronizedTableEditor) {
+ return (AbstractSynchronizedTableEditor)activeEditor;
}
}
return null;
@@ -105,7 +105,7 @@ public abstract class AbstractMoveRowHandler extends AbstractHandler {
* the current nattable widget
*/
protected ITableWidget getTableWidget() {
- final AbstractTableEditor editor = getCurrentTableEditor();
+ final AbstractSynchronizedTableEditor editor = getCurrentTableEditor();
if(editor != null) {
final ITableWidgetProvider provider = (ITableWidgetProvider)editor.getAdapter(ITableWidgetProvider.class);
if(provider != 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
deleted file mode 100644
index 0e5d7964456..00000000000
--- a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/AbstractSynchronizedTableListener.java
+++ /dev/null
@@ -1,263 +0,0 @@
-/**
- * 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/AbstractTableTriggerListener.java b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/AbstractTableTriggerListener.java
new file mode 100644
index 00000000000..3886b835e84
--- /dev/null
+++ b/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/AbstractTableTriggerListener.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 org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.TriggerListener;
+import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTable;
+
+
+
+public abstract class AbstractTableTriggerListener extends TriggerListener {
+
+ /** The table. */
+ protected final PapyrusTable table;
+
+ /**
+ * Instantiates a new abstract table trigger listener.
+ *
+ * @param papyrusTable
+ * the papyrus table
+ */
+ public AbstractTableTriggerListener(final PapyrusTable papyrusTable) {
+ this.table = papyrusTable;
+ }
+
+ /**
+ * @see org.eclipse.emf.transaction.TriggerListener#trigger(org.eclipse.emf.transaction.TransactionalEditingDomain,
+ * org.eclipse.emf.common.notify.Notification)
+ *
+ * @param domain
+ * @param notification
+ * @return
+ */
+
+ @Override
+ protected final Command trigger(final TransactionalEditingDomain domain, final Notification notification) {
+ if(isManagedNotification(notification)) {
+ return getSynchronizationCommand(domain, notification);
+ }
+ return null;
+ }
+
+ /**
+ * Gets the synchronization command.
+ *
+ * @param domain
+ * the domain
+ * @param notification
+ * the notification
+ * @return the synchronization command
+ */
+ protected Command getSynchronizationCommand(final TransactionalEditingDomain domain, final Notification notification) {
+ return null;
+ }
+
+ /**
+ * Checks if is managed notification.
+ *
+ * @param notification
+ * the notification
+ * @return true, if is managed notification
+ */
+ protected abstract boolean isManagedNotification(Notification notification);
+
+ /**
+ * Gets the command name.
+ *
+ * @param notification
+ * the notification
+ * @return the command name
+ */
+ protected abstract String getCommandName(final Notification notification);
+}
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
index 92a06e83d2d..06d9299790d 100644
--- 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
@@ -12,18 +12,54 @@
*/
package org.eclipse.papyrus.infra.table.efacet.common.listener;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+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.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
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;
+import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrustablePackage;
/**
*
* 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 {
+public class FillingListener extends AbstractTableTriggerListener {
+
+ /**
+ * this set stores the eobjects already managed by an addRow command
+ */
+ private final Set<EObject> addedEObjects = new HashSet<EObject>();
+
+ /**
+ * this set stores the eobjects already managed by a deleteRow command
+ */
+ private final Set<EObject> deletedEObjects = new HashSet<EObject>();
/**
@@ -40,6 +76,191 @@ public class FillingListener extends AbstractSynchronizedTableListener {
/**
*
+ * @param domain
+ * the editing domain used for the command
+ * @return
+ */
+ @Override
+ public Command getSynchronizationCommand(final TransactionalEditingDomain domain, final Notification notification) {
+ //we build the list of the eobjects to add and remove
+ List<EObject> toAdd = null;
+ List<EObject> toRemove = null;
+ CompoundCommand compoundCommand = null;
+ if(this.table.isUsingUser()) {
+ toAdd = Collections.emptyList();
+ toRemove = Collections.emptyList();
+ } else if(this.table.isUsingContextFeature()) {
+ final EReference ref = this.table.getContextFeature();
+ if(!ref.isDerived()) {//TODO improve the usage of the notification in this case
+ //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];
+ }
+
+ //we clean the list (remove eobject already managed)
+ toAdd.removeAll(this.addedEObjects);
+ toRemove.removeAll(this.deletedEObjects);
+
+ //we update the list of already managed elements
+ this.addedEObjects.addAll(toAdd);
+ this.deletedEObjects.addAll(toRemove);
+
+ final ITableCommandFactory factory = getTableCmdFactory(domain, this.table.getTable().eResource().getResourceSet(), this.table.getTable());
+ final Command removeCommand = createRemoveCommand(domain, factory, toRemove);
+ final Command addCommand = createAddCommand(domain, factory, toAdd);
+
+ if(removeCommand != null || addCommand != null) {
+ compoundCommand = new CompoundCommand(getCommandName(notification));
+ if(removeCommand != null && removeCommand.canExecute()) {
+ compoundCommand.append(removeCommand);
+ }
+ if(addCommand != null && addCommand.canExecute()) {
+ compoundCommand.append(addCommand);
+ }
+ }
+ return compoundCommand;
+ }
+
+ /**
+ *
+ * @param domain
+ * the editing domain
+ * @param factory
+ * the factory to use to build the command
+ * @param toRemove
+ * the eobjets to remove
+ * @return
+ * the command to remove rows
+ */
+ private final Command createRemoveCommand(final TransactionalEditingDomain domain, final ITableCommandFactory factory, final List<EObject> toRemove) {
+ CompoundCommand cmd = null;
+ if(!toRemove.isEmpty()) {
+ cmd = new CompoundCommand("Table Synchronization Command (Remove Rows)");
+ cmd.append(factory.createRemoveRowByEObjectCommand(toRemove));
+ cmd.append(new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Clean the set deletedEObjects", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ FillingListener.this.deletedEObjects.removeAll(toRemove);
+ return CommandResult.newOKCommandResult();
+ }
+ }));
+ }
+ return cmd;
+ }
+
+ /**
+ *
+ * @param domain
+ * the editing domain
+ * @param factory
+ * the factory to use to build the command
+ * @param toAdd
+ * the eobjects to add
+ * @return
+ * the command to add rows
+ */
+ private final Command createAddCommand(final TransactionalEditingDomain domain, final ITableCommandFactory factory, final List<EObject> toAdd) {
+ CompoundCommand cmd = null;
+ if(!toAdd.isEmpty()) {
+ cmd = new CompoundCommand("Table Synchronization Command (Remove Rows)");
+ //duplicated code from the widget
+ cmd.append(factory.createAddRowsCommand(toAdd));
+ cmd.append(factory.createSetFacetSetsCommand(this.table.getTable().getFacetSets()));
+
+ cmd.append(new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Clean the set addedEObjects", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ FillingListener.this.addedEObjects.removeAll(toAdd);;
+ return CommandResult.newOKCommandResult();
+ }
+ }));
+ }
+ return cmd;
+ }
+
+ /**
+ *
+ * @param editingDomain
+ * the editing domain
+ * @param resourceSet
+ * the resource set
+ * @param table
+ * the table
+ * @return
+ * the command factory for these parameters
+ */
+ 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;
+ }
+
+
+ /**
+ *
+ * @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;
+ }
+
+ /**
+ *
* @see org.eclipse.papyrus.infra.table.efacet.common.listener.AbstractSynchronizedTableListener#isManagedNotification(org.eclipse.emf.common.notify.Notification)
*
* @param notification
@@ -47,10 +268,41 @@ public class FillingListener extends AbstractSynchronizedTableListener {
*/
@Override
protected boolean isManagedNotification(final Notification notification) {
+ return isUsingQueries() || isTableOpening(notification) || isModifyingModel(notification) || isFillingModeChanging(notification);
+ }
+
+ /**
+ *
+ * @return
+ * <code>true</code> if the table is filled using queries
+ */
+ protected boolean isUsingQueries() {
+ return this.table.isUsingQueries();
+ }
+
+ /**
+ *
+ * @param notification
+ * a notification
+ * @return
+ * <code>true</code> if the filling mode is changing
+ */
+ protected boolean isFillingModeChanging(final Notification notification) {
+ return (notification.getNotifier() == this.table && notification.getFeature() == PapyrustablePackage.eINSTANCE.getPapyrusTable_FillingMode());
+ }
+
+ /**
+ *
+ * @param notification
+ * a notification
+ * @return
+ * <code>true</code> if we are opening a table
+ */
+ protected boolean isTableOpening(final Notification notification) {
final Object notifier = notification.getNotifier();
- if(!this.table.isUsingUser() && notifier instanceof EObject) {
+ if(notifier instanceof EObject) {
final EObject eobject = (EObject)notifier;
- if(notifier instanceof TabFolder) {//to synchronized an opening table
+ if(notifier instanceof TabFolder) {
final Object newValue = notification.getNewValue();
PageRef ref = null;
if(newValue instanceof PageRef) {
@@ -59,10 +311,52 @@ public class FillingListener extends AbstractSynchronizedTableListener {
if(ref != null && ref.getEmfPageIdentifier() == this.table) {
return true;
}
- } else if(eobject.eResource() != null && eobject.eResource().getURI().fileExtension().equals("uml")) { //$NON-NLS-1$
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @param notification
+ * a notification
+ * @return
+ * <code>true</code> if we are modifying the model
+ */
+ protected boolean isModifyingModel(final Notification notification) {
+ final Object notifier = notification.getNotifier();
+ if(notifier instanceof EObject) {
+ final EObject eobject = (EObject)notifier;
+ if(eobject.eResource() != null && eobject.eResource() == this.table.getTable().getContext().eResource()) { //$NON-NLS-1$
return true;
}
}
return false;
}
+
+ /**
+ *
+ * @param notification
+ * the notification
+ * @return
+ * the name of the command to use
+ */
+ @Override
+ protected String getCommandName(final Notification notification) {
+ final String commandName;
+ if(isUsingQueries()) {
+ commandName = "Synchronized Table Command (Contents Changes Using Queries)";
+ } else if(isFillingModeChanging(notification)) {
+ commandName = "Synchronized Table Command (Filling Mode Changed)";
+ } else if(isTableOpening(notification)) {
+ commandName = "Synchronized Table Command (Updating Opening Table)";
+ } else if(isModifyingModel(notification)) {
+ commandName = "Synchronized Table Command (Update for Model Changes)";
+ } else {
+ commandName = "";
+ }
+ return commandName;
+ }
+
+
}
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
index 0113b5a6ba0..ea0113c4228 100644
--- 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
@@ -29,7 +29,7 @@ import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTabl
* This listener allows to know when a line has been moved in the table
*
*/
-public class MoveTableLineListener extends AbstractSynchronizedTableListener {
+public class MoveTableLineListener extends AbstractTableTriggerListener {
/**
*
@@ -78,8 +78,14 @@ public class MoveTableLineListener extends AbstractSynchronizedTableListener {
final EObject movedValue = ((Row)notification.getNewValue()).getElement();
if(currentValue instanceof List<?>) {
final MoveCommand cmd = new MoveCommand(domain, tableContext, this.table.getContextFeature(), movedValue, notification.getPosition());
+ cmd.setLabel(getCommandName(notification));
return cmd;
}
- return super.getSynchronizationCommand(domain, notification);
+ return null;
+ }
+
+ @Override
+ protected String getCommandName(final Notification notification) {
+ return "Move Line Command (Update the Model)";
}
}
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
deleted file mode 100644
index cce7e2adfad..00000000000
--- a/incoming/TableEFacet/org.eclipse.papyrus.infra.table.efacet.common/src/org/eclipse/papyrus/infra/table/efacet/common/listener/TableFillingModeListener.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * 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
index 010c059f1e4..f45ab1a19b4 100644
--- 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
@@ -14,7 +14,7 @@ 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;
+import org.eclipse.papyrus.infra.table.efacet.common.editor.AbstractSynchronizedTableEditor;
/**
*
@@ -38,7 +38,7 @@ public class TablePropertyTester extends PropertyTester {
*/
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 expectedValue.equals((((CoreMultiDiagramEditor)receiver).getActiveEditor() instanceof AbstractSynchronizedTableEditor));
}
return false;
}
diff --git a/incoming/TableEFacet/org.eclipse.papyrus.table.efacet.uml.generic/src/org/eclipse/papyrus/uml/table/efacet/generic/editor/GenericTableEditor.java b/incoming/TableEFacet/org.eclipse.papyrus.table.efacet.uml.generic/src/org/eclipse/papyrus/uml/table/efacet/generic/editor/GenericTableEditor.java
index ba56a2ba7a7..a763d822383 100644
--- a/incoming/TableEFacet/org.eclipse.papyrus.table.efacet.uml.generic/src/org/eclipse/papyrus/uml/table/efacet/generic/editor/GenericTableEditor.java
+++ b/incoming/TableEFacet/org.eclipse.papyrus.table.efacet.uml.generic/src/org/eclipse/papyrus/uml/table/efacet/generic/editor/GenericTableEditor.java
@@ -14,12 +14,12 @@
package org.eclipse.papyrus.uml.table.efacet.generic.editor;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.table.efacet.common.editor.AbstractTableEditor;
+import org.eclipse.papyrus.infra.table.efacet.common.editor.AbstractSynchronizedTableEditor;
import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTable;
-public class GenericTableEditor extends AbstractTableEditor {
+public class GenericTableEditor extends AbstractSynchronizedTableEditor {
/** the type of the editor */
public static final String EDITOR_TYPE = "PapyrusGenericTable"; //$NON-NLS-1$

Back to the top