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