Search in sources :

Example 1 with AttributeRowsMergeStrategy

use of org.gephi.datalab.spi.rows.merge.AttributeRowsMergeStrategy in project gephi by gephi.

the class MergeNodeDuplicatesUI method loadColumnsStrategies.

private void loadColumnsStrategies() {
    JPanel strategiesPanel = new JPanel();
    strategiesPanel.setLayout(new MigLayout("fillx"));
    if (duplicateGroups != null && duplicateGroups.size() > 0) {
        strategiesPanel.add(new JLabel(NbBundle.getMessage(MergeNodeDuplicatesUI.class, "MergeNodeDuplicatesUI.duplicateGroupsNumber", duplicateGroups.size())), "wrap 15px");
        //Use first group of duplicated nodes to set strategies for all of them
        List<Node> nodes = duplicateGroups.get(0);
        //Prepare node rows:
        rows = new Element[nodes.size()];
        for (int i = 0; i < nodes.size(); i++) {
            rows[i] = nodes.get(i);
        }
        strategiesConfigurationButtons = new StrategyConfigurationButton[columns.length];
        strategiesComboBoxes = new StrategyComboBox[columns.length];
        for (int i = 0; i < columns.length; i++) {
            //Strategy information label:
            StrategyInfoLabel infoLabel = new StrategyInfoLabel(i);
            //Strategy configuration button:
            strategiesConfigurationButtons[i] = new StrategyConfigurationButton(i);
            //Strategy selection:
            StrategyComboBox strategyComboBox = new StrategyComboBox(strategiesConfigurationButtons[i], infoLabel);
            strategiesComboBoxes[i] = strategyComboBox;
            for (AttributeRowsMergeStrategy strategy : getColumnAvailableStrategies(columns[i])) {
                strategyComboBox.addItem(new StrategyWrapper(strategy));
            }
            strategyComboBox.refresh();
            strategiesPanel.add(new JLabel(columns[i].getTitle() + ": "), "wrap");
            strategiesPanel.add(infoLabel, "split 3");
            strategiesPanel.add(strategiesConfigurationButtons[i]);
            strategiesPanel.add(strategyComboBox, "growx, wrap 15px");
        }
        dialogControls.setOkButtonEnabled(true);
    } else {
        strategiesPanel.add(new JLabel(getMessage("MergeNodeDuplicatesUI.noDuplicatesText")));
        dialogControls.setOkButtonEnabled(false);
    }
    scrollStrategies.setViewportView(strategiesPanel);
}
Also used : JPanel(javax.swing.JPanel) AttributeRowsMergeStrategy(org.gephi.datalab.spi.rows.merge.AttributeRowsMergeStrategy) MigLayout(net.miginfocom.swing.MigLayout) Node(org.gephi.graph.api.Node) JLabel(javax.swing.JLabel)

Example 2 with AttributeRowsMergeStrategy

use of org.gephi.datalab.spi.rows.merge.AttributeRowsMergeStrategy in project gephi by gephi.

the class MergeNodesUI method loadColumnsStrategies.

private void loadColumnsStrategies(JPanel settingsPanel) {
    Column[] columns = manipulator.getColumns();
    strategiesConfigurationButtons = new StrategyConfigurationButton[columns.length];
    strategiesComboBoxes = new StrategyComboBox[columns.length];
    for (int i = 0; i < columns.length; i++) {
        //Strategy information label:
        StrategyInfoLabel infoLabel = new StrategyInfoLabel(i);
        //Strategy configuration button:
        strategiesConfigurationButtons[i] = new StrategyConfigurationButton(i);
        //Strategy selection:
        StrategyComboBox strategyComboBox = new StrategyComboBox(strategiesConfigurationButtons[i], infoLabel);
        strategiesComboBoxes[i] = strategyComboBox;
        for (AttributeRowsMergeStrategy strategy : getColumnAvailableStrategies(columns[i])) {
            strategyComboBox.addItem(new StrategyWrapper(strategy));
        }
        strategyComboBox.refresh();
        settingsPanel.add(new JLabel(columns[i].getTitle() + ": "), "wrap");
        settingsPanel.add(infoLabel, "split 3");
        settingsPanel.add(strategiesConfigurationButtons[i]);
        settingsPanel.add(strategyComboBox, "growx, wrap 15px");
    }
}
Also used : AttributeRowsMergeStrategy(org.gephi.datalab.spi.rows.merge.AttributeRowsMergeStrategy) Column(org.gephi.graph.api.Column) JLabel(javax.swing.JLabel)

Example 3 with AttributeRowsMergeStrategy

use of org.gephi.datalab.spi.rows.merge.AttributeRowsMergeStrategy in project gephi by gephi.

the class DataLaboratoryHelper method getAttributeRowsMergeStrategies.

/**
     * <p>Prepares an array that has one new instance of every AttributeRowsMergeStrategy implementation that is registered.</p>
     * <p>It also returns the manipulators ordered first by type and then by position.</p>
     * @return Array of all AttributeRowsMergeStrategy implementations
     */
public AttributeRowsMergeStrategy[] getAttributeRowsMergeStrategies() {
    ArrayList<AttributeRowsMergeStrategy> strategies = new ArrayList<>();
    for (AttributeRowsMergeStrategyBuilder cs : Lookup.getDefault().lookupAll(AttributeRowsMergeStrategyBuilder.class)) {
        strategies.add(cs.getAttributeRowsMergeStrategy());
    }
    sortManipulators(strategies);
    return strategies.toArray(new AttributeRowsMergeStrategy[0]);
}
Also used : AttributeRowsMergeStrategy(org.gephi.datalab.spi.rows.merge.AttributeRowsMergeStrategy) ArrayList(java.util.ArrayList) AttributeRowsMergeStrategyBuilder(org.gephi.datalab.spi.rows.merge.AttributeRowsMergeStrategyBuilder)

Example 4 with AttributeRowsMergeStrategy

use of org.gephi.datalab.spi.rows.merge.AttributeRowsMergeStrategy in project gephi by gephi.

the class AttributeColumnsControllerImpl method mergeRowsValues.

@Override
public void mergeRowsValues(Column[] columns, AttributeRowsMergeStrategy[] mergeStrategies, Element[] rows, Element selectedRow, Element resultRow) {
    if (columns.length != mergeStrategies.length) {
        throw new IllegalArgumentException("The number of columns must be equal to the number of merge strategies provided");
    }
    if (selectedRow == null) {
        selectedRow = rows[0];
    }
    AttributeRowsMergeStrategy mergeStrategy;
    Object value;
    int i = 0;
    for (Column column : columns) {
        mergeStrategy = mergeStrategies[i];
        if (mergeStrategy != null) {
            mergeStrategy.setup(rows, selectedRow, column);
            if (mergeStrategy.canExecute()) {
                mergeStrategy.execute();
                value = mergeStrategy.getReducedValue();
            } else {
                value = selectedRow.getAttribute(column);
            }
        } else {
            value = selectedRow.getAttribute(column);
        }
        setAttributeValue(value, resultRow, column);
        i++;
    }
}
Also used : AttributeRowsMergeStrategy(org.gephi.datalab.spi.rows.merge.AttributeRowsMergeStrategy) Column(org.gephi.graph.api.Column)

Aggregations

AttributeRowsMergeStrategy (org.gephi.datalab.spi.rows.merge.AttributeRowsMergeStrategy)4 JLabel (javax.swing.JLabel)2 Column (org.gephi.graph.api.Column)2 ArrayList (java.util.ArrayList)1 JPanel (javax.swing.JPanel)1 MigLayout (net.miginfocom.swing.MigLayout)1 AttributeRowsMergeStrategyBuilder (org.gephi.datalab.spi.rows.merge.AttributeRowsMergeStrategyBuilder)1 Node (org.gephi.graph.api.Node)1