use of org.cytoscape.browser.internal.util.ValidatedObjectAndEditString in project cytoscape-impl by cytoscape.
the class BrowserTable method selectFromTable.
private void selectFromTable() {
final TableModel model = this.getModel();
if (model instanceof BrowserTableModel == false)
return;
final BrowserTableModel btModel = (BrowserTableModel) model;
if (btModel.getViewMode() != BrowserTableModel.ViewMode.ALL)
return;
final CyTable table = btModel.getDataTable();
final CyColumn pKey = table.getPrimaryKey();
final String pKeyName = pKey.getName();
final int[] rowsSelected = getSelectedRows();
if (rowsSelected.length == 0)
return;
final int selectedRowCount = getSelectedRowCount();
final Set<CyRow> targetRows = new HashSet<CyRow>();
for (int i = 0; i < selectedRowCount; i++) {
// getting the row from data table solves the problem with hidden or
// moved SUID column. However, since the rows might be sorted we
// need to convert the index to model
final ValidatedObjectAndEditString selected = (ValidatedObjectAndEditString) btModel.getValueAt(convertRowIndexToModel(rowsSelected[i]), pKeyName);
targetRows.add(btModel.getRow(selected.getValidatedObject()));
}
// Clear selection for non-global table
final CyTableManager tableManager = serviceRegistrar.getService(CyTableManager.class);
if (tableManager.getGlobalTables().contains(table) == false) {
List<CyRow> allRows = btModel.getDataTable().getAllRows();
try {
ignoreRowSetEvents = true;
for (CyRow row : allRows) {
final Boolean val = row.get(CyNetwork.SELECTED, Boolean.class);
if (targetRows.contains(row)) {
row.set(CyNetwork.SELECTED, true);
continue;
}
if (val != null && (val == true))
row.set(CyNetwork.SELECTED, false);
}
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
final CyNetworkView curView = applicationManager.getCurrentNetworkView();
if (curView != null) {
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
eventHelper.flushPayloadEvents();
curView.updateView();
}
} finally {
ignoreRowSetEvents = false;
}
repaint();
}
}
use of org.cytoscape.browser.internal.util.ValidatedObjectAndEditString in project cytoscape-impl by cytoscape.
the class BrowserTable method showListContents.
public void showListContents(int modelRow, int modelColumn, MouseEvent e) {
final BrowserTableModel model = (BrowserTableModel) getModel();
final Class<?> columnType = model.getColumn(modelColumn).getType();
if (columnType == List.class) {
final ValidatedObjectAndEditString value = (ValidatedObjectAndEditString) model.getValueAt(modelRow, modelColumn);
if (value != null) {
final List<?> list = (List<?>) value.getValidatedObject();
if (list != null && !list.isEmpty())
showCellMenu(List.class, list, "Entries", e);
}
}
}
use of org.cytoscape.browser.internal.util.ValidatedObjectAndEditString in project cytoscape-impl by cytoscape.
the class BrowserTable method changeRowSelection.
protected void changeRowSelection(final Set<Long> suidSelected, final Set<Long> suidUnselected) {
final BrowserTableModel model = (BrowserTableModel) getModel();
final CyTable dataTable = model.getDataTable();
final String pKeyName = dataTable.getPrimaryKey().getName();
final int rowCount = getRowCount();
try {
ignoreRowSelectionEvents = true;
for (int i = 0; i < rowCount; i++) {
// Getting the row from data table solves the problem with hidden or moved SUID column.
// However, since the rows might be sorted we need to convert the index to model
int modelRow = convertRowIndexToModel(i);
final ValidatedObjectAndEditString tableKey = (ValidatedObjectAndEditString) model.getValueAt(modelRow, pKeyName);
Long pk = null;
try {
// TODO: Temp fix: is it a requirement that all CyTables have a Long SUID column as PK?
pk = Long.parseLong(tableKey.getEditString());
} catch (NumberFormatException nfe) {
logger.error("Error parsing long from table " + getName(), nfe);
}
if (pk != null) {
if (suidSelected.contains(pk))
addRowSelectionInterval(i, i);
else if (suidUnselected.contains(pk))
removeRowSelectionInterval(i, i);
}
}
} finally {
ignoreRowSelectionEvents = false;
}
}
use of org.cytoscape.browser.internal.util.ValidatedObjectAndEditString in project cytoscape-impl by cytoscape.
the class BrowserTable method maybeShowPopup.
private void maybeShowPopup(final MouseEvent e) {
if (e.isPopupTrigger()) {
if (LookAndFeelUtil.isWindows())
selectFocusedCell(e);
// Show context menu
final int viewColumn = getColumnModel().getColumnIndexAtX(e.getX());
final int viewRow = e.getY() / getRowHeight();
final int modelColumn = convertColumnIndexToModel(viewColumn);
final int modelRow = convertRowIndexToModel(viewRow);
final BrowserTableModel tableModel = (BrowserTableModel) this.getModel();
// Bail out if we're at the ID column:
if (tableModel.isPrimaryKey(modelColumn))
return;
// Make sure the column and row we're clicking on actually exists!
if (modelColumn >= tableModel.getColumnCount() || modelRow >= tableModel.getRowCount())
return;
final CyColumn cyColumn = tableModel.getColumn(modelColumn);
final Object primaryKeyValue = ((ValidatedObjectAndEditString) tableModel.getValueAt(modelRow, tableModel.getDataTable().getPrimaryKey().getName())).getValidatedObject();
popupMenuHelper.createTableCellMenu(cyColumn, primaryKeyValue, tableModel.getTableType(), this, e.getX(), e.getY(), this);
}
}
Aggregations