use of org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem in project core by jcryptool.
the class FileExplorerView method init.
@Override
public void init(IViewSite site, IMemento memento) throws PartInitException {
super.init(site, memento);
if (memento != null && memento.getBoolean(MEMENTOKEY_INVISIBLE_FILES_HIDDEN) != null) {
boolean invis_files_hidden = memento.getBoolean(MEMENTOKEY_INVISIBLE_FILES_HIDDEN);
this.setHideInvisible(invis_files_hidden);
} else {
setHideInvisible(getDefaultForHideInvisibleFiles());
}
getViewSite().getActionBars().getMenuManager().addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
if (!menuButtonInitialized) {
try {
IContributionItem[] items = getViewSite().getActionBars().getMenuManager().getItems();
for (IContributionItem item : items) {
if ("org.jcryptool.fileexplorer.invisibleToggle".equals(item.getId())) {
if (item instanceof CommandContributionItem) {
CommandContributionItem invisibleToggle = (CommandContributionItem) item;
State state = invisibleToggle.getCommand().getCommand().getState(RegistryToggleState.STATE_ID);
if (state == null)
throw new UnsupportedOperationException(// $NON-NLS-1$
"The 'show invisible files' command does not have a toggle state");
else if (!(state.getValue() instanceof Boolean))
throw new UnsupportedOperationException(// $NON-NLS-1$
"The 'show invisible files' command's toggle state doesn't contain a boolean value");
else {
state.setValue(!isHideInvisible());
}
} else if (item instanceof HandledContributionItem) {
HandledContributionItem invisibleToggle = (HandledContributionItem) item;
// The MCommand's element ID seems to be the command ID
// Knowing the command ID, we can retrieve the Command (not
// MCommand!)
// from the ECommandService
String commandId = invisibleToggle.getModel().getCommand().getElementId();
ECommandService commandService = (ECommandService) PlatformUI.getWorkbench().getService(ECommandService.class);
State state = commandService.getCommand(commandId).getState(RegistryToggleState.STATE_ID);
if (state == null)
throw new UnsupportedOperationException(// $NON-NLS-1$
"The 'show invisible files' command does not have a toggle state");
else if (!(state.getValue() instanceof Boolean))
throw new UnsupportedOperationException(// $NON-NLS-1$
"The 'show invisible files' command's toggle state doesn't contain a boolean value");
else {
state.setValue(!isHideInvisible());
}
}
}
}
menuButtonInitialized = true;
} catch (UnsupportedOperationException e) {
LogUtil.logError(e.getMessage());
}
}
}
});
}
Aggregations