View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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(
55  				// ((ActionListAction)action).getActionList() );
56  				// if( subMenu == null )
57  				// subMenu = new JMenu(
58  				// ((ActionListAction)action).getActionList().getLabel() );
59  				// menu.add( subMenu);
60  			}
61  			else if( action != null )
62  			{
63  				JComponent component = null;
64  
65  				if( action instanceof SoapUIActionMarker )
66  				{
67  					SoapUIAction soapUIAction = ( ( SoapUIActionMarker )action ).getSoapUIAction();
68  					component = ActionComponentRegistry.buildActionComponent( soapUIAction, modelItem );
69  					actionMap.put( soapUIAction.getId(), action );
70  				}
71  
72  				if( component != null )
73  					add( component );
74  				else
75  					add( action );
76  			}
77  		}
78  	}
79  
80  	public JXSoapUIActionListToolBar( ModelItem modelItem )
81  	{
82  		this( ActionListBuilder.buildActions( modelItem, "EditorToolbar" ), modelItem );
83  	}
84  
85  	public void setEnabled( String actionId, boolean enabled )
86  	{
87  		if( actionMap.containsKey( actionId ) )
88  			actionMap.get( actionId ).setEnabled( enabled );
89  	}
90  
91  }