Exemple #1
0
  /** DOC chuang Comment method "checkColumnNames". */
  public String checkColumnNames() {
    List<ConceptTarget> list = getModel().getBeansList();
    Set<String> conflictNames = new HashSet<String>();
    Set<String> names = new HashSet<String>();

    int lstSize = list.size();
    for (int i = 0; i < lstSize; i++) {
      String name = list.get(i).getTargetName();

      if (name == null || name.trim().equals("")) {
        return "Column name can't be null";
      }

      if (names.contains(name)) {
        conflictNames.add(name);
      } else {
        names.add(name);
      }
    }
    setRowBackground(list, conflictNames);

    if (conflictNames.isEmpty()) {
      return null;
    } else {

      // create error message
      StringBuffer buf = new StringBuffer();
      buf.append(
          Messages.getString("ExtractionFieldsWithXPathEditorView.columnName")); // $NON-NLS-1$
      for (String name : conflictNames) {
        buf.append(name);
        buf.append(","); // $NON-NLS-1$
      }
      buf.deleteCharAt(buf.length() - 1);
      buf.append(Messages.getString("ExtractionFieldsWithXPathEditorView.exist")); // $NON-NLS-1$
      return buf.toString();
    }
  }
Exemple #2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.talend.commons.ui.swt.advanced.macrotable.AbstractExtendedTableViewer#createColumns(org.talend.commons.ui
   * .swt.tableviewer.TableViewerCreator, org.eclipse.swt.widgets.Table)
   */
  @Override
  protected void createColumns(
      TableViewerCreator<ConceptTarget> tableViewerCreator, final Table table) {
    CellEditorValueAdapter intValueAdapter =
        new CellEditorValueAdapter() {

          @Override
          public Object getOriginalTypedValue(final CellEditor cellEditor, Object value) {
            try {
              return new Integer(value.toString());
            } catch (Exception ex) {
              return null;
            }
          }

          @Override
          public Object getCellEditorTypedValue(final CellEditor cellEditor, Object value) {
            if (value != null) {
              return String.valueOf(value);
            }
            return ""; //$NON-NLS-1$
          }
        };

    // //////////////////////////////////////////////////////////////////////////////////////

    // column for mouse selection
    TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setTitle(""); // $NON-NLS-1$
    column.setDefaultInternalValue(""); // $NON-NLS-1$
    column.setWidth(15);

    // //////////////////////////////////////////////////////////////////////////////////////
    // X Path Query

    column = new TableViewerCreatorColumn(tableViewerCreator);
    xPathColumn = column;
    column.setTitle(
        Messages.getString("ExtractionFieldsWithXPathEditorView.columnTitle.xPath")); // $NON-NLS-1$
    column.setBeanPropertyAccessors(
        new IBeanPropertyAccessors<ConceptTarget, String>() {

          public String get(ConceptTarget bean) {
            return bean.getRelativeLoopExpression();
          }

          public void set(ConceptTarget bean, String value) {
            bean.setRelativeLoopExpression(value);
          }
        });
    xPathCellEditor =
        new TextCellEditorWithProposal(tableViewerCreator.getTable(), SWT.NONE, column);
    column.setCellEditor(xPathCellEditor);
    xPathCellEditor.addListener(
        new DialogErrorForCellEditorListener(xPathCellEditor, column) {

          @Override
          public void newValidValueTyped(
              int itemIndex, Object previousValue, Object newValue, CELL_EDITOR_STATE state) {
            if (state == CELL_EDITOR_STATE.EDITING) {
              linker.onXPathValueChanged(table, newValue.toString(), itemIndex);
            }
          }

          @Override
          public String validateValue(String newValue, int beanPosition) {
            String currentLoopXPath = linker.getCurrentLoopXPath();
            String value = null;
            if (newValue.trim().length() == 0) {
              return null;
            } else if (newValue.trim().startsWith("/")) { // $NON-NLS-1$
              value = newValue;
            } else {
              value = currentLoopXPath + "/" + newValue; // $NON-NLS-1$
            }
            return linker.validateXPathExpression(value);
          }
        });
    column.setModifiable(true);
    column.setWeight(30);
    column.setMinimumWidth(50);
    column.setDefaultInternalValue(""); // $NON-NLS-1$
    // //////////////////////////////////////////////////////////////////////////////////////

    // //////////////////////////////////////////////////////////////////////////////////////
    // Tag Name
    column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setTitle(
        Messages.getString(
            "ExtractionFieldsWithXPathEditorView.columnTitle.columnName")); //$NON-NLS-1$
    column.setBeanPropertyAccessors(
        new IBeanPropertyAccessors<ConceptTarget, String>() {

          public String get(ConceptTarget bean) {
            return bean.getTargetName();
          }

          public void set(ConceptTarget bean, String value) {
            bean.setTargetName(value);
          }
        });
    column.setModifiable(true);
    column.setWeight(10);
    column.setMinimumWidth(50);
    // column.setCellEditor(new TextCellEditor(table));
    column.setDefaultInternalValue(""); // $NON-NLS-1$

    final TextCellEditorWithProposal tagNameCellEditor =
        createTagNameEditor(tableViewerCreator, column);
    column.setCellEditor(tagNameCellEditor);
  }