目录

自定义菜单配置

概述

用户通过报表提供的接口动态的定制报表设计器中的菜单,通过定制的菜单在报表设计器中实现用户自定义的功能,例如远程文件服务。

编程实现菜单功能

菜单要实现的功能由程序员自己编程实现,所有的功能通过继承CMAction抽象类来实现。

com.runqian.report4.ide.configmenu.CMAction

对于该抽象类用户唯一要实现的方法就是 public void actionPerformed(ActionEvent e) {} 即菜单执行时要真正干什么活。 该类有两个保护变量: protected String argument; protected ICMHandler handler; argument 即在配置菜单按钮时配置文件指定的argument字符串 handler 即ICMHandler,这是一个润乾报表提供的消息处理类,程序员可以通过这个接口发送消息以获取到自己想得到的一些东西。关于这个类所处理的消息在下一小节说明。

com.runqian.report4.ide.configmenu.ICMHandler

public Object processMessage(String desc, Object argument);

desc 消息的简短描述

argument 传给润乾报表的参数

返回值 润乾报表执行消息后返回给程序员的想要得到的东东

目前支持的参数简介:

图片标题


 

另外:com.runqian.report4.ide.GVIde是一静态类,里面包含了IDE的组成构件,用户可以直接访问该类的属性以获取自己感兴趣的IDE构件。

可以访问的构件说明:

1.  appFrame:IDE应用程序的主窗口,该窗口的值只可能是com.runqian.report4.ide.FrameMain 或 com.runqian.datamanager.ide.FrameManager,类型(JFrame)

补充:com.runqian.report4.ide.FrameMain.jSplitPane :设计器主窗口的分栏面板。类型(JsplitPane)

2. appMenu :设计器的主菜单对象。类型(JMenu)

3. dsActive :当前活动的数据源定义,类型(com.runqian.report4.ide.base.DataSource)

4. dsModel :数据源列表定义,类型(com.runqian.report4.ide.base.DataSourceListModel)

5. toolBarProperty :设计器第一个工具条,可设置颜色的那条。类型(com.runqian.report4.ide.ToolBarProperty)

6. toolBarEditor : 设计其第二个工具条,可设置表达式的那条,类型(com.runqian.report4.ide.ToolBarEditor)

例子

实现一个自定义菜单类,能够远程打开报表模板

package one.client;import javax.swing.*;import java.net.*;import java.io.*;import java.awt.event.ActionEvent;import java.util.*;import com.runqian.report4.ide.configmenu.CMAction;public class OneHttpOpenRaq extends CMAction {String raqFile = "";public void actionPerformed( ActionEvent e ) {DialogInputFile dif = new DialogInputFile( null, "请输入报表名称", "" );dif.show();if ( dif.getOption() != JOptionPane.OK_OPTION ) {return;}raqFile = dif.getFile();String surl = argument+"?action=open&fileName="+raqFile;try {URL url = new URL( surl );URLConnection uc = url.openConnection();uc.setDoInput( true );uc.setDoOutput( true );InputStream is = uc.getInputStream();if ( is == null ) {JOptionPane.showMessageDialog( null, "服务器端没有报表文件:" + raqFile, "提示", JOptionPane.WARNING_MESSAGE );return;}HashMap hm = new HashMap();hm.put( "stream", is );hm.put( "filename", raqFile );handler.processMessage( "httpopen", hm );}catch ( Exception x ) {x.printStackTrace();}}}
[注意] 注意

这个类用到了例子代码中的类"example.client.DialogInputFile",在report4.jar中

增加菜单按钮

自定义菜单的配置文件名为systemconfig.xml,该文件同时也是系统数据源等一些其它系统信息的配置文件。远程设计时该文件应当打进jar包,按照第二章的流程进行部署、签名、下载配置。

systemconfig.xml文件结构

<?xml version="1.0" encoding="GB2312"?><REPORT><CONFIG_MENU><F_10 argument="http://192.168.0.27:7070/report4/raqFileServer" classname="one.client.OneHttpOpenRaq" text="打开" hotkey="ctrl+h"/><F_20002 argument="http://192.168.0.27:7070/report4/raqFileServer" classname="example.client.HttpSaveRaq" text="保存为HTTP报表" hotkey="T"/><S_20010 argument="http://192.168.0.27:7070/report4/fileServer" classname="example.client.HttpOpenSemantics" text="打开远程语义层"/><D_20012 argument="http://192.168.0.27:7070/report4/fileServer" classname="example.client.HttpOpenSemantics" text="打开远程语义层"/><D_20015 argument="http://192.168.0.27:7070/report4/fileServer" classname="example.client.HttpSaveSemantics" text="保存远程语义层"/></CONFIG_MENU><CONFIG splashfile="/runqiansplash.jpg"></CONFIG></REPORT>

上述内容中,<CONFIG_MENU></CONFIG_MENU>节点间为自定义菜单的配置,详细说明如下:

F_10为菜单项的数字标识号, F_ 前缀表示菜单将添加到润乾报表的文件菜单中;

S_ 前缀表示将添加到润乾报表系统菜单上; 

D_ 前缀表示将添加到润乾数据管理平台的文件菜单中;

后面跟的序号原则上大于 20000。但是如果小于20000而和系统的其他命令冲突则会造成程序菜单混乱。但是和以下的系统菜单序号相同时,则程序不追加新的配置菜单项,而会把如下列出的系统菜单的行为重定向到配置菜单指定的操作。

可替换的系统菜单命令列表:

NEW = 5;OPEN = 10;QUICKOPEN = 15;SAVE = 20;SAVEAS = 25;CLOSE = 30;CLOSE_ALL = 35;PRINT = 50;PREVIEW = 55;QUIT = 60;

Argument 为任意意义的字符串参数,用户在自定义的类里面可以使用该参数,当然也可以不用。

Classname 增加的菜单项需要执行的类名, 且该类必须实现com.runqian.report4.ide.configmenu.CMAction抽象类。

Text 菜单显示的中文名称

Hotkey 为菜单项指定热键,只能为某个字母,或者 ctrl+字母 两种格式。

CONFIG 系统的配置选项: Splahfile = IDE启动时的splash 画面文件。该文件为类路径上搜索的相对路径。 不指定该选项则不启动splash窗口。

将实现菜单功能的相关类进行远程下载部署

将上述实现的自定义菜单类OneHttpOpenRaq.class以及自定义菜单的配置文件report4config.xml打成jar,按照第二章的流程,进行部署、签名以及下载配置

运行成功后的报表设计器(BS和CS的)

注意: 上面例子里自定义菜单用到的systemconfig.xml、OneHttpOpenRaq.class、runqiansplash.jpg最好单独打包,签名、配置在jnlp文件中,其中: systemconfig.xml需要放在designer\config目录下。 OneHttpOpenRaq.class按照JAVA标准的jar包的目录规则存放。 runqiansplash.jpg根据在systemconfig.xml的目录存放,例子是指定放在designer\config目录下的。

自动控制设计器菜单栏和工具栏

在默认情况下,远程下载的设计器的菜单栏和工具栏都是完整的,但在实际应用中,可能有些菜单项对于客户端用户来说用不上,又或许是希望有些客户不能对某些菜单项进行操作,那么就可以对设计器的某些菜单栏和工具栏进行是否可见控制。

菜单栏和工具栏的自动控制功能由程序员自己编程实现,所有的菜单项都通过GCMenu获取对应的菜单项。

代码例子:

FrameMain mainFram = FrameMain.main0(args);//设置菜单的可视MenuMain menu = (MenuMain)GVIde.appMenu;JMenuItem menuiNEW= menu.getMenuItem(GCMenu.iNEW);menuiNEW.setVisible(false);……… //设置工具栏的可视ToolBarProperty topBar = (ToolBarProperty)GVIde.toolBarProperty;JComponent comp = topBar.getButtonComponent(GCMenu.iNEW);comp.setVisible(false);comp = topBar.getButtonComponent(GCToolBar.iBOLD);comp.setVisible(false);……….mainFram.setVisible(true);mainFram.startAutoRecent();FrameMain.startAutoLogin();

从上面的代码例子可以看出来,我们可以通过GCMenu类里i开头的项,获取相应的菜单项,比如:GCMenu.iNEW。

com.runqian.report4.ide.base.GCMenupublic class GCMenu {//文件public static final String FILE = "file";public static final String NEW = "file.new";public static final String OPEN = "file.open";public static final String QUICKOPEN = "file.quickopen";public static final String SAVE = "file.save";public static final String SAVEAS = "file.saveas";public static final String CLOSE = "file.close";public static final String CLOSE_ALL = "file.closeall";public static final String PRINT = "file.print";public static final String PREVIEW = "file.preview";public static final String QUIT = "file.quit";// public static final short iFILE = 0;public static final short iNEW = 5;public static final short iOPEN = 10;public static final short iQUICKOPEN = 15;public static final short iSAVE = 20;public static final short iSAVEAS = 25;public static final short iCLOSE = 30;public static final short iCLOSE_ALL = 35;public static final short iPRINT = 50;public static final short iPREVIEW = 55;public static final short iQUIT = 60;//导出public static final String EXPORT = "file.export";public static final String EXPORT_EXCEL = "file.export.excel";public static final String EXPORT_EXCEL_PAGE = "file.export.excelPage";public static final String EXPORT_EXCEL_FORMULA = "file.export.excelFormula";public static final String EXPORT_WORD = "file.export.word";public static final String EXPORT_WORD_PAGE = "file.export.wordPage";public static final String EXPORT_PDF = "file.export.pdf";public static final String EXPORT_PDF_PAGE = "file.export.pdfPage";public static final String EXPORT_TEXT = "file.export.text";public static final String EXPORT_XML = "file.export.xml";public static final String RECENT_FILES = "file.recentFiles";public static final String RECENT_CONNS = "file.recentConns";public static final String EXPORT_HTML = "file.export.html";public static final short iEXPORT = 100;public static final short iEXPORT_EXCEL = iEXPORT + ReportExporter.EXPORT_EXCEL;public static final short iEXPORT_EXCEL_PAGE = iEXPORT + ReportExporter.EXPORT_EXCEL_PAGE;public static final short iEXPORT_EXCEL_FORMULA = iEXPORT + ReportExporter.EXPORT_EXCEL_FORMULA;public static final short iEXPORT_WORD = iEXPORT + ReportExporter.EXPORT_WORD;public static final short iEXPORT_WORD_PAGE = iEXPORT +ReportExporter.EXPORT_WORD_PAGE;public static final short iEXPORT_PDF = iEXPORT + ReportExporter.EXPORT_PDF;public static final short iEXPORT_PDF_PAGE = iEXPORT +ReportExporter.EXPORT_PDF_PAGE;public static final short iEXPORT_TEXT = iEXPORT + ReportExporter.EXPORT_TEXT;public static final short iEXPORT_XML = iEXPORT + ReportExporter.EXPORT_XML;public static final short iEXPORT_HTML = iEXPORT + ReportExporter.EXPORT_HTML;// public static final short iRECENT_FILES = 150;// public static final short iRECENT_CONNS = 155;//编辑public static final String EDIT = "edit";public static final String UNDO = "edit.undo";public static final String REDO = "edit.redo";public static final String CUT = "edit.cut";public static final String COPY = "edit.copy";public static final String PASTE = "edit.paste";public static final String DELETE = "edit.delete";public static final String CLEAR_ALL = "edit.clearAll";public static final String CLEAR_FORMAT = "edit.clearFormat";public static final String CLEAR_CONTENT = "edit.clearContent";public static final String CLEAR_INPUT = "edit.clearInput";public static final String SEARCH = "edit.search";public static final String REPLACE = "edit.replace";public static final String CHECKLINEREPORT = "edit.checkLineReport";public static final String CHECKWHOLEREPORT = "edit.checkWholeReport";// public static final short iEDIT = 200;public static final short iUNDO = 205;public static final short iREDO = 210;public static final short iCUT = 215;public static final short iCOPY = 220;public static final short iPASTE = 225; //粘贴格子public static final short iDELETE = 230;public static final short iCLEAR_ALL = 235;public static final short iCLEAR_FORMAT = 240;public static final short iCLEAR_CONTENT = 245;public static final short iCLEAR_INPUT = 246;public static final short iSEARCH = 250;public static final short iREPLACE = 255;public static final short iCHECKLINEREPORT = 275;public static final short iCHECKWHOLEREPORT = 280;//属性public static final String PROPERTY = "property";public static final String PROPERTY_ROW = "property.row";public static final String PROPERTY_COL = "property.col";public static final String PROPERTY_CEL_BORDER = "property.celBorder";public static final String PROPERTY_CEL_DATATYPE = "property.celDatatype";public static final String PROPERTY_CEL_GRAPH = "property.celGraph";public static final String PROPERTY_CEL_SUBREPORT = "property.celSubreport";public static final String PROPERTY_CEL_BARCODE = "property.celBarcode";// public static final String PROPERTY_CEL_FMTSTRING = "property.celFmtString";public static final String PROPERTY_CEL_EXPRESSION = "property.celExpression";public static final String PROPERTY_REPORT = "property.report";public static final String PROPERTY_EXPORT = "property.export";public static final String PROPERTY_PRINT = "property.print";public static final String ATTACHED_DATASETS = "property.attacheddatasets";public static final String REPORTINPUT = "property.reportInput";// public static final short iPROPERTY = 300;public static final short iPROPERTY_ROW = 305;public static final short iPROPERTY_COL = 310;public static final short iPROPERTY_CEL_BORDER = 325;public static final short iPROPERTY_CEL_DATATYPE = 330;public static final short iPROPERTY_CEL_GRAPH = 335;public static final short iPROPERTY_CEL_SUBREPORT = 340;public static final short iPROPERTY_CEL_BARCODE = 345;// public static final short iPROPERTY_CEL_FMTSTRING = 346;public static final short iPROPERTY_CEL_EXPRESSION = 346;public static final short iPROPERTY_REPORT = 350;public static final short iPROPERTY_EXPORT = 355;public static final short iPROPERTY_PRINT = 358;public static final short iATTACHED_DATASETS = 360;public static final short iREPORTINPUT = 365;//插入public static final String INSERT = "insert";public static final String INSERT_BEFOREROW = "insert.insertBeforeRow";// public static final String INSERT_AFTERROW = "insert.insertAfterRow";public static final String INSERT_BEFORECOL = "insert.insertBeforeCol";// public static final String INSERT_AFTERCOL = "insert.insertAfterCol";public static final String ADDROW = "insert.addRow";public static final String ADDCOL = "insert.AddCol";public static final String BACKGROUND = "insert.backGround";public static final String INSERT_DATASET = "insert.dataset";// public static final String INSERTDATASET_GRID = "insert.dataset.grid";// public static final String INSERTDATASET_CROSS = "insert.dataset.cross";// public static final String INSERTDATASET_GROUP = "insert.dataset.group";public static final String INSERT_ROWTYPE = "insert.RowType";public static final String INSERT_COLTYPE = "insert.ColType";// public static final short iINSERT = 400;public static final short iINSERT_BEFOREROW = 405;// public static final short iINSERT_AFTERROW = 406;public static final short iINSERT_BEFORECOL = 410;// public static final short iINSERT_AFTERCOL = 411;public static final short iADDROW = 415;public static final short iADDCOL = 420;public static final short iBACKGROUND = 425;public static final short iINSERT_DATASET = 430;// public static final short iINSERTDATASET_GRID = 440;// public static final short iINSERTDATASET_CROSS = 445;// public static final short iINSERTDATASET_GROUP = 450;public static final short iINSERT_ROWTYPE = 455;public static final short iINSERT_COLTYPE = 456;//配置public static final String CONFIGURE = "configure";public static final String ARGUMENT = "configure.argument";public static final String MACRO = "configure.macro";public static final String DATASET = "configure.dataset";// public static final short iCONFIGURE = 500;public static final short iARGUMENT = 505;public static final short iMACRO = 510;public static final short iDATASET = 515;//系统public static final String SYSTEM = "system";public static final String DATASOURCE = "system.dataSource";public static final String ADDTO_CSSMANAGER = "system.addtocssmanager";public static final String ADDTO_STYLE_CELL = "system.addtostylecell";public static final String IMPORTEXCEL = "system.importExcel";public static final String XMLEDITOR = "system.xmlEditor";public static final String JSPEDITOR = "system.jspEditor";public static final String FUNCEDITOR = "system.funcEditor";public static final String PALETTEEDITOR = "system.paletteEditor";public static final String RAQTRANSFER = "system.raqTransfer";// public static final String RAQGROUP = "system.raqGroup";public static final String OPTION = "system.options";public static final String CONSOLE = "system.console";// public static final short iSYSTEM = 600;public static final short iDATASOURCE = 605;public static final short iADDTO_CSSMANAGER = 610;public static final short iADDTO_STYLE_CELL = 611;public static final short iIMPORTEXCEL = 612;public static final short iXMLEDITOR = 614;public static final short iJSPEDITOR = 615;public static final short iFUNCEDITOR = 616;public static final short iPALETTEEDITOR = 618;public static final short iRAQTRANSFER = 620;// public static final short iRAQGROUP = 621;public static final short iOPTION = 625;public static final short iCONSOLE = 630;//模板public static final String TEMPLATE = "template";public static final String SAVETO_TEMPLATE = "template.saveAsTemplate";public static final String TIDY_TEMPLATE = "template.tidyTemplate";// public static final short iTEMPLATE = 700;public static final short iSAVETO_TEMPLATE = 705;public static final short iTIDY_TEMPLATE = 710;//语义层public static final String SEMANTICS = "semantics";public static final String SEMANTICSOPEN = "semantics.open";public static final String SEMANTICSCLOSE = "semantics.close";public static final String SEMANTICSRECENT = "semantics.recent";public static final String SEMANTICSEDITOR = "semantics.editor";public static final String SEMANTICSTRANSLATOR = "semantics.translator";public static final String SEMANTICSREFRESH = "semantics.refresh";public static final String EDITENUMGROUP = "semantics.editenumgroup";public static final String SEMANTICSEXPAND = "semantics.expand";public static final String SEMANTICSSESSION = "semantics.sessionvariable";// public static final short iTOOLS = 800;public static final short iSEMANTICSOPEN = 805;public static final short iSEMANTICSCLOSE = 806;public static final short iSEMANTICSRECENT = 807;public static final short iSEMANTICSEDITOR = 815;public static final short iSEMANTICSTRANSLATOR = 816;public static final short iSEMANTICSREFRESH = 817;public static final short iEDITENUMGROUP = 821;public static final short iSEMANTICSEXPAND = 823;public static final short iSEMANTICSSESSION = 825;//远程设计public static final String REMOTE = "remote";public static final String REMOTE_LOGIN = "remote.login";public static final String REMOTE_LOGOUT = "remote.logout";public static final String REMOTE_OPEN = "remote.open";public static final String REMOTE_SAVE = "remote.save";public static final String REMOTE_SAVEAS = "remote.saveas";public static final String REMOTE_GETSEMANTICS = "remote.getsemantics";public static final String REMOTE_SESSIONVARIABLE = "remote.sessionvariable";public static final short iREMOTE_LOGIN = 850;public static final short iREMOTE_LOGOUT = 851;public static final short iREMOTE_OPEN = 852;public static final short iREMOTE_SAVE = 853;public static final short iREMOTE_SAVEAS = 854;public static final short iREMOTE_GETSEMANTICS = 855;public static final short iREMOTE_SESSIONVARIABLE = 856;//窗口public static final String WINDOW = "window";public static final String CASCADE = "window.cascade"; //层叠(C)public static final String TILEHORIZONTAL = "window.tileHorizontal"; //水平平铺(H)public static final String TILEVERTICAL = "window.tileVertical"; //垂直平铺(V)public static final String LAYER = "window.layer"; //填充(L)// public static final short iWINDOW = 900;public static final short iCASCADE = 905;public static final short iTILEHORIZONTAL = 910; //水平平铺(H)public static final short iTILEVERTICAL = 915; //垂直平铺(V)public static final short iLAYER = 920; //填充(L)//帮助public static final String HELP = "help";public static final String ABOUT = "help.about";public static final String MEMORYTIDY = "help.memoryTidy";// public static final short iHELP = 1000;public static final short iABOUT = 1005;public static final short iMEMORYTIDY = 1010;public static javax.swing.ImageIcon getImageIcon(String menuId) {String iconText;int dot = menuId.indexOf(".");if (dot > 0) {iconText = menuId.substring(dot + 1);}else {iconText = menuId;}String iconPath = GC.IMAGES_PATH + "m_" + iconText.toLowerCase() + ".gif";return GM.getImageIcon(iconPath);}}