View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.support.action.swing;
14  
15  import java.util.HashMap;
16  import java.util.Map;
17  
18  import javax.swing.Action;
19  import javax.swing.BorderFactory;
20  import javax.swing.JComponent;
21  
22  import com.eviware.soapui.model.ModelItem;
23  import com.eviware.soapui.support.action.SoapUIAction;
24  import com.eviware.soapui.support.actions.MarkerAction;
25  import com.eviware.soapui.support.components.JXToolBar;
26  import com.jgoodies.looks.HeaderStyle;
27  import com.jgoodies.looks.Options;
28  
29  public class JXSoapUIActionListToolBar extends JXToolBar
30  {
31  	private Map<String,Action> actionMap = new HashMap<String, Action>();
32  
33  	@SuppressWarnings("unchecked")
34  	public JXSoapUIActionListToolBar(ActionList actions, ModelItem modelItem )
35  	{
36  		addSpace( 1 );
37  		setRollover( true );
38  		putClientProperty( Options.HEADER_STYLE_KEY, HeaderStyle.SINGLE );
39  		setBorder( BorderFactory.createEmptyBorder( 3, 0, 3, 0 ) );
40  		
41  		for (int i = 0; i < actions.getActionCount(); i++)
42  	   {
43  	   	Action action = actions.getActionAt(i);
44  	   	
45  	   	if( action instanceof MarkerAction )
46  	   		continue;
47  	   	
48  			if( action == ActionSupport.SEPARATOR_ACTION )
49  			{
50  	   	   addSeparator();
51  			}
52  			else if( action instanceof ActionSupport.ActionListAction )
53  			{
54  //				JMenu subMenu = buildMenu( ((ActionListAction)action).getActionList() );
55  //				if( subMenu == null )
56  //					subMenu = new JMenu( ((ActionListAction)action).getActionList().getLabel() );
57  //				menu.add( subMenu);
58  			}
59  	   	else if( action != null )
60  	   	{
61  	   		JComponent component = null;
62  	   		
63  	   		if( action instanceof SoapUIActionMarker )
64  	   		{
65  	   			SoapUIAction soapUIAction = ((SoapUIActionMarker)action).getSoapUIAction();
66  					component = ActionComponentRegistry.buildActionComponent( soapUIAction, modelItem );
67  					actionMap.put(soapUIAction.getId(), action);
68  	   		}
69  	   		
70  	   		if( component != null )
71     				add( component );
72  	   		else
73  	   			add( action );
74  	   	}
75  	   }
76  	}
77  
78  	public JXSoapUIActionListToolBar(ModelItem modelItem)
79  	{
80  		this( ActionListBuilder.buildActions(modelItem, "EditorToolbar" ), modelItem );
81  	}
82  	
83  	public void setEnabled( String actionId, boolean enabled )
84  	{
85  		if( actionMap.containsKey(actionId))
86  			actionMap.get(actionId).setEnabled(enabled);
87  	}
88  
89  }