Search in sources :

Example 26 with AttributeColumnsController

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

the class AttributeColumnsMergeStrategiesControllerImpl method booleanLogicOperationsMerge.

@Override
public Column booleanLogicOperationsMerge(Table table, Column[] columnsToMerge, BooleanOperations[] booleanOperations, String newColumnTitle) {
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    if (table == null || columnsToMerge == null || booleanOperations == null || booleanOperations.length != columnsToMerge.length - 1) {
        throw new IllegalArgumentException("table, columns or operations can't be null and operations length must be columns length -1");
    }
    for (Column column : columnsToMerge) {
        if (!column.getTypeClass().equals(Boolean.class)) {
            throw new IllegalArgumentException("All columns have to be boolean columns");
        }
    }
    Column newColumn;
    newColumn = ac.addAttributeColumn(table, newColumnTitle, Boolean.class);
    if (newColumn == null) {
        return null;
    }
    Boolean value;
    Boolean secondValue;
    for (Element row : ac.getTableAttributeRows(table)) {
        value = (Boolean) row.getAttribute(columnsToMerge[0]);
        // Use false if null
        value = value != null ? value : false;
        for (int i = 0; i < booleanOperations.length; i++) {
            secondValue = (Boolean) row.getAttribute(columnsToMerge[i + 1]);
            // Use false if null
            secondValue = secondValue != null ? secondValue : false;
            switch(booleanOperations[i]) {
                case AND:
                    value = value && secondValue;
                    break;
                case OR:
                    value = value || secondValue;
                    break;
                case XOR:
                    value = value ^ secondValue;
                    break;
                case NAND:
                    value = !(value && secondValue);
                    break;
                case NOR:
                    value = !(value || secondValue);
                    break;
            }
        }
        row.setAttribute(newColumn, value);
    }
    return newColumn;
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element)

Example 27 with AttributeColumnsController

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

the class AttributeColumnsMergeStrategiesControllerImpl method minValueNumbersMerge.

@Override
public Column minValueNumbersMerge(Table table, Column[] columnsToMerge, String newColumnTitle) {
    checkTableAndColumnsAreNumberOrNumberList(table, columnsToMerge);
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    Column newColumn;
    // Create as BIGDECIMAL column by default. Then it can be duplicated to other type.
    newColumn = ac.addAttributeColumn(table, newColumnTitle, BigDecimal.class);
    if (newColumn == null) {
        return null;
    }
    BigDecimal min;
    for (Element row : ac.getTableAttributeRows(table)) {
        min = StatisticsUtils.minValue(ac.getRowNumbers(row, columnsToMerge));
        row.setAttribute(newColumn, min);
    }
    return newColumn;
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element) BigDecimal(java.math.BigDecimal)

Example 28 with AttributeColumnsController

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

the class AttributeColumnsMergeStrategiesControllerImpl method firstQuartileNumberMerge.

@Override
public Column firstQuartileNumberMerge(Table table, Column[] columnsToMerge, String newColumnTitle) {
    checkTableAndColumnsAreNumberOrNumberList(table, columnsToMerge);
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    Column newColumn;
    // Create as BIGDECIMAL column by default. Then it can be duplicated to other type.
    newColumn = ac.addAttributeColumn(table, newColumnTitle, BigDecimal.class);
    if (newColumn == null) {
        return null;
    }
    BigDecimal Q1;
    for (Element row : ac.getTableAttributeRows(table)) {
        Q1 = StatisticsUtils.quartile1(ac.getRowNumbers(row, columnsToMerge));
        row.setAttribute(newColumn, Q1);
    }
    return newColumn;
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element) BigDecimal(java.math.BigDecimal)

Example 29 with AttributeColumnsController

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

the class ClearColumnData method canManipulateColumn.

@Override
public boolean canManipulateColumn(Table table, Column column) {
    boolean result;
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    result = ac.canClearColumnData(column);
    // Also make sure that there is at least 1 row
    return result && ac.getTableRowsCount(table) > 0;
}
Also used : AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController)

Example 30 with AttributeColumnsController

use of org.gephi.datalab.api.AttributeColumnsController 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)

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