Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #405: exception during workbench shutdown #410

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public String getLabel() {
*/
@Override
public Image getImage() {
return CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.CORRECTION_CHANGE);
return CheckstyleUIPluginImages.CORRECTION_CHANGE.getImage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

/**
* Image provider for Checkstyle markers.
*
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like auto formatting.
Is it possible to auto format whole project ones to avoid such extra changes in future?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's why I have it quite high in the bullet point list of #388. I also don't like reviews that contain whitespace and formatting changes.

* @author Lars Ködderitzsch
*/
public class CheckstyleMarkerImageProvider implements IAnnotationImageProvider {
Expand All @@ -41,11 +41,11 @@ public class CheckstyleMarkerImageProvider implements IAnnotationImageProvider {
public Image getManagedImage(Annotation annotation) {
String type = annotation.getType();
if (CheckstyleMarker.ERROR_TYPE.equals(type)) {
return CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.MARKER_ERROR);
return CheckstyleUIPluginImages.MARKER_ERROR.getImage();
} else if (CheckstyleMarker.WARNING_TYPE.equals(type)) {
return CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.MARKER_WARNING);
return CheckstyleUIPluginImages.MARKER_WARNING.getImage();
} else if (CheckstyleMarker.INFO_TYPE.equals(type)) {
return CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.MARKER_INFO);
return CheckstyleUIPluginImages.MARKER_INFO.getImage();
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

package net.sf.eclipsecs.ui;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ResourceLocator;
Expand All @@ -35,142 +34,113 @@
*
* @author Lars Ködderitzsch
*/
public abstract class CheckstyleUIPluginImages {
public enum CheckstyleUIPluginImages {

/** Image descriptor for the plugin logo. */
public static final ImageDescriptor PLUGIN_LOGO;

PLUGIN_LOGO(() -> AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/eclipse-cs-little.png")),
/** Image descriptor for the error marker. */
public static final ImageDescriptor MARKER_ERROR;

MARKER_ERROR(() -> AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/checkstyle_error.gif")),
/** Image descriptor for the warning marker. */
public static final ImageDescriptor MARKER_WARNING;

MARKER_WARNING(() -> AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/checkstyle_warning.gif")),
/** Image descriptor for the info marker. */
public static final ImageDescriptor MARKER_INFO;

MARKER_INFO(() -> AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/checkstyle_info.gif")),
/** Image descriptor for the help icon. */
public static final ImageDescriptor HELP_ICON;

HELP_ICON(() -> PlatformUI.getWorkbench().getSharedImages()
.getImageDescriptor(ISharedImages.IMG_LCL_LINKTO_HELP)),
/** Image descriptor for the add correction icon. */
public static final ImageDescriptor CORRECTION_ADD;

CORRECTION_ADD(() -> AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/add_correction.gif")),
/** Image descriptor for the change correction icon. */
public static final ImageDescriptor CORRECTION_CHANGE;

CORRECTION_CHANGE(() -> AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/correction_change.gif")),
/** Image descriptor for the remove correction icon. */
public static final ImageDescriptor CORRECTION_REMOVE;

CORRECTION_REMOVE(() -> AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/remove_correction.gif")),
/** Image descriptor for the tick icon. */
public static final ImageDescriptor TICK_ICON;
TICK_ICON(() -> AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/tick.gif")),

/** Image descriptor for the filter icon. */
public static final ImageDescriptor FILTER_ICON;

FILTER_ICON(() -> ResourceLocator.imageDescriptorFromBundle("org.eclipse.ui.ide",
"platform:/plugin/org.eclipse.ui.ide/icons/full/elcl16/filter_ps.png")
.orElse(MARKER_ERROR.getImageDescriptor())),
/** Image descriptor for the Checkstyle violation view icon. */
public static final ImageDescriptor LIST_VIEW_ICON;

LIST_VIEW_ICON(() -> AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/listingView.gif")),
/** Image descriptor for the graph view icon. */
public static final ImageDescriptor GRAPH_VIEW_ICON;

GRAPH_VIEW_ICON(() -> AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/graphView.gif")),
/** Image descriptor for the graph view icon. */
public static final ImageDescriptor EXPORT_REPORT_ICON;
EXPORT_REPORT_ICON(() -> AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/exportReport.gif")),

/** Image descriptor for the module group icon. */
public static final ImageDescriptor MODULEGROUP_ICON;

MODULEGROUP_ICON(() -> AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/modulegroup.gif")),
/** Image descriptor for the ticked module group icon. */
public static final ImageDescriptor MODULEGROUP_TICKED_ICON;

MODULEGROUP_TICKED_ICON(() -> AbstractUIPlugin
.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID, "icons/modulegroup_used.gif")),
/** Image descriptor for the module icon. */
public static final ImageDescriptor MODULE_ICON;

MODULE_ICON(() -> AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/module.gif")),
/** Image descriptor for the ticked module icon. */
public static final ImageDescriptor MODULE_TICKED_ICON;

MODULE_TICKED_ICON(() -> AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/module_used.gif")),
/** Image descriptor for the refresh icon. */
public static final ImageDescriptor REFRESH_ICON;

/** Image cache. */
private static final Map<ImageDescriptor, Image> CACHED_IMAGES = new HashMap<>();
REFRESH_ICON(() -> ResourceLocator.imageDescriptorFromBundle("org.eclipse.search",
"platform:/plugin/org.eclipse.search/icons/full/elcl16/refresh.png")
.orElse(MARKER_ERROR.getImageDescriptor()));

static {
/**
* lazy creation factory
*/
private Supplier<ImageDescriptor> factory;

PLUGIN_LOGO = AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/eclipse-cs-little.png"); //$NON-NLS-1$
MARKER_ERROR = AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/checkstyle_error.gif"); //$NON-NLS-1$
MARKER_WARNING = AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/checkstyle_warning.gif"); //$NON-NLS-1$
MARKER_INFO = AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/checkstyle_info.gif"); //$NON-NLS-1$
HELP_ICON = PlatformUI.getWorkbench().getSharedImages()
.getImageDescriptor(ISharedImages.IMG_LCL_LINKTO_HELP);
CORRECTION_ADD = AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/add_correction.gif"); //$NON-NLS-1$
CORRECTION_CHANGE = AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/correction_change.gif"); //$NON-NLS-1$
CORRECTION_REMOVE = AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/remove_correction.gif"); //$NON-NLS-1$
TICK_ICON = AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/tick.gif"); //$NON-NLS-1$
/**
* image descriptor
*/
private ImageDescriptor imageDescriptor;

FILTER_ICON = ResourceLocator.imageDescriptorFromBundle("org.eclipse.ui.ide",
"platform:/plugin/org.eclipse.ui.ide/icons/full/elcl16/filter_ps.png")
.orElse(MARKER_ERROR);
LIST_VIEW_ICON = AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/listingView.gif"); //$NON-NLS-1$
GRAPH_VIEW_ICON = AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/graphView.gif"); //$NON-NLS-1$
EXPORT_REPORT_ICON = AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/exportReport.gif"); //$NON-NLS-1$
/**
* image that got created from the descriptor
*/
private Image image;

MODULEGROUP_ICON = AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/modulegroup.gif"); //$NON-NLS-1$
MODULEGROUP_TICKED_ICON = AbstractUIPlugin
.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID, "icons/modulegroup_used.gif"); //$NON-NLS-1$
MODULE_ICON = AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/module.gif"); //$NON-NLS-1$
MODULE_TICKED_ICON = AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
"icons/module_used.gif"); //$NON-NLS-1$
REFRESH_ICON = ResourceLocator.imageDescriptorFromBundle("org.eclipse.search",
"platform:/plugin/org.eclipse.search/icons/full/elcl16/refresh.png")
.orElse(MARKER_ERROR);
private CheckstyleUIPluginImages(Supplier<ImageDescriptor> factory) {
this.factory = factory;
}

/**
* Hidden default constructor.
*/
private CheckstyleUIPluginImages() {
// NOOP
public ImageDescriptor getImageDescriptor() {
if (imageDescriptor == null) {
imageDescriptor = factory.get();
}
return imageDescriptor;
}

/**
* Gets an image from a given descriptor.
*
* @param descriptor
* the descriptor
* @return the image
*/
public static Image getImage(ImageDescriptor descriptor) {

Image image = CACHED_IMAGES.get(descriptor);
public Image getImage() {
if (image == null) {
image = descriptor.createImage();
CACHED_IMAGES.put(descriptor, image);
image = getImageDescriptor().createImage();
}
return image;
}

/**
* Disposes the cached images and clears the cache.
* Disposes the cached images.
*/
public static void clearCachedImages() {

for (Image image : CACHED_IMAGES.values()) {
image.dispose();
for (CheckstyleUIPluginImages value : values()) {
if (value.image != null) {
value.image.dispose();
}
}

CACHED_IMAGES.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ private void initialize() {
}

// set the logo
this.setTitleImage(CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.PLUGIN_LOGO));
this.setTitleImage(CheckstyleUIPluginImages.PLUGIN_LOGO.getImage());

mAddButton.setEnabled(mConfigurable);
mRemoveButton.setEnabled(mConfigurable);
Expand Down Expand Up @@ -908,14 +908,13 @@ public Image getImage(Object element) {

if (element instanceof RuleGroupMetadata) {
image = isGroupUsed((RuleGroupMetadata) element)
? CheckstyleUIPluginImages
.getImage(CheckstyleUIPluginImages.MODULEGROUP_TICKED_ICON)
: CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.MODULEGROUP_ICON);
? CheckstyleUIPluginImages.MODULEGROUP_TICKED_ICON.getImage()
: CheckstyleUIPluginImages.MODULEGROUP_ICON.getImage();
} else if (element instanceof RuleMetadata) {

image = isMetadataUsed((RuleMetadata) element)
? CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.MODULE_TICKED_ICON)
: CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.MODULE_ICON);
? CheckstyleUIPluginImages.MODULE_TICKED_ICON.getImage()
: CheckstyleUIPluginImages.MODULE_ICON.getImage();
}
return image;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void create() {
protected Control createDialogArea(Composite parent) {

// set the logo
this.setTitleImage(CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.PLUGIN_LOGO));
this.setTitleImage(CheckstyleUIPluginImages.PLUGIN_LOGO.getImage());

Composite composite = (Composite) super.createDialogArea(parent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ public Image getColumnImage(Object element, int columnIndex) {
if (mWorkingSet instanceof GlobalCheckConfigurationWorkingSet) {

if (((GlobalCheckConfigurationWorkingSet) mWorkingSet).getDefaultCheckConfig() == cfg) {
image = CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.TICK_ICON);
image = CheckstyleUIPluginImages.TICK_ICON.getImage();
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void create() {
protected Control createDialogArea(Composite parent) {

// set the logo
this.setTitleImage(CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.PLUGIN_LOGO));
this.setTitleImage(CheckstyleUIPluginImages.PLUGIN_LOGO.getImage());
this.setTitle(Messages.ResolvablePropertiesDialog_titleMessageArea);
this.setMessage(Messages.ResolvablePropertiesDialog_msgAdditionalProperties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private void initialize() {
}

// set the logo
this.setTitleImage(CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.PLUGIN_LOGO));
this.setTitleImage(CheckstyleUIPluginImages.PLUGIN_LOGO.getImage());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import net.sf.eclipsecs.core.util.CheckstyleLog;
import net.sf.eclipsecs.core.util.CheckstylePluginException;
import net.sf.eclipsecs.ui.CheckstyleUIPlugin;
import net.sf.eclipsecs.ui.CheckstyleUIPluginImages;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;

Expand Down Expand Up @@ -65,15 +65,15 @@ public final class ConfigurationTypesUI {
private static final Map<String, Class<? extends ICheckConfigurationEditor>> CONFIGURATION_TYPE_EDITORS;

/** Map of icon paths for the configuration types. */
private static final Map<String, String> CONFIGATION_TYPE_ICONS;
private static final Map<String, String> CONFIGURATION_TYPE_ICONS;

/**
* Initialize the configured to the filter extension point.
*/
static {

CONFIGURATION_TYPE_EDITORS = new HashMap<>();
CONFIGATION_TYPE_ICONS = new HashMap<>();
CONFIGURATION_TYPE_ICONS = new HashMap<>();

IExtensionRegistry pluginRegistry = Platform.getExtensionRegistry();

Expand All @@ -92,7 +92,7 @@ public final class ConfigurationTypesUI {
String iconPath = elements[i].getAttribute(ATTR_ICON);

CONFIGURATION_TYPE_EDITORS.put(internalName, editor.getClass());
CONFIGATION_TYPE_ICONS.put(internalName, iconPath);
CONFIGURATION_TYPE_ICONS.put(internalName, iconPath);
} catch (Exception e) {
CheckstyleLog.log(e);
}
Expand Down Expand Up @@ -142,12 +142,18 @@ public static ICheckConfigurationEditor getNewEditor(IConfigurationType configTy
*/
public static Image getConfigurationTypeImage(IConfigurationType configType) {

String iconPath = CONFIGATION_TYPE_ICONS.get(configType.getInternalName());
String iconPath = CONFIGURATION_TYPE_ICONS.get(configType.getInternalName());

if (iconPath != null) {
ImageDescriptor descriptor = AbstractUIPlugin
.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID, iconPath);
return CheckstyleUIPluginImages.getImage(descriptor);
ImageRegistry imageRegistry = JFaceResources.getImageRegistry();
Image image = imageRegistry.get(iconPath);
if (image == null) {
ImageDescriptor descriptor = AbstractUIPlugin
.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID, iconPath);
imageRegistry.put(iconPath, descriptor);
image = imageRegistry.get(iconPath);
}
return image;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void initialize() {
gd = new GridData();
gd.verticalAlignment = SWT.BEGINNING;
lblPropertyInfo.setLayoutData(gd);
lblPropertyInfo.setImage(CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.HELP_ICON));
lblPropertyInfo.setImage(CheckstyleUIPluginImages.HELP_ICON.getImage());
lblPropertyInfo.setToolTipText(mProp.getMetaData().getDescription());
SWTUtil.addTooltipOnPressSupport(lblPropertyInfo);
}
Expand All @@ -86,7 +86,7 @@ public void setEnabled(boolean enabled) {

/**
* Returns the widget containing the values.
*
*
* @return the widget containing the value
*/
protected abstract Control getValueWidget(Composite parent);
Expand Down
Loading