Search in sources :

Example 1 with ValidatedObjectAndEditString

use of org.cytoscape.browser.internal.util.ValidatedObjectAndEditString in project cytoscape-impl by cytoscape.

the class BrowserTableModel method getValidatedObjectAndEditString.

private ValidatedObjectAndEditString getValidatedObjectAndEditString(final CyRow row, final String columnName) {
    if (row == null)
        return null;
    Object raw = row.getRaw(columnName);
    if (raw == null) {
        CyColumn column = row.getTable().getColumn(columnName);
        if (column != null)
            raw = column.getDefaultValue();
    }
    if (raw == null)
        return null;
    // Optimisation hack:
    final boolean isEquation = raw instanceof Equation;
    final Object cooked = !isEquation ? raw : getColumnValue(row, columnName);
    final String editString = createEditString(raw);
    if (cooked != null)
        return new ValidatedObjectAndEditString(cooked, editString, isEquation);
    final String lastInternalError = dataTable.getLastInternalError();
    return new ValidatedObjectAndEditString(cooked, editString, lastInternalError, isEquation);
}
Also used : ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) CyColumn(org.cytoscape.model.CyColumn) Equation(org.cytoscape.equations.Equation) ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString)

Example 2 with ValidatedObjectAndEditString

use of org.cytoscape.browser.internal.util.ValidatedObjectAndEditString in project cytoscape-impl by cytoscape.

the class MultiLineTableCellEditor method getTableCellEditorComponent.

@Override
public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int row, final int column) {
    final String text = (value != null) ? ((ValidatedObjectAndEditString) value).getEditString() : "";
    textArea.setTable(table);
    textArea.setText(text);
    return textArea;
}
Also used : ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString)

Example 3 with ValidatedObjectAndEditString

use of org.cytoscape.browser.internal.util.ValidatedObjectAndEditString in project cytoscape-impl by cytoscape.

the class BrowserTable method copyToClipBoard.

private String copyToClipBoard() {
    final StringBuffer sbf = new StringBuffer();
    /*
		 * Check to ensure we have selected only a contiguous block of cells.
		 */
    final int numcols = this.getSelectedColumnCount();
    final int numrows = this.getSelectedRowCount();
    final int[] rowsselected = this.getSelectedRows();
    final int[] colsselected = this.getSelectedColumns();
    // Return if no cell is selected.
    if (numcols == 0 && numrows == 0)
        return null;
    if (!((numrows - 1 == rowsselected[rowsselected.length - 1] - rowsselected[0] && numrows == rowsselected.length) && (numcols - 1 == colsselected[colsselected.length - 1] - colsselected[0] && numcols == colsselected.length))) {
        final JFrame rootFrame = (JFrame) SwingUtilities.getRoot(this);
        JOptionPane.showMessageDialog(rootFrame, "Invalid Copy Selection", "Invalid Copy Selection", JOptionPane.ERROR_MESSAGE);
        return null;
    }
    for (int i = 0; i < numrows; i++) {
        for (int j = 0; j < numcols; j++) {
            final Object cellValue = this.getValueAt(rowsselected[i], colsselected[j]);
            final String cellText = cellValue instanceof ValidatedObjectAndEditString ? ((ValidatedObjectAndEditString) cellValue).getEditString() : null;
            sbf.append(cellText != null ? escape(cellText) : "");
            if (j < numcols - 1)
                sbf.append(CELL_BREAK);
        }
        sbf.append(LINE_BREAK);
    }
    final StringSelection selection = new StringSelection(sbf.toString());
    systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    systemClipboard.setContents(selection, selection);
    return sbf.toString();
}
Also used : ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) JFrame(javax.swing.JFrame) EventObject(java.util.EventObject) ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) StringSelection(java.awt.datatransfer.StringSelection)

Example 4 with ValidatedObjectAndEditString

use of org.cytoscape.browser.internal.util.ValidatedObjectAndEditString in project cytoscape-impl by cytoscape.

the class BrowserTableCellRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
    final ValidatedObjectAndEditString objEditStr = (ValidatedObjectAndEditString) value;
    final Object validatedObj = objEditStr != null ? objEditStr.getValidatedObject() : null;
    if (validatedObj instanceof Boolean)
        setFont(iconManager.getIconFont(12.0f));
    else
        setFont(defaultFont);
    setBackground(UIManager.getColor("Table.background"));
    setIcon(objEditStr != null && objEditStr.isEquation() ? EQUATION_ICON : null);
    setVerticalTextPosition(JLabel.CENTER);
    setHorizontalTextPosition(JLabel.CENTER);
    if (validatedObj instanceof Boolean)
        setHorizontalAlignment(JLabel.CENTER);
    else
        setHorizontalAlignment(validatedObj instanceof Number ? JLabel.RIGHT : JLabel.LEFT);
    final boolean isError = objEditStr != null && objEditStr.getErrorText() != null;
    // First, set values
    if (objEditStr == null || (objEditStr.getValidatedObject() == null && objEditStr.getErrorText() == null)) {
        setText("");
        setToolTipText(null);
    } else {
        final String displayText;
        if (objEditStr.getErrorText() != null)
            displayText = "#ERR: " + objEditStr.getErrorText();
        else if (validatedObj instanceof Boolean)
            displayText = validatedObj == Boolean.TRUE ? IconManager.ICON_CHECK_SQUARE : IconManager.ICON_SQUARE_O;
        else if (validatedObj instanceof Double) {
            final BrowserTableColumnModel model = (BrowserTableColumnModel) table.getColumnModel();
            final String colName = table.getColumnName(column);
            String formatStr = model.getColumnFormat(colName);
            if (formatStr == null)
                formatStr = propManager.getProperties().getProperty(SetColumnFormatDialog.FLOAT_FORMAT_PROPERTY);
            if (formatStr == null)
                displayText = validatedObj.toString();
            else
                displayText = String.format(formatStr, validatedObj);
        } else
            displayText = validatedObj.toString();
        setText(displayText);
        String tooltipText = validatedObj instanceof Boolean ? validatedObj.toString() : displayText;
        if (tooltipText.length() > 100)
            setToolTipText(tooltipText.substring(0, 100) + "...");
        else
            setToolTipText(tooltipText);
    }
    // If selected, return
    if (isSelected) {
        if (table.getSelectedColumn() == column && table.getSelectedRow() == row) {
            // Selected
            // cell
            setBackground(UIManager.getColor("Table.focusCellBackground"));
            setForeground(UIManager.getColor("Table.focusCellForeground"));
        } else {
            setForeground(isError ? LookAndFeelUtil.getErrorColor() : UIManager.getColor("Table.selectionForeground"));
            setBackground(UIManager.getColor("Table.selectionBackground"));
        }
    } else {
        // If non-editable, grey it out.
        if (table.getModel() instanceof BrowserTableModel && !table.isCellEditable(0, column))
            setForeground(UIManager.getColor("TextField.inactiveForeground"));
        else
            setForeground(isError ? LookAndFeelUtil.getErrorColor() : UIManager.getColor("Table.foreground"));
    }
    return this;
}
Also used : ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString)

Example 5 with ValidatedObjectAndEditString

use of org.cytoscape.browser.internal.util.ValidatedObjectAndEditString in project cytoscape-impl by cytoscape.

the class PopupMenuHelper method selectElementsFromSelectedRows.

private void selectElementsFromSelectedRows(final JTable table, final Class<? extends CyIdentifiable> tableType) {
    final Thread t = new Thread() {

        @Override
        public void run() {
            final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
            final CyNetwork net = applicationManager.getCurrentNetwork();
            if (net != null) {
                final BrowserTableModel tableModel = (BrowserTableModel) table.getModel();
                final int[] selectedRows = table.getSelectedRows();
                final Set<CyRow> targetRows = new HashSet<CyRow>();
                for (final int rowIndex : selectedRows) {
                    // 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) tableModel.getValueAt(table.convertRowIndexToModel(rowIndex), CyNetwork.SUID);
                    targetRows.add(tableModel.getRow(selected.getValidatedObject()));
                }
                final CyTable cyTable = tableType == CyNode.class ? net.getDefaultNodeTable() : net.getDefaultEdgeTable();
                for (final CyRow cyRow : cyTable.getAllRows()) cyRow.set(CyNetwork.SELECTED, targetRows.contains(cyRow));
                final CyNetworkView view = applicationManager.getCurrentNetworkView();
                if (view != null) {
                    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
                    eventHelper.flushPayloadEvents();
                    view.updateView();
                }
            }
        }
    };
    t.start();
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) Point(java.awt.Point) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashSet(java.util.HashSet)

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