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);
}
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;
}
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();
}
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;
}
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();
}
Aggregations