Browse Source

REPORT-19636 填报属性里,智能添加单元格组时,鼠标连续选中一片单元格,如果拖动稍微快了一点,选择会出现丢失

bugfix/10.0
Hades 5 years ago
parent
commit
007291ce02
  1. 72
      designer-realize/src/main/java/com/fr/design/write/submit/SmartInsertDBManipulationPane.java

72
designer-realize/src/main/java/com/fr/design/write/submit/SmartInsertDBManipulationPane.java

@ -32,11 +32,20 @@ import com.fr.stable.ColumnRowGroup;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.write.DMLConfigJob; import com.fr.write.DMLConfigJob;
import javax.swing.*; import javax.swing.BorderFactory;
import javax.swing.JDialog;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn; import javax.swing.table.TableColumn;
import java.awt.*; import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
public class SmartInsertDBManipulationPane extends DBManipulationPane { public class SmartInsertDBManipulationPane extends DBManipulationPane {
private static final Selection NO_SELECTION = new CellSelection(-1, -1, -1, -1); private static final Selection NO_SELECTION = new CellSelection(-1, -1, -1, -1);
@ -115,6 +124,7 @@ public class SmartInsertDBManipulationPane extends DBManipulationPane {
* *
* @param evt 事件对象 * @param evt 事件对象
*/ */
@Override
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
BasicPane bPane = new BasicPane() { BasicPane bPane = new BasicPane() {
@Override @Override
@ -131,6 +141,7 @@ public class SmartInsertDBManipulationPane extends DBManipulationPane {
double f = TableLayout.FILL; double f = TableLayout.FILL;
bPane.add(TableLayoutHelper.createTableLayoutPane(coms, new double[]{p, p}, new double[]{p, f}), BorderLayout.NORTH); bPane.add(TableLayoutHelper.createTableLayoutPane(coms, new double[]{p, p}, new double[]{p, f}), BorderLayout.NORTH);
BasicDialog dlg = bPane.showSmallWindow(SwingUtilities.getWindowAncestor(SmartInsertDBManipulationPane.this), new DialogActionAdapter() { BasicDialog dlg = bPane.showSmallWindow(SwingUtilities.getWindowAncestor(SmartInsertDBManipulationPane.this), new DialogActionAdapter() {
@Override
public void doOk() { public void doOk() {
int row_offset = ((Number) rowSpinner.getValue()).intValue(); int row_offset = ((Number) rowSpinner.getValue()).intValue();
int column_offset = ((Number) columnSpinner.getValue()).intValue(); int column_offset = ((Number) columnSpinner.getValue()).intValue();
@ -177,6 +188,7 @@ public class SmartInsertDBManipulationPane extends DBManipulationPane {
* *
* @param evt 事件s * @param evt 事件s
*/ */
@Override
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
showCellWindow(false); showCellWindow(false);
} }
@ -192,6 +204,7 @@ public class SmartInsertDBManipulationPane extends DBManipulationPane {
* *
* @param e 事件s * @param e 事件s
*/ */
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showCellWindow(true); showCellWindow(true);
} }
@ -268,6 +281,7 @@ public class SmartInsertDBManipulationPane extends DBManipulationPane {
* *
* @throws Exception * @throws Exception
*/ */
@Override
public void checkValid() throws Exception { public void checkValid() throws Exception {
KeyColumnTableModel model = (KeyColumnTableModel) keyColumnValuesTable.getModel(); KeyColumnTableModel model = (KeyColumnTableModel) keyColumnValuesTable.getModel();
int cnt = model.getRowCount(); int cnt = model.getRowCount();
@ -294,6 +308,10 @@ public class SmartInsertDBManipulationPane extends DBManipulationPane {
// 单元格组要记录下之前的选中情况 // 单元格组要记录下之前的选中情况
private CellSelection oriCellSelection = null; private CellSelection oriCellSelection = null;
private List<String> newAdd = new ArrayList<String>();
private List<String> oldAdd = new ArrayList<String>();
public SmartJTablePane4DB(KeyColumnTableModel model, ElementCasePane actionReportPane) { public SmartJTablePane4DB(KeyColumnTableModel model, ElementCasePane actionReportPane) {
this(model, actionReportPane, false); this(model, actionReportPane, false);
} }
@ -347,6 +365,7 @@ public class SmartInsertDBManipulationPane extends DBManipulationPane {
* *
* @throws Exception * @throws Exception
*/ */
@Override
public void checkValid() throws Exception { public void checkValid() throws Exception {
SmartInsertDBManipulationPane.this.checkValid(); SmartInsertDBManipulationPane.this.checkValid();
} }
@ -402,19 +421,21 @@ public class SmartInsertDBManipulationPane extends DBManipulationPane {
// 要考虑多选的情况 要结合之前的看看 可能是增加 也可能需要减少 // 要考虑多选的情况 要结合之前的看看 可能是增加 也可能需要减少
ColumnRowGroup add = new ColumnRowGroup(); ColumnRowGroup add = new ColumnRowGroup();
int removeCount = 0;
if (oriCellSelection != null && isSameStartPoint(cellselection, oriCellSelection)) { if (oriCellSelection != null && isSameStartPoint(cellselection, oriCellSelection)) {
removeCount = dealDragSelection(add, cellselection); dealDragSelection(add, cellselection, newValue);
} else if (cellselection.getSelectedType() == CellSelection.CHOOSE_ROW || cellselection.getSelectedType() == CellSelection.CHOOSE_COLUMN) { } else if (cellselection.getSelectedType() == CellSelection.CHOOSE_ROW || cellselection.getSelectedType() == CellSelection.CHOOSE_COLUMN) {
dealSelectColRow(add, cellselection); dealSelectColRow(add, cellselection);
} else { } else {
add.addColumnRow(ColumnRow.valueOf(cellselection.getColumn(), cellselection.getRow())); ColumnRow columnRow = ColumnRow.valueOf(cellselection.getColumn(), cellselection.getRow());
String allColumnRow = columnRow.toString();
if (!allColumnRow.contains(columnRow.toString())) {
add.addColumnRow(columnRow);
}
} }
if (add.getSize() > 0) { if (add.getSize() > 0) {
newValue.addAll(add); newValue.addAll(add);
} else if (removeCount > 0) {
newValue.splice(newValue.getSize() - removeCount, removeCount);
} }
kcv.cv.obj = newValue; kcv.cv.obj = newValue;
@ -438,24 +459,29 @@ public class SmartInsertDBManipulationPane extends DBManipulationPane {
return cs1.getColumn() == cs2.getColumn() && cs1.getRow() == cs2.getRow(); return cs1.getColumn() == cs2.getColumn() && cs1.getRow() == cs2.getRow();
} }
private int dealDragSelection(ColumnRowGroup add, CellSelection cellselection) { private void dealDragSelection(ColumnRowGroup add, CellSelection cellselection, ColumnRowGroup newValue) {
int removeCount = 0; int c = cellselection.getColumn();
if (cellselection.getRowSpan() == oriCellSelection.getRowSpan() + 1) { int cs = cellselection.getColumnSpan();
for (int i = 0; i < cellselection.getColumnSpan(); i++) { int r = cellselection.getRow();int rs = cellselection.getRowSpan();
add.addColumnRow(ColumnRow.valueOf( String allColumnRow = newValue.toString();
cellselection.getColumn() + i, cellselection.getRow() + cellselection.getRowSpan() - 1)); newAdd.clear();
} for (int i = 0; i < cs; i++) {
} else if (cellselection.getRowSpan() == oriCellSelection.getRowSpan() - 1) { for (int j = 0; j < rs; j++) {
removeCount = cellselection.getColumnSpan(); ColumnRow columnRow = ColumnRow.valueOf(c + i, r + j);
} else if (cellselection.getColumnSpan() == oriCellSelection.getColumnSpan() + 1) { if (!allColumnRow.contains(columnRow.toString())) {
for (int i = 0; i < cellselection.getRowSpan(); i++) { add.addColumnRow(columnRow);
add.addColumnRow(ColumnRow.valueOf( }
cellselection.getColumn() + cellselection.getColumnSpan() - 1, cellselection.getRow() + i)); newAdd.add(columnRow.toString());
} }
} else if (cellselection.getColumnSpan() == oriCellSelection.getColumnSpan() - 1) {
removeCount = cellselection.getRowSpan();
} }
return removeCount; int oldSize = oldAdd.size();
int newSize = newAdd.size();
if (oldSize > newSize && oldAdd.containsAll(newAdd)) {
int diff = oldSize - newSize;
newValue.splice(newValue.getSize() - diff, diff);
}
oldAdd.clear();
oldAdd.addAll(newAdd);
} }
private void dealSelectColRow(ColumnRowGroup add, CellSelection se) { private void dealSelectColRow(ColumnRowGroup add, CellSelection se) {

Loading…
Cancel
Save