package com.vci.client.uif.engine.client.tableArea;
|
|
import java.awt.FlowLayout;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
import javax.swing.JToggleButton;
|
|
import com.vci.client.portal.utility.DataModelFactory;
|
import com.vci.client.portal.utility.PLDefination;
|
import com.vci.client.portal.utility.UITools;
|
import com.vci.client.ui.swing.VCISwingUtil;
|
import com.vci.client.ui.swing.components.VCIJButton;
|
import com.vci.client.ui.swing.components.VCIJPanel;
|
import com.vci.client.uif.actions.client.UIFUtils;
|
import com.vci.client.uif.engine.client.BasePanel;
|
import com.vci.client.uif.engine.client.IRegionPanel;
|
import com.vci.client.uif.engine.client.tableArea.action.EditInTableActionInPoint;
|
import com.vci.client.uif.engine.client.tableArea.editable.EditableTablePanel;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.portal.data.PLAction;
|
import com.vci.corba.portal.data.PLCommandParameter;
|
import com.vci.corba.portal.data.PLTabButton;
|
|
public class TablePanelButtonAreaPanel extends BasePanel implements ActionListener{
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 5729565844495488380L;
|
private String tabId = "";
|
private IRegionPanel ownerPanel = null;
|
|
private Map<String, String> params = new HashMap<String, String>();
|
|
public TablePanelButtonAreaPanel(String tabId, String type, String context,
|
PLDefination defination, DataModelFactory factory,
|
IRegionPanel ownerPanel) {
|
super(factory, type, context, defination);
|
this.tabId = tabId;
|
this.ownerPanel = ownerPanel;
|
}
|
|
public void init(){
|
setLayout(new WrapLayout(FlowLayout.LEFT));
|
getButtonPanel();
|
//this.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
}
|
|
private void getButtonPanel(){
|
VCIJButton[] btns = getBtns();
|
for (VCIJButton btn : btns) {
|
if(EditInTableActionInPoint.EDIT_IN_TABLE.equals(btn.getActionCommand())){
|
addEditButtons(this);
|
} else {
|
this.add(btn);
|
}
|
}
|
}
|
|
public String getTabId() {
|
return tabId;
|
}
|
|
public void setTabId(String tabId) {
|
this.tabId = tabId;
|
}
|
|
public IRegionPanel getOwnerPanel() {
|
return ownerPanel;
|
}
|
|
public void setOwnerPanel(IRegionPanel ownerPanel) {
|
this.ownerPanel = ownerPanel;
|
}
|
|
private VCIJButton[] btns = null;
|
public VCIJButton[] getBtns() {
|
if(btns == null){
|
btns = getButtonsByTabPageId(getTabId(), ownerPanel);
|
}
|
return btns;
|
}
|
|
public void setBtns(VCIJButton[] btns) {
|
this.btns = btns;
|
}
|
|
|
private TablePanel tablePanel = null;
|
private JToggleButton btnStartEditor = new JToggleButton("开始编辑", VCISwingUtil.createImageIcon("lock_open.png"));
|
private VCIJButton btnClearSelected = VCISwingUtil.createVCIJButton("clearSelected", "清除已选", "", "clear.gif", this);
|
private VCIJButton btnStopEditor = VCISwingUtil.createVCIJButton("endEditor", "结束编辑", "", "lock_edit.png", this);
|
private void addEditButtons(VCIJPanel pal){
|
// 当前只在TablePanel上支持编辑
|
if(ownerPanel instanceof TablePanel){
|
//初始化参数列表
|
initParams();
|
// 标识支持编辑
|
setEditable(true);
|
btnStartEditor.setActionCommand("startEditor");
|
btnStartEditor.addActionListener(this);
|
tablePanel = (TablePanel)ownerPanel;
|
if(tablePanel.isSupportEditTableCell()){
|
pal.add(btnStartEditor);
|
pal.add(btnClearSelected);
|
pal.add(btnStopEditor);
|
// ‘清除’、‘结束编辑’ 正常情况下,不可用
|
btnClearSelected.setEnabled(false);
|
btnStopEditor.setEnabled(false);
|
}
|
}
|
}
|
|
private void initParams() {
|
String oid = ownerPanel.getPageDefinition().plOId;
|
try {
|
PLTabButton[] buttons = UITools.getService().getPLTabButtonsByTableOId(oid);
|
String buttonOid = "";
|
for(int i = buttons.length - 1; i >= 0; i--) {
|
PLAction action = UITools.getService().getPLActionById(buttons[i].plActionOId);
|
if(action != null &&
|
EditInTableActionInPoint.EDIT_IN_TABLE.equals(action.plCode)) {
|
buttonOid = buttons[i].plOId;
|
}
|
}
|
PLCommandParameter[] btnParams = UITools.getService().getPLCommandParametersByCommandOId(buttonOid);
|
for(PLCommandParameter cp : btnParams){
|
String key = cp.plKey;
|
String value = cp.plValue;
|
params.put(key, value);
|
}
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
}
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
String actionCommand = e.getActionCommand();
|
if(actionCommand.equals(btnStartEditor.getActionCommand())) startEditor();
|
else if(actionCommand.equals(btnClearSelected.getActionCommand())) clearSelected();
|
else if(actionCommand.equals(btnStopEditor.getActionCommand())) endEditor();
|
}
|
|
private void clearSelected(){
|
if(tablePanel.getDataTablePanel().getTable().getCellEditor() != null){
|
tablePanel.getDataTablePanel().getTable().getCellEditor().cancelCellEditing();
|
}
|
tablePanel.getDataTablePanel().clearCheckboxSelected();
|
}
|
private boolean editable = false;
|
public boolean isEditable() {
|
return editable;
|
}
|
public void setEditable(boolean editable) {
|
this.editable = editable;
|
}
|
|
/**
|
* 是否在编辑中
|
*/
|
private boolean editing = false;
|
public boolean isEditing() {
|
return editing;
|
}
|
public void setEditing(boolean editing) {
|
this.editing = editing;
|
}
|
|
private void startEditor(){
|
// 当进入可编辑状态后,‘清除’、‘结束编辑’才可用
|
tablePanel.getDataTablePanel().setCellEditable(true);
|
tablePanel.getDataTablePanel().setLastClickRowToChecked(false);
|
btnStartEditor.setEnabled(false);
|
btnStartEditor.setSelected(true);
|
btnClearSelected.setEnabled(true);
|
btnStopEditor.setEnabled(true);
|
setEditing(true);
|
}
|
|
@SuppressWarnings("deprecation")
|
private void endEditor(){
|
try{
|
// 调用 结束编辑后的事件处理逻辑(内部判断是否发生了变更)
|
if (tablePanel.getDataTablePanel().getTable().isEditing()) {
|
tablePanel.getDataTablePanel().getTable().getCellEditor().stopCellEditing();
|
}
|
saveChange();
|
}catch(Exception e){
|
//TODO 异常处理
|
e.printStackTrace();
|
UIFUtils.showErrorMessage(tablePanel, e);
|
} finally{
|
// 当结束编辑后,‘清除’、‘结束编辑’还原为不可用,
|
tablePanel.getDataTablePanel().setCellEditable(false);
|
tablePanel.getDataTablePanel().setLastClickRowToChecked(true);
|
btnStartEditor.setEnabled(true);
|
btnStartEditor.setSelected(false);
|
btnClearSelected.setEnabled(false);
|
btnStopEditor.setEnabled(false);
|
setEditing(false);
|
}
|
}
|
|
private void saveChange() throws Exception{
|
if(tablePanel instanceof EditableTablePanel){
|
((EditableTablePanel)tablePanel).saveChange(params);
|
}
|
}
|
}
|