diff --git a/Plugin/src/contextquickie2/plugin/ExplorerCommandContributionItem.java b/Plugin/src/contextquickie2/plugin/DisposableCommandContributionItem.java similarity index 87% rename from Plugin/src/contextquickie2/plugin/ExplorerCommandContributionItem.java rename to Plugin/src/contextquickie2/plugin/DisposableCommandContributionItem.java index ffb313f..97e239d 100644 --- a/Plugin/src/contextquickie2/plugin/ExplorerCommandContributionItem.java +++ b/Plugin/src/contextquickie2/plugin/DisposableCommandContributionItem.java @@ -21,22 +21,26 @@ of this software and associated documentation files(the "Software"), to deal OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ***********************************************************************************************************************/ + package contextquickie2.plugin; import org.eclipse.ui.menus.CommandContributionItem; import org.eclipse.ui.menus.CommandContributionItemParameter; -public class ExplorerCommandContributionItem extends CommandContributionItem { - +public class DisposableCommandContributionItem extends CommandContributionItem +{ private EclipseExplorerContextMenuEntry currentEntry; - public ExplorerCommandContributionItem(EclipseExplorerContextMenuEntry entry, CommandContributionItemParameter contributionParameters) { + public DisposableCommandContributionItem( + EclipseExplorerContextMenuEntry entry, CommandContributionItemParameter contributionParameters) + { super(contributionParameters); this.currentEntry = entry; } @Override - public void dispose() { + public void dispose() + { super.dispose(); if (this.currentEntry != null) { diff --git a/Plugin/src/contextquickie2/plugin/DisposableMenuManager.java b/Plugin/src/contextquickie2/plugin/DisposableMenuManager.java new file mode 100644 index 0000000..005e795 --- /dev/null +++ b/Plugin/src/contextquickie2/plugin/DisposableMenuManager.java @@ -0,0 +1,49 @@ +/*********************************************************************************************************************** + MIT License + + Copyright(c) 2020 Roland Reinl + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files(the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and /or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions : + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +***********************************************************************************************************************/ + +package contextquickie2.plugin; + +import org.eclipse.jface.action.MenuManager; + +public class DisposableMenuManager extends MenuManager +{ + private EclipseExplorerContextMenuEntry currentEntry; + + public DisposableMenuManager(EclipseExplorerContextMenuEntry entry) + { + super(entry.getWrappedEntry().getText(), entry.getImageDescriptor(), null); + this.currentEntry = entry; + } + + @Override + public void dispose() + { + super.dispose(); + if (this.currentEntry != null) + { + this.currentEntry.dispose(); + this.currentEntry = null; + } + } +} diff --git a/Plugin/src/contextquickie2/plugin/EclipseExplorerContextMenuEntry.java b/Plugin/src/contextquickie2/plugin/EclipseExplorerContextMenuEntry.java index 39b3079..aba2ea2 100644 --- a/Plugin/src/contextquickie2/plugin/EclipseExplorerContextMenuEntry.java +++ b/Plugin/src/contextquickie2/plugin/EclipseExplorerContextMenuEntry.java @@ -190,13 +190,10 @@ public ExplorerContextMenuEntry getWrappedEntry() { return this.entry; } - - @Override - protected void finalize() throws Throwable - { - this.dispose(); - } + /** + * Releases all unmanaged resources (images) which are used by this instance. + */ public void dispose() { if ((this.image != null) && (this.image.isDisposed() == false)) diff --git a/Plugin/src/contextquickie2/plugin/MenuBuilder.java b/Plugin/src/contextquickie2/plugin/MenuBuilder.java index c0fff9d..c381105 100644 --- a/Plugin/src/contextquickie2/plugin/MenuBuilder.java +++ b/Plugin/src/contextquickie2/plugin/MenuBuilder.java @@ -187,9 +187,8 @@ private IContributionItem createMenuEntry(EclipseExplorerContextMenuEntry entry, } else if (entry.getEntries().iterator().hasNext()) { - final MenuManager subMenu = new MenuManager(entry.getWrappedEntry().getText(), null, null); + final MenuManager subMenu = new DisposableMenuManager(entry); Iterator iterator = entry.getEntries().iterator(); - subMenu.setImageDescriptor(entry.getImageDescriptor()); while (iterator.hasNext()) { subMenu.add(this.createMenuEntry(iterator.next(), selectedResources)); @@ -212,7 +211,7 @@ else if (entry.getEntries().iterator().hasNext()) commandParameter.label = entry.getWrappedEntry().getText(); commandParameter.tooltip = entry.getWrappedEntry().getHelpText(); commandParameter.icon = entry.getImageDescriptor(); - result = new ExplorerCommandContributionItem(entry, commandParameter); + result = new DisposableCommandContributionItem(entry, commandParameter); } return result;