Package org.gephi.data.attributes.api

Examples of org.gephi.data.attributes.api.AttributeType


                case XMLStreamReader.END_ELEMENT:
                    if (ELEMENT_NODE_ROW.equalsIgnoreCase(reader.getLocalName()) || ELEMENT_EDGE_ROW.equalsIgnoreCase(reader.getLocalName())) {
                        end = true;
                    }
                    if (!value.isEmpty() && col != null) {
                        AttributeType type = col.getType();
                        Object v = type.parse(value);
                        v = model.getManagedValue(v, type);
                        row.setValue(col, value);
                    }
                    value = "";
                    col = null;
View Full Code Here


    public void readColumn(XMLStreamReader reader, AttributeTableImpl table) throws XMLStreamException {

        int index = 0;
        String id = "";
        String title = "";
        AttributeType type = AttributeType.STRING;
        AttributeOrigin origin = AttributeOrigin.DATA;
        String defaultValue = "";

        boolean end = false;
        String name = null;
        while (reader.hasNext() && !end) {
            int t = reader.next();

            switch (t) {
                case XMLStreamReader.START_ELEMENT:
                    name = reader.getLocalName();
                    break;
                case XMLStreamReader.CHARACTERS:
                    if (!reader.isWhiteSpace()) {
                        if (ELEMENT_COLUMN_INDEX.equalsIgnoreCase(name)) {
                            index = Integer.parseInt(reader.getText());
                        } else if (ELEMENT_COLUMN_ID.equalsIgnoreCase(name)) {
                            id += reader.getText();
                        } else if (ELEMENT_COLUMN_TITLE.equalsIgnoreCase(name)) {
                            title += reader.getText();
                        } else if (ELEMENT_COLUMN_TYPE.equalsIgnoreCase(name)) {
                            type = AttributeType.valueOf(reader.getText());
                        } else if (ELEMENT_COLUMN_ORIGIN.equalsIgnoreCase(name)) {
                            origin = AttributeOrigin.valueOf(reader.getText());
                        } else if (ELEMENT_COLUMN_DEFAULT.equalsIgnoreCase(name)) {
                            if (!reader.getText().isEmpty()) {
                                defaultValue += reader.getText();
                            }
                        }
                    }
                    break;
                case XMLStreamReader.END_ELEMENT:
                    if (ELEMENT_COLUMN.equalsIgnoreCase(reader.getLocalName())) {
                        end = true;
                    }
                    break;
            }
        }
        Object defaultVal = !defaultValue.isEmpty() ? type.parse(defaultValue) : null;
        if (!table.hasColumn(title)) {
            table.addColumn(id, title, type, origin, defaultVal);
        } else {
            table.replaceColumn(table.getColumn(title), id, title, type, origin, defaultVal);
        }
View Full Code Here

    @Override
    public boolean areAllColumnsOfSameType(AttributeColumn[] columns) {
        if (columns.length == 0) {
            return false;
        }
        AttributeType type = columns[0].getType();
        return areAllColumnsOfType(columns, type);
    }
View Full Code Here

        return true;
    }

    @Override
    public boolean isNumberColumn(AttributeColumn column) {
        AttributeType attributeType = column.getType();
        return Number.class.isAssignableFrom(attributeType.getType());
    }
View Full Code Here

        return true;
    }

    @Override
    public boolean isNumberListColumn(AttributeColumn column) {
        AttributeType attributeType = column.getType();
        return NumberList.class.isAssignableFrom(attributeType.getType());
    }
View Full Code Here

    private static String start = "-Infinity";
    private static String end = "Infinity";

    @Override
    public void execute(AttributeTable table, AttributeColumn column) {
        AttributeType dynamicType = getEquivalentDynamicType(column.getType());

        AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
        Attributes[] rows = ac.getTableAttributeRows(table);
        Object[] values = new Object[rows.length];

        for (int i = 0; i < values.length; i++) {
            try {
                values[i] = dynamicType.parse(String.format("[%s,%s,%s]", start, end, rows[i].getValue(column.getIndex()).toString()));
            } catch (Exception e) {
            }
        }

        AttributeColumn dynamicColumn = table.replaceColumn(column, column.getId(), column.getTitle(), dynamicType, column.getOrigin(), null);
View Full Code Here

*/
@ServiceProvider(service = AttributeColumnsController.class)
public class AttributeColumnsControllerImpl implements AttributeColumnsController {

    public boolean setAttributeValue(Object value, Attributes row, AttributeColumn column) {
        AttributeType targetType = column.getType();
        if (value != null && !value.getClass().equals(targetType.getType())) {
            try {
                value = targetType.parse(value.toString());//Try to convert to target type
            } catch (Exception ex) {
                value = null;//Could not parse
            }
        }

View Full Code Here

    public AttributeColumn convertAttributeColumnToNewDynamicColumn(AttributeTable table, AttributeColumn column, double low, double high, boolean lopen, boolean ropen, String newColumnTitle) {
        return convertColumnToDynamic(table, column, low, high, lopen, ropen, newColumnTitle);
    }

    private AttributeColumn convertColumnToDynamic(AttributeTable table, AttributeColumn column, double low, double high, boolean lopen, boolean ropen, String newColumnTitle) {
        AttributeType oldType = column.getType();
        AttributeType newType = TypeConvertor.getDynamicType(oldType);

        if (newColumnTitle != null) {
            if (newColumnTitle.equals(column.getTitle())) {
                throw new IllegalArgumentException("Column titles can't be equal");
            }
        }

        int oldColumnIndex = column.getIndex();

        Attributes rows[] = getTableAttributeRows(table);

        Object[] oldValues = new Object[rows.length];
        for (int i = 0; i < rows.length; i++) {
            oldValues[i] = rows[i].getValue(oldColumnIndex);
        }

        AttributeColumn newColumn;
        if (newColumnTitle == null) {
            newColumn = table.replaceColumn(column, column.getId(), column.getTitle(), newType, column.getOrigin(), null);
        } else {
            newColumn = table.addColumn(newColumnTitle, newColumnTitle, newType, column.getOrigin(), null);
        }
        int newColumnIndex = newColumn.getIndex();
       
        Object value;
        for (int i = 0; i < rows.length; i++) {
            if (oldValues[i] != null) {
                Interval interval = new Interval(low, high, lopen, ropen, oldValues[i]);
                value = newType.createDynamicObject(Arrays.asList(new Interval[]{interval}));
            } else {
                value = null;
            }
           
            rows[i].setValue(newColumnIndex, value);
View Full Code Here

            throw new IllegalArgumentException("Source and target columns can't be equal");
        }

        final int sourceColumnIndex = sourceColumn.getIndex();
        final int targetColumnIndex = targetColumn.getIndex();
        AttributeType targetType = targetColumn.getType();
        if (targetType != sourceColumn.getType()) {
            Object value;
            for (Attributes row : getTableAttributeRows(table)) {
                value = row.getValue(sourceColumnIndex);
                setAttributeValue(value, row, targetColumn);
View Full Code Here

                final Object propertyValue = vertex.getProperty(propertyKey);
                AttributeColumn attributeColumn;
                if (attributeModel.getNodeTable().hasColumn(propertyKey)) {
                    attributeColumn = attributeModel.getNodeTable().getColumn(propertyKey);
                } else {
                    final AttributeType attributeType = AttributeTypeMapper.map(propertyValue);
                    attributeColumn = attributeModel.getNodeTable().addColumn(propertyKey, attributeType);
                }
                gephiNode.addAttributeValue(attributeColumn, propertyValue);
                report.log(NbBundle.getMessage(GraphDbImporter.class,
                        "Report_AttributeAdded", propertyKey, propertyValue));
View Full Code Here

TOP

Related Classes of org.gephi.data.attributes.api.AttributeType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.