Search in sources :

Example 6 with ValidatedObjectAndEditString

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();
    }
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) CyColumn(org.cytoscape.model.CyColumn) ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) CyRow(org.cytoscape.model.CyRow) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) CyTableManager(org.cytoscape.model.CyTableManager) CyNetworkView(org.cytoscape.view.model.CyNetworkView) TableModel(javax.swing.table.TableModel) HashSet(java.util.HashSet)

Example 7 with ValidatedObjectAndEditString

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);
        }
    }
}
Also used : ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) List(java.util.List) ArrayList(java.util.ArrayList)

Example 8 with ValidatedObjectAndEditString

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;
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString)

Example 9 with ValidatedObjectAndEditString

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);
    }
}
Also used : ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) CyColumn(org.cytoscape.model.CyColumn) EventObject(java.util.EventObject)

Aggregations

ValidatedObjectAndEditString (org.cytoscape.browser.internal.util.ValidatedObjectAndEditString)9 CyColumn (org.cytoscape.model.CyColumn)3 CyTable (org.cytoscape.model.CyTable)3 EventObject (java.util.EventObject)2 HashSet (java.util.HashSet)2 CyApplicationManager (org.cytoscape.application.CyApplicationManager)2 CyEventHelper (org.cytoscape.event.CyEventHelper)2 CyRow (org.cytoscape.model.CyRow)2 CyNetworkView (org.cytoscape.view.model.CyNetworkView)2 Point (java.awt.Point)1 StringSelection (java.awt.datatransfer.StringSelection)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JFrame (javax.swing.JFrame)1 TableModel (javax.swing.table.TableModel)1 Equation (org.cytoscape.equations.Equation)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNode (org.cytoscape.model.CyNode)1 CyTableManager (org.cytoscape.model.CyTableManager)1