Skip to content

Commit

Permalink
fix counting rows during attribute editing
Browse files Browse the repository at this point in the history
  • Loading branch information
dpolivaev committed Mar 29, 2019
1 parent ef6b04a commit a1ada31
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@
import org.freeplane.features.styles.MapStyleModel;
import org.freeplane.features.text.TextController;
import org.freeplane.features.text.mindmapmode.EditNodeBase;
import org.freeplane.features.text.mindmapmode.MTextController;
import org.freeplane.features.text.mindmapmode.EditNodeBase.EditedComponent;
import org.freeplane.features.text.mindmapmode.EditNodeBase.IEditControl;
import org.freeplane.features.text.mindmapmode.MTextController;
import org.freeplane.features.ui.ViewController;
import org.freeplane.view.swing.map.FreeplaneTooltip;
import org.freeplane.view.swing.map.MapView;
Expand Down Expand Up @@ -591,16 +591,29 @@ float getZoom() {
/**
*/
public void insertRow(final int row) {
int actuallyInsertedRow = row;
if (getModel() instanceof ExtendedAttributeTableModelDecorator) {
final ExtendedAttributeTableModelDecorator model = (ExtendedAttributeTableModelDecorator) getModel();
if (isEditing() && getCellEditor() != null && !getCellEditor().stopCellEditing()) {
return;
}
model.insertRow(row);
changeSelection(row, 0, false, false);
if (editCellAt(row, 0)) {
getEditorComponent().requestFocusInWindow();
if (isEditing()) {
final int editingRow = getEditingRow();
final int rowCount = getRowCount();
if (!getCellEditor().stopCellEditing()) {
return;
}
final int updatedRowCount = getRowCount();
if(updatedRowCount < rowCount && row >= editingRow) {
actuallyInsertedRow--;
}
}
insertRow(model, actuallyInsertedRow);
}
}

private void insertRow(final ExtendedAttributeTableModelDecorator model, final int row) {
model.insertRow(row);
changeSelection(row, 0, false, false);
if (editCellAt(row, 0)) {
getEditorComponent().requestFocusInWindow();
}
}

Expand Down Expand Up @@ -793,7 +806,6 @@ public void setOptimalColumnWidths() {
Component comp = null;
int maxCellWidth = 2 * (int) (Math.ceil(getFont().getSize2D() / UITools.FONT_SCALE_FACTOR + EXTRA_HEIGHT));
int rowCount = getRowCount();
boolean isInsideNodeView = getNodeViewAncestor() != null;
if(rowCount > 0) {
for (int col = 0; col < 2; col++) {
for (int row = 0; row < rowCount; row++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javax.swing.event.TableModelEvent;

import org.freeplane.features.attribute.Attribute;
import org.freeplane.features.attribute.NodeAttributeTableModel;

/**
* @author Dimitry Polivaev
Expand Down Expand Up @@ -72,13 +73,15 @@ public int getRowCount() {

@Override
public Object getValueAt(final int row, final int col) {
if (row < newRow) {
return getNodeAttributeModel().getValueAt(row, col);
}
if (row == newRow) {
final NodeAttributeTableModel attributes = getNodeAttributeModel();
if (row == newRow || row >= attributes.getRowCount()) {
return "";
}
return getNodeAttributeModel().getValueAt(row - 1, col);
else if (row < newRow) {
return attributes.getValueAt(row, col);
}
else
return attributes.getValueAt(row - 1, col);
}

public void insertRow(final int index) {
Expand Down

0 comments on commit a1ada31

Please sign in to comment.