示例#1
0
  public void rebuildInputTable(
      InputTable inputTable, IMetadataTable metadataTable, PigMapData mapData) {
    if (metadataTable != null && metadataTable.getListColumns() != null) {
      List<IMetadataColumn> listColumns = metadataTable.getListColumns();
      EList<TableNode> nodes = inputTable.getNodes();
      for (int i = 0; i < listColumns.size(); i++) {
        IMetadataColumn column = listColumns.get(i);
        TableNode found = null;
        int j = 0;
        for (; j < nodes.size(); j++) {
          TableNode node = nodes.get(j);
          if (node.getName() != null && node.getName().equals(column.getLabel())) {
            found = node;
            break;
          }
        }
        if (found != null) {
          // set in case talend type changed in metadata
          found.setType(column.getTalendType());
          if (i != j) {
            // do switch to keep the same sequence
            TableNode temp = nodes.get(j);
            nodes.remove(j);
            nodes.add(i, temp);
          }
        } else {
          found = PigmapFactory.eINSTANCE.createTableNode();
          found.setName(column.getLabel());
          found.setType(column.getTalendType());
          found.setNullable(column.isNullable());
          nodes.add(i, found);
        }
      }

      if (nodes.size() > listColumns.size()) {
        List unUsed = new ArrayList();
        for (int i = listColumns.size(); i < nodes.size(); i++) {
          PigMapUtil.detachNodeConnections(nodes.get(i), mapData);
          unUsed.add(nodes.get(i));
        }
        nodes.removeAll(unUsed);
      }
    }

    // re-build the connections in case any unnecessary connections are created because of previous
    // bugs and can't
    // be deleted
    if (inputTable.isLookup()) {
      rebuildInputNodesConnections(inputTable.getNodes(), mapData);
    }
  }
 public void update(int type) {
   switch (type) {
     case PigmapPackage.INPUT_TABLE__JOIN_MODEL:
       joinModel.setText(inputTable.getJoinModel());
       break;
     case PigmapPackage.INPUT_TABLE__JOIN_OPTIMIZATION:
       joinOptimization.setText(getJoinOptimizationDisplayName(inputTable.getJoinOptimization()));
       break;
     case PigmapPackage.INPUT_TABLE__CUSTOM_PARTITIONER:
       customPartitioner.setText(inputTable.getCustomPartitioner());
       break;
     case PigmapPackage.INPUT_TABLE__INCREASE_PARALLELISM:
       increaseParallelism.setText(inputTable.getIncreaseParallelism());
     default:
       break;
   }
 }
示例#3
0
  public void rebuildModelInputs(List<? extends IConnection> inputConn, PigMapData mapData) {
    // remove no used input table
    if (mapData.getInputTables().size() != inputConn.size()) {
      List tableToRemove = new ArrayList();
      for (InputTable inputTable : mapData.getInputTables()) {
        boolean found = false;
        for (IConnection connection : inputConn) {
          if (inputTable.getName().equals(connection.getName())) {
            found = true;
          }
        }
        if (!found) {
          for (TableNode tableNode : inputTable.getNodes()) {
            PigMapUtil.detachNodeConnections(tableNode, mapData);
          }
          tableToRemove.add(inputTable);
          PigMapUtil.detachFilterSource(inputTable, mapData);
        }
      }
      mapData.getInputTables().removeAll(tableToRemove);
    }

    for (IConnection inData : inputConn) {
      String name = inData.getName();
      InputTable inputTable = null;
      for (InputTable in : mapData.getInputTables()) {
        if (in.getName() != null && in.getName().equals(name)) {
          inputTable = in;
          break;
        }
      }
      if (inputTable == null) {
        inputTable = PigmapFactory.eINSTANCE.createInputTable();
        inputTable.setName(name);
        inputTable.setLookup(EConnectionType.FLOW_MAIN != inData.getLineStyle());
        mapData
            .getInputTables()
            .add(inputTable.isLookup() ? mapData.getInputTables().size() : 0, inputTable);
      } else {
        inputTable.setLookup(EConnectionType.FLOW_MAIN != inData.getLineStyle());
      }
      // by default
      if (inputTable.isLookup() && inputTable.getJoinModel() == null) {
        inputTable.setJoinModel(TableSettingsConstant.LEFT_OUTER_JOIN);
      }
      if (inputTable.isLookup() && inputTable.getJoinOptimization() == null) {
        inputTable.setJoinOptimization(PIG_MAP_JOIN_OPTIMIZATION.NONE.toString());
      }
      rebuildInputTable(inputTable, inData.getMetadataTable(), mapData);
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see org.talend.designer.gefabstractmap.figures.table.AbstractTable#createColumns()
   */
  @Override
  protected void createColumns() {
    TableColumn column = new TableColumn(ColumnKeyConstant.TREE_SETTING_PROPERTY);
    column.setText("Property");
    addColumn(column);

    ColumnSash sash = new ColumnSash(this);
    sash.setLeftColumn(column);
    addSeparator(sash);

    column = new TableColumn(ColumnKeyConstant.TREE_SETTING_VALUE);
    column.setText("Value");
    sash.setRightColumn(column);
    addColumn(column);

    Figure container = getTableItemContainer();

    joinModelRow = new Figure();
    joinModelRow.setLayoutManager(new RowLayout());
    Label label = new Label();
    label.setText("Join Model");
    label.setLabelAlignment(PositionConstants.LEFT);
    CompoundBorder compoundBorder =
        new CompoundBorder(new ColumnBorder(), new RowBorder(2, 5, 2, -1));
    label.setBorder(compoundBorder);
    joinModelRow.add(label);
    joinModel = new ComboCellLabel();
    joinModel.setDirectEditType(DirectEditType.JOIN_MODEL);
    joinModel.setText(inputTable.getJoinModel());
    joinModel.setLabelAlignment(PositionConstants.LEFT);
    joinModel.setBorder(new RowBorder(2, 5, 2, -1));
    joinModelRow.add(joinModel);
    container.add(joinModelRow);

    //
    joinOptimizationRow = new Figure();
    joinOptimizationRow.setLayoutManager(new RowLayout());
    label = new Label();
    label.setText("Join Optimization");
    label.setLabelAlignment(PositionConstants.LEFT);
    compoundBorder = new CompoundBorder(new ColumnBorder(), new RowBorder(2, 5, 2, -1));
    label.setBorder(compoundBorder);
    joinOptimizationRow.add(label);
    joinOptimization = new ComboCellLabel();
    joinOptimization.setDirectEditType(DirectEditType.JOIN_OPTIMIZATION);
    joinOptimization.setText(getJoinOptimizationDisplayName(inputTable.getJoinOptimization()));
    joinOptimization.setLabelAlignment(PositionConstants.LEFT);
    joinOptimization.setBorder(new RowBorder(2, 5, 2, -1));
    joinOptimizationRow.add(joinOptimization);
    container.add(joinOptimizationRow);

    //
    customPartitionerRow = new Figure();
    customPartitionerRow.setLayoutManager(new RowLayout());
    label = new Label();
    label.setText("Custom Partitioner");
    label.setLabelAlignment(PositionConstants.LEFT);
    compoundBorder = new CompoundBorder(new ColumnBorder(), new RowBorder(2, 5, 2, -1));
    label.setBorder(compoundBorder);
    customPartitionerRow.add(label);
    customPartitioner = new TextCellLabel();
    customPartitioner.setDirectEditType(DirectEditType.CUSTOM_PARTITIONER);
    customPartitioner.setText(inputTable.getCustomPartitioner());
    customPartitioner.setLabelAlignment(PositionConstants.LEFT);
    customPartitioner.setBorder(new RowBorder(2, 5, 2, -1));
    customPartitionerRow.add(customPartitioner);
    container.add(customPartitionerRow);

    //
    increaseParallelismRow = new Figure();
    increaseParallelismRow.setLayoutManager(new RowLayout());
    label = new Label();
    label.setText("Increase Parallelism");
    label.setLabelAlignment(PositionConstants.LEFT);
    compoundBorder = new CompoundBorder(new ColumnBorder(), new RowBorder(2, 5, 2, -1));
    label.setBorder(compoundBorder);
    increaseParallelismRow.add(label);
    increaseParallelism = new TextCellLabel();
    increaseParallelism.setDirectEditType(DirectEditType.INCREASE_PARALLELISM);
    increaseParallelism.setText(inputTable.getIncreaseParallelism());
    increaseParallelism.setLabelAlignment(PositionConstants.LEFT);
    increaseParallelism.setBorder(new RowBorder(2, 5, 2, -1));
    increaseParallelismRow.add(increaseParallelism);
    container.add(increaseParallelismRow);
    container.setOpaque(true);
    container.setBackgroundColor(ColorConstants.white);

    container.addMouseListener(
        new MouseListener() {

          Figure selectedFigure = null;

          @Override
          public void mousePressed(MouseEvent me) {
            boolean joinOptimization = joinOptimizationRow.containsPoint(me.x, me.y);
            if (joinOptimization) {
              if (selectedFigure != joinOptimizationRow) {
                joinOptimizationRow.setOpaque(true);
                joinOptimizationRow.setBackgroundColor(
                    ColorProviderMapper.getColor(ColorInfo.COLOR_COLUMN_TREE_SETTING));
                customPartitionerRow.setOpaque(false);
                joinModelRow.setOpaque(false);
                increaseParallelismRow.setOpaque(false);
              }
              return;
            }
            boolean customPartitioner = customPartitionerRow.containsPoint(me.x, me.y);
            if (customPartitioner) {
              if (selectedFigure != customPartitionerRow) {
                customPartitionerRow.setOpaque(true);
                customPartitionerRow.setBackgroundColor(
                    ColorProviderMapper.getColor(ColorInfo.COLOR_COLUMN_TREE_SETTING));
                joinOptimizationRow.setOpaque(false);
                joinModelRow.setOpaque(false);
                increaseParallelismRow.setOpaque(false);
              }
              return;
            }
            boolean joinModel = joinModelRow.containsPoint(me.x, me.y);
            if (joinModel) {
              if (selectedFigure != joinModelRow) {
                joinModelRow.setOpaque(true);
                joinModelRow.setBackgroundColor(
                    ColorProviderMapper.getColor(ColorInfo.COLOR_COLUMN_TREE_SETTING));
                joinOptimizationRow.setOpaque(false);
                customPartitionerRow.setOpaque(false);
                increaseParallelismRow.setOpaque(false);
              }
              return;
            }
            boolean increaseParallelism = increaseParallelismRow.containsPoint(me.x, me.y);
            if (increaseParallelism) {
              if (selectedFigure != increaseParallelismRow) {
                increaseParallelismRow.setOpaque(true);
                increaseParallelismRow.setBackgroundColor(
                    ColorProviderMapper.getColor(ColorInfo.COLOR_COLUMN_TREE_SETTING));
                joinOptimizationRow.setOpaque(false);
                customPartitionerRow.setOpaque(false);
                joinModelRow.setOpaque(false);
              }
            }
          }

          @Override
          public void mouseReleased(MouseEvent me) {}

          @Override
          public void mouseDoubleClicked(MouseEvent me) {}
        });
  }