@Override
  public void setup(
      AttributeColumnsManipulator m,
      GraphModel graphModel,
      Table table,
      Column column,
      DialogControls dialogControls) {
    this.table = table;
    this.dialogControls = dialogControls;
    this.manipulator = (ConvertColumnToDynamic) m;

    buildValidationPanel();

    descriptionLabel.setText(
        NbBundle.getMessage(
            ConvertColumnToDynamicTimestampsUI.class,
            "ConvertColumnToDynamicUI.descriptionLabel.text",
            column.getTitle()));
    titleTextField.setText(
        NbBundle.getMessage(
            ConvertColumnToDynamicTimestampsUI.class,
            "ConvertColumnToDynamicUI.new.title",
            column.getTitle()));

    refreshTitleEnabledState();
  }
    public ColumnEstimator(Column column) {
      this.column = column;
      this.comboBox = new JComboBox();
      this.label = new JLabel(column.getTitle());

      initAvailableEstimators();
      Estimator currentEstimator = column.getEstimator();
      comboBox.setSelectedItem(new EstimatorWrapper(currentEstimator));
    }
Esempio n. 3
0
  @Test
  public void testGetAttributeKeys() {
    GraphStore store = new GraphStore();
    Column column = generateBasicColumn(store);

    NodeImpl node = new NodeImpl("0", store);
    Set<String> pk = node.getAttributeKeys();
    Assert.assertTrue(pk.contains(column.getId()));
    Assert.assertEquals(pk.size(), 1 + getElementPropertiesLength());
  }
Esempio n. 4
0
  @Test
  public void testGetAttributeKey() {
    GraphStore store = new GraphStore();
    Column column = generateBasicColumn(store);

    NodeImpl node = new NodeImpl("0", store);
    node.setAttribute(column, 1);
    Object res = node.getAttribute(column.getId());
    Assert.assertEquals(res, 1);
  }
 protected String getId(Transformer transformer, Column column) {
   return getIdPrefix()
       + "_"
       + transformer.getClass().getSimpleName()
       + "_column_"
       + column.getId();
 }
Esempio n. 6
0
 @Test
 public void testGetAttributeColumnsEmpty() {
   GraphStore store = new GraphStore();
   NodeImpl node = new NodeImpl("0", store);
   Iterable<Column> pk = node.getAttributeColumns();
   Assert.assertNotNull(pk);
   Iterator<Column> itr = pk.iterator();
   Assert.assertNotNull(itr);
   int size = 0;
   for (; itr.hasNext(); ) {
     Column c = itr.next();
     Assert.assertTrue(c.isProperty());
     size++;
   }
   Assert.assertTrue(size == getElementPropertiesLength());
 }
Esempio n. 7
0
  @Test
  public void testGetDefaultValue() {
    GraphStore store = new GraphStore();
    Integer defaultValue = 25;
    Column column =
        new ColumnImpl("age", Integer.class, "Age", defaultValue, Origin.DATA, true, false);
    store.nodeTable.store.addColumn(column);

    NodeImpl node = new NodeImpl("0", store);
    Object res = node.getAttribute(column.getId());
    Assert.assertEquals(res, defaultValue);

    node.setAttribute(column, null);
    res = node.getAttribute(column.getId());
    Assert.assertEquals(res, defaultValue);

    node.setAttribute(column, 1);
    res = node.getAttribute(column.getId());
    Assert.assertEquals(res, 1);
  }
Esempio n. 8
0
  @Test
  public void testGetTimestampAttributeInView() {
    GraphStore store = new GraphStore();
    Column column = generateTimestampColumn(store);

    NodeImpl node = new NodeImpl("0", store);
    GraphView view = store.viewStore.createView();

    Assert.assertNull(node.getAttribute(column, view));
    node.setAttribute(column, 10, 1.0);
    Assert.assertEquals(node.getAttribute(column, view), 10);
    node.setAttribute(column, 0, 5.0);
    node.setAttribute(column, 20, 2.0);

    store.viewStore.setTimeInterval(view, new Interval(5.0, 5.0));
    Assert.assertEquals(node.getAttribute(column, view), 0);
    store.viewStore.setTimeInterval(view, new Interval(1.0, 2.0));
    Assert.assertEquals(node.getAttribute(column, view), 10);
    column.setEstimator(Estimator.AVERAGE);
    Assert.assertEquals(node.getAttribute(column, view), 15.0);
    Assert.assertEquals(node.getAttribute("age", view), 15.0);
  }
 private boolean isRanking(Graph graph, Column column) {
   if (column.isDynamic() && column.isNumber()) {
     ElementIterable<? extends Element> iterable =
         AttributeUtils.isNodeColumn(column) ? graph.getNodes() : graph.getEdges();
     for (Element el : iterable) {
       if (el.getAttribute(column, graph.getView()) != null) {
         iterable.doBreak();
         return true;
       }
     }
   } else if (!column.isDynamic() && column.isIndexed() && column.isNumber()) {
     Index index;
     if (AttributeUtils.isNodeColumn(column)) {
       index = localScale ? graphModel.getNodeIndex(graph.getView()) : graphModel.getNodeIndex();
     } else {
       index = localScale ? graphModel.getEdgeIndex(graph.getView()) : graphModel.getEdgeIndex();
     }
     if (index.countValues(column) > 0) {
       return true;
     }
   }
   return false;
 }
Esempio n. 10
0
 private boolean isPartition(Graph graph, Column column) {
   if (column.isDynamic()) {
     Set<Object> set = new HashSet<Object>();
     boolean hasNullValue = false;
     int elements = 0;
     ElementIterable<? extends Element> iterable =
         AttributeUtils.isNodeColumn(column) ? graph.getNodes() : graph.getEdges();
     for (Element el : iterable) {
       TimeMap val = (TimeMap) el.getAttribute(column);
       if (val != null) {
         Object[] va = val.toValuesArray();
         for (Object v : va) {
           if (v != null) {
             set.add(v);
           } else {
             hasNullValue = true;
           }
           elements++;
         }
       }
     }
     double ratio = set.size() / (double) elements;
     return ratio <= 0.9;
   } else if (column.isIndexed()) {
     Index index;
     if (AttributeUtils.isNodeColumn(column)) {
       index = graphModel.getNodeIndex(graph.getView());
     } else {
       index = graphModel.getEdgeIndex(graph.getView());
     }
     int valueCount = index.countValues(column);
     int elementCount = index.countElements(column);
     double ratio = valueCount / (double) elementCount;
     return ratio <= 0.9;
   }
   return false;
 }
 private void initAvailableEstimators() {
   Class<? extends TimeMap> type = column.getTypeClass();
   try {
     TimeMap dummy = type.newInstance();
     for (Estimator estimator : Estimator.values()) {
       if (dummy.isSupported(estimator)) {
         comboBox.addItem(new EstimatorWrapper(estimator));
       }
     }
   } catch (InstantiationException ex) {
     throw new RuntimeException(ex);
   } catch (IllegalAccessException ex) {
     throw new RuntimeException(ex);
   }
 }
 @Override
 public void setValueAsString(String value) {
   setValueToAllElements(AttributeUtils.parse(value, column.getTypeClass()));
 }
Esempio n. 13
0
 protected String getIdCol(Column column) {
   return (AttributeUtils.isNodeColumn(column) ? "node" : "edge") + "_column_" + column.getId();
 }
Esempio n. 14
0
    private void refreshAttributeFunctions(boolean graphHasChanged) {
      Set<Column> columns = new HashSet<Column>();
      for (Column column : getTable()) {
        if (!column.isProperty()) {
          columns.add(column);
        }
      }

      // Clean
      for (Iterator<Map.Entry<Column, ColumnObserver>> itr = columnObservers.entrySet().iterator();
          itr.hasNext(); ) {
        Map.Entry<Column, ColumnObserver> entry = itr.next();
        if (!columns.contains(entry.getKey()) || forcedColumnsRefresh.contains(entry.getKey())) {
          rankings.remove(getIdCol(entry.getKey()));
          partitions.remove(getIdCol(entry.getKey()));
          for (Transformer t : getTransformers()) {
            attributeFunctions.remove(getId(t, entry.getKey()));
          }
          itr.remove();
          if (!entry.getValue().isDestroyed()) {
            entry.getValue().destroy();
          }
        }
      }

      // Get columns to be refreshed
      Set<Column> toRefreshColumns = new HashSet<Column>(forcedColumnsRefresh);
      for (Column column : columns) {
        if (!columnObservers.containsKey(column)) {
          columnObservers.put(column, column.createColumnObserver());
          toRefreshColumns.add(column);
        } else if (columnObservers.get(column).hasColumnChanged() || graphHasChanged) {
          toRefreshColumns.add(column);
        }
      }
      forcedColumnsRefresh.clear();

      // Refresh ranking and partitions
      for (Column column : toRefreshColumns) {
        RankingImpl ranking = rankings.get(getIdCol(column));
        PartitionImpl partition = partitions.get(getIdCol(column));
        if (ranking == null && partition == null) {
          String id = getIdCol(column);
          if (forcedPartition.contains(id)
              || (!forcedRanking.contains(id) && isPartition(graph, column))) {
            if (column.isIndexed()) {
              partition = new AttributePartitionImpl(column, getIndex(false));
            } else {
              partition = new AttributePartitionImpl(column, graph);
            }
            partitions.put(getIdCol(column), partition);
          }

          if (forcedRanking.contains(id) || isRanking(graph, column)) {
            if (column.isIndexed()) {
              ranking = new AttributeRankingImpl(column, getIndex(localScale));
            } else {
              ranking = new AttributeRankingImpl(column, graph);
            }
            rankings.put(getIdCol(column), ranking);
          }
        }
        if (ranking != null) {
          ranking.refresh();
        }
        if (partition != null) {
          partition.refresh();
        }
      }

      // Ranking functions
      for (Transformer t : getRankingTransformers()) {
        for (Column col : toRefreshColumns) {
          RankingImpl ranking = rankings.get(getIdCol(col));
          if (ranking != null) {
            String id = getId(t, col);
            if (!attributeFunctions.containsKey(id)) {
              attributeFunctions.put(
                  id,
                  new AttributeFunctionImpl(
                      id, graph, col, t, getTransformerUI(t), ranking, defaultInterpolator));
            }
          }
        }
      }

      // Partition functions
      for (Transformer t : getPartitionTransformers()) {
        for (Column col : toRefreshColumns) {
          PartitionImpl partition = partitions.get(getIdCol(col));
          if (partition != null) {
            String id = getId(t, col);
            if (!attributeFunctions.containsKey(id)) {
              attributeFunctions.put(
                  id, new AttributeFunctionImpl(id, graph, col, t, getTransformerUI(t), partition));
            }
          }
        }
      }
    }
Esempio n. 15
0
 @Override
 public boolean canExecute() {
   return AttributeUtils.isNumberType(column.getTypeClass());
 }