|
|
|
@ -1,15 +1,6 @@
|
|
|
|
|
package com.fr.design.menu; |
|
|
|
|
|
|
|
|
|
import com.fr.design.DesignState; |
|
|
|
|
import com.fr.design.actions.MenuAction; |
|
|
|
|
import com.fr.file.XMLFileManager; |
|
|
|
|
import com.fr.general.FRLogger; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
import com.fr.stable.xml.XMLPrintWriter; |
|
|
|
|
import com.fr.stable.xml.XMLReadable; |
|
|
|
|
import com.fr.stable.xml.XMLableReader; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Created by IntelliJ IDEA. |
|
|
|
@ -18,24 +9,18 @@ import java.util.ArrayList;
|
|
|
|
|
* Date: 13-12-23 |
|
|
|
|
* Time: 下午5:25 |
|
|
|
|
*/ |
|
|
|
|
public class MenuManager extends XMLFileManager { |
|
|
|
|
|
|
|
|
|
public class MenuManager { |
|
|
|
|
|
|
|
|
|
private static MenuManager menuManager = null; |
|
|
|
|
//文件、模板、插入、单元格、服务器、帮助六大菜单
|
|
|
|
|
public static final int FILE = 0; |
|
|
|
|
public static final int TEMPLATE = 1; |
|
|
|
|
public static final int INSERT = 2; |
|
|
|
|
public static final int CELL = 3; |
|
|
|
|
public static final int SERVER = 4; |
|
|
|
|
private static final int INSERT = 2; |
|
|
|
|
private static final int CELL = 3; |
|
|
|
|
private static final int SERVER = 4; |
|
|
|
|
public static final int HELP = 5; |
|
|
|
|
private static final boolean[] DEFAULT_TOP_MENUS = new boolean[]{true, true, true, true, true, true}; |
|
|
|
|
|
|
|
|
|
private boolean[] topMenuVisibleGroup = DEFAULT_TOP_MENUS; |
|
|
|
|
|
|
|
|
|
private ArrayList<MenuDef> menus = new ArrayList<MenuDef>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public synchronized static MenuManager getInstance() { |
|
|
|
|
if (menuManager == null) { |
|
|
|
|
menuManager = new MenuManager(); |
|
|
|
@ -43,24 +28,13 @@ public class MenuManager extends XMLFileManager {
|
|
|
|
|
return menuManager; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public MenuManager() { |
|
|
|
|
private MenuManager() { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public ArrayList<MenuDef> getXMLMenus() { |
|
|
|
|
menus.clear(); |
|
|
|
|
menuManager.readXMLFile(); |
|
|
|
|
return menus; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean[] getTopMenuVisibleGroup() { |
|
|
|
|
return topMenuVisibleGroup; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//菜单的16种情况
|
|
|
|
|
public void setMenus4Designer(DesignState state) { |
|
|
|
|
topMenuVisibleGroup = DEFAULT_TOP_MENUS; |
|
|
|
|
boolean[] topMenuVisibleGroup = DEFAULT_TOP_MENUS; |
|
|
|
|
int designSate = state.getDesignState(); |
|
|
|
|
boolean isFormLayout = designSate == DesignState.PARAMETER_PANE || designSate == DesignState.JFORM; |
|
|
|
|
if (isFormLayout || (designSate == DesignState.POLY_SHEET)) { |
|
|
|
@ -79,96 +53,4 @@ public class MenuManager extends XMLFileManager {
|
|
|
|
|
topMenuVisibleGroup[SERVER] = state.isRoot(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 文件名 |
|
|
|
|
* @return 文件名 |
|
|
|
|
*/ |
|
|
|
|
public String fileName() { |
|
|
|
|
return "menu.xml"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void readXML(XMLableReader reader) { |
|
|
|
|
if (reader.getTagName().equals("MenuBar")) { |
|
|
|
|
reader.readXMLObject(new XMLReadable() { |
|
|
|
|
@Override |
|
|
|
|
public void readXML(XMLableReader reader) { |
|
|
|
|
readTopMenus(reader); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void readTopMenus(XMLableReader reader) { |
|
|
|
|
if (reader.isChildNode()) { |
|
|
|
|
if (reader.getTagName().equals("Menu")) { |
|
|
|
|
//最顶端的Menus
|
|
|
|
|
final MenuDef topMenu = new MenuDef(); |
|
|
|
|
String tmpVal; |
|
|
|
|
if ((tmpVal = reader.getAttrAsString("name", StringUtils.EMPTY)) != StringUtils.EMPTY) { |
|
|
|
|
topMenu.setName(tmpVal); |
|
|
|
|
} |
|
|
|
|
if ((tmpVal = reader.getAttrAsString("mnemonic", StringUtils.EMPTY)) != StringUtils.EMPTY) { |
|
|
|
|
topMenu.setMnemonic(tmpVal.charAt(0)); |
|
|
|
|
} |
|
|
|
|
if ((tmpVal = reader.getAttrAsString("iconPath", StringUtils.EMPTY)) != StringUtils.EMPTY) { |
|
|
|
|
topMenu.setIconPath(tmpVal); |
|
|
|
|
} |
|
|
|
|
menus.add(topMenu); |
|
|
|
|
reader.readXMLObject(new XMLReadable() { |
|
|
|
|
@Override |
|
|
|
|
public void readXML(XMLableReader reader) { |
|
|
|
|
readSubMenus(reader, topMenu); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void readSubMenus(XMLableReader reader, MenuDef menu) { |
|
|
|
|
if (reader.isChildNode()) { |
|
|
|
|
if (reader.getTagName().equals("Action")) { |
|
|
|
|
String name = StringUtils.EMPTY, tmpVal = StringUtils.EMPTY; |
|
|
|
|
if ((tmpVal = reader.getAttrAsString("class", StringUtils.EMPTY)) != StringUtils.EMPTY) { |
|
|
|
|
name = tmpVal; |
|
|
|
|
} |
|
|
|
|
//读取模板数据集菜单
|
|
|
|
|
if (name.isEmpty()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
MenuAction action = (MenuAction) reader.getAttrAsClass().newInstance(); |
|
|
|
|
menu.addShortCut(action); |
|
|
|
|
} catch (Exception exp) { |
|
|
|
|
FRLogger.getLogger().error(exp.getMessage(), exp); |
|
|
|
|
} |
|
|
|
|
} else if (reader.getTagName().equals("Menu")) { |
|
|
|
|
final MenuDef submenu = new MenuDef(); |
|
|
|
|
String tmpVal = StringUtils.EMPTY; |
|
|
|
|
if ((tmpVal = reader.getAttrAsString("name", StringUtils.EMPTY)) != StringUtils.EMPTY) { |
|
|
|
|
submenu.setName(tmpVal); |
|
|
|
|
} |
|
|
|
|
if ((tmpVal = reader.getAttrAsString("mnemonic", StringUtils.EMPTY)) != StringUtils.EMPTY) { |
|
|
|
|
submenu.setMnemonic(tmpVal.charAt(0)); |
|
|
|
|
} |
|
|
|
|
if ((tmpVal = reader.getAttrAsString("iconPath", StringUtils.EMPTY)) != StringUtils.EMPTY) { |
|
|
|
|
submenu.setIconPath(tmpVal); |
|
|
|
|
} |
|
|
|
|
menu.addShortCut(submenu); |
|
|
|
|
reader.readXMLObject(new XMLReadable() { |
|
|
|
|
@Override |
|
|
|
|
public void readXML(XMLableReader reader) { |
|
|
|
|
readSubMenus(reader, submenu); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void writeXML(XMLPrintWriter writer) { |
|
|
|
|
} |
|
|
|
|
} |