Search in sources :

Example 31 with AttributeColumnsController

use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.

the class EditNodes method prepareNodesAttributes.

/**
 * Prepare set of attributes of the node(s).
 *
 * @return Set of these attributes
 */
private Sheet.Set prepareNodesAttributes() {
    try {
        // DynamicModel dm=Lookup.getDefault().lookup(DynamicController.class).getModel();
        // if(dm!=null){
        // currentTimeFormat=dm.getTimeFormat();
        // }
        AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
        Sheet.Set set = new Sheet.Set();
        set.setName("attributes");
        if (nodes.length > 1) {
            set.setDisplayName(NbBundle.getMessage(EditNodes.class, "EditNodes.attributes.text.multiple"));
        } else {
            set.setDisplayName(NbBundle.getMessage(EditNodes.class, "EditNodes.attributes.text", nodes[0].getLabel()));
        }
        Node row = nodes[0];
        AttributeValueWrapper wrap;
        for (Column column : row.getAttributeColumns()) {
            if (multipleNodes) {
                wrap = new MultipleRowsAttributeValueWrapper(nodes, column, currentTimeFormat, dateTimeZone);
            } else {
                wrap = new SingleRowAttributeValueWrapper(nodes[0], column, currentTimeFormat, dateTimeZone);
            }
            Property p;
            Class<?> type = column.getTypeClass();
            PropertyEditor propEditor = PropertyEditorManager.findEditor(type);
            if (ac.canChangeColumnData(column)) {
                // Editable column, provide "set" method:
                if (propEditor != null && !type.isArray()) {
                    // The type can be edited by default:
                    p = new PropertySupport.Reflection(wrap, type, "getValue" + type.getSimpleName(), "setValue" + type.getSimpleName());
                } else {
                    // Use the AttributeType as String:
                    p = new PropertySupport.Reflection(wrap, String.class, "getValueAsString", "setValueAsString");
                }
            } else // Not editable column, do not provide "set" method:
            if (propEditor != null) {
                // The type can be edited by default:
                p = new PropertySupport.Reflection(wrap, type, "getValue" + type.getSimpleName(), null);
            } else {
                // Use the AttributeType as String:
                p = new PropertySupport.Reflection(wrap, String.class, "getValueAsString", null);
            }
            p.setDisplayName(column.getTitle());
            p.setName(column.getId());
            set.put(p);
        }
        return set;
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
        return null;
    }
}
Also used : Node(org.gephi.graph.api.Node) AbstractNode(org.openide.nodes.AbstractNode) AttributeValueWrapper(org.gephi.ui.tools.plugin.edit.EditWindowUtils.AttributeValueWrapper) Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) PropertyEditor(java.beans.PropertyEditor) Sheet(org.openide.nodes.Sheet) PropertySupport(org.openide.nodes.PropertySupport)

Aggregations

AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)31 Column (org.gephi.graph.api.Column)23 Element (org.gephi.graph.api.Element)14 BigDecimal (java.math.BigDecimal)8 ArrayList (java.util.ArrayList)7 DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)5 Edge (org.gephi.graph.api.Edge)3 PropertyEditor (java.beans.PropertyEditor)2 Node (org.gephi.graph.api.Node)2 TimeFormat (org.gephi.graph.api.TimeFormat)2 IntervalSet (org.gephi.graph.api.types.IntervalSet)2 AttributeValueWrapper (org.gephi.ui.tools.plugin.edit.EditWindowUtils.AttributeValueWrapper)2 DateTimeZone (org.joda.time.DateTimeZone)2 PropertySupport (org.openide.nodes.PropertySupport)2 Sheet (org.openide.nodes.Sheet)2 CsvWriter (com.csvreader.CsvWriter)1 Dialog (java.awt.Dialog)1 File (java.io.File)1 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1