9 changed files with 2920 additions and 0 deletions
@ -0,0 +1,170 @@ |
|||||||
|
package com.fr.design.write.submit.batch; |
||||||
|
|
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
import com.fr.general.xml.GeneralXMLTools; |
||||||
|
import com.fr.js.AbstractJavaScript; |
||||||
|
import com.fr.js.Callback; |
||||||
|
import com.fr.js.JavaScript; |
||||||
|
import com.fr.js.JavaScriptXMLUtils; |
||||||
|
import com.fr.json.JSONObject; |
||||||
|
import com.fr.stable.ParameterProvider; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
import com.fr.stable.web.Repository; |
||||||
|
import com.fr.stable.xml.XMLPrintWriter; |
||||||
|
import com.fr.stable.xml.XMLableReader; |
||||||
|
import com.fr.write.batch.SubmitMain; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by loy on 16/8/22. |
||||||
|
*/ |
||||||
|
public class BatchCommit2DBJavaScript extends AbstractJavaScript implements Callback { |
||||||
|
|
||||||
|
public static String RECALCULATE_TAG = "shouldRecalculate"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 回调函数标识 |
||||||
|
*/ |
||||||
|
public static final String CALLBACK = "callback"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 回调参数标识 |
||||||
|
*/ |
||||||
|
public static final String FEEDBACKMAP = "feedbackMap"; |
||||||
|
|
||||||
|
/** |
||||||
|
* javascript所使用的参数 |
||||||
|
*/ |
||||||
|
protected ParameterProvider[] parameters; |
||||||
|
//这个MAP里放的是提交过程生成的参数,比如提交入库,在所有回调事件里,都会将其传递进去,以供解析。
|
||||||
|
protected Map<Object, Object> paraMap = new HashMap<Object, Object>(); |
||||||
|
|
||||||
|
private boolean recalculate; |
||||||
|
|
||||||
|
private List dbManipulationList = new ArrayList(); |
||||||
|
//回调函数
|
||||||
|
private JavaScript callBack; |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取数据入库配置信息 |
||||||
|
*/ |
||||||
|
public List getDBManipulation() { |
||||||
|
return dbManipulationList; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置数据入库配置信息 |
||||||
|
* |
||||||
|
* @param dbManipulationList 数据库配置信息 |
||||||
|
*/ |
||||||
|
public void setDBManipulation(List dbManipulationList) { |
||||||
|
this.dbManipulationList = dbManipulationList; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 回调函数,该函数将在主函数执行完毕以后开始执行 |
||||||
|
*/ |
||||||
|
public JavaScript getCallBack() { |
||||||
|
return callBack; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置回调函数 |
||||||
|
* |
||||||
|
* @param callback 回调函数 |
||||||
|
*/ |
||||||
|
public void setCallBack(JavaScript callback) { |
||||||
|
this.callBack = callback; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* JS响应 |
||||||
|
* |
||||||
|
* @param repo 环境 |
||||||
|
* @return 返回生成的JS字符串 |
||||||
|
*/ |
||||||
|
public String actionJS(Repository repo) { |
||||||
|
String dmlconf = GeneralXMLTools.writeXMLableAsString(this); |
||||||
|
if (!this.paraMap.isEmpty() && callBack != null) { |
||||||
|
callBack.addParameterMap(paraMap); |
||||||
|
} |
||||||
|
String js = "var fm = this.options.form;if(fm == null) {fm = new FR.BatchForm()};fm.batchCommit({" + |
||||||
|
"xmlconf" + ":" + JSONObject.quote(dmlconf) + |
||||||
|
(callBack != null ? "," + CALLBACK + ":" + JSONObject.quote(GeneralXMLTools.writeXMLableAsString(callBack)) : "") + |
||||||
|
(this.paraMap.isEmpty() ? "" : "," + FEEDBACKMAP + ":" + new JSONObject(paraMap).toString()) + |
||||||
|
"},this)"; |
||||||
|
return js; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 转化为字符串 |
||||||
|
* |
||||||
|
* @return 返回字符串形式 |
||||||
|
*/ |
||||||
|
public String toString() { |
||||||
|
return (dbManipulationList == null) ? StringUtils.EMPTY : dbManipulationList.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
public void writeXML(XMLPrintWriter writer) { |
||||||
|
super.writeXML(writer); |
||||||
|
|
||||||
|
if (this.dbManipulationList != null) { |
||||||
|
for (int i = 0; i < dbManipulationList.size(); i++) { |
||||||
|
((SubmitMain) this.dbManipulationList.get(i)).writeXML(writer); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
if (this.callBack != null) { |
||||||
|
GeneralXMLTools.writeXMLable(writer, this.callBack, JavaScript.XML_TAG); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void readXML(XMLableReader reader) { |
||||||
|
super.readXML(reader); |
||||||
|
|
||||||
|
if (reader.isAttr()) { |
||||||
|
dbManipulationList = new ArrayList(); |
||||||
|
} else if (reader.isChildNode()) { |
||||||
|
String tagName = reader.getTagName(); |
||||||
|
if (JavaScript.XML_TAG.equals(tagName)) { |
||||||
|
this.callBack = JavaScriptXMLUtils.readJavaScript(reader); |
||||||
|
} else { |
||||||
|
if ("Attributes".equals(tagName)) { |
||||||
|
dbManipulationList.add(new SubmitMain()); |
||||||
|
} |
||||||
|
if (dbManipulationList.size() > 0) { |
||||||
|
((SubmitMain) dbManipulationList.get(dbManipulationList.size() - 1)).readXML(reader); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public boolean equals(Object obj) { |
||||||
|
return obj instanceof BatchCommit2DBJavaScript |
||||||
|
&& super.equals(obj) |
||||||
|
&& ComparatorUtils.equals(((BatchCommit2DBJavaScript) obj).callBack, this.callBack) |
||||||
|
&& ComparatorUtils.equals(((BatchCommit2DBJavaScript) obj).dbManipulationList, this.dbManipulationList); |
||||||
|
} |
||||||
|
|
||||||
|
public Object clone() throws CloneNotSupportedException { |
||||||
|
BatchCommit2DBJavaScript cloned = (BatchCommit2DBJavaScript) super.clone(); |
||||||
|
if (this.dbManipulationList != null) { |
||||||
|
cloned.dbManipulationList = new ArrayList(); |
||||||
|
for (int i = 0; i < this.dbManipulationList.size(); i++) { |
||||||
|
cloned.dbManipulationList.add(((SubmitMain) this.dbManipulationList.get(i)).clone()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (this.callBack != null) { |
||||||
|
cloned.callBack = (JavaScript) this.callBack.clone(); |
||||||
|
} |
||||||
|
|
||||||
|
return cloned; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,186 @@ |
|||||||
|
package com.fr.design.write.submit.batch; |
||||||
|
|
||||||
|
import com.fr.design.beans.FurtherBasicBeanPane; |
||||||
|
import com.fr.design.gui.ibutton.UIButton; |
||||||
|
import com.fr.design.javascript.JavaScriptActionPane; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.write.batch.SubmitMain; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import java.awt.*; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by loy on 16/8/22. |
||||||
|
*/ |
||||||
|
public class BatchCommit2DBJavaScriptPane extends FurtherBasicBeanPane<BatchCommit2DBJavaScript> { |
||||||
|
private List dbmPaneList = new ArrayList(); |
||||||
|
private BatchCommitTabbedPane commitTabbedPane; |
||||||
|
private JavaScriptActionPane javaScriptActionPane; |
||||||
|
private UIButton addCallbackButton; |
||||||
|
|
||||||
|
private JPanel cardPane; |
||||||
|
private String[] cardNames; |
||||||
|
|
||||||
|
/** |
||||||
|
* 构造函数,控件事件的提交入库面板 |
||||||
|
*/ |
||||||
|
public BatchCommit2DBJavaScriptPane() { |
||||||
|
init(null); |
||||||
|
} |
||||||
|
|
||||||
|
// public BatchCommit2DBJavaScriptPane(final JavaScriptActionPane javaScriptActionPane, List dbManipulationPaneList) {
|
||||||
|
public BatchCommit2DBJavaScriptPane(final JavaScriptActionPane javaScriptActionPane) { |
||||||
|
// this.dbmPaneList=dbManipulationPaneList;
|
||||||
|
init(javaScriptActionPane); |
||||||
|
} |
||||||
|
|
||||||
|
private void init(final JavaScriptActionPane javaScriptActionPane) { |
||||||
|
this.dbmPaneList.add(new BatchSubmitPane()); |
||||||
|
this.javaScriptActionPane = javaScriptActionPane; |
||||||
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
commitTabbedPane = new BatchCommitTabbedPane(this, dbmPaneList); |
||||||
|
commitTabbedPane.setPreferredSize(new Dimension(commitTabbedPane.getWidth(), 20)); |
||||||
|
this.add(commitTabbedPane, BorderLayout.NORTH); |
||||||
|
|
||||||
|
cardPane = new JPanel(new CardLayout()); |
||||||
|
cardNames = new String[dbmPaneList.size()]; |
||||||
|
for (int i = 0; i < this.dbmPaneList.size(); i++) { |
||||||
|
if (((BatchSubmitPane) this.dbmPaneList.get(i)).getSubMitName() == null) { |
||||||
|
cardNames[i] = ""; |
||||||
|
} else { |
||||||
|
cardNames[i] = ((BatchSubmitPane) this.dbmPaneList.get(i)).getSubMitName(); |
||||||
|
} |
||||||
|
cardPane.add((BatchSubmitPane) this.dbmPaneList.get(i), cardNames[i]); |
||||||
|
} |
||||||
|
this.add(cardPane, BorderLayout.CENTER); |
||||||
|
|
||||||
|
JPanel btPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
||||||
|
this.add(btPane, BorderLayout.SOUTH); |
||||||
|
|
||||||
|
if (javaScriptActionPane != null) { |
||||||
|
addCallbackButton = javaScriptActionPane.createCallButton(); |
||||||
|
btPane.add(addCallbackButton); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 更新DBManipulationPane |
||||||
|
*/ |
||||||
|
public void updateCardPane() { |
||||||
|
cardNames = new String[dbmPaneList.size()]; |
||||||
|
for (int i = 0; i < this.dbmPaneList.size(); i++) { |
||||||
|
if (((BatchSubmitPane) this.dbmPaneList.get(i)).getSubMitName() == null) { |
||||||
|
cardNames[i] = ""; |
||||||
|
} else { |
||||||
|
cardNames[i] = ((BatchSubmitPane) this.dbmPaneList.get(i)).getSubMitName(); |
||||||
|
} |
||||||
|
cardPane.add((BatchSubmitPane) this.dbmPaneList.get(i), cardNames[i]); |
||||||
|
} |
||||||
|
CardLayout cardLayout = (CardLayout) cardPane.getLayout(); |
||||||
|
cardLayout.show(cardPane, cardNames[commitTabbedPane.getSelectedIndex()]); |
||||||
|
} |
||||||
|
|
||||||
|
public void setList(List list) { |
||||||
|
this.dbmPaneList = list; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 新建DBManipulationPane |
||||||
|
* |
||||||
|
* @return 新建的DBManipulationPane |
||||||
|
*/ |
||||||
|
public BatchSubmitPane createDBManipulationPane() { |
||||||
|
BatchSubmitPane db = new BatchSubmitPane(); |
||||||
|
// BatchSubmitPane db = javaScriptActionPane.createDBManipulationPane();
|
||||||
|
db.populateBean(null); |
||||||
|
dbmPaneList.add(db); |
||||||
|
return db; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 窗口名称 |
||||||
|
* |
||||||
|
* @return 返回窗口名称 |
||||||
|
*/ |
||||||
|
public String title4PopupWindow() { |
||||||
|
return Inter.getLocText("Performance-plugin_submitbatch_name"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 界面重置 |
||||||
|
*/ |
||||||
|
public void reset() { |
||||||
|
if (javaScriptActionPane != null) { |
||||||
|
this.javaScriptActionPane.setCall(null); |
||||||
|
} |
||||||
|
//重置后只保留,只留第一个tab
|
||||||
|
while (dbmPaneList.size() > 1) { |
||||||
|
dbmPaneList.remove(1); |
||||||
|
} |
||||||
|
((BatchSubmitPane) dbmPaneList.get(0)).populateBean(null); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
/** |
||||||
|
* 将JavaBean内的数据输出至界面上 |
||||||
|
*/ |
||||||
|
public void populateBean(BatchCommit2DBJavaScript commit2db) { |
||||||
|
if (commit2db == null) { |
||||||
|
reset(); |
||||||
|
return; |
||||||
|
} |
||||||
|
//先把原来的list清除,然后再根据传入参数重新add
|
||||||
|
dbmPaneList.clear(); |
||||||
|
if (javaScriptActionPane != null) { |
||||||
|
this.javaScriptActionPane.setCall(commit2db.getCallBack()); |
||||||
|
} |
||||||
|
for (int i = 0; i < commit2db.getDBManipulation().size(); i++) { |
||||||
|
BatchSubmitPane dbmp = new BatchSubmitPane(); |
||||||
|
// BatchSubmitPane dbmp = javaScriptActionPane.createDBManipulationPane();
|
||||||
|
dbmp.populateBean((SubmitMain) commit2db.getDBManipulation().get(i)); |
||||||
|
dbmPaneList.add(dbmp); |
||||||
|
} |
||||||
|
commitTabbedPane.refreshTab(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 更新数据层JavaBean |
||||||
|
* |
||||||
|
* @return 返回JavaBean |
||||||
|
*/ |
||||||
|
public BatchCommit2DBJavaScript updateBean() { |
||||||
|
BatchCommit2DBJavaScript commit2dbJavaScript = new BatchCommit2DBJavaScript(); |
||||||
|
|
||||||
|
List dbmaniList = new ArrayList(); |
||||||
|
for (int i = 0; i < this.dbmPaneList.size(); i++) { |
||||||
|
BatchSubmitPane dbmpane = (BatchSubmitPane) this.dbmPaneList.get(i); |
||||||
|
if (i > dbmPaneList.size() - 1) { |
||||||
|
dbmPaneList.add(dbmpane); |
||||||
|
} |
||||||
|
SubmitMain dbManipulation = dbmpane.updateBean(); |
||||||
|
dbmaniList.add(dbManipulation); |
||||||
|
} |
||||||
|
commit2dbJavaScript.setDBManipulation(dbmaniList); |
||||||
|
|
||||||
|
if (javaScriptActionPane != null) { |
||||||
|
commit2dbJavaScript.setCallBack(this.javaScriptActionPane.getCall()); |
||||||
|
} |
||||||
|
|
||||||
|
return commit2dbJavaScript; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断是否是能接受的数据类型 |
||||||
|
* |
||||||
|
* @param ob 对象 |
||||||
|
* @return 返回是否是能接受的数据类型 |
||||||
|
*/ |
||||||
|
public boolean accept(Object ob) { |
||||||
|
return ob instanceof BatchCommit2DBJavaScript; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,529 @@ |
|||||||
|
package com.fr.design.write.submit.batch; |
||||||
|
|
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
import com.fr.design.constants.UIConstants; |
||||||
|
import com.fr.design.gui.ibutton.UIButton; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
import com.fr.general.Inter; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import java.awt.*; |
||||||
|
import java.awt.event.*; |
||||||
|
import java.awt.geom.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by loy on 16/8/22. |
||||||
|
*/ |
||||||
|
public class BatchCommitTabbedPane extends JComponent implements MouseListener, MouseMotionListener { |
||||||
|
private Icon closeIcon = BaseUtils.readIcon("com/fr/design/images/gui/tab_delete.png"); |
||||||
|
private static final Icon ADD_NORMAL = BaseUtils.readIcon("com/fr/design/images/gui/tab_add_normal.png"); |
||||||
|
private static final Icon ADD_OVER = BaseUtils.readIcon("com/fr/design/images/gui/tab_add_hover.png"); |
||||||
|
private static final Icon ADD_CLICK = BaseUtils.readIcon("com/fr/design/images/gui/tab_add_click.png"); |
||||||
|
private static final Image DESIGN_IMAGE = BaseUtils.readImage("com/fr/design/images/sheet/left_right_btn.png"); |
||||||
|
private static final Icon LEFT_ICON = BaseUtils.createIcon(DESIGN_IMAGE, 0, 0, 14, 14); |
||||||
|
private static final Icon RIGHT_ICON = BaseUtils.createIcon(DESIGN_IMAGE, 14, 0, 14, 14); |
||||||
|
private static final Icon DISABLED_LEFT_ICON = BaseUtils.createIcon(DESIGN_IMAGE, 0, 14, 14, 14); |
||||||
|
private static final Icon DISABLED_RIGHT_ICON = BaseUtils.createIcon(DESIGN_IMAGE, 14, 14, 14, 14); |
||||||
|
private Icon addIcon = ADD_NORMAL; |
||||||
|
|
||||||
|
private static final int TOOLBAR_HEIGHT = 16; // 按钮高度
|
||||||
|
private static final int GAP = 5; //间隔
|
||||||
|
private static final int SMALLGAP = 3; |
||||||
|
|
||||||
|
private static final int FIRST_TAB_POSITION = 20; |
||||||
|
|
||||||
|
|
||||||
|
// 左移和右移按钮
|
||||||
|
private UIButton leftButton; |
||||||
|
private UIButton rightButton; |
||||||
|
|
||||||
|
private JPanel buttonPane; |
||||||
|
|
||||||
|
private java.util.List dbManipulationPaneList ; |
||||||
|
|
||||||
|
private BatchCommit2DBJavaScriptPane commit2DBJavaScriptPane; |
||||||
|
|
||||||
|
// 能显示的tab个数
|
||||||
|
private int showCount = 0; |
||||||
|
|
||||||
|
//选了30度和60度的特殊角度的x,y作为经过的两个点的坐标
|
||||||
|
private double specialLocation1 = 2.5; |
||||||
|
private double specialLocation2 = 4.330127; |
||||||
|
|
||||||
|
private int mouseOveredIndex = -1; |
||||||
|
|
||||||
|
private int selectedIndex = -1; |
||||||
|
|
||||||
|
private static final double CORNOR_RADIUS = 5.0; |
||||||
|
|
||||||
|
|
||||||
|
//tab栏可以放下的每个tab的实际宽度
|
||||||
|
private int tabWidth = 70; |
||||||
|
|
||||||
|
|
||||||
|
//当前标签页栏存放的所有标签页的index
|
||||||
|
private int scrollIndex = 0; |
||||||
|
private int lastOneIndex = 0; |
||||||
|
|
||||||
|
//添加标签位置
|
||||||
|
private int addX = -1; |
||||||
|
private int addY = -1; |
||||||
|
|
||||||
|
|
||||||
|
//各删除标签位置
|
||||||
|
private int[] closeIconStartX; |
||||||
|
|
||||||
|
|
||||||
|
public BatchCommitTabbedPane(BatchCommit2DBJavaScriptPane commit2DBJavaScriptPane, java.util.List dbManipulationPaneList ){ |
||||||
|
this.commit2DBJavaScriptPane = commit2DBJavaScriptPane; |
||||||
|
this.dbManipulationPaneList = dbManipulationPaneList; |
||||||
|
this.setLayout(new BorderLayout(0, 0)); |
||||||
|
this.addMouseListener(this); |
||||||
|
this.addMouseMotionListener(this); |
||||||
|
this.setBorder(null); |
||||||
|
this.setForeground(new Color(99, 99, 99)); |
||||||
|
leftButton = new UIButton(LEFT_ICON) { |
||||||
|
public Dimension getPreferredSize() { |
||||||
|
return new Dimension(super.getPreferredSize().width, TOOLBAR_HEIGHT); |
||||||
|
} |
||||||
|
}; |
||||||
|
leftButton.set4ToolbarButton(); |
||||||
|
leftButton.setDisabledIcon(DISABLED_LEFT_ICON); |
||||||
|
rightButton = new UIButton(RIGHT_ICON) { |
||||||
|
public Dimension getPreferredSize() { |
||||||
|
return new Dimension(super.getPreferredSize().width, TOOLBAR_HEIGHT); |
||||||
|
} |
||||||
|
}; |
||||||
|
rightButton.set4ToolbarButton(); |
||||||
|
rightButton.setDisabledIcon(DISABLED_RIGHT_ICON); |
||||||
|
buttonPane = new JPanel(new BorderLayout(3, 0)); |
||||||
|
buttonPane.add(rightButton, BorderLayout.EAST); |
||||||
|
buttonPane.add(leftButton, BorderLayout.CENTER); |
||||||
|
this.add(buttonPane, BorderLayout.EAST); |
||||||
|
leftButton.addActionListener(createLeftButtonActionListener()); |
||||||
|
rightButton.addActionListener(createRightButtonActionListener()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private ActionListener createRightButtonActionListener(){ |
||||||
|
return new ActionListener() { |
||||||
|
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
int tabCount = getTabCount(); |
||||||
|
if (lastOneIndex < tabCount && lastOneIndex + showCount <= tabCount) { |
||||||
|
scrollIndex += showCount; |
||||||
|
lastOneIndex += showCount; |
||||||
|
selectedIndex = lastOneIndex; |
||||||
|
} else if(lastOneIndex < tabCount && lastOneIndex + showCount > tabCount){ |
||||||
|
lastOneIndex = tabCount -1; |
||||||
|
scrollIndex = lastOneIndex - showCount; |
||||||
|
selectedIndex = lastOneIndex; |
||||||
|
} |
||||||
|
repaint(); |
||||||
|
} |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
private ActionListener createLeftButtonActionListener() { |
||||||
|
return new ActionListener() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
if(scrollIndex >= showCount) { |
||||||
|
scrollIndex -= showCount; |
||||||
|
selectedIndex = scrollIndex; |
||||||
|
lastOneIndex -= showCount; |
||||||
|
} else if (scrollIndex > 0 && scrollIndex< showCount){ |
||||||
|
scrollIndex =0; |
||||||
|
selectedIndex = 0; |
||||||
|
lastOneIndex = showCount; |
||||||
|
|
||||||
|
} |
||||||
|
repaint(); |
||||||
|
} |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
private void checkButton(boolean buttonEnabled) { |
||||||
|
leftButton.setEnabled(buttonEnabled); |
||||||
|
rightButton.setEnabled(buttonEnabled); |
||||||
|
} |
||||||
|
|
||||||
|
public int getSelectedIndex(){ |
||||||
|
return selectedIndex; |
||||||
|
} |
||||||
|
|
||||||
|
public void paintComponent(Graphics g){ |
||||||
|
super.paintComponent(g); |
||||||
|
double maxWidth = getWidth() - buttonPane.getWidth(); |
||||||
|
Graphics2D g2d = (Graphics2D) g; |
||||||
|
paintBackgroundAndLine(g2d, maxWidth); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private void paintBackgroundAndLine(Graphics2D g2d, double maxWidth) { |
||||||
|
//能画的个数
|
||||||
|
showCount = (int) (maxWidth) / tabWidth; |
||||||
|
//计算开始画的最小模板index和最大模板index
|
||||||
|
if (selectedIndex >= dbManipulationPaneList.size()) { |
||||||
|
selectedIndex = dbManipulationPaneList.size() - 1; |
||||||
|
} |
||||||
|
if (selectedIndex < 0) { |
||||||
|
selectedIndex = 0; |
||||||
|
} |
||||||
|
calMinAndMaxIndex(); |
||||||
|
closeIconStartX = new int[lastOneIndex - scrollIndex + 1]; |
||||||
|
|
||||||
|
int startX = 0; |
||||||
|
//从可以开始展示在tab面板上的tab开始画
|
||||||
|
for (int i = scrollIndex; i <= lastOneIndex; i++) { |
||||||
|
BatchSubmitPane dbManipulationPane = (BatchSubmitPane)dbManipulationPaneList.get(i); |
||||||
|
String name ; |
||||||
|
if (dbManipulationPane.getSubMitName() != null){ |
||||||
|
name = dbManipulationPane.getSubMitName(); |
||||||
|
} else { |
||||||
|
name = createName(); |
||||||
|
dbManipulationPane.setSubMitName(name); |
||||||
|
} |
||||||
|
if (i == selectedIndex) { |
||||||
|
closeIconStartX[i - scrollIndex] = paintSelectedTab(g2d, startX,name, i); |
||||||
|
} else { |
||||||
|
closeIconStartX[i - scrollIndex] = paintUnSelectedTab(g2d,startX,name,i); |
||||||
|
} |
||||||
|
startX += tabWidth; |
||||||
|
} |
||||||
|
paintUnderLine(startX, maxWidth, g2d); |
||||||
|
addX = startX + GAP; |
||||||
|
addIcon.paintIcon(this,g2d,addX,0); |
||||||
|
checkButton(getTabCount() > showCount); |
||||||
|
} |
||||||
|
|
||||||
|
public int getTabCount(){ |
||||||
|
return dbManipulationPaneList.size(); |
||||||
|
} |
||||||
|
|
||||||
|
private String createName(){ |
||||||
|
String prefix = Inter.getLocText("FR-Designer-CommitTab_Submit"); |
||||||
|
int count = getTabCount(); |
||||||
|
while (true) { |
||||||
|
//从提交1开始
|
||||||
|
count = count == 0 ? 1 : count; |
||||||
|
String newName = prefix + count; |
||||||
|
boolean repeated = false; |
||||||
|
for (int i= 0;i < getTabCount();i++) { |
||||||
|
if (ComparatorUtils.equals( ((BatchSubmitPane)dbManipulationPaneList.get(i)).getSubMitName(), newName)) { |
||||||
|
repeated = true; |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (!repeated) { |
||||||
|
return newName; |
||||||
|
} |
||||||
|
|
||||||
|
count++; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void paintUnderLine(double startX, double maxWidth, Graphics2D g2d) { |
||||||
|
//画下面的那条线
|
||||||
|
if (startX < maxWidth) { |
||||||
|
GeneralPath generalPath = new GeneralPath(Path2D.WIND_EVEN_ODD, 2); |
||||||
|
generalPath.moveTo((float) startX, (float) (getHeight() - 1)); |
||||||
|
generalPath.lineTo((float) maxWidth, (float) (getHeight() - 1)); |
||||||
|
g2d.fill(generalPath); |
||||||
|
g2d.setPaint(UIConstants.LINE_COLOR); |
||||||
|
g2d.draw(new Line2D.Double((float) startX, (float) (getHeight() - 1), (float) maxWidth , (float) (getHeight() - 1))); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private void calMinAndMaxIndex() { //如果个数大于最多能容纳的个数,则多余的进行处理
|
||||||
|
|
||||||
|
if (dbManipulationPaneList.size() > showCount) { |
||||||
|
|
||||||
|
if (selectedIndex >= lastOneIndex) { //所点击列表中的标签页处在标签页栏最后一个标签页之后,则标签页栏左移至所点击标签页出现
|
||||||
|
scrollIndex = selectedIndex - showCount + 1; |
||||||
|
lastOneIndex = selectedIndex; |
||||||
|
if (scrollIndex <= 0) { |
||||||
|
scrollIndex = 0; |
||||||
|
lastOneIndex = showCount - 1; |
||||||
|
} |
||||||
|
} else if (selectedIndex <= scrollIndex) { //所点击列表中的标签页处在标签页栏第一个标签页之前,则标签页栏右移至所点击标签页出现
|
||||||
|
|
||||||
|
scrollIndex = selectedIndex; |
||||||
|
lastOneIndex = scrollIndex + showCount - 1; |
||||||
|
if (lastOneIndex > dbManipulationPaneList.size() - 1) { |
||||||
|
lastOneIndex = dbManipulationPaneList.size() - 1; |
||||||
|
} |
||||||
|
} else { |
||||||
|
if (selectedIndex >= dbManipulationPaneList.size() - 1) { |
||||||
|
selectedIndex = dbManipulationPaneList.size() - 1; |
||||||
|
lastOneIndex = selectedIndex; |
||||||
|
scrollIndex = selectedIndex - showCount + 1; |
||||||
|
} else { |
||||||
|
lastOneIndex = scrollIndex + showCount - 1; |
||||||
|
if (lastOneIndex > dbManipulationPaneList.size() - 1) { |
||||||
|
lastOneIndex = dbManipulationPaneList.size() - 1; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} else { |
||||||
|
scrollIndex = 0; |
||||||
|
lastOneIndex = dbManipulationPaneList.size() - 1; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 画选中的tab |
||||||
|
* |
||||||
|
* @param g2d |
||||||
|
* @param sheetName |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private int paintSelectedTab(Graphics2D g2d,int startX, String sheetName, int selfIndex) { |
||||||
|
double[] x = {startX, startX, startX + tabWidth, startX + tabWidth, startX}; |
||||||
|
double[] y = {-1, getHeight(), getHeight(), -1, -1}; |
||||||
|
RoundRectangle2D.Double rect1 = new RoundRectangle2D.Double(startX, 1, this.getWidth(), this.getHeight(), 7, 7); |
||||||
|
g2d.setPaint(new GradientPaint(1, 1, new Color(255, 255, 255), 1, getHeight() - 1, UIConstants.NORMAL_BACKGROUND)); |
||||||
|
|
||||||
|
GeneralPath generalPath = new GeneralPath(Path2D.WIND_EVEN_ODD, x.length); |
||||||
|
generalPath.moveTo((float) x[0] + CORNOR_RADIUS, (float) y[0]); |
||||||
|
generalPath.curveTo(((float) x[0] + CORNOR_RADIUS - specialLocation1), (y[0] + CORNOR_RADIUS - specialLocation2), ((float) x[0] + CORNOR_RADIUS - specialLocation2), (y[0] + CORNOR_RADIUS - specialLocation1), (double) x[0], y[0] + CORNOR_RADIUS); |
||||||
|
|
||||||
|
for (int index = 1; index <= 2; index++) { |
||||||
|
generalPath.lineTo((float) x[index], (float) y[index]); |
||||||
|
} |
||||||
|
|
||||||
|
generalPath.lineTo((float) x[3], (float) y[3] + CORNOR_RADIUS); |
||||||
|
generalPath.curveTo(((float) x[3] - CORNOR_RADIUS + specialLocation1), ((float) y[3] + CORNOR_RADIUS - specialLocation2), ((float) x[3] - CORNOR_RADIUS + specialLocation2), ((float) y[3] + CORNOR_RADIUS - specialLocation1), (float) x[3] - CORNOR_RADIUS, (float) y[3]); |
||||||
|
generalPath.lineTo((float) x[0] + CORNOR_RADIUS, (float) y[0]); |
||||||
|
|
||||||
|
generalPath.closePath(); |
||||||
|
g2d.fill(generalPath); |
||||||
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
||||||
|
g2d.setPaint(UIConstants.LINE_COLOR); |
||||||
|
g2d.draw(new Arc2D.Double(x[0], y[0], CORNOR_RADIUS * 2, CORNOR_RADIUS * 2, 90, 90, 0)); |
||||||
|
g2d.draw(new Line2D.Double(x[0], y[0] + CORNOR_RADIUS, x[1], y[1])); |
||||||
|
g2d.draw(new Line2D.Double(x[1], y[1], x[2], y[2])); |
||||||
|
g2d.draw(new Line2D.Double(x[2], y[2], x[3], y[3] + CORNOR_RADIUS)); |
||||||
|
g2d.draw(new Line2D.Double(x[0] + 3 ,0,x[2] - 3,0)); |
||||||
|
g2d.draw(new Arc2D.Double(x[3] - CORNOR_RADIUS * 2, y[3], CORNOR_RADIUS * 2, CORNOR_RADIUS * 2, 90, -90, 0)); |
||||||
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); |
||||||
|
// 画字符
|
||||||
|
g2d.setPaint(getForeground()); |
||||||
|
g2d.drawString(sheetName, startX + 2 * GAP, getHeight()-GAP); |
||||||
|
int closePosition = startX + tabWidth - closeIcon.getIconWidth() - SMALLGAP; |
||||||
|
int closeY = (getHeight() - closeIcon.getIconHeight()) / 2; |
||||||
|
if (canClose() && mouseOveredIndex == selfIndex){ |
||||||
|
closeIcon.paintIcon(this, g2d, closePosition, closeY); |
||||||
|
} |
||||||
|
return closePosition; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 画没有选中的tab |
||||||
|
* |
||||||
|
* @param g2d |
||||||
|
* @param startX |
||||||
|
* @param sheetName |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private int paintUnSelectedTab(Graphics2D g2d, int startX, String sheetName, int selfIndex) { |
||||||
|
double[] x = {startX, startX, startX + tabWidth, startX + tabWidth, startX}; |
||||||
|
double[] y = {-1, getHeight() - 1, getHeight() - 1, -1, -1}; |
||||||
|
if (selfIndex == mouseOveredIndex) { |
||||||
|
g2d.setPaint(new GradientPaint(1, 1, new Color(255, 255, 255), 1, getHeight() - 1, UIConstants.NORMAL_BACKGROUND)); |
||||||
|
} else { |
||||||
|
g2d.setPaint(new GradientPaint(1, 1, UIConstants.NORMAL_BACKGROUND, 1, getHeight() - 1, UIConstants.NORMAL_BACKGROUND)); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
GeneralPath generalPath = new GeneralPath(Path2D.WIND_EVEN_ODD, x.length); |
||||||
|
generalPath.moveTo((float) x[0] + CORNOR_RADIUS, (float) y[0]); |
||||||
|
generalPath.curveTo(((float) x[0] + CORNOR_RADIUS - specialLocation1), (y[0] + CORNOR_RADIUS - specialLocation2), ((float) x[0] + CORNOR_RADIUS - specialLocation2), (y[0] + CORNOR_RADIUS - specialLocation1), (double) x[0], y[0] + CORNOR_RADIUS); |
||||||
|
|
||||||
|
for (int index = 1; index <= 2; index++) { |
||||||
|
generalPath.lineTo((float) x[index], (float) y[index]); |
||||||
|
} |
||||||
|
|
||||||
|
generalPath.lineTo((float) x[3], (float) y[3] + CORNOR_RADIUS); |
||||||
|
generalPath.curveTo(((float) x[3] - CORNOR_RADIUS + specialLocation1), ((float) y[3] + CORNOR_RADIUS - specialLocation2), ((float) x[3] - CORNOR_RADIUS + specialLocation2), ((float) y[3] + CORNOR_RADIUS - specialLocation1), (float) x[3] - CORNOR_RADIUS, (float) y[3]); |
||||||
|
generalPath.lineTo((float) x[0] + CORNOR_RADIUS, (float) y[0]); |
||||||
|
|
||||||
|
generalPath.closePath(); |
||||||
|
|
||||||
|
g2d.fill(generalPath); |
||||||
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
||||||
|
g2d.setPaint(UIConstants.LINE_COLOR); |
||||||
|
|
||||||
|
g2d.draw(new Arc2D.Double(x[0], y[0], CORNOR_RADIUS * 2, CORNOR_RADIUS * 2, 90, 90, 0)); |
||||||
|
g2d.draw(new Line2D.Double(x[0], y[0] + CORNOR_RADIUS, x[1], y[1])); |
||||||
|
g2d.draw(new Line2D.Double(x[1], y[1], x[2], y[2])); |
||||||
|
g2d.draw(new Line2D.Double(x[2], y[2], x[3], y[3] + CORNOR_RADIUS)); |
||||||
|
g2d.draw(new Line2D.Double(x[0] + 3 ,0,x[2] - 3,0)); |
||||||
|
g2d.draw(new Arc2D.Double(x[3] - CORNOR_RADIUS * 2, y[3], CORNOR_RADIUS * 2, CORNOR_RADIUS * 2, 90, -90, 0)); |
||||||
|
|
||||||
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); |
||||||
|
// 画字符
|
||||||
|
g2d.setPaint(getForeground()); |
||||||
|
g2d.drawString(sheetName, startX + 2 * GAP, getHeight() - GAP ); |
||||||
|
int closeY = (getHeight() - closeIcon.getIconHeight()) / 2; |
||||||
|
int closePosition = startX + tabWidth - closeIcon.getIconWidth() - SMALLGAP; |
||||||
|
if (canClose() && mouseOveredIndex == selfIndex){ |
||||||
|
closeIcon.paintIcon(this, g2d, closePosition, closeY); |
||||||
|
} |
||||||
|
return closePosition; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 鼠标按下 |
||||||
|
* @param e 事件 |
||||||
|
*/ |
||||||
|
public void mouseClicked(MouseEvent e) { |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 鼠标按下 |
||||||
|
* @param e 事件 |
||||||
|
*/ |
||||||
|
public void mousePressed(MouseEvent e) { |
||||||
|
int x = e.getX(), y = e.getY(); |
||||||
|
if (addX!= -1 && isOverAddIcon(x, y)){ |
||||||
|
addIcon = ADD_CLICK; |
||||||
|
commit2DBJavaScriptPane.createDBManipulationPane(); |
||||||
|
selectedIndex = dbManipulationPaneList.size()-1; |
||||||
|
commit2DBJavaScriptPane.updateCardPane(); |
||||||
|
} else if (isOverCloseIcon(x)){ |
||||||
|
int re = JOptionPane.showConfirmDialog(SwingUtilities.getWindowAncestor(this), Inter.getLocText("FR-Designer-CommitTab_SureToDelete")+ "?", Inter.getLocText("FR-Designer-CommitTab_Remove") |
||||||
|
, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); |
||||||
|
if (re == JOptionPane.OK_OPTION) { |
||||||
|
dbManipulationPaneList.remove(getTabIndex(x)); |
||||||
|
commit2DBJavaScriptPane.setList(dbManipulationPaneList); |
||||||
|
// 删除tab以后,获得第一个tab,再刷新一下,否则画面会停留在已删除的tab上,第一个tab是不可删除的
|
||||||
|
selectedIndex = getTabIndex(FIRST_TAB_POSITION); |
||||||
|
commit2DBJavaScriptPane.updateCardPane(); |
||||||
|
|
||||||
|
} |
||||||
|
} else if (selectedIndex != getTabIndex(x)){ |
||||||
|
selectedIndex = getTabIndex(x); |
||||||
|
commit2DBJavaScriptPane.updateCardPane(); |
||||||
|
} |
||||||
|
repaint(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 鼠标离开 |
||||||
|
* @param e 事件 |
||||||
|
*/ |
||||||
|
public void mouseReleased(MouseEvent e) { |
||||||
|
if(addX != -1 && isOverAddIcon(e.getX(), e.getY())){ |
||||||
|
addIcon = ADD_NORMAL; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 鼠标进入 |
||||||
|
* @param e 事件 |
||||||
|
*/ |
||||||
|
public void mouseEntered(MouseEvent e) { |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 鼠标离开 |
||||||
|
* @param e 事件 |
||||||
|
*/ |
||||||
|
public void mouseExited(MouseEvent e) { |
||||||
|
mouseOveredIndex = -1; |
||||||
|
repaint(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 鼠标拖动 |
||||||
|
* @param e 事件 |
||||||
|
*/ |
||||||
|
public void mouseDragged(MouseEvent e) { |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 鼠标移动 |
||||||
|
* @param e 事件 |
||||||
|
*/ |
||||||
|
public void mouseMoved(MouseEvent e) { |
||||||
|
if(addX!= -1 && isOverAddIcon(e.getX(), e.getY())){ |
||||||
|
addIcon = ADD_OVER; |
||||||
|
} else { |
||||||
|
mouseOveredIndex = getTabIndex(e.getX()); |
||||||
|
addIcon = ADD_NORMAL; |
||||||
|
} |
||||||
|
repaint(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 判断鼠标所在Tab |
||||||
|
* @param evtX |
||||||
|
* @return index |
||||||
|
*/ |
||||||
|
private int getTabIndex ( int evtX ){ |
||||||
|
int x = 0; |
||||||
|
for( int i = scrollIndex;i <= lastOneIndex;i++){ |
||||||
|
if(evtX > x && evtX <= x + tabWidth ){ |
||||||
|
return i; |
||||||
|
} |
||||||
|
x = x + tabWidth; |
||||||
|
} |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断鼠标是否在添加按钮上 |
||||||
|
* @param x 鼠标坐标x |
||||||
|
* @param y 鼠标坐标y |
||||||
|
* @return 返回鼠标是否在添加按钮上 |
||||||
|
*/ |
||||||
|
private boolean isOverAddIcon(int x, int y){ |
||||||
|
int addWidth = addIcon.getIconWidth(),addHeight = addIcon.getIconHeight(); |
||||||
|
return x >= addX && x <= addX + addWidth && y > addY && y <= addY + addHeight; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 判断鼠标是否在关闭按钮上 |
||||||
|
* @param evtX x |
||||||
|
* @return 返回鼠标是否在关闭按钮上 |
||||||
|
*/ |
||||||
|
private boolean isOverCloseIcon(int evtX) { |
||||||
|
boolean isOverCloseIcon = false; |
||||||
|
if( canClose()){ |
||||||
|
for (int i = 0; i < closeIconStartX.length; i++) { |
||||||
|
if (evtX >= closeIconStartX[i] && evtX <= closeIconStartX[i] + closeIcon.getIconWidth()) { |
||||||
|
isOverCloseIcon = true; |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return isOverCloseIcon; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 如果tab只剩下最后一个,则不画删除按钮 |
||||||
|
* @return 返回当前tab还可否关闭 |
||||||
|
*/ |
||||||
|
private boolean canClose(){ |
||||||
|
return closeIconStartX.length > 1; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 刷新tab,停留在第一个tab上面 |
||||||
|
*/ |
||||||
|
public void refreshTab(){ |
||||||
|
selectedIndex = getTabIndex(FIRST_TAB_POSITION); |
||||||
|
commit2DBJavaScriptPane.updateCardPane(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
package com.fr.design.write.submit.batch; |
||||||
|
|
||||||
|
import com.fr.design.beans.FurtherBasicBeanPane; |
||||||
|
import com.fr.design.fun.impl.AbstractJavaScriptActionProvider; |
||||||
|
import com.fr.design.javascript.JavaScriptActionPane; |
||||||
|
import com.fr.js.JavaScript; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by loy on 16/8/22. |
||||||
|
*/ |
||||||
|
public class BatchJavaScriptActionProvider extends AbstractJavaScriptActionProvider { |
||||||
|
|
||||||
|
@Override |
||||||
|
public FurtherBasicBeanPane<? extends JavaScript> getJavaScriptActionPane() { |
||||||
|
return new BatchCommit2DBJavaScriptPane(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public FurtherBasicBeanPane<? extends JavaScript> getJavaScriptActionPane(JavaScriptActionPane pane) { |
||||||
|
return new BatchCommit2DBJavaScriptPane(pane); |
||||||
|
} |
||||||
|
|
||||||
|
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,42 @@ |
|||||||
|
package com.fr.design.write.submit.batch; |
||||||
|
|
||||||
|
import com.fr.design.beans.BasicBeanPane; |
||||||
|
import com.fr.design.fun.impl.AbstractSubmitProvider; |
||||||
|
import com.fr.general.Inter; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by loy on 16/8/13. |
||||||
|
*/ |
||||||
|
public class BatchSubmitProvider extends AbstractSubmitProvider { |
||||||
|
private volatile static BatchSubmitProvider instance; |
||||||
|
|
||||||
|
public static BatchSubmitProvider getInstance() { |
||||||
|
if (instance == null) { |
||||||
|
synchronized (BatchSubmitProvider.class) { |
||||||
|
if (instance == null) { |
||||||
|
instance = new BatchSubmitProvider(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return instance; |
||||||
|
} |
||||||
|
@Override |
||||||
|
public BasicBeanPane appearanceForSubmit() { |
||||||
|
return new SmartInsertBatchSubmitPane(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String dataForSubmit() { |
||||||
|
return Inter.getLocText("Performance-plugin_submitbatch_name"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String keyForSubmit() { |
||||||
|
return "submitbatch"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int currentAPILevel() { |
||||||
|
return 1; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,591 @@ |
|||||||
|
package com.fr.design.write.submit.batch; |
||||||
|
|
||||||
|
import com.fr.cache.list.IntList; |
||||||
|
import com.fr.data.ClassSubmitJob; |
||||||
|
import com.fr.design.actions.UpdateAction; |
||||||
|
import com.fr.design.cell.smartaction.AbstractSmartJTablePaneAction; |
||||||
|
import com.fr.design.cell.smartaction.SmartJTablePane; |
||||||
|
import com.fr.design.cell.smartaction.SmartJTablePaneAction; |
||||||
|
import com.fr.design.dialog.BasicDialog; |
||||||
|
import com.fr.design.dialog.BasicPane; |
||||||
|
import com.fr.design.dialog.DialogActionAdapter; |
||||||
|
import com.fr.design.editor.ValueEditorPaneFactory; |
||||||
|
import com.fr.design.gui.controlpane.NameObjectCreator; |
||||||
|
import com.fr.design.gui.controlpane.NameableCreator; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.gui.ispinner.UIBasicSpinner; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.layout.TableLayout; |
||||||
|
import com.fr.design.layout.TableLayoutHelper; |
||||||
|
import com.fr.design.mainframe.DesignerContext; |
||||||
|
import com.fr.design.mainframe.ElementCasePane; |
||||||
|
import com.fr.design.mainframe.JTemplate; |
||||||
|
import com.fr.design.mainframe.JWorkBook; |
||||||
|
import com.fr.design.selection.SelectionEvent; |
||||||
|
import com.fr.design.selection.SelectionListener; |
||||||
|
import com.fr.design.write.submit.CustomSubmitJobPane; |
||||||
|
import com.fr.design.write.submit.SmartInsertDMLJobPane; |
||||||
|
import com.fr.design.write.submit.SubmitJobListPane; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.grid.selection.CellSelection; |
||||||
|
import com.fr.grid.selection.FloatSelection; |
||||||
|
import com.fr.grid.selection.Selection; |
||||||
|
import com.fr.stable.ColumnRow; |
||||||
|
import com.fr.stable.ColumnRowGroup; |
||||||
|
import com.fr.write.DMLConfigJob; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import javax.swing.table.DefaultTableCellRenderer; |
||||||
|
import javax.swing.table.TableCellRenderer; |
||||||
|
import javax.swing.table.TableColumn; |
||||||
|
import java.awt.*; |
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by loy on 16/8/16. |
||||||
|
*/ |
||||||
|
public class SmartInsertBatchSubmitPane extends BatchSubmitPane { |
||||||
|
private static final Selection NO_SELECTION = new CellSelection(-1, -1, -1, -1); |
||||||
|
private ElementCasePane ePane; |
||||||
|
private static int CELL_GROUP_LIMIT = 6; |
||||||
|
|
||||||
|
public SmartInsertBatchSubmitPane(ElementCasePane ePane) { |
||||||
|
super(ValueEditorPaneFactory.extendedCellGroupEditors()); |
||||||
|
this.ePane = ePane; |
||||||
|
} |
||||||
|
|
||||||
|
public SmartInsertBatchSubmitPane() { |
||||||
|
super(ValueEditorPaneFactory.extendedCellGroupEditors()); |
||||||
|
JTemplate jTemplate = DesignerContext.getDesignerFrame().getSelectedJTemplate(); |
||||||
|
this.ePane = ((JWorkBook) jTemplate).getEditingElementCasePane(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected SubmitJobListPane createSubmitJobListPane() { |
||||||
|
return new SmartInsertSubmitJobListPane(); |
||||||
|
} |
||||||
|
|
||||||
|
class SmartInsertSubmitJobListPane extends SubmitJobListPane { |
||||||
|
|
||||||
|
public SmartInsertSubmitJobListPane() { |
||||||
|
super(ePane); |
||||||
|
} |
||||||
|
|
||||||
|
public void hideParentDialog() { |
||||||
|
hideDialog4AddCellAction(); |
||||||
|
} |
||||||
|
|
||||||
|
public void showParentDialog() { |
||||||
|
showDialogAfterAddCellAction(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public NameableCreator[] createNameableCreators() { |
||||||
|
return new NameableCreator[] { |
||||||
|
new NameObjectCreator(Inter.getLocText(new String[]{"Submit", "Event"}), |
||||||
|
"/com/fr/web/images/reportlet.png", |
||||||
|
DMLConfigJob.class, |
||||||
|
SmartInsertDMLJobPane.class), |
||||||
|
new NameObjectCreator(Inter.getLocText(new String[]{"Custom", "Event"}), |
||||||
|
"/com/fr/web/images/reportlet.png", |
||||||
|
ClassSubmitJob.class, |
||||||
|
CustomSubmitJobPane.class) }; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected UpdateAction[] getActions() { |
||||||
|
return new UpdateAction[] { |
||||||
|
new BatchSubmitPane.SmartAddFieldsAction(), |
||||||
|
new BatchSubmitPane.AddFieldAction(), |
||||||
|
new SmartAddCellAction(), |
||||||
|
new SmartAddCellGroupAction(), |
||||||
|
new BatchModCellAction(), |
||||||
|
new BatchSubmitPane.RemoveFieldAction() |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
public class BatchModCellAction extends UpdateAction { |
||||||
|
public BatchModCellAction() { |
||||||
|
this.setName(Inter.getLocText("RWA-Batch_Modify_Cells")); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 执行事件 |
||||||
|
* @param evt 事件对象 |
||||||
|
*/ |
||||||
|
public void actionPerformed(ActionEvent evt) { |
||||||
|
BasicPane bPane = new BasicPane() { |
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return Inter.getLocText("RWA-Batch_Modify_Cells"); |
||||||
|
} |
||||||
|
}; |
||||||
|
bPane.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
bPane.setBorder(BorderFactory.createEmptyBorder(30, 0, 0, 0)); |
||||||
|
final UIBasicSpinner columnSpinner = new UIBasicSpinner(); |
||||||
|
final UIBasicSpinner rowSpinner = new UIBasicSpinner(); |
||||||
|
Component[][] coms = new Component[][] { { new UILabel(Inter.getLocText("RWA-Row_Offset")), rowSpinner },{ new UILabel(Inter.getLocText("RWA-Column_Offset")), columnSpinner } }; |
||||||
|
double p = TableLayout.PREFERRED; |
||||||
|
double f = TableLayout.FILL; |
||||||
|
bPane.add(TableLayoutHelper.createTableLayoutPane(coms, new double[]{p, p}, new double[]{p, f}), BorderLayout.NORTH); |
||||||
|
BasicDialog dlg = bPane.showSmallWindow(SwingUtilities.getWindowAncestor(SmartInsertBatchSubmitPane.this), new DialogActionAdapter() { |
||||||
|
public void doOk() { |
||||||
|
int row_offset = ((Number)rowSpinner.getValue()).intValue(); |
||||||
|
int column_offset = ((Number)columnSpinner.getValue()).intValue(); |
||||||
|
BatchSubmitPane.KeyColumnTableModel model = (BatchSubmitPane.KeyColumnTableModel)keyColumnValuesTable.getModel(); |
||||||
|
int[] selectedRows = keyColumnValuesTable.getSelectedRows(); |
||||||
|
// 如果一行都没选中,取所有的行
|
||||||
|
if (selectedRows.length == 0) { |
||||||
|
selectedRows = IntList.range(model.getRowCount()); |
||||||
|
} |
||||||
|
for (int i = 0; i < selectedRows.length; i++) { |
||||||
|
int row = selectedRows[i]; |
||||||
|
BatchSubmitPane.KeyColumnNameValue kcnv = model.getKeyColumnNameValue(row); |
||||||
|
if (kcnv.cv.obj instanceof ColumnRow) { |
||||||
|
ColumnRow or = (ColumnRow)kcnv.cv.obj; |
||||||
|
int n_column = or.getColumn() + column_offset; |
||||||
|
if (n_column < 0) { |
||||||
|
n_column = 0; |
||||||
|
} |
||||||
|
int n_row = or.getRow() + row_offset; |
||||||
|
if (n_row < 0) { |
||||||
|
n_row = 0; |
||||||
|
} |
||||||
|
kcnv.cv.obj = ColumnRow.valueOf(n_column, n_row); |
||||||
|
} |
||||||
|
} |
||||||
|
model.fireTableDataChanged(); |
||||||
|
keyColumnValuesTable.validate(); |
||||||
|
for (int i = 0; i < selectedRows.length; i++) { |
||||||
|
keyColumnValuesTable.addRowSelectionInterval(selectedRows[i], selectedRows[i]); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
dlg.setVisible(true); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class SmartAddCellAction extends UpdateAction { |
||||||
|
public SmartAddCellAction() { |
||||||
|
this.setName(Inter.getLocText("RWA-Smart_Add_Cells")); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 执行事件 |
||||||
|
* @param evt 事件s |
||||||
|
*/ |
||||||
|
public void actionPerformed(ActionEvent evt) { |
||||||
|
|
||||||
|
// Grid.GridSelectionListener
|
||||||
|
if (ePane == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
/* |
||||||
|
* 布局 |
||||||
|
*/ |
||||||
|
BasicPane bPane = new SmartJTablePane4DB(keyColumnValuesTable.getTableModel4SmartAddCell(), ePane); |
||||||
|
|
||||||
|
// ReportWriteAttrDialog.this.setVisible(false);
|
||||||
|
hideDialog4AddCellAction(); |
||||||
|
/* |
||||||
|
* 当前的ReportPane不可编辑,不可切换Sheet,加GridSelectionChangeListener |
||||||
|
*/ |
||||||
|
ePane.setSelection(NO_SELECTION); |
||||||
|
ePane.setEditable(false); |
||||||
|
ePane.getGrid().setNotShowingTableSelectPane(false); |
||||||
|
|
||||||
|
BasicDialog dlg = bPane.showWindow(SwingUtilities.getWindowAncestor(SmartInsertBatchSubmitPane.this)); |
||||||
|
|
||||||
|
dlg.setModal(false); |
||||||
|
dlg.setVisible(true); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class SmartAddCellGroupAction extends UpdateAction { |
||||||
|
public SmartAddCellGroupAction() { |
||||||
|
this.setName(Inter.getLocText("RWA-Smart_Add_Cell_Group")); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 智能添加单元格组 |
||||||
|
* @param e 事件s |
||||||
|
*/ |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
if (ePane == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
BasicPane bPane = new SmartJTablePane4DB(keyColumnValuesTable.getTableModel4SmartAddCell(), ePane, true); |
||||||
|
|
||||||
|
// ReportWriteAttrDialog.this.setVisible(false);
|
||||||
|
hideDialog4AddCellAction(); |
||||||
|
/* |
||||||
|
* 当前的ReportPane不可编辑,不可切换Sheet,加GridSelectionChangeListener |
||||||
|
*/ |
||||||
|
ePane.setSelection(NO_SELECTION); |
||||||
|
ePane.setEditable(false); |
||||||
|
ePane.getGrid().setNotShowingTableSelectPane(false); |
||||||
|
|
||||||
|
BasicDialog dlg = bPane.showWindow(SwingUtilities.getWindowAncestor(SmartInsertBatchSubmitPane.this)); |
||||||
|
|
||||||
|
dlg.setModal(false); |
||||||
|
dlg.setVisible(true); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void showDialogAfterAddCellAction() { |
||||||
|
Container dialog = this; |
||||||
|
if (parentPane != null && parentPane.getContentDBManiPane() instanceof SmartInsertBatchSubmitPane && parentPane.getContentDBManiPane() != this) { |
||||||
|
((SmartInsertBatchSubmitPane)parentPane.getContentDBManiPane()).showDialogAfterAddCellAction(); |
||||||
|
} |
||||||
|
while (dialog.getParent() != null) { |
||||||
|
dialog = dialog.getParent(); |
||||||
|
if (dialog instanceof SmartInsertSubmitJobListPane) { |
||||||
|
((SmartInsertSubmitJobListPane)dialog).showParentDialog(); |
||||||
|
} else if (dialog instanceof Dialog) { |
||||||
|
dialog.setVisible(true); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void hideDialog4AddCellAction() { |
||||||
|
Container dialog = this; |
||||||
|
if (parentPane != null && parentPane.getContentDBManiPane() instanceof SmartInsertBatchSubmitPane && parentPane.getContentDBManiPane() != this) { |
||||||
|
((SmartInsertBatchSubmitPane)parentPane.getContentDBManiPane()).hideDialog4AddCellAction(); |
||||||
|
} |
||||||
|
while (dialog.getParent() != null) { |
||||||
|
dialog = dialog.getParent(); |
||||||
|
if (dialog instanceof SmartInsertSubmitJobListPane) { |
||||||
|
((SmartInsertSubmitJobListPane)dialog).hideParentDialog(); |
||||||
|
} else if (dialog instanceof Dialog) { |
||||||
|
// 条件属性中添加的控件的话有两层dialog,需要都隐藏
|
||||||
|
dialog.setVisible(false); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 检测是否合法 |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public void checkValid() throws Exception { |
||||||
|
BatchSubmitPane.KeyColumnTableModel model = (BatchSubmitPane.KeyColumnTableModel)keyColumnValuesTable.getModel(); |
||||||
|
int cnt = model.getRowCount(); |
||||||
|
int groupLength = -1; |
||||||
|
for (int i=0; i<cnt; i++) { |
||||||
|
BatchSubmitPane.KeyColumnNameValue kcv = model.getKeyColumnNameValue(i); |
||||||
|
Object val = kcv.cv.obj; |
||||||
|
if (val instanceof ColumnRowGroup) { |
||||||
|
int len = ((ColumnRowGroup) val).getSize(); |
||||||
|
if (groupLength < 0) { |
||||||
|
groupLength = len; |
||||||
|
} else if (len != groupLength) { |
||||||
|
throw new Exception(Inter.getLocText("Report-Write_Attributes_Group_Warning")); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private boolean possibleParentContainer(Container p) { |
||||||
|
return p instanceof Dialog || p instanceof BasicPane || |
||||||
|
p instanceof JPanel || p instanceof JRootPane || p instanceof JLayeredPane; |
||||||
|
} |
||||||
|
|
||||||
|
private class SmartJTablePane4DB extends SmartJTablePane { |
||||||
|
|
||||||
|
// 是否是单元格组
|
||||||
|
private boolean isCellGroup = false; |
||||||
|
|
||||||
|
// 单元格组要记录下之前的选中情况
|
||||||
|
private CellSelection oriCellSelection = null; |
||||||
|
|
||||||
|
public SmartJTablePane4DB(BatchSubmitPane.KeyColumnTableModel model, ElementCasePane actionReportPane) { |
||||||
|
this(model, actionReportPane, false); |
||||||
|
} |
||||||
|
|
||||||
|
public SmartJTablePane4DB(BatchSubmitPane.KeyColumnTableModel model, ElementCasePane actionReportPane, boolean isCellGroup) { |
||||||
|
super(model, actionReportPane); |
||||||
|
this.isCellGroup = isCellGroup; |
||||||
|
this.setCellRenderer(); |
||||||
|
this.changeGridSelectionChangeListener(isCellGroup ? groupListener : listener); |
||||||
|
this.changeSmartJTablePaneAction(a); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
if (isCellGroup) { |
||||||
|
return Inter.getLocText("RWA-Smart_Add_Cell_Group"); |
||||||
|
} else { |
||||||
|
return Inter.getLocText("RWA-Smart_Add_Cells"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setCellRenderer() { |
||||||
|
/* |
||||||
|
* set Width |
||||||
|
*/ |
||||||
|
TableColumn column0 = table.getColumnModel().getColumn(0); |
||||||
|
column0.setMaxWidth(40); |
||||||
|
/* |
||||||
|
* 设置Column 1的Renderer |
||||||
|
*/ |
||||||
|
TableColumn column1 = table.getColumnModel().getColumn(1); |
||||||
|
column1.setCellRenderer(new BatchSubmitPane.ColumnNameTableCellRenderer()); |
||||||
|
|
||||||
|
/* |
||||||
|
* 设置Column 2的Renderer |
||||||
|
*/ |
||||||
|
TableColumn column2 = table.getColumnModel().getColumn(2); |
||||||
|
// column2.setCellRenderer(new SelectedColumnValueTableCellRenderer());
|
||||||
|
|
||||||
|
if (isCellGroup) { |
||||||
|
column2.setCellRenderer(new ColumnRowGroupCellRenderer2()); |
||||||
|
column2.setCellEditor(new BatchSubmitPane.ColumnValueEditor(ValueEditorPaneFactory.cellGroupEditor())); |
||||||
|
} else { |
||||||
|
column2.setCellRenderer(new SelectedColumnValueTableCellRenderer()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 检查是否合法 |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public void checkValid() throws Exception { |
||||||
|
SmartInsertBatchSubmitPane.this.checkValid(); |
||||||
|
} |
||||||
|
|
||||||
|
private SelectionListener listener = new SelectionListener() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void selectionChanged(SelectionEvent e) { |
||||||
|
BatchSubmitPane.KeyColumnTableModel model = (BatchSubmitPane.KeyColumnTableModel)table.getModel(); |
||||||
|
if (editingRowIndex < 0 || editingRowIndex >= model.getRowCount()) { |
||||||
|
return; |
||||||
|
} |
||||||
|
BatchSubmitPane.KeyColumnNameValue kcv = model.getKeyColumnNameValue(editingRowIndex); |
||||||
|
ElementCasePane currentReportPane = (ElementCasePane)e.getSource(); |
||||||
|
Selection selection = currentReportPane.getSelection(); |
||||||
|
if (selection == NO_SELECTION || selection instanceof FloatSelection) { |
||||||
|
return; |
||||||
|
} |
||||||
|
CellSelection cellselection = (CellSelection)selection; |
||||||
|
kcv.cv.obj = ColumnRow.valueOf(cellselection.getColumn(), cellselection.getRow()); |
||||||
|
|
||||||
|
if (editingRowIndex >= model.getRowCount() - 1) { |
||||||
|
setEditingRowIndex(0); |
||||||
|
} else { |
||||||
|
setEditingRowIndex(editingRowIndex + 1); |
||||||
|
} |
||||||
|
|
||||||
|
model.fireTableDataChanged(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* 单元格组的点选格子事件 |
||||||
|
*/ |
||||||
|
private SelectionListener groupListener = new SelectionListener() { |
||||||
|
@Override |
||||||
|
public void selectionChanged(SelectionEvent e) { |
||||||
|
BatchSubmitPane.KeyColumnTableModel model = (BatchSubmitPane.KeyColumnTableModel)table.getModel(); |
||||||
|
if (editingRowIndex < 0 || editingRowIndex >= model.getRowCount()) { |
||||||
|
return; |
||||||
|
} |
||||||
|
BatchSubmitPane.KeyColumnNameValue kcv = model.getKeyColumnNameValue(editingRowIndex); |
||||||
|
ElementCasePane currentReportPane = (ElementCasePane)e.getSource(); |
||||||
|
Selection selection = currentReportPane.getSelection(); |
||||||
|
if (selection == NO_SELECTION || selection instanceof FloatSelection) { |
||||||
|
return; |
||||||
|
} |
||||||
|
CellSelection cellselection = (CellSelection)selection; |
||||||
|
Object oriValue = kcv.cv.obj; |
||||||
|
ColumnRowGroup newValue = getColumnRowGroupValue(oriValue); |
||||||
|
|
||||||
|
// 要考虑多选的情况 要结合之前的看看 可能是增加 也可能需要减少
|
||||||
|
ColumnRowGroup add = new ColumnRowGroup(); |
||||||
|
int removeCount = 0; |
||||||
|
if (oriCellSelection != null && sameStartPoint(cellselection, oriCellSelection)) { |
||||||
|
removeCount = dealDragSelection(add, cellselection); |
||||||
|
} else if (cellselection.getSelectedType() == CellSelection.CHOOSE_ROW || cellselection.getSelectedType() == CellSelection.CHOOSE_COLUMN) { |
||||||
|
dealSelectColRow(add, cellselection); |
||||||
|
} else { |
||||||
|
add.addColumnRow(ColumnRow.valueOf(cellselection.getColumn(), cellselection.getRow())); |
||||||
|
} |
||||||
|
|
||||||
|
if (add.getSize() > 0) { |
||||||
|
newValue.addAll(add); |
||||||
|
} else if (removeCount > 0) { |
||||||
|
newValue.splice(newValue.getSize()-removeCount, removeCount); |
||||||
|
} |
||||||
|
|
||||||
|
kcv.cv.obj = newValue; |
||||||
|
|
||||||
|
model.fireTableDataChanged(); |
||||||
|
|
||||||
|
oriCellSelection = cellselection; |
||||||
|
} |
||||||
|
|
||||||
|
private ColumnRowGroup getColumnRowGroupValue(Object oriValue) { |
||||||
|
ColumnRowGroup newValue = new ColumnRowGroup(); |
||||||
|
if (oriValue instanceof ColumnRowGroup) { |
||||||
|
newValue.addAll((ColumnRowGroup)oriValue); |
||||||
|
} else if (oriValue instanceof ColumnRow) { |
||||||
|
newValue.addColumnRow((ColumnRow) oriValue); |
||||||
|
} |
||||||
|
return newValue; |
||||||
|
} |
||||||
|
|
||||||
|
private boolean sameStartPoint(CellSelection cs1, CellSelection cs2) { |
||||||
|
return cs1.getColumn() == cs2.getColumn() && cs1.getRow() == cs2.getRow(); |
||||||
|
} |
||||||
|
|
||||||
|
private int dealDragSelection(ColumnRowGroup add, CellSelection cellselection) { |
||||||
|
int removeCount = 0; |
||||||
|
if (cellselection.getRowSpan() == oriCellSelection.getRowSpan() + 1) { |
||||||
|
for (int i=0; i<cellselection.getColumnSpan(); i++) { |
||||||
|
add.addColumnRow(ColumnRow.valueOf( |
||||||
|
cellselection.getColumn() + i, cellselection.getRow() + cellselection.getRowSpan() -1)); |
||||||
|
} |
||||||
|
} else if (cellselection.getRowSpan() == oriCellSelection.getRowSpan() - 1) { |
||||||
|
removeCount = cellselection.getColumnSpan(); |
||||||
|
} else if (cellselection.getColumnSpan() == oriCellSelection.getColumnSpan() + 1) { |
||||||
|
for (int i=0; i<cellselection.getRowSpan(); i++) { |
||||||
|
add.addColumnRow(ColumnRow.valueOf( |
||||||
|
cellselection.getColumn() + cellselection.getColumnSpan() - 1, cellselection.getRow() + i)); |
||||||
|
} |
||||||
|
} else if (cellselection.getColumnSpan() == oriCellSelection.getColumnSpan() - 1) { |
||||||
|
removeCount = cellselection.getRowSpan(); |
||||||
|
} |
||||||
|
return removeCount; |
||||||
|
} |
||||||
|
|
||||||
|
private void dealSelectColRow(ColumnRowGroup add, CellSelection se) { |
||||||
|
int c = se.getColumn(), cs = se.getColumnSpan(), |
||||||
|
r = se.getRow(), rs = se.getRowSpan(); |
||||||
|
for (int i=0; i<cs; i++) { |
||||||
|
for (int j=0; j<rs; j++) { |
||||||
|
add.addColumnRow(ColumnRow.valueOf(c+i, r+j)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
private SmartJTablePaneAction a = new AbstractSmartJTablePaneAction(this, SmartInsertBatchSubmitPane.this) { |
||||||
|
@Override |
||||||
|
public void doOk() { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void showDialog() { |
||||||
|
Container container = SmartJTablePane4DB.this; |
||||||
|
while (container.getParent() != null) { |
||||||
|
container = container.getParent(); |
||||||
|
if (container instanceof JDialog) { |
||||||
|
container.setVisible(false); |
||||||
|
} |
||||||
|
} |
||||||
|
updateUpdateCheckBoxEnable(); |
||||||
|
((SmartInsertBatchSubmitPane)dialog).showDialogAfterAddCellAction(); |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
/* |
||||||
|
* ColumnValueTableCellRenderer |
||||||
|
*/ |
||||||
|
private class SelectedColumnValueTableCellRenderer extends DefaultTableCellRenderer { |
||||||
|
@Override |
||||||
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
||||||
|
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
||||||
|
|
||||||
|
if (value instanceof BatchSubmitPane.ColumnValue) { |
||||||
|
if (((BatchSubmitPane.ColumnValue)value).obj != null) { |
||||||
|
this.setText(((BatchSubmitPane.ColumnValue)value).obj.toString()); |
||||||
|
} else { |
||||||
|
this.setText(""); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (row == SmartJTablePane4DB.this.editingRowIndex) { |
||||||
|
this.setBackground(Color.cyan); |
||||||
|
} else { |
||||||
|
this.setBackground(Color.white); |
||||||
|
} |
||||||
|
|
||||||
|
return this; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private class ColumnRowGroupCellRenderer implements TableCellRenderer { |
||||||
|
|
||||||
|
@Override |
||||||
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, |
||||||
|
boolean hasFocus, int row, int column) { |
||||||
|
JPanel pane = new JPanel(); |
||||||
|
UILabel text = new UILabel(); |
||||||
|
|
||||||
|
String tip = Inter.getLocText("FR-Designer_Double_Click_Edit_OR_Clear"); |
||||||
|
|
||||||
|
if (value instanceof BatchSubmitPane.ColumnValue) { |
||||||
|
Object cv = ((BatchSubmitPane.ColumnValue) value).obj; |
||||||
|
if (cv instanceof ColumnRowGroup && ((ColumnRowGroup)cv).getSize() >= CELL_GROUP_LIMIT) { |
||||||
|
text.setText("[" + Inter.getLocText(new String[]{"Has_Selected", "Classifier-Ge", "Cell"}, |
||||||
|
new String[]{((ColumnRowGroup)cv).getSize()+"", ""}) + "]"); |
||||||
|
tip = cv.toString() + " " + tip; |
||||||
|
} else if (cv != null) { |
||||||
|
text.setText(cv.toString()); |
||||||
|
} else { |
||||||
|
text.setText(""); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (row == SmartJTablePane4DB.this.editingRowIndex) { |
||||||
|
pane.setBackground(Color.cyan); |
||||||
|
} else { |
||||||
|
pane.setBackground(Color.white); |
||||||
|
} |
||||||
|
|
||||||
|
pane.setToolTipText(tip); |
||||||
|
pane.add(text); |
||||||
|
|
||||||
|
return pane; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private class ColumnRowGroupCellRenderer2 extends DefaultTableCellRenderer { |
||||||
|
@Override |
||||||
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
||||||
|
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
||||||
|
|
||||||
|
String tip = Inter.getLocText("FR-Designer_Double_Click_Edit_OR_Clear"); |
||||||
|
|
||||||
|
if (value instanceof BatchSubmitPane.ColumnValue) { |
||||||
|
Object cv = ((BatchSubmitPane.ColumnValue) value).obj; |
||||||
|
if (cv instanceof ColumnRowGroup && ((ColumnRowGroup)cv).getSize() >= CELL_GROUP_LIMIT) { |
||||||
|
this.setText("[" + Inter.getLocText(new String[]{"Has_Selected", "Classifier-Ge", "Cell"}, |
||||||
|
new String[]{((ColumnRowGroup)cv).getSize()+"", ""}) + "]"); |
||||||
|
tip = cv.toString() + " " + tip; |
||||||
|
} else if (cv != null) { |
||||||
|
this.setText(cv.toString()); |
||||||
|
} else { |
||||||
|
this.setText(""); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
this.setToolTipText(tip); |
||||||
|
|
||||||
|
if (row == SmartJTablePane4DB.this.editingRowIndex) { |
||||||
|
this.setBackground(Color.cyan); |
||||||
|
} else { |
||||||
|
this.setBackground(Color.white); |
||||||
|
} |
||||||
|
|
||||||
|
return this; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,288 @@ |
|||||||
|
package com.fr.design.write.submit.batch.service; |
||||||
|
|
||||||
|
import com.fr.base.*; |
||||||
|
import com.fr.data.NetworkHelper; |
||||||
|
import com.fr.data.core.db.DBUtils; |
||||||
|
import com.fr.data.impl.NameDatabaseConnection; |
||||||
|
import com.fr.design.write.submit.batch.BatchCommit2DBJavaScript; |
||||||
|
import com.fr.form.ui.WebContentUtils; |
||||||
|
import com.fr.general.xml.GeneralXMLTools; |
||||||
|
import com.fr.js.JavaScript; |
||||||
|
import com.fr.json.JSONException; |
||||||
|
import com.fr.json.JSONFunction; |
||||||
|
import com.fr.json.JSONObject; |
||||||
|
import com.fr.script.Calculator; |
||||||
|
import com.fr.stable.ColumnRow; |
||||||
|
import com.fr.stable.ParameterProvider; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
import com.fr.stable.UtilEvalError; |
||||||
|
import com.fr.stable.fun.impl.NoSessionIDOPService; |
||||||
|
import com.fr.stable.script.NameSpace; |
||||||
|
import com.fr.web.RepositoryDeal; |
||||||
|
import com.fr.web.core.ReportSessionIDInfor; |
||||||
|
import com.fr.web.core.SessionDealWith; |
||||||
|
import com.fr.web.core.SessionIDInfor; |
||||||
|
import com.fr.web.utils.WebUtils; |
||||||
|
import com.fr.write.batch.SubmitMain; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.sql.Connection; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by loy on 16/8/23. |
||||||
|
*/ |
||||||
|
public class BatchDBCommitService extends NoSessionIDOPService { |
||||||
|
private static BatchDBCommitService service = null; |
||||||
|
|
||||||
|
public static final String ARG_XMLCONF = "xmlconf"; |
||||||
|
public static final String ARG_SESSIONID = "sessionID"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 构造 |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static BatchDBCommitService getInstance() { |
||||||
|
if (service == null) { |
||||||
|
service = new BatchDBCommitService(); |
||||||
|
} |
||||||
|
|
||||||
|
return service; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* OP值 |
||||||
|
* |
||||||
|
* @return 返回OP值 |
||||||
|
*/ |
||||||
|
public String actionOP() { |
||||||
|
return "batchcommit"; |
||||||
|
} |
||||||
|
|
||||||
|
private Map sessionMap = new HashMap(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 提交入库请求处理 |
||||||
|
* |
||||||
|
* @param req 请求 |
||||||
|
* @param res 响应 |
||||||
|
* @throws Exception 抛出异常 |
||||||
|
*/ |
||||||
|
public void process(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||||
|
String sessionID = WebUtils.getHTTPRequestParameter(req, ARG_SESSIONID); |
||||||
|
CountLock lock = getCountLock(sessionID); |
||||||
|
try { |
||||||
|
synchronized (lock) { |
||||||
|
process0(req, res); |
||||||
|
} |
||||||
|
} finally { |
||||||
|
releaseLock(sessionID, lock); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private void releaseLock(String sessionID, CountLock lock) { |
||||||
|
synchronized (sessionMap) { |
||||||
|
lock.reduce(); |
||||||
|
if (lock.getCount() == 0) { |
||||||
|
sessionMap.remove(sessionID); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private CountLock getCountLock(String sessionID) { |
||||||
|
CountLock lock; |
||||||
|
synchronized (sessionMap) { |
||||||
|
lock = (CountLock) sessionMap.get(sessionID); |
||||||
|
if (lock == null) { |
||||||
|
lock = new CountLock(); |
||||||
|
sessionMap.put(sessionID, lock); |
||||||
|
} |
||||||
|
lock.increase(); |
||||||
|
} |
||||||
|
return lock; |
||||||
|
} |
||||||
|
|
||||||
|
private void process0(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||||
|
String dbManiXML = NetworkHelper.getHTTPRequestEncodeParameter(req, ARG_XMLCONF, false); |
||||||
|
if (dbManiXML != null) { |
||||||
|
BatchCommit2DBJavaScript commit2DBJS = (BatchCommit2DBJavaScript) GeneralXMLTools.readStringAsXMLable(dbManiXML); |
||||||
|
Calculator ca = Calculator.createCalculator(); |
||||||
|
RepositoryDeal repo = prepareRepository(req, ca); |
||||||
|
NameSpace ns = ParameterMapNameSpace.create(WebUtils.parameters4SessionIDInfor(req)); |
||||||
|
ca.pushNameSpace(ns); |
||||||
|
Map<String, Object> feedbackMap = prepareFeedBackMap(req, ca); |
||||||
|
boolean success = true; |
||||||
|
JSONObject fr_submitinfo = new JSONObject(); |
||||||
|
Map<String, Connection> connectionMap = new HashMap<String, Connection>(); |
||||||
|
try { |
||||||
|
String location = WebUtils.getHTTPRequestParameter(req, "location"); |
||||||
|
ColumnRow cr = ColumnRow.valueOf(location); |
||||||
|
for (int i = 0; i < commit2DBJS.getDBManipulation().size(); i++) { |
||||||
|
if (cr != ColumnRow.ERROR) { |
||||||
|
ca.setCurrentFromColumnRow(cr);// commit的时候, 也会去set关联格子的ColumnRow, 为防止上一个提交对下一个造成影响, 这边每次重置
|
||||||
|
} |
||||||
|
SubmitMain dbManipulation = (SubmitMain) commit2DBJS.getDBManipulation().get(i); |
||||||
|
if (dbManipulation != null && dbManipulation.getDmlConfig() != null) { |
||||||
|
String dbName = dbManipulation.getDBName(ca); |
||||||
|
Connection conn = createConnection(dbName, connectionMap); |
||||||
|
ca.putConnection(dbName, conn); |
||||||
|
dbManipulation.doJob(ca); |
||||||
|
connectionMap.put(dbName, conn); |
||||||
|
} |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
FRContext.getLogger().error(e.getMessage(), e); |
||||||
|
Iterator iter = connectionMap.entrySet().iterator(); |
||||||
|
while (iter.hasNext()) { |
||||||
|
DBUtils.rollback((Connection) ((Map.Entry) iter.next()).getValue()); |
||||||
|
} |
||||||
|
success = false; |
||||||
|
fr_submitinfo.put("failinfo", e.getMessage()); |
||||||
|
} finally { |
||||||
|
DBUtils.commitConnections(connectionMap); |
||||||
|
} |
||||||
|
ca.removeNameSpace(ns); |
||||||
|
JSONObject jo = new JSONObject(); |
||||||
|
createJo(req, jo, feedbackMap, success, fr_submitinfo, repo); |
||||||
|
java.io.PrintWriter writer = WebUtils.createPrintWriter(res); |
||||||
|
writer.write(jo.toString()); |
||||||
|
writer.flush(); |
||||||
|
writer.close(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private Connection createConnection(String dbName, Map<String, Connection> connectionMap) throws Exception { |
||||||
|
Connection conn = null; |
||||||
|
if (connectionMap.containsKey(dbName)) { |
||||||
|
return connectionMap.get(dbName); |
||||||
|
} else { |
||||||
|
NameDatabaseConnection db = new NameDatabaseConnection(dbName); |
||||||
|
return db.createConnection(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private RepositoryDeal prepareRepository(HttpServletRequest req, Calculator ca) { |
||||||
|
String sessionID = WebUtils.getHTTPRequestParameter(req, ARG_SESSIONID); |
||||||
|
SessionIDInfor sessionIDInfor = SessionDealWith.getSessionIDInfor(sessionID); |
||||||
|
|
||||||
|
RepositoryDeal repo = null; |
||||||
|
if (sessionIDInfor != null) { |
||||||
|
repo = new RepositoryDeal(req, sessionIDInfor); |
||||||
|
if (sessionIDInfor instanceof ReportSessionIDInfor) { |
||||||
|
dealWithParaForCa(req, ca, (ReportSessionIDInfor) sessionIDInfor); |
||||||
|
} |
||||||
|
|
||||||
|
NameSpace sessionNamespace = sessionIDInfor.asNameSpace(sessionID); |
||||||
|
ca.pushNameSpace(sessionNamespace); |
||||||
|
} |
||||||
|
|
||||||
|
return repo; |
||||||
|
} |
||||||
|
|
||||||
|
private Map<String, Object> prepareFeedBackMap(HttpServletRequest req, Calculator ca) { |
||||||
|
String feedback = WebUtils.getHTTPRequestParameter(req, "feedbackMap"); |
||||||
|
Map feedbackMap = null; |
||||||
|
if (StringUtils.isNotEmpty(feedback)) { |
||||||
|
try { |
||||||
|
feedbackMap = new JSONObject(feedback).toMap(); |
||||||
|
} catch (JSONException e) { |
||||||
|
FRContext.getLogger().error(e.getMessage()); |
||||||
|
} |
||||||
|
NameSpace feedbackNS = ParameterMapNameSpace.create(feedbackMap); |
||||||
|
ca.pushNameSpace(feedbackNS); |
||||||
|
} |
||||||
|
|
||||||
|
return feedbackMap; |
||||||
|
} |
||||||
|
|
||||||
|
private void dealWithParaForCa(HttpServletRequest req, Calculator ca, ReportSessionIDInfor sessionIDInfor) { |
||||||
|
ca.setAttribute(Calculator.SHEET_NUMBER_KEY, WebUtils.getHTTPRequestParameter(req, "sheetNum")); |
||||||
|
sessionIDInfor.setUpAttribute4dbCommit(ca); |
||||||
|
|
||||||
|
// 提交入库可能用当前模板的参数
|
||||||
|
NameSpace paras = ParameterMapNameSpace.create(sessionIDInfor.getParameterMap4Execute()); |
||||||
|
ca.pushNameSpace(paras); |
||||||
|
} |
||||||
|
|
||||||
|
private void createJo(HttpServletRequest req, JSONObject jo, Map feedbackMap, |
||||||
|
boolean success, JSONObject fr_submitinfo, RepositoryDeal repo) throws Exception { |
||||||
|
// 生成的时候没有encode的,用没有进行urldecode的方法获取callback语句,防止+和%出错
|
||||||
|
String callBackXML = NetworkHelper.getHTTPRequestEncodeParameter(req, "callback", false); |
||||||
|
JavaScript callBack = (JavaScript) GeneralXMLTools.readStringAsXMLable(callBackXML); |
||||||
|
fr_submitinfo.put("success", success); |
||||||
|
|
||||||
|
if (callBack != null) { |
||||||
|
dealWithSuccessPara(callBack, fr_submitinfo, repo); |
||||||
|
if (feedbackMap != null) { |
||||||
|
callBack.addParameterMap(feedbackMap); |
||||||
|
} |
||||||
|
jo.put("callback", new JSONFunction(new String[]{"res"}, callBack.createJS(repo), repo.getDevice())); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void dealWithSuccessPara(JavaScript callBack, JSONObject fr_submitinfo, RepositoryDeal repo) { |
||||||
|
Map submitInfo = new HashMap(); |
||||||
|
submitInfo.put(WebContentUtils.FR_SUBMITINFO, fr_submitinfo); |
||||||
|
if (callBack != null) { |
||||||
|
callBack.addParameterMap(submitInfo); |
||||||
|
ParameterProvider[] ps = new ParameterProvider[callBack.getParameters().length + 1]; |
||||||
|
int len = callBack.getParameters().length; |
||||||
|
for (int i = 0; i < len; i++) { |
||||||
|
ps[i] = callBack.getParameters()[i]; |
||||||
|
} |
||||||
|
ps[len] = new Parameter(WebContentUtils.FR_SUBMITINFO, fr_submitinfo); |
||||||
|
callBack.setParameters(ps); |
||||||
|
} |
||||||
|
|
||||||
|
// if the parameter contains "fr_submitinfo" then recalculate it
|
||||||
|
ParameterProvider[] paras; |
||||||
|
if (callBack != null) { |
||||||
|
paras = callBack.getParameters(); |
||||||
|
} else { |
||||||
|
paras = new Parameter[0]; |
||||||
|
} |
||||||
|
Calculator ca = Calculator.createCalculator(); |
||||||
|
if (repo != null) { |
||||||
|
NameSpace ns = ParameterMapNameSpace.create(repo.getReportParameterMap()); |
||||||
|
ca.pushNameSpace(ns); |
||||||
|
} |
||||||
|
ca.pushNameSpace(ParameterMapNameSpace.create(submitInfo)); |
||||||
|
|
||||||
|
for (int i = 0; i < paras.length; i++) { |
||||||
|
Object obj = paras[i].getValue(); |
||||||
|
if (obj instanceof Formula && needToRecalculate(paras[i])) { |
||||||
|
try { |
||||||
|
((Formula) obj).setResult(ca.eval((Formula) obj)); |
||||||
|
} catch (UtilEvalError utilEvalError) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private boolean needToRecalculate(ParameterProvider p) { |
||||||
|
return Utils.objectToString(p.getValue()).toLowerCase().indexOf(WebContentUtils.FR_SUBMITINFO) != -1; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
class CountLock { |
||||||
|
private int count; |
||||||
|
|
||||||
|
public void increase() { |
||||||
|
count++; |
||||||
|
} |
||||||
|
|
||||||
|
public void reduce() { |
||||||
|
count--; |
||||||
|
} |
||||||
|
|
||||||
|
public int getCount() { |
||||||
|
return count; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue