Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnsgar Radermacher2015-01-19 15:32:49 +0000
committerAnsgar Radermacher2015-01-19 15:32:49 +0000
commit92a979d35b8357c6543440101aeadc828b6276c5 (patch)
tree2a4bfc2adbaa235edc6c5751fb8c0232d5445e84
parent6a7adafaeaae89b50dae6eeb311ddcf8df9dd14f (diff)
downloadorg.eclipse.papyrus-92a979d35b8357c6543440101aeadc828b6276c5.tar.gz
org.eclipse.papyrus-92a979d35b8357c6543440101aeadc828b6276c5.tar.xz
org.eclipse.papyrus-92a979d35b8357c6543440101aeadc828b6276c5.zip
457841 - [codegen] It should be possible to manage a list of changes / editor
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.codegen.base/META-INF/MANIFEST.MF11
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/Activator.java5
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/codesync/ChangeObject.java32
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/codesync/ManageChangeEvents.java137
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/codesync/RecordEventsListener.java104
5 files changed, 285 insertions, 4 deletions
diff --git a/extraplugins/codegen/org.eclipse.papyrus.codegen.base/META-INF/MANIFEST.MF b/extraplugins/codegen/org.eclipse.papyrus.codegen.base/META-INF/MANIFEST.MF
index 8973becae22..1d4ac72ec1c 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.codegen.base/META-INF/MANIFEST.MF
+++ b/extraplugins/codegen/org.eclipse.papyrus.codegen.base/META-INF/MANIFEST.MF
@@ -5,13 +5,16 @@ Bundle-SymbolicName: org.eclipse.papyrus.codegen.base;singleton:=true
Bundle-Version: 1.1.0.qualifier
Bundle-Activator: org.eclipse.papyrus.codegen.base.Activator
Require-Bundle: org.eclipse.core.runtime,
- org.eclipse.acceleo.engine;bundle-version="3.2.2",
- org.eclipse.acceleo.parser;bundle-version="3.2.2",
org.eclipse.uml2.uml;bundle-version="4.0.2",
org.eclipse.core.filesystem;bundle-version="1.3.200",
- org.eclipse.core.resources;bundle-version="3.9.1"
+ org.eclipse.core.resources;bundle-version="3.9.1",
+ org.eclipse.papyrus.infra.core;bundle-version="1.1.0",
+ org.eclipse.papyrus.infra.core.log;bundle-version="1.1.0",
+ org.eclipse.papyrus.infra.emf;bundle-version="1.1.0",
+ org.eclipse.emf.transaction;bundle-version="1.8.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
-Export-Package: org.eclipse.papyrus.codegen.base
+Export-Package: org.eclipse.papyrus.codegen.base,
+ org.eclipse.papyrus.codegen.base.codesync
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/Activator.java b/extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/Activator.java
index 2960486475e..b4c1e58de7f 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/Activator.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/Activator.java
@@ -1,5 +1,6 @@
package org.eclipse.papyrus.codegen.base;
+import org.eclipse.papyrus.infra.core.log.LogHelper;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -17,6 +18,8 @@ public class Activator implements BundleActivator {
return context;
}
+ public static LogHelper log;
+
/*
* (non-Javadoc)
*
@@ -25,6 +28,7 @@ public class Activator implements BundleActivator {
@Override
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
+ log = new LogHelper();
}
/*
@@ -35,5 +39,6 @@ public class Activator implements BundleActivator {
@Override
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
+ log = null;
}
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/codesync/ChangeObject.java b/extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/codesync/ChangeObject.java
new file mode 100644
index 00000000000..d0a52ccdd5c
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/codesync/ChangeObject.java
@@ -0,0 +1,32 @@
+/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Ansgar Radermacher (CEA LIST) Ansgar.Radermacher@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.codegen.base.codesync;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * Simple data type that stores the tuple of event-type and associated e-Object
+ */
+public class ChangeObject {
+ /**
+ * The eventType. @link org.eclipse.emf.common.notify.Notification
+ */
+ int eventType;
+
+ /**
+ * The associated EObject
+ */
+ EObject eObject;
+}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/codesync/ManageChangeEvents.java b/extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/codesync/ManageChangeEvents.java
new file mode 100644
index 00000000000..fdac34742d7
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/codesync/ManageChangeEvents.java
@@ -0,0 +1,137 @@
+/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Ansgar Radermacher (CEA LIST) Ansgar.Radermacher@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.codegen.base.codesync;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.codegen.base.Activator;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.services.EditorLifecycleEventListener;
+import org.eclipse.papyrus.infra.core.services.EditorLifecycleManager;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResourceSet;
+
+/**
+ * Manage and update change events for incremental code generation
+ */
+public class ManageChangeEvents {
+
+ protected static Map<TransactionalEditingDomain, RecordEventsListener> registeredListeners =
+ new HashMap<TransactionalEditingDomain, RecordEventsListener>();
+
+ /**
+ * An internal listener for life cycle events of Papyrus
+ */
+ protected static class LifeCycleListener implements EditorLifecycleEventListener {
+
+ TransactionalEditingDomain domain;
+
+ LifeCycleListener(TransactionalEditingDomain domain) {
+ this.domain = domain;
+ }
+
+ public void postInit(IMultiDiagramEditor editor) {
+ }
+
+ public void postDisplay(IMultiDiagramEditor editor) {
+ }
+
+ /**
+ * Executed before an editor will close => stop recording for this editing domain
+ */
+ public void beforeClose(IMultiDiagramEditor editor) {
+ stopRecording(domain);
+ }
+ }
+
+ /**
+ * Start recording changes for an editing domain
+ *
+ * @param domain
+ * a transactional editing domain. Can be obtained via TransactionUtil from an EObject
+ */
+ public static void startRecording(TransactionalEditingDomain domain) {
+ if (!registeredListeners.containsKey(domain)) {
+ RecordEventsListener recordEvents = new RecordEventsListener();
+ registeredListeners.put(domain, recordEvents);
+ // register a listener that records events
+ domain.addResourceSetListener(recordEvents);
+
+ // register a listener for editor lifecycle events, in order to
+ // cleanup the set of registered listeners after the editor is closed.
+ try {
+ ServicesRegistry registry = ServiceUtilsForResourceSet.getInstance().getServiceRegistry(
+ domain.getResourceSet());
+ EditorLifecycleManager lifecycleManager = registry.getService(EditorLifecycleManager.class);
+ lifecycleManager.addEditorLifecycleEventsListener(new LifeCycleListener(domain));
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ }
+
+ }
+
+ /**
+ * Stop recording changes for an editing domain
+ *
+ * @param domain
+ * a transactional editing domain. Can be obtained via TransactionUtil from an EObject
+ */
+ public static void stopRecording(TransactionalEditingDomain domain) {
+ RecordEventsListener recordEvents = registeredListeners.get(domain);
+ if (recordEvents != null) {
+ domain.removeResourceSetListener(recordEvents);
+ }
+ registeredListeners.remove(domain);
+ }
+
+ /**
+ * Get the list of changes for an editing domain
+ *
+ * @param domain
+ * a transactional editing domain. Can be obtained via TransactionUtil from an EObject
+ * @return the list of changes or null, if there is currently no event listener (which means
+ * typcially, that event recording has not been started yet)
+ */
+ public static EList<ChangeObject> getChangeList(TransactionalEditingDomain domain) {
+ RecordEventsListener recordEvents = registeredListeners.get(domain);
+ if (recordEvents != null) {
+ return recordEvents.getChangeList();
+ }
+ return null;
+ }
+
+ /**
+ * initialize the difference list for an editing domain
+ *
+ * @param domain
+ * a transactional editing domain. Can be obtained via TransactionUtil from an EObject
+ * @param startAutomatically
+ * if true, start event recording, if there is currently no event recording active
+ */
+ public static void initChangeList(TransactionalEditingDomain domain, boolean startAutomatically) {
+ RecordEventsListener recordEvents = registeredListeners.get(domain);
+ if (recordEvents != null) {
+ recordEvents.initChangeList();
+ }
+ else if (startAutomatically) {
+ startRecording(domain);
+ }
+ }
+}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/codesync/RecordEventsListener.java b/extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/codesync/RecordEventsListener.java
new file mode 100644
index 00000000000..0b3938d9e78
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/codesync/RecordEventsListener.java
@@ -0,0 +1,104 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * Patrick Tessier (CEA LIST) patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.codegen.base.codesync;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.NotificationFilter;
+import org.eclipse.emf.transaction.ResourceSetChangeEvent;
+import org.eclipse.emf.transaction.ResourceSetListener;
+import org.eclipse.emf.transaction.RollbackException;
+import org.eclipse.uml2.uml.Element;
+
+/**
+ * This listener is used to register ADD ant SET about in the diff model during
+ * the launch of the revision mode. It also create review element in the review
+ * model. See package commands for specification of review creation commands.
+ *
+ */
+public class RecordEventsListener implements ResourceSetListener {
+
+ protected EList<ChangeObject> changeList;
+
+ /**
+ * constructor
+ *
+ * @param reviewResourceManager
+ */
+ public RecordEventsListener() {
+ changeList = new BasicEList<ChangeObject>();
+ }
+
+ public NotificationFilter getFilter() {
+ return null;
+ }
+
+ /**
+ * @return the list of recorded change events
+ */
+ public EList<ChangeObject> getChangeList() {
+ return changeList;
+ }
+
+ /**
+ * initialize (reset) the list of recorded changes
+ */
+ public void initChangeList() {
+ changeList.clear();
+ }
+
+ @Override
+ public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
+ for (Notification notification : event.getNotifications()) {
+ int eventType = notification.getEventType();
+ if (notification.getNotifier() instanceof EObject) {
+ EObject notifier = (EObject) notification.getNotifier();
+ if ((eventType != Notification.REMOVING_ADAPTER) && (eventType != Notification.RESOLVE)) {
+ if ((notifier instanceof Element) || (notifier instanceof EAnnotation)) {
+ ChangeObject changeObject = new ChangeObject();
+ changeObject.eventType = notification.getEventType();
+ changeObject.eObject = notifier;
+ changeList.add(changeObject);
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void resourceSetChanged(ResourceSetChangeEvent event) {
+
+ }
+
+ @Override
+ public boolean isAggregatePrecommitListener() {
+ return false;
+ }
+
+ @Override
+ public boolean isPrecommitOnly() {
+ return false;
+ }
+
+ @Override
+ public boolean isPostcommitOnly() {
+ return false;
+ }
+
+}

Back to the top