Search in sources :

Example 1 with SourceColumnSemantic

use of org.cytoscape.tableimport.internal.util.SourceColumnSemantic in project cytoscape-impl by cytoscape.

the class ImportTablePanel method propertyChange.

/**
 * Listening to local signals used among Swing components in this dialog.
 */
@Override
public void propertyChange(final PropertyChangeEvent evt) {
    if (evt.getPropertyName().equals(ATTR_TYPE_CHANGED)) {
        SourceColumnSemantic type = null;
        int index = -1;
        if (evt instanceof IndexedPropertyChangeEvent) {
            type = (SourceColumnSemantic) ((IndexedPropertyChangeEvent) evt).getNewValue();
            index = ((IndexedPropertyChangeEvent) evt).getIndex();
        }
        // Update UI based on the primary key selection
        if (type == KEY && index >= 0 && importType != NETWORK_IMPORT) {
            getPreviewPanel().repaint();
            final JTable table = getPreviewPanel().getPreviewTable();
            // Update table view
            ColumnResizer.adjustColumnPreferredWidths(table);
            table.repaint();
        }
    }
}
Also used : SourceColumnSemantic(org.cytoscape.tableimport.internal.util.SourceColumnSemantic) JTable(javax.swing.JTable) IndexedPropertyChangeEvent(java.beans.IndexedPropertyChangeEvent)

Example 2 with SourceColumnSemantic

use of org.cytoscape.tableimport.internal.util.SourceColumnSemantic in project cytoscape-impl by cytoscape.

the class PreviewTablePanel method showEditDialog.

private void showEditDialog(final int colIdx) {
    if (colIdx == lastDialogIndex && System.currentTimeMillis() - lastDialogTime < 100)
        return;
    lastDialogIndex = -1;
    lastDialogTime = 0;
    final Window parent = SwingUtilities.getWindowAncestor(PreviewTablePanel.this);
    final PreviewTableModel model = (PreviewTableModel) getPreviewTable().getModel();
    final String attrName = model.getColumnName(colIdx);
    final List<SourceColumnSemantic> availableTypes = TypeUtil.getAvailableTypes(importType);
    final AttributeEditorPanel attrEditorPanel = new AttributeEditorPanel(parent, attrName, availableTypes, types[colIdx], dataTypes[colIdx], listDelimiters[colIdx], iconManager);
    if (LookAndFeelUtil.isWinLAF()) {
        attrEditorPanel.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, UIManager.getColor("activeCaptionBorder")));
        attrEditorPanel.setBackground(UIManager.getColor("TableHeader.background"));
    }
    editDialog = new EditDialog(parent, ModalityType.MODELESS, colIdx, attrEditorPanel);
    editDialog.setUndecorated(true);
    editDialog.add(attrEditorPanel);
    final ActionMap actionMap = attrEditorPanel.getActionMap();
    final InputMap inputMap = attrEditorPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "VK_ESCAPE");
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "VK_ENTER");
    actionMap.put("VK_ESCAPE", new AbstractAction("VK_ESCAPE") {

        @Override
        public void actionPerformed(ActionEvent e) {
            disposeEditDialog();
        }
    });
    actionMap.put("VK_ENTER", new AbstractAction("VK_ENTER") {

        @Override
        public void actionPerformed(ActionEvent e) {
            disposeEditDialog();
        }
    });
    attrEditorPanel.addPropertyChangeListener("attributeName", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            final String attrName = (String) evt.getNewValue();
            if (attrName != null && !attrName.trim().isEmpty()) {
                ((PreviewTableModel) getPreviewTable().getModel()).setColumnName(colIdx, attrName);
                getPreviewTable().getColumnModel().getColumn(colIdx).setHeaderValue(attrName);
                updatePreviewTable();
            }
        }
    });
    attrEditorPanel.addPropertyChangeListener("attributeType", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            setType(colIdx, (SourceColumnSemantic) evt.getNewValue());
            updatePreviewTable();
        }
    });
    attrEditorPanel.addPropertyChangeListener("attributeDataType", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            final AttributeDataType newDataType = (AttributeDataType) evt.getNewValue();
            if (newDataType.isList())
                setListDelimiter(colIdx, attrEditorPanel.getListDelimiter());
            setDataType(colIdx, newDataType);
            updatePreviewTable();
        }
    });
    attrEditorPanel.addPropertyChangeListener("listDelimiter", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            setListDelimiter(colIdx, (String) evt.getNewValue());
            updatePreviewTable();
        }
    });
    positionEditDialog();
    editDialog.addWindowListener(new WindowAdapter() {

        @Override
        public void windowOpened(WindowEvent e) {
            getPreviewTable().getTableHeader().repaint();
            attrEditorPanel.getAttributeNameTextField().requestFocusInWindow();
        }

        @Override
        public void windowClosed(WindowEvent e) {
            getPreviewTable().getTableHeader().repaint();
        }
    });
    editDialog.addWindowFocusListener(new WindowFocusListener() {

        @Override
        public void windowLostFocus(WindowEvent e) {
            if (editDialog != null) {
                lastDialogIndex = editDialog.index;
                lastDialogTime = System.currentTimeMillis();
            }
            disposeEditDialog();
        }

        @Override
        public void windowGainedFocus(WindowEvent e) {
        }
    });
    editDialog.pack();
    editDialog.setVisible(true);
}
Also used : Window(java.awt.Window) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) WindowAdapter(java.awt.event.WindowAdapter) SourceColumnSemantic(org.cytoscape.tableimport.internal.util.SourceColumnSemantic) AttributeDataType(org.cytoscape.tableimport.internal.util.AttributeDataType) WindowEvent(java.awt.event.WindowEvent) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction) WindowFocusListener(java.awt.event.WindowFocusListener)

Example 3 with SourceColumnSemantic

use of org.cytoscape.tableimport.internal.util.SourceColumnSemantic in project cytoscape-impl by cytoscape.

the class AttributeLineParser method parseAll.

/**
 * Import everything regardless associated nodes/edges exist or not.
 * @param parts entries in a line.
 */
public void parseAll(final CyTable table, final String[] parts) {
    // Get key
    final Object primaryKey;
    final int partsLen = parts.length;
    final AttributeDataType typeKey = mapping.getDataTypes()[mapping.getKeyIndex()];
    switch(typeKey) {
        case TYPE_BOOLEAN:
            primaryKey = Boolean.valueOf(parts[mapping.getKeyIndex()].trim());
            break;
        case TYPE_INTEGER:
            primaryKey = Integer.valueOf(parts[mapping.getKeyIndex()].trim());
            break;
        case TYPE_LONG:
            primaryKey = Long.valueOf(parts[mapping.getKeyIndex()].trim());
            break;
        case TYPE_FLOATING:
            primaryKey = Double.valueOf(parts[mapping.getKeyIndex()].trim());
            break;
        default:
            primaryKey = parts[mapping.getKeyIndex()].trim();
    }
    if (partsLen == 1) {
        table.getRow(parts[0]);
    } else {
        final SourceColumnSemantic[] types = mapping.getTypes();
        for (int i = 0; i < partsLen; i++) {
            if (i != mapping.getKeyIndex() && types[i] != SourceColumnSemantic.NONE) {
                if (parts[i] == null)
                    continue;
                else
                    mapAttribute(table, primaryKey, parts[i].trim(), i);
            }
        }
    }
}
Also used : SourceColumnSemantic(org.cytoscape.tableimport.internal.util.SourceColumnSemantic) AttributeDataType(org.cytoscape.tableimport.internal.util.AttributeDataType)

Example 4 with SourceColumnSemantic

use of org.cytoscape.tableimport.internal.util.SourceColumnSemantic in project cytoscape-impl by cytoscape.

the class NetworkLineParser method parseEntry.

public void parseEntry(final String[] parts) {
    final CyNode source = createNode(parts, mapping.getSourceIndex());
    final CyNode target = createNode(parts, mapping.getTargetIndex());
    final SourceColumnSemantic[] types = mapping.getTypes();
    final List<Integer> srcAttrIdxs = new ArrayList<>();
    final List<Integer> tgtAttrIdxs = new ArrayList<>();
    final List<Integer> edgeAttrIdxs = new ArrayList<>();
    for (int i = 0; i < types.length; i++) {
        if (types[i] == SourceColumnSemantic.SOURCE_ATTR)
            srcAttrIdxs.add(i);
        else if (types[i] == SourceColumnSemantic.TARGET_ATTR)
            tgtAttrIdxs.add(i);
        else if (types[i] == SourceColumnSemantic.EDGE_ATTR || types[i] == SourceColumnSemantic.ATTR)
            edgeAttrIdxs.add(i);
    }
    if (source != null)
        addAttributes(source, parts, srcAttrIdxs);
    if (target != null)
        addAttributes(target, parts, tgtAttrIdxs);
    // Single column nodes list.  Just add nodes.
    if (source == null || target == null)
        return;
    final String interaction;
    if ((mapping.getInteractionIndex() == -1) || (mapping.getInteractionIndex() > (parts.length - 1)) || (parts[mapping.getInteractionIndex()] == null)) {
        interaction = mapping.getDefaultInteraction();
    } else {
        interaction = parts[mapping.getInteractionIndex()];
    }
    final CyEdge edge = network.addEdge(source, target, true);
    network.getRow(edge).set(CyEdge.INTERACTION, interaction);
    String edgeName = network.getRow(source).get(CyNetwork.NAME, String.class) + " (" + interaction + ") " + network.getRow(target).get(CyNetwork.NAME, String.class);
    network.getRow(edge).set(CyNetwork.NAME, edgeName);
    edgeList.add(edge.getSUID());
    if (edge != null)
        addAttributes(edge, parts, edgeAttrIdxs);
}
Also used : SourceColumnSemantic(org.cytoscape.tableimport.internal.util.SourceColumnSemantic) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge)

Example 5 with SourceColumnSemantic

use of org.cytoscape.tableimport.internal.util.SourceColumnSemantic in project cytoscape-impl by cytoscape.

the class ImportTablePanel method getAttributeMappingParameters.

public AttributeMappingParameters getAttributeMappingParameters() throws Exception {
    final String sourceName = getPreviewPanel().getSourceName();
    final String[] attrNames = getPreviewPanel().getAttributeNames();
    final SourceColumnSemantic[] types = getPreviewPanel().getTypes();
    if (!isAttributeNamesValid(attrNames, types))
        return null;
    final SourceColumnSemantic[] typesCopy = Arrays.copyOf(types, types.length);
    final AttributeDataType[] dataTypes = getPreviewPanel().getDataTypes();
    final AttributeDataType[] dataTypesCopy = Arrays.copyOf(dataTypes, dataTypes.length);
    final String[] listDelimiters = getPreviewPanel().getListDelimiters();
    final String[] listDelimitersCopy = Arrays.copyOf(listDelimiters, listDelimiters.length);
    int startLineNumber = getStartLineNumber();
    String commentChar = null;
    if (!getCommentLinePrefix().isEmpty())
        commentChar = getCommentLinePrefix();
    // Build mapping parameter object.
    final List<String> del = checkDelimiter();
    final int keyInFile = getPreviewPanel().getColumnIndex(KEY);
    final AttributeMappingParameters mapping = new AttributeMappingParameters(sourceName, del, listDelimitersCopy, keyInFile, attrNames, dataTypesCopy, typesCopy, startLineNumber, commentChar);
    return mapping;
}
Also used : SourceColumnSemantic(org.cytoscape.tableimport.internal.util.SourceColumnSemantic) AttributeDataType(org.cytoscape.tableimport.internal.util.AttributeDataType) AttributeMappingParameters(org.cytoscape.tableimport.internal.reader.AttributeMappingParameters)

Aggregations

SourceColumnSemantic (org.cytoscape.tableimport.internal.util.SourceColumnSemantic)13 AttributeDataType (org.cytoscape.tableimport.internal.util.AttributeDataType)8 ArrayList (java.util.ArrayList)4 JToggleButton (javax.swing.JToggleButton)3 IOException (java.io.IOException)2 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)2 Sheet (org.apache.poi.ss.usermodel.Sheet)2 Workbook (org.apache.poi.ss.usermodel.Workbook)2 AttributeMappingParameters (org.cytoscape.tableimport.internal.reader.AttributeMappingParameters)2 NetworkTableMappingParameters (org.cytoscape.tableimport.internal.reader.NetworkTableMappingParameters)2 Window (java.awt.Window)1 ActionEvent (java.awt.event.ActionEvent)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 WindowFocusListener (java.awt.event.WindowFocusListener)1 IndexedPropertyChangeEvent (java.beans.IndexedPropertyChangeEvent)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 FileInputStream (java.io.FileInputStream)1 AbstractAction (javax.swing.AbstractAction)1