| /******************************************************************************* |
| * Copyright (c) 2009 Zoltan Ujhelyi and Istvan Rath and Daniel Varro. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Istvan Rath - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.viatra2.visualisation.modelspace.actions.groups; |
| |
| import java.util.HashSet; |
| |
| import org.eclipse.jface.action.IMenuManager; |
| import org.eclipse.jface.action.MenuManager; |
| import org.eclipse.ui.actions.ActionGroup; |
| import org.eclipse.viatra2.visualisation.common.extensions.Category; |
| import org.eclipse.viatra2.visualisation.common.extensions.FilterConfiguration; |
| import org.eclipse.viatra2.visualisation.common.extensions.NamedElement; |
| import org.eclipse.viatra2.visualisation.common.extensions.internal.ExtensionAccess; |
| import org.eclipse.viatra2.visualisation.modelspace.actions.SelectFilterConfigurationAction; |
| |
| /** |
| * @author Istvan Rath |
| */ |
| public class CustomFilterGroup extends ActionGroup { |
| |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see |
| * org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface. |
| * action.IMenuManager) |
| */ |
| @Override |
| public void fillContextMenu(IMenuManager manager) { |
| |
| IMenuManager menu = new MenuManager("Custom filter configurations"); |
| manager.add(menu); |
| HashSet<NamedElement<FilterConfiguration>> addedFilterConfigs = new HashSet<NamedElement<FilterConfiguration>>(); |
| // ExtensionAccess.reInit(); |
| for (Category c : ExtensionAccess.getAllCategories()) { |
| IMenuManager cateroryMenu = new MenuManager(c.name); |
| for (NamedElement<FilterConfiguration> fc_named : c.filterConfigurations.values()) { |
| SelectFilterConfigurationAction action = new SelectFilterConfigurationAction(fc_named.name, fc_named.element); |
| cateroryMenu.add(action); |
| addedFilterConfigs.add(fc_named); |
| } |
| menu.add(cateroryMenu); |
| } |
| // category specification is optional for filterconfigs -> |
| // check whether there are any that we missed |
| HashSet<NamedElement<FilterConfiguration>> remaining = new HashSet<NamedElement<FilterConfiguration>>(); |
| remaining.addAll( ExtensionAccess.getAllFilterConfigurations() ); |
| remaining.removeAll(addedFilterConfigs); |
| if (!remaining.isEmpty()) { |
| IMenuManager unknowns = new MenuManager("Unspecified"); |
| // for (Object o : ExtensionAccess.get) |
| for (NamedElement<FilterConfiguration> fc_n : remaining) { |
| SelectFilterConfigurationAction action = new SelectFilterConfigurationAction(fc_n.name, fc_n.element); |
| unknowns.add(action); |
| } |
| menu.add(unknowns); |
| } |
| |
| } |
| |
| } |