From 4a53b546ad6aceea53cc450d2e0b0b08344646c5 Mon Sep 17 00:00:00 2001 From: Alexander Fedorov Date: Thu, 23 May 2024 14:28:29 +0300 Subject: [PATCH] [#1370] Operator fails on startup Rework LocImageRegistry --- ...oc.internal.workbench.LocImageRegistry.xml | 2 +- .../internal/workbench/LocImageRegistry.java | 25 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/bundles/org.eclipse.passage.loc.workbench/OSGI-INF/org.eclipse.passage.loc.internal.workbench.LocImageRegistry.xml b/bundles/org.eclipse.passage.loc.workbench/OSGI-INF/org.eclipse.passage.loc.internal.workbench.LocImageRegistry.xml index f4a6f9a37..aed8a0e2d 100644 --- a/bundles/org.eclipse.passage.loc.workbench/OSGI-INF/org.eclipse.passage.loc.internal.workbench.LocImageRegistry.xml +++ b/bundles/org.eclipse.passage.loc.workbench/OSGI-INF/org.eclipse.passage.loc.internal.workbench.LocImageRegistry.xml @@ -1,5 +1,5 @@ - + diff --git a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/LocImageRegistry.java b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/LocImageRegistry.java index 498489016..a71cbdfb5 100644 --- a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/LocImageRegistry.java +++ b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/LocImageRegistry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018, 2020 ArSysOp + * Copyright (c) 2018, 2024 ArSysOp * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -15,6 +15,8 @@ import java.net.MalformedURLException; import java.net.URL; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.passage.loc.jface.LocImages; @@ -24,17 +26,16 @@ import org.osgi.service.component.annotations.Deactivate; @Component -public class LocImageRegistry implements LocImages { +public final class LocImageRegistry implements LocImages { - private ImageRegistry imageRegistry; + private final ImageRegistry images = new ImageRegistry(); @Activate - public void activate() { - imageRegistry = new ImageRegistry(); + public void register() { addBaseImages(); } - protected void addBaseImages() { + private void addBaseImages() { String pattern = "platform:/plugin/org.eclipse.passage.loc.workbench/images/%s"; //$NON-NLS-1$ register(IMG_TOOL_ADD, String.format(pattern, "add.png")); //$NON-NLS-1$ register(IMG_TOOL_EDIT, String.format(pattern, "edit.png")); //$NON-NLS-1$ @@ -44,27 +45,25 @@ protected void addBaseImages() { private void register(String key, String url) { try { ImageDescriptor created = ImageDescriptor.createFromURL(new URL(url)); - imageRegistry.put(key, created); + images.put(key, created); } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Platform.getLog(getClass()).log(Status.error(key, e)); } } @Deactivate public void deactivate() { - imageRegistry.dispose(); - imageRegistry = null; + images.dispose(); } @Override public Image getImage(String identifier) { - return imageRegistry.get(identifier); + return images.get(identifier); } @Override public ImageDescriptor getImageDescriptor(String identifier) { - return imageRegistry.getDescriptor(identifier); + return images.getDescriptor(identifier); } }