public boolean include(
Entry<? extends TableModel, ? extends Object> entry)
{
- int col = ((UrlLinkTableModel) entry.getModel()).getIdColumn();
- String id = entry.getStringValue(col);
- return sequenceUrlLinks.isUserEntry(id);
+ return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
}
};
}
int modelIndex = linkUrlTable.convertRowIndexToModel(index);
- // determine if the new selection is a custom url or not
- int col = ((UrlLinkTableModel) linkUrlTable.getModel())
- .getNameColumn();
- if (!sequenceUrlLinks.isUserEntry((String) linkUrlTable.getModel()
- .getValueAt(modelIndex, col)))
+ // enable/disable edit and delete link buttons
+ if (((UrlLinkTableModel) linkUrlTable.getModel())
+ .isRowDeletable(modelIndex))
{
- // entry is not a user-defined url and so should not be edited
- // disable edit and delete buttons
- deleteLink.setEnabled(false);
- editLink.setEnabled(false);
+ deleteLink.setEnabled(true);
}
else
{
- deleteLink.setEnabled(true);
- editLink.setEnabled(true);
+ deleteLink.setEnabled(false);
}
- // BUT if it's the default url, don't allow deletion
- col = ((UrlLinkTableModel) linkUrlTable.getModel())
- .getDefaultColumn();
- if ((boolean) linkUrlTable.getValueAt(index, col))
+ if (((UrlLinkTableModel) linkUrlTable.getModel())
+ .isRowEditable(modelIndex))
{
- deleteLink.setEnabled(false);
+ editLink.setEnabled(true);
+ }
+ else
+ {
+ editLink.setEnabled(false);
}
}
}
import java.util.Iterator;
import java.util.List;
+import javax.swing.RowFilter.Entry;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
+import javax.swing.table.TableModel;
/**
* TableModel for UrlLinks table
return data.get(rowIndex).isEditable(columnIndex);
}
+ /**
+ * Determine if a row is editable indirectly (rather than directly in table as
+ * in isCellEditable)
+ *
+ * @param rowIndex
+ * @return true if row can be edited indirectly
+ */
+ public boolean isRowEditable(int rowIndex)
+ {
+ // to edit, row must be a user entered row
+ return (dataProvider.isUserEntry(data.get(rowIndex).getId()));
+ }
+
+ /**
+ * Determine if a row is deletable
+ *
+ * @param rowIndex
+ * the row to be tested
+ * @return true if row can be deleted
+ */
+ public boolean isRowDeletable(int rowIndex)
+ {
+ // to delete, row must be a user entered row, and not the default row
+ return (dataProvider.isUserEntry(data.get(rowIndex).getId()) && !data
+ .get(rowIndex).getIsDefault());
+ }
+
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex)
{
{
return UrlLinkDisplay.SELECTED;
}
+
+ public boolean isUserEntry(
+ Entry<? extends TableModel, ? extends Object> entry)
+ {
+ return dataProvider
+ .isUserEntry(entry.getStringValue(UrlLinkDisplay.ID));
+ }
}
}
}
}
+
+ /*
+ * Test row 'deletability'
+ */
+ @Test(groups = { "Functional" })
+ public void testDeletable()
+ {
+ UrlLinkTableModel m = new UrlLinkTableModel(prov);
+
+ for (int row = 0; row < m.getRowCount(); row++)
+ {
+ if (row > 4)
+ {
+ Assert.assertTrue(m.isRowDeletable(row));
+ }
+ else
+ {
+ Assert.assertFalse(m.isRowDeletable(row));
+ }
+ }
+ }
+
+ /*
+ * Test indirect row editability
+ */
+ @Test(groups = { "Functional" })
+ public void testRowEditable()
+ {
+ UrlLinkTableModel m = new UrlLinkTableModel(prov);
+
+ for (int row = 0; row < m.getRowCount(); row++)
+ {
+ if (row > 3)
+ {
+ Assert.assertTrue(m.isRowEditable(row));
+ }
+ else
+ {
+ Assert.assertFalse(m.isRowEditable(row));
+ }
+ }
+ }
}