From 5df7d18edfe21aa3a7730aa1a9679c3e47a15c7b Mon Sep 17 00:00:00 2001 From: Alliu Qemal Date: Wed, 20 Nov 2024 13:43:18 +0100 Subject: [PATCH 1/2] Added open type in editor on instance viewer screen --- .../plugin.xml | 59 +++++++++++++------ .../application/handlers/OpenTypeHandler.java | 11 ++++ 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/plugins/org.eclipse.fordiac.ide.application/plugin.xml b/plugins/org.eclipse.fordiac.ide.application/plugin.xml index 8e6cb1a46e..ab7d6d6697 100644 --- a/plugins/org.eclipse.fordiac.ide.application/plugin.xml +++ b/plugins/org.eclipse.fordiac.ide.application/plugin.xml @@ -921,6 +921,26 @@ + + + + + + + + + + + + + + + + + + + + - + @@ -1475,15 +1495,14 @@ + - - - - + + @@ -1499,19 +1518,25 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + - + + diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/handlers/OpenTypeHandler.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/handlers/OpenTypeHandler.java index 447bd7e9b5..7e5b3b9dc3 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/handlers/OpenTypeHandler.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/handlers/OpenTypeHandler.java @@ -17,6 +17,7 @@ import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.Status; +import org.eclipse.fordiac.ide.model.libraryElement.FBNetwork; import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement; import org.eclipse.fordiac.ide.model.libraryElement.IInterfaceElement; import org.eclipse.fordiac.ide.model.libraryElement.LibraryElement; @@ -77,6 +78,7 @@ private static IFile getSelectedTypeFile(final ISelection sel) { } final LibraryElement type = switch (obj) { + case final FBNetwork fbn -> getTypeFromFbn(fbn); case final FBNetworkElement fbnEl -> fbnEl.getType(); case final IInterfaceElement ie -> ie.getType(); default -> null; @@ -86,6 +88,15 @@ private static IFile getSelectedTypeFile(final ISelection sel) { return type.getTypeEntry().getFile(); } } + + return null; + } + + private static LibraryElement getTypeFromFbn(final FBNetwork fbn) { + if (fbn.eContainer() instanceof final FBNetworkElement fbne) { + return fbne.getType(); + } + return null; } From bd4b15b3463508f220cb1781fe152c033505f7a3 Mon Sep 17 00:00:00 2001 From: Qemal Alliu Date: Thu, 23 Jan 2025 15:25:53 +0100 Subject: [PATCH 2/2] Added open type in editor on instance viewer screen --- .../plugin.xml | 31 ++----- .../application/handlers/OpenTypeHandler.java | 93 ++++++++++++++----- 2 files changed, 74 insertions(+), 50 deletions(-) diff --git a/plugins/org.eclipse.fordiac.ide.application/plugin.xml b/plugins/org.eclipse.fordiac.ide.application/plugin.xml index ab7d6d6697..b82e39cdd4 100644 --- a/plugins/org.eclipse.fordiac.ide.application/plugin.xml +++ b/plugins/org.eclipse.fordiac.ide.application/plugin.xml @@ -921,26 +921,6 @@ - - - - - - - - - - - - - - - - - - - - - + @@ -1495,14 +1475,15 @@ - - - + + + + @@ -1523,7 +1504,7 @@ - + diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/handlers/OpenTypeHandler.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/handlers/OpenTypeHandler.java index 7e5b3b9dc3..12fb941787 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/handlers/OpenTypeHandler.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/handlers/OpenTypeHandler.java @@ -12,50 +12,54 @@ *******************************************************************************/ package org.eclipse.fordiac.ide.application.handlers; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.Status; +import org.eclipse.emf.ecore.EObject; import org.eclipse.fordiac.ide.model.libraryElement.FBNetwork; import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement; import org.eclipse.fordiac.ide.model.libraryElement.IInterfaceElement; -import org.eclipse.fordiac.ide.model.libraryElement.LibraryElement; +import org.eclipse.fordiac.ide.model.libraryElement.INamedElement; +import org.eclipse.fordiac.ide.model.libraryElement.SubApp; +import org.eclipse.fordiac.ide.model.libraryElement.SubAppType; +import org.eclipse.fordiac.ide.model.libraryElement.TypedSubApp; +import org.eclipse.fordiac.ide.model.libraryElement.UntypedSubApp; +import org.eclipse.fordiac.ide.model.ui.actions.OpenListenerManager; import org.eclipse.fordiac.ide.ui.FordiacLogHelper; import org.eclipse.gef.EditPart; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IEditorDescriptor; import org.eclipse.ui.ISources; import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.ui.part.FileEditorInput; public class OpenTypeHandler extends AbstractHandler { @Override public Object execute(final ExecutionEvent event) throws ExecutionException { + final IStructuredSelection sel = HandlerUtil.getCurrentStructuredSelection(event); - final IFile typeFile = getSelectedTypeFile(sel); - if (typeFile != null) { - openTypeEditor(typeFile); + final EObject object = getSelectedObject(sel); + + if (object != null) { + openTypeEditor(object); } - return Status.OK_STATUS; + + return null; } - private static void openTypeEditor(final IFile file) { + private static void openTypeEditor(final EObject object) { final IWorkbench workbench = PlatformUI.getWorkbench(); - if (null != workbench) { + if (workbench != null) { final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow(); - if (null != activeWorkbenchWindow) { - final IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); - final IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry() - .getDefaultEditor(file.getName()); + if (activeWorkbenchWindow != null) { try { - activePage.openEditor(new FileEditorInput(file), desc.getId()); + OpenListenerManager.openEditor(object); } catch (final Exception e) { FordiacLogHelper.logError(e.getMessage(), e); } @@ -67,37 +71,76 @@ private static void openTypeEditor(final IFile file) { public void setEnabled(final Object evaluationContext) { final ISelection sel = (ISelection) HandlerUtil.getVariable(evaluationContext, ISources.ACTIVE_CURRENT_SELECTION_NAME); - setBaseEnabled(getSelectedTypeFile(sel) != null); + + setBaseEnabled(getSelectedObject(sel) != null); } - private static IFile getSelectedTypeFile(final ISelection sel) { + private static EObject getSelectedObject(final ISelection sel) { if ((sel instanceof final IStructuredSelection structSel) && !sel.isEmpty() && (structSel.size() == 1)) { Object obj = structSel.getFirstElement(); + if (obj instanceof final EditPart ep) { obj = ep.getModel(); } - final LibraryElement type = switch (obj) { + final EObject type = switch (obj) { case final FBNetwork fbn -> getTypeFromFbn(fbn); case final FBNetworkElement fbnEl -> fbnEl.getType(); case final IInterfaceElement ie -> ie.getType(); default -> null; }; - if ((type != null) && (type.getTypeEntry() != null)) { - return type.getTypeEntry().getFile(); + if ((type != null)) { + return type; } } return null; } - private static LibraryElement getTypeFromFbn(final FBNetwork fbn) { - if (fbn.eContainer() instanceof final FBNetworkElement fbne) { - return fbne.getType(); + private static EObject getTypeFromFbn(final FBNetwork fbn) { + + if (fbn.eContainer() instanceof final UntypedSubApp usa) { + EObject element = usa; + + final List subAppNames = new ArrayList<>(); + + while (element != null) { + if (element instanceof final INamedElement ine) { + subAppNames.add(ine.getName()); + } + + if (element.eContainer() instanceof final TypedSubApp tsa) { + subAppNames.add(tsa.getName()); + + return getUntypedSubApp(subAppNames.reversed(), tsa.getType()); + } + + element = element.eContainer(); + } + } + + if (fbn.eContainer() instanceof final TypedSubApp tsa) { + return tsa.getType(); } return null; } + private static SubApp getUntypedSubApp(final List subAppNames, final SubAppType type) { + FBNetwork fb = type.getFBNetwork(); + SubApp lastSubapp = null; + + for (final String subAppName : subAppNames) { + final SubApp sa = fb.getSubAppNamed(subAppName); + + if (sa != null) { + lastSubapp = sa; + fb = sa.getSubAppNetwork(); + } + } + + return lastSubapp; + } + }