Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreperico2009-12-08 13:55:39 +0000
committereperico2009-12-08 13:55:39 +0000
commit6adc121bd9c0c6b88733012975cccdc1102ae9ff (patch)
tree2b2adac24e187d7f58cd44ffc86977fce572184c /plugins/profile-tool
parent06b90e62f47c1d2d9195e913034aa96cc3709bc1 (diff)
downloadorg.eclipse.papyrus-6adc121bd9c0c6b88733012975cccdc1102ae9ff.tar.gz
org.eclipse.papyrus-6adc121bd9c0c6b88733012975cccdc1102ae9ff.tar.xz
org.eclipse.papyrus-6adc121bd9c0c6b88733012975cccdc1102ae9ff.zip
NEW - bug 296901: [Profile] provide a way to generate profile based diagram
https://bugs.eclipse.org/bugs/show_bug.cgi?id=296901 delete bin folders - add a ResourceUtil class
Diffstat (limited to 'plugins/profile-tool')
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.resource/src/org/eclipse/papyrus/resource/util/ResourceUtil.java99
1 files changed, 99 insertions, 0 deletions
diff --git a/plugins/profile-tool/org.eclipse.papyrus.resource/src/org/eclipse/papyrus/resource/util/ResourceUtil.java b/plugins/profile-tool/org.eclipse.papyrus.resource/src/org/eclipse/papyrus/resource/util/ResourceUtil.java
new file mode 100644
index 00000000000..bbe506e8f9f
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.resource/src/org/eclipse/papyrus/resource/util/ResourceUtil.java
@@ -0,0 +1,99 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * 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:
+ * Tristan Faure (Atos Origin) tristan.faure@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.resource.util;
+
+import java.util.Iterator;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.resource.Resource;
+import org.eclipse.papyrus.resource.ResourceFactory;
+
+/**
+ * This class provides static methods to help users using Resources
+ *
+ * @author tristan.faure@atosorigin.com
+ *
+ */
+public class ResourceUtil {
+
+ /**
+ * Get in the EMF Resource of the eobject e the Resource Papyrus If it doesn't exist, it adds it
+ *
+ * @param e
+ * the eobject contained in the resource browsed
+ * @return the Resource or null if the parameter is null or if the eobject in parameter doesn't
+ * have an EMF Resource
+ */
+ public static Resource getResource(EObject e) {
+ if (e == null || e.eResource() == null) {
+ return null;
+ }
+ return getResource(e.eResource());
+ }
+
+ /**
+ * Get in the EMF Resource the Resource papyrus If it doesn't exist, it adds it
+ *
+ * @param eResource
+ * the Papyrus Resource browsed
+ * @return the Resource or null if the parameter is null
+ */
+ public static Resource getResource(org.eclipse.emf.ecore.resource.Resource eResource) {
+ if (eResource == null) {
+ return null;
+ }
+ Resource result = null;
+ for (EObject e : eResource.getContents()) {
+ if (e instanceof Resource) {
+ result = (Resource) e;
+ break;
+ }
+ }
+ if (result == null) {
+ result = ResourceFactory.eINSTANCE.createResource();
+ eResource.getContents().add(result);
+ }
+ return result;
+ }
+
+ /**
+ * Remove the Papyrus Resource from the EMF Resource of e
+ *
+ * @param e
+ */
+ public static void removeResource(EObject e) {
+ if (e == null || e.eResource() == null) {
+ return;
+ }
+ removeResource(e.eResource());
+ }
+
+ /**
+ * Remove the Papyrus Resource from the EMF Resource eResource
+ *
+ * @param eResource
+ */
+ public static void removeResource(org.eclipse.emf.ecore.resource.Resource eResource) {
+ if (eResource == null) {
+ return;
+ }
+ Iterator<EObject> i = eResource.getContents().iterator();
+ while (i.hasNext()) {
+ EObject current = i.next();
+ if (current instanceof Resource) {
+ i.remove();
+ }
+ }
+ }
+}

Back to the top