当前位置: 首页 > 工具软件 > SmartRCP > 使用案例 >

smartrcp工具栏的实现

洪昊然
2023-12-01

本篇展示flex工具栏的实现:

<?xml version="1.0" encoding="utf-8"?>
<gui:RCPModule xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:gui="cn.smartinvoke.gui.*"
 xmlns:rcp="cn.smartinvoke.rcp.*"
        layout="vertical" creationComplete="init()">
        <mx:Script>
                <![CDATA[
					import cn.smartinvoke.smartrcp.gui.FlashShell;
					import cn.smartinvoke.smartrcp.gui.control.CActionManager;
					import cn.smartinvoke.smartrcp.gui.control.CAppToolBarManager;
					import cn.smartinvoke.smartrcp.gui.control.CNativeMenuBuilder;
					import cn.smartinvoke.smartrcp.gui.control.ViewManager;
					import cn.smartinvoke.smartrcp.gui.module.CActionEvent;
					import cn.smartinvoke.smartrcp.gui.module.CPartEvent;
					import cn.smartinvoke.smartrcp.util.JFaceConstant;
					import cn.smartinvoke.smartrcp.util.Log;
					
					import cn.smartinvoke.rcp.*;
					
					import mx.controls.Alert;
                        
                        var action:CAction;
                        var dropDownMenu:CNativeMenuBuilder;
                        function init():void{
							var info:String="本模块主要演示smartrcp在工具栏上的功能,本模块
运行时会自动增加一工具栏按钮,点击" +
								"该按钮会出现下拉菜单,也可以设置工具栏的样式";
							
							smartrcpDemo.Instance.setInfo(info);
							
                            this.action=new CAction("toolBarTest","测试","icons/help.gif","hello...");
                            this.action.type=CAction.AS_DROP_DOWN_MENU;//下拉菜单样式
                            
                            //添加到全局action管理器,这样toolBar才可以根据该action的id添加此按钮
                            var actionManager:CActionManager=CActionManager.Instance;
                            actionManager.addAction(this.action);

                            //下拉菜单
                            dropDownMenu=new CNativeMenuBuilder(FlashShell.MainShell.getShell());
                            dropDownMenu.initAction(this.cActions);
                            dropDownMenu.initMenu(this.relation);
                            dropDownMenu.addListener(function (evt:CActionEvent):void{
                               this.infoLabel.text="当前点击的action id为"+evt.actionId;
                            },this);
                            
                             //添加对应的事件监听
                            actionManager.addListener(this.action.actionId,function(evt:CActionEvent):void{
                               this.dropDownMenu.show(evt.x,evt.y);
                            },this);
                           
                            //获得全局工具栏管理器对象
                            var toolBarManager:CAppToolBarManager=CAppToolBarManager.Instance;
                            //添加对应的action
                            toolBarManager.insertItem(action.actionId);
                            
                            //-------------当此视图退出时,删除对应的工具栏
                            ViewManager.Instance.addListener(this.viewEventHandler,this);
                        }
                        function viewEventHandler(evt:CPartEvent):void{
                                if(evt.type==CPartEvent.Part_Closed){
                                	var closeModule:String=evt.taget.getModulePath();
                                	Log.Instance.println("module close :"+closeModule);
                                	if(closeModule.indexOf("AppToolBar_T.swf")!=-1){
                                        CAppToolBarManager.Instance.removeItem(this.action.actionId);
                                    }
                                }
                        }
                        
                        function onDelClick():void{
                            CAppToolBarManager.Instance.removeItem(this.action.actionId);
                        }
                        
                        function removeAllItems():void{
                                CAppToolBarManager.Instance.removeAll();
                        }
                        var enable:Boolean=false;
                        function setDisable():void{
                                CActionManager.Instance.updateEnable(this.action.actionId,enable);
                                enable=!enable;
                        }
                        function changeToolBarStyle():void{
                                var curToolBar:CToolBar=CAppToolBarManager.Instance.getCurToolBar();
                                if(curToolBar!=null){
                                  if(listType.selectedItem==null){
                                  	Alert.show("请选择工具栏样式");return;
                                  }
                                  curToolBar.type=listType.selectedItem.data;
                                  CAppToolBarManager.Instance.fillToolBar(curToolBar);
                                }
                        }
                        function addSpace():void{
                                var curToolBar:CToolBar=CAppToolBarManager.Instance.getCurToolBar();
                                if(curToolBar!=null){
                                   //在当前添加的action前加上一个分割符
                                   var index:int=curToolBar.actionIds.getItemIndex(this.action.actionId);
                                   curToolBar.actionIds.addItemAt(JFaceConstant.Menu_Separator_Str,index);
                                   CAppToolBarManager.Instance.fillToolBar(curToolBar);
                                }
                        }
                ]]>
        </mx:Script>
        
    <rcp:CMenuRelation id="relation">
        <rcp:actions>
                <mx:String>a1</mx:String>
                <mx:String>-</mx:String>
                <rcp:CMenuRelation label="子菜单">
                        <rcp:actions>
                                <mx:String>a3</mx:String>
                                <rcp:CMenuRelation label="子菜单">
                                  <rcp:actions>
                                   <mx:String>a4</mx:String>
                                  </rcp:actions>
                                </rcp:CMenuRelation>
                        </rcp:actions>
                </rcp:CMenuRelation>
                <mx:String>a2</mx:String>
        </rcp:actions>
    </rcp:CMenuRelation>
        <mx:Array id="cActions">
                <rcp:CAction actionId="a1" text="hello1"/><rcp:CAction actionId="a2" text="hello2"/>
                <rcp:CAction actionId="a3" text="hello3"/><rcp:CAction actionId="a4" text="hello4"/>
        </mx:Array>
    <mx:Panel title="工具栏图标的添加删除与样式设置" cornerRadius="0" layout="horizontal" 
horizontalAlign="center" verticalAlign="middle"
            styleName="opaquePanel" width="100%" height="100%">
        <mx:VBox width="50%" height="100%">
            <mx:Label text="选择样式"/>
                <mx:List id="listType" width="200" selectedIndex="1">
                  <mx:dataProvider>
                        <mx:ArrayCollection>
                         <mx:Object label="图标右字符" data="{CToolBar.Image_Text_Horizontal}"/>
                         <mx:Object label="图标下字符" data="{CToolBar.Image_Text_Vertical}"/>
                         <mx:Object label="图标" data="{CToolBar.Image}"/>
                        </mx:ArrayCollection>
                  </mx:dataProvider>
                </mx:List>
                <mx:Button label="更改样式" click="changeToolBarStyle()"/>
        </mx:VBox>
        <mx:Button label="删除工具按钮" click="onDelClick()"/>
        <mx:Button label="清空工具栏" click="removeAllItems()"/>
        <mx:Button label="改变按钮状态" click="setDisable()"/>
        
        <mx:Label id="infoLabel" width="100%"/>
    </mx:Panel>
</gui:RCPModule>
 
 类似资料: