Skip to content

Commit

Permalink
Ensure that the right subeditor is opened
Browse files Browse the repository at this point in the history
As editor model and systemexplorer model may deviate this change ensures
that opening sub-editors (e.g., untyped subapps, applications) are
always using the right model.

Furthermore old link helpers which where used bevore we had the
breadcrumb editors are removed as these are by now mostly outdated and
confuse a lot for searching the right editors.
  • Loading branch information
azoitl committed Jun 24, 2024
1 parent 7867721 commit f373967
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,20 @@ public OpenCompositeInstanceViewerOpenListener() {
@Override
public void run(final IAction action) {
final EObject root = EcoreUtil.getRootContainer(compositeFBInstance);
if (root instanceof AutomationSystem) {
openInSystemEditor(((AutomationSystem) root).getTypeEntry().getFile(), compositeFBInstance);
} else if (root instanceof SubAppType) {
openInSubappTypeEditor((SubAppType) root, compositeFBInstance);
} else if (root instanceof CompositeFBType) {
openInFBTypeEditor((CompositeFBType) root, compositeFBInstance);
if (root instanceof final AutomationSystem as) {
openInSystemEditor(as.getTypeEntry().getFile(), compositeFBInstance);
} else if (root instanceof final SubAppType subAppType) {
openInSubappTypeEditor(subAppType, compositeFBInstance);
} else if (root instanceof final CompositeFBType cfbType) {
openInFBTypeEditor(cfbType, compositeFBInstance);
}
}

@Override
public void selectionChanged(final IAction action, final ISelection selection) {
if (selection instanceof IStructuredSelection) {
final IStructuredSelection structuredSel = (IStructuredSelection) selection;
if (structuredSel.getFirstElement() instanceof FB) {
compositeFBInstance = (FB) structuredSel.getFirstElement();
}
if (selection instanceof final IStructuredSelection structuredSel
&& structuredSel.getFirstElement() instanceof final FB firstEl) {
compositeFBInstance = firstEl;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
package org.eclipse.fordiac.ide.model.ui.actions;

import org.eclipse.core.resources.IFile;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.fordiac.ide.model.libraryElement.FBType;
import org.eclipse.fordiac.ide.model.libraryElement.Group;
import org.eclipse.fordiac.ide.model.libraryElement.LibraryElement;
import org.eclipse.fordiac.ide.model.libraryElement.SubAppType;
import org.eclipse.fordiac.ide.model.ui.editors.AbstractBreadCrumbEditor;
import org.eclipse.fordiac.ide.model.ui.editors.HandlerHelper;
Expand Down Expand Up @@ -66,12 +69,13 @@ protected void openInBreadCrumbEditor(final IFile file, final String editorId, f
final IEditorPart openedEditor = getOpenedEditor();
if (null != openedEditor) {
final AbstractBreadCrumbEditor breadCrumbEditor = getBreadCrumbEditor(openedEditor);
if (null != breadCrumbEditor) {
if (sameLevelAsParent(element)) {
breadCrumbEditor.getBreadcrumb().setInput(element.eContainer().eContainer());
HandlerHelper.selectElement(element, getOpenedEditor());
final EObject elementToOpen = getElementToOpen(openedEditor, element);
if (breadCrumbEditor != null && elementToOpen != null) {
if (sameLevelAsParent(elementToOpen)) {
breadCrumbEditor.getBreadcrumb().setInput(elementToOpen.eContainer().eContainer());
HandlerHelper.selectElement(elementToOpen, openedEditor);
} else {
breadCrumbEditor.getBreadcrumb().setInput(element);
breadCrumbEditor.getBreadcrumb().setInput(elementToOpen);
}
}
}
Expand All @@ -87,8 +91,8 @@ protected void openInFBTypeEditor(final FBType root, final EObject element) {

public static AbstractBreadCrumbEditor getBreadCrumbEditor(final IEditorPart openedEditor) {
AbstractBreadCrumbEditor breadCrumbEditor = openedEditor.getAdapter(AbstractBreadCrumbEditor.class);
if ((breadCrumbEditor == null) && (openedEditor instanceof FormEditor)) {
breadCrumbEditor = getBreadCrumbFromMultiPageEditor((FormEditor) openedEditor);
if ((breadCrumbEditor == null) && (openedEditor instanceof final FormEditor formEditor)) {
breadCrumbEditor = getBreadCrumbFromMultiPageEditor(formEditor);
}
return breadCrumbEditor;
}
Expand All @@ -97,9 +101,9 @@ private static AbstractBreadCrumbEditor getBreadCrumbFromMultiPageEditor(final F
final IEditorInput input = openedEditor.getActiveEditor().getEditorInput();

for (final IEditorPart subEditor : openedEditor.findEditors(input)) {
if (subEditor instanceof AbstractBreadCrumbEditor) {
if (subEditor instanceof final AbstractBreadCrumbEditor bcEditor) {
openedEditor.setActiveEditor(subEditor);
return (AbstractBreadCrumbEditor) subEditor;
return bcEditor;
}
}
return null;
Expand All @@ -109,4 +113,18 @@ private static boolean sameLevelAsParent(final Object element) {
return element instanceof Group;
}

public static EObject getElementToOpen(final IEditorPart openedEditor, final EObject element) {
final LibraryElement editorLibElement = openedEditor.getAdapter(LibraryElement.class);
if (editorLibElement == null) {
return null;
}

if (editorLibElement == EcoreUtil.getRootContainer(element)) {
// we are in the same model we can safely use element
return element;
}
final URI elementURI = EcoreUtil.getURI(element);
return editorLibElement.eResource().getEObject(elementURI.fragment());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,12 @@ public void run(final IAction action) {
@Override
public void selectionChanged(final IAction action, final ISelection selection) {
res = null;
if (selection instanceof IStructuredSelection) {
final IStructuredSelection structuredSel = (IStructuredSelection) selection;
if (structuredSel.getFirstElement() instanceof Resource) {
res = (Resource) structuredSel.getFirstElement();
}
if (selection instanceof final IStructuredSelection structuredSel
&& structuredSel.getFirstElement() instanceof final Resource firstSel) {
res = firstSel;
}
}


@Override
public Class<? extends EObject> getHandledClass() {
return Resource.class;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2009, 2011, 2013, 2017 Profactor GbmH, fortiss GmbH
* Copyright (c) 2008, 2024 Profactor GbmH, fortiss GmbH
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -33,11 +33,9 @@ public void run(final IAction action) {

@Override
public void selectionChanged(final IAction action, final ISelection selection) {
if (selection instanceof IStructuredSelection) {
final IStructuredSelection structuredSel = (IStructuredSelection) selection;
if (structuredSel.getFirstElement() instanceof SystemConfiguration) {
sysConf = (SystemConfiguration) structuredSel.getFirstElement();
}
if (selection instanceof final IStructuredSelection structuredSel
&& structuredSel.getFirstElement() instanceof final SystemConfiguration firstEl) {
sysConf = firstEl;
}
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit f373967

Please sign in to comment.