Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortarendt2012-11-29 04:30:22 -0500
committertarendt2012-11-29 04:30:22 -0500
commitc754e223d273eccd8dc70cac1b1ff436131b4cde (patch)
treebfa780e1c0b4eadbba53b549d4d39aff643089ed
parent929a29ccf23f222d7c3c84478700a936a7d1d9de (diff)
downloadorg.eclipse.emf.refactor.refactoring-c754e223d273eccd8dc70cac1b1ff436131b4cde.tar.gz
org.eclipse.emf.refactor.refactoring-c754e223d273eccd8dc70cac1b1ff436131b4cde.tar.xz
org.eclipse.emf.refactor.refactoring-c754e223d273eccd8dc70cac1b1ff436131b4cde.zip
manager classes added
-rw-r--r--org.eclipse.emf.refactor.refactoring.papyrus/src/org/eclipse/emf/refactor/refactoring/papyrus/managers/PapyrusProjectManager.java60
-rw-r--r--org.eclipse.emf.refactor.refactoring.papyrus/src/org/eclipse/emf/refactor/refactoring/papyrus/managers/PapyrusSelectionManager.java38
2 files changed, 98 insertions, 0 deletions
diff --git a/org.eclipse.emf.refactor.refactoring.papyrus/src/org/eclipse/emf/refactor/refactoring/papyrus/managers/PapyrusProjectManager.java b/org.eclipse.emf.refactor.refactoring.papyrus/src/org/eclipse/emf/refactor/refactoring/papyrus/managers/PapyrusProjectManager.java
new file mode 100644
index 0000000..2f9c0f4
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.papyrus/src/org/eclipse/emf/refactor/refactoring/papyrus/managers/PapyrusProjectManager.java
@@ -0,0 +1,60 @@
+package org.eclipse.emf.refactor.refactoring.papyrus.managers;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.refactor.refactoring.managers.ProjectManager;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorInput;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+public class PapyrusProjectManager extends ProjectManager {
+
+ @SuppressWarnings("finally")
+ public static IProject getActualProject(ISelection selection) {
+ IProject actualProject = ProjectManager.getActualProject();
+ IWorkbenchWindow window = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ try {
+ IEditorPart editorPart = window.getActivePage().getActiveEditor();
+ if (editorPart != null) {
+ IEditorInput input = editorPart.getEditorInput();
+ if (input instanceof IFileEditorInput) {
+ IFileEditorInput fileInput = (IFileEditorInput) input;
+ actualProject = fileInput.getFile().getProject();
+ }
+ if (input instanceof DiagramEditorInput) {
+ actualProject = getProjectFromISelection(selection);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ return actualProject;
+ }
+ }
+
+ private static IProject getProjectFromISelection(ISelection selection) {
+ IProject project = null;
+ Object o = PapyrusSelectionManager.getSelection(selection)[0];
+ if (o instanceof IGraphicalEditPart) {
+ System.out.println("instanceof IGraphicalEditPart");
+ IGraphicalEditPart gep = (IGraphicalEditPart) o;
+ EObject element = gep.resolveSemanticElement();
+ System.out.println("element: " + element);
+ if (element != null) {
+ URI uri = gep.resolveSemanticElement().eResource().getURI();
+ System.out.println("URI: " + uri);
+ String projectName = uri.segmentsList().get(1).toString();
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ }
+ }
+ return project;
+ }
+}
diff --git a/org.eclipse.emf.refactor.refactoring.papyrus/src/org/eclipse/emf/refactor/refactoring/papyrus/managers/PapyrusSelectionManager.java b/org.eclipse.emf.refactor.refactoring.papyrus/src/org/eclipse/emf/refactor/refactoring/papyrus/managers/PapyrusSelectionManager.java
new file mode 100644
index 0000000..7166a10
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.papyrus/src/org/eclipse/emf/refactor/refactoring/papyrus/managers/PapyrusSelectionManager.java
@@ -0,0 +1,38 @@
+package org.eclipse.emf.refactor.refactoring.papyrus.managers;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.facet.infra.browser.uicore.internal.model.ModelElementItem;
+import org.eclipse.emf.refactor.refactoring.managers.SelectionManager;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.jface.viewers.ISelection;
+
+@SuppressWarnings("restriction")
+public class PapyrusSelectionManager extends SelectionManager {
+
+ public static List<EObject> getESelection(ISelection selection) {
+ if (selection == null)
+ return null;
+ List<EObject> r = SelectionManager.getESelection(selection);
+ for (Object o : getSelection(selection)) {
+ if (o instanceof ModelElementItem) {
+ System.out.println("instanceof ModelElementItem");
+ ModelElementItem mei = (ModelElementItem) o;
+ System.out.println("element: " + mei.getEObject());
+ r.add(mei.getEObject());
+ } else {
+ if (o instanceof IGraphicalEditPart) {
+ System.out.println("instanceof IGraphicalEditPart");
+ IGraphicalEditPart gep = (IGraphicalEditPart) o;
+ System.out.println("element: " + gep.resolveSemanticElement());
+ r.add(gep.resolveSemanticElement());
+ } else {
+ return null;
+ }
+ }
+ }
+ return r;
+ }
+
+}

Back to the top