Search in sources :

Example 1 with AttributeValueWrapper

use of org.gephi.ui.tools.plugin.edit.EditWindowUtils.AttributeValueWrapper in project gephi by gephi.

the class EditEdges method prepareEdgesAttributes.

/**
 * Prepare set of attributes of the edges.
 *
 * @return Set of these attributes
 */
private Sheet.Set prepareEdgesAttributes() {
    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 (edges.length > 1) {
            set.setDisplayName(NbBundle.getMessage(EditEdges.class, "EditEdges.attributes.text.multiple"));
        } else {
            set.setDisplayName(NbBundle.getMessage(EditEdges.class, "EditEdges.attributes.text", edges[0].getLabel()));
        }
        Edge row = edges[0];
        AttributeValueWrapper wrap;
        for (Column column : row.getAttributeColumns()) {
            if (multipleEdges) {
                wrap = new MultipleRowsAttributeValueWrapper(edges, column, currentTimeFormat, dateTimeZone);
            } else {
                wrap = new SingleRowAttributeValueWrapper(edges[0], column, currentTimeFormat, dateTimeZone);
            }
            Class<?> type = column.getTypeClass();
            Property p;
            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 : 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) Edge(org.gephi.graph.api.Edge) PropertySupport(org.openide.nodes.PropertySupport)

Example 2 with AttributeValueWrapper

use of org.gephi.ui.tools.plugin.edit.EditWindowUtils.AttributeValueWrapper 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

PropertyEditor (java.beans.PropertyEditor)2 AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)2 Column (org.gephi.graph.api.Column)2 AttributeValueWrapper (org.gephi.ui.tools.plugin.edit.EditWindowUtils.AttributeValueWrapper)2 PropertySupport (org.openide.nodes.PropertySupport)2 Sheet (org.openide.nodes.Sheet)2 Edge (org.gephi.graph.api.Edge)1 Node (org.gephi.graph.api.Node)1 AbstractNode (org.openide.nodes.AbstractNode)1