?? icswriter.java
字號:
package com.corba.mnq.xls;
import com.corba.mnq.main.CorbaMNQ;
import com.corba.mnq.tool.idl.Args;
import com.corba.mnq.tool.idl.IdlAttribute;
import com.corba.mnq.tool.idl.IdlConstant;
import com.corba.mnq.tool.idl.IdlExcept;
import com.corba.mnq.tool.idl.IdlFile;
import com.corba.mnq.tool.idl.IdlInterface;
import com.corba.mnq.tool.idl.IdlModule;
import com.corba.mnq.tool.idl.IdlOperation;
import com.corba.mnq.tool.idl.IdlType;
import com.corba.mnq.ui.MNQMutableTreeNode;
import javax.swing.JCheckBox;
import java.io.File;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class IcsWriter {
public static Map node2check = new Hashtable();
private static common.Logger logger = common.Logger.getLogger(IcsWriter.class);
private File file;
private WritableWorkbook outBook;
private WritableSheet specSheet;
private WritableSheet reportSheet;
private int currentLine = 1; // 0 was reserved as title
private int[] typeNum = { 0, 0, 0, 0, 0, 0, 0, 0 };
private boolean open(String fileName) {
try {
logger.setSuppressWarnings(Boolean.getBoolean("jxl.nowarnings"));
String temp = CorbaMNQ.ossDir + File.separator + "etc" + File.separator + "TS.data";
File input = new File(temp);
file = new File(fileName);
Workbook inBook = Workbook.getWorkbook(input);
outBook = Workbook.createWorkbook(file, inBook);
inBook.close();
specSheet = outBook.getSheet("TestSpec");
reportSheet = outBook.getSheet("TestReport");
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
return true;
}
private boolean writeNode(String id, String name, String type, String mo, String result) {
Label lb1 = new Label(0, currentLine, id);
Label lb2 = new Label(1, currentLine, name);
Label lb3 = new Label(2, currentLine, type);
Label lb4 = new Label(3, currentLine, mo);
Label lb5 = new Label(4, currentLine, result);
try {
specSheet.addCell(lb1);
specSheet.addCell(lb2);
specSheet.addCell(lb3);
specSheet.addCell(lb4);
specSheet.addCell(lb5);
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
currentLine++;
return true;
}
public boolean close() {
try {
outBook.write();
outBook.close();
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
return true;
}
private boolean genNodeSpec(MNQMutableTreeNode node, String id) {
JCheckBox check = (JCheckBox) node2check.get(node);
if (!check.isSelected())
return true;
Object o = node.getUserObject();
String name = o.toString();
String om = "M";
String result = "UnTested";
String type = "Other";
if (o instanceof IdlFile) {
type = "File";
typeNum[0]++;
} else if (o instanceof IdlModule) {
type = "Module";
typeNum[1]++;
} else if (o instanceof IdlInterface) {
type = "Interface";
typeNum[2]++;
} else if (o instanceof IdlExcept) {
type = "Exception";
typeNum[3]++;
} else if (o instanceof IdlConstant) {
type = "Constant";
typeNum[4]++;
} else if (o instanceof IdlOperation) {
type = "Operation";
typeNum[5]++;
} else if (o instanceof IdlAttribute) {
type = "Attribute";
typeNum[6]++;
} else if (o instanceof IdlType) {
type = "Parameter";
typeNum[7]++;
} else {
type = "Other";
}
if (!type.equals("Other")) {
if (!writeNode(id, name, type, om, result))
return false;
}
if (!node.isLeaf()) {
int i = 1;
for (Enumeration e = node.children(); e.hasMoreElements();) {
MNQMutableTreeNode sub = (MNQMutableTreeNode) e.nextElement();
if (!genNodeSpec(sub, id + "." + i))
return false;
i++;
}
}
if (o instanceof IdlOperation) {
IdlOperation op = (IdlOperation) o;
List ls = op.getParametersNode();
int j = 1;
for (int i = 0; i < ls.size(); i++) {
Args args = (Args) ls.get(i);
if (!writeNode(id + "." + (j + 1), args.cName, "Parameter", om, result))
return false;
j++;
}
List ls1 = op.getExceptions();
for (int i = 0; i < ls1.size(); i++) {
Object ext = ls1.get(i);
if (!writeNode(id + "." + (j + 1), ext.toString(), "Exception", om, result))
return false;
j++;
}
}
return true;
}
private boolean genReport() {
for (int j = 2; j < 8; j++) {
for (int i = 1; i < 9; i++) {
Number n = (Number) reportSheet.getWritableCell(j, i);
if (j == 2 || j == 7) // m or untested
n.setValue(typeNum[i - 1]);
else
// other
n.setValue(0);
}
}
return true;
}
public boolean genSpec(MNQMutableTreeNode root, String file) {
if (!open(file))
return false;
if (!root.isLeaf()) {
int i = 1;
for (Enumeration e = root.children(); e.hasMoreElements();) {
MNQMutableTreeNode node = (MNQMutableTreeNode) e.nextElement();
JCheckBox check = (JCheckBox) node2check.get(node);
if (!check.isSelected())
continue;
if (!genNodeSpec(node, "" + i))
return false;
i++;
}
}
// if( !genReport()) return false;
return close();
}
/**
* @param args
*/
public static void main_(String[] args) {
// TODO Auto-generated method stub
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -