Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alliuqemal committed Jan 23, 2025
1 parent f26afca commit 140820d
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ public class OpenTypeHandler extends AbstractHandler {
public Object execute(final ExecutionEvent event) throws ExecutionException {

final IStructuredSelection sel = HandlerUtil.getCurrentStructuredSelection(event);
final EObject type = getTypeFromSelection(sel);
final EObject object = getSelectedObject(sel);

if (type != null) {
openTypeEditor(type);
if (object != null) {
openTypeEditor(object);
}

return null;
}

private static void openTypeEditor(final EObject type) {
private static void openTypeEditor(final EObject object) {
final IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench != null) {
final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
if (activeWorkbenchWindow != null) {
try {
OpenListenerManager.openEditor(type);
OpenListenerManager.openEditor(object);
} catch (final Exception e) {
FordiacLogHelper.logError(e.getMessage(), e);
}
Expand All @@ -72,10 +72,10 @@ public void setEnabled(final Object evaluationContext) {
final ISelection sel = (ISelection) HandlerUtil.getVariable(evaluationContext,
ISources.ACTIVE_CURRENT_SELECTION_NAME);

setBaseEnabled(getTypeFromSelection(sel) != null);
setBaseEnabled(getSelectedObject(sel) != null);
}

private static EObject getTypeFromSelection(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();

Expand Down Expand Up @@ -103,17 +103,17 @@ private static EObject getTypeFromFbn(final FBNetwork fbn) {
if (fbn.eContainer() instanceof final UntypedSubApp usa) {
EObject element = usa;

final List<String> subApps = new ArrayList<>();
final List<String> subAppNames = new ArrayList<>();

while (element != null) {
if (element instanceof final INamedElement ine) {
subApps.add(ine.getName());
subAppNames.add(ine.getName());
}

if (element.eContainer() instanceof final TypedSubApp tsa) {
subApps.add(tsa.getName());
subAppNames.add(tsa.getName());

return getEObjectFromString(subApps, tsa.getType());
return getUntypedSubApp(subAppNames.reversed(), tsa.getType());
}

element = element.eContainer();
Expand All @@ -127,20 +127,20 @@ private static EObject getTypeFromFbn(final FBNetwork fbn) {
return null;
}

private static SubApp getEObjectFromString(final List<String> subApps, final SubAppType type) {
private static SubApp getUntypedSubApp(final List<String> subAppNames, final SubAppType type) {
FBNetwork fb = type.getFBNetwork();
SubApp last = null;
SubApp lastSubapp = null;

for (final String s : subApps.reversed()) {
final SubApp sa = fb.getSubAppNamed(s);
for (final String subAppName : subAppNames) {
final SubApp sa = fb.getSubAppNamed(subAppName);

if (sa != null) {
last = sa;
lastSubapp = sa;
fb = sa.getSubAppNetwork();
}
}

return last;
return lastSubapp;
}

}

0 comments on commit 140820d

Please sign in to comment.