use of org.cytoscape.tableimport.internal.util.AttributeDataType 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.AttributeDataType in project cytoscape-impl by cytoscape.
the class AttributeLineParser method mapAttribute.
/**
* Based on the attribute types, map the entry to CyAttributes.<br>
*/
private void mapAttribute(final CyTable table, final Object key, final String entry, final int index) {
final AttributeDataType type = mapping.getDataTypes()[index];
try {
if (type.isList()) {
final String[] delimiters = mapping.getListDelimiters();
String delimiter = delimiters != null && delimiters.length > index ? delimiters[index] : AbstractMappingParameters.DEF_LIST_DELIMITER;
if (delimiter == null || delimiter.isEmpty())
delimiter = AbstractMappingParameters.DEF_LIST_DELIMITER;
Object value = parse(entry, type, delimiter);
setListAttribute(table, type, key, mapping.getAttributeNames()[index], value);
} else {
setAttribute(table, type, key, mapping.getAttributeNames()[index], entry);
}
} catch (Exception e) {
invalid.put(key.toString(), entry);
}
}
use of org.cytoscape.tableimport.internal.util.AttributeDataType 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.AttributeDataType in project cytoscape-impl by cytoscape.
the class NetworkLineParser method mapAttribute.
/**
* Based on the attribute types, map the entry to Node or Edge tables.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private <T extends CyIdentifiable> void mapAttribute(final T element, final String entry, final int index) {
if (entry == null || entry.length() == 0)
return;
final AttributeDataType type = mapping.getDataTypes()[index];
if (type.isList()) {
final CyTable table = network.getRow(element).getTable();
if (table.getColumn(mapping.getAttributeNames()[index]) == null)
table.createListColumn(mapping.getAttributeNames()[index], type.getListType(), false);
final String[] delimiters = mapping.getListDelimiters();
String delimiter = delimiters != null && delimiters.length > index ? delimiters[index] : AbstractMappingParameters.DEF_LIST_DELIMITER;
if (delimiter == null || delimiter.isEmpty())
delimiter = AbstractMappingParameters.DEF_LIST_DELIMITER;
Object value = parse(entry, type, delimiter);
if (value instanceof List) {
// In case of list, do not overwrite the attribute. Get the existing list, and add it to the list.
List<Object> curList = network.getRow(element).get(mapping.getAttributeNames()[index], List.class);
if (curList == null)
curList = new ArrayList<>();
curList.addAll((List) value);
value = curList;
}
network.getRow(element).set(mapping.getAttributeNames()[index], value);
} else {
createColumn(element, mapping.getAttributeNames()[index], type.getType());
final Object value = parse(entry, type, null);
network.getRow(element).set(mapping.getAttributeNames()[index], value);
}
}
use of org.cytoscape.tableimport.internal.util.AttributeDataType 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