private TableViewerCreatorColumn createValueColumn(
      TableViewerCreator<HashMap<String, Object>> tableViewerCreator) {
    TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setTitle("Value"); // $NON-NLS-1$
    column.setBeanPropertyAccessors(
        new IBeanPropertyAccessors<HashMap<String, Object>, String>() {

          @Override
          public String get(HashMap<String, Object> bean) {
            return (String) bean.get(VALUE);
          }

          @Override
          public void set(HashMap<String, Object> bean, String value) {
            bean.put(VALUE, value);
          }
        });
    column.setCellEditor(new TextCellEditor(tableViewerCreator.getTable()));

    column.setModifiable(true);
    column.setWeight(30);
    column.setMinimumWidth(50);
    column.setDefaultInternalValue(""); // $NON-NLS-1$
    return column;
  }
Exemplo n.º 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);
  }