View Javadoc
1   package fr.ifremer.quadrige2.magicdraw.menu;
2   
3   /*-
4    * #%L
5    * Quadrige2 Core :: Quadrige2 Magicdraw plugin
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2017 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  import com.nomagic.actions.AMConfigurator;
26  import com.nomagic.actions.ActionsCategory;
27  import com.nomagic.actions.ActionsManager;
28  import com.nomagic.actions.NMAction;
29  import com.nomagic.magicdraw.actions.MDActionsCategory;
30  
31  /**
32   * Class for configuring main menu and adding  new sub-menu.
33   * @version $Date: 2011-11-11 05:46:25 -0600 (Fri, 11 Nov 2011) $ $Revision: 115454 $
34   * @author Donatas Simkunas
35   */
36  public class MainMenuConfigurator implements AMConfigurator
37  {
38  
39  	String MENU_CATEGORY="Quadrige2";
40  	
41  
42  	/**
43  	 * Action will be added to manager.
44  	 */
45  	private NMAction action;
46  
47  	/**
48  	 * Creates configurator.
49  	 * @param action action to be added to main menu.
50  	 */
51  	public MainMenuConfigurator(NMAction action)
52  	{
53  		this.action = action;
54  	}
55  
56  	/**
57  	 * @see com.nomagic.actions.AMConfigurator#configure(ActionsManager)
58  	 *  Methods adds action to given manager Examples category.
59  	 */
60  	@Override
61  	public void configure(ActionsManager manager)
62  	{
63  		// searching for action category
64  		ActionsCategory category = (ActionsCategory) manager.getActionFor(MENU_CATEGORY);
65  
66  		if( category == null )
67  		{
68  			// creating new category
69  			category = new MDActionsCategory(MENU_CATEGORY, MENU_CATEGORY);
70  			category.setNested(true);
71  			manager.addCategory(category);
72  		}
73  		category.addAction(action);
74  	}
75  	@Override
76  	public int getPriority()
77  	{
78  		return AMConfigurator.MEDIUM_PRIORITY;
79  	}
80  
81  }