/*
* File : MenuExtensionPoint.java
* Created : 24.06.2006
* By : kahless
*
* GOIM - Gamers Own Instant Messenger
* Copyright (C) 2005-2006 Herbert Poul
* (JabberId: kahless@sphene.net / Email: herbert.poul@gmail.com)
* http://goim.sphene.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package net.sphene.goim.rcp.extensionpoints.menu;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.MenuManager;
/**
* Responsible for retrieving all MenuExtensions..
* @author kahless
*/
public class MenuExtensionPoint {
private static final String EXTENSION_POINT = "net.sphene.goim.rcp.menu";
// private static final String ID_ATTRIBUTE = "id";
// private static final String NAME_ATTRIBUTE = "name";
private static final String CLASS_ATTRIBUTE = "class";
private static List<IMenuExtension> menuExtensions;
/**
* Fills a given global MenuManager
* @param menuManager
* @return the number of items which were added to the menu
* @throws CoreException
*/
public static int fillGlobalMenuManager(MenuManager menuManager) throws CoreException {
List<IMenuExtension> extensions = getMenuExtensions();
int count = 0;
for (IMenuExtension extension : extensions) {
count += extension.fillGlobalMenuManager(menuManager);
}
return count;
}
protected static synchronized List<IMenuExtension> getMenuExtensions() throws CoreException {
if(menuExtensions != null) return menuExtensions;
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint extensionPoint = registry.getExtensionPoint(EXTENSION_POINT);
menuExtensions = new ArrayList<IMenuExtension>();
for(IConfigurationElement element : extensionPoint.getConfigurationElements()) {
IMenuExtension ex = (IMenuExtension)element.createExecutableExtension(CLASS_ATTRIBUTE);
menuExtensions.add(ex);
}
return menuExtensions;
}
}