/*
  * (non-Javadoc)
  *
  * @see org.talend.commons.ui.swt.tableviewer.behavior.DefaultTableLabelProvider#getBackground(java.lang.Object,
  * int)
  */
 @Override
 public Color getBackground(Object element, int columnIndex) {
   if (!(element instanceof IMetadataColumn)) {
     return null;
   }
   IMetadataColumn column = (IMetadataColumn) element;
   TableViewerCreatorColumnNotModifiable tableColumn =
       (TableViewerCreatorColumnNotModifiable) tableViewerCreator.getColumns().get(columnIndex);
   if (column.isCustom()) {
     if (column.isReadOnly()
         || readOnly
         || tableColumn.getId().equals(AbstractMetadataTableEditorView.ID_COLUMN_NAME)) {
       return CELL_READ_ONLY_COLOR;
     } else {
       return CUSTOM_CELL_BG_COLOR;
     }
   }
   if (column.isReadOnly()) {
     return TABLE_READ_ONLY_COLOR;
   }
   // qli modified to fix the bug 6654.
   if (tableEditorView.isShowTalendTypeColumn() && tableEditorView.getCurrentDbms() != null) {
     if (tableColumn.getId().equals(AbstractMetadataTableEditorView.ID_COLUMN_DBTYPE)
         && !"".equals(column.getType()) // $NON-NLS-1$
         && !TypesManager.checkDBType(
             tableEditorView.getCurrentDbms(), column.getTalendType(), column.getType())) {
       return CELL_WRONG_DB_TYPE_COLOR;
     }
   }
   return super.getBackground(element, columnIndex);
 }
 public static void addCustomManagementToTable(
     final MetadataTableEditorView tableEditorView, final boolean readOnly) {
   CustomTableLabelProvider tableProvider =
       new CustomTableLabelProvider(tableEditorView, readOnly);
   tableEditorView.getTableViewerCreator().setLabelProvider(tableProvider);
   tableEditorView
       .getTableViewerCreator()
       .setCellModifier(new CustomTableCellModifier(tableEditorView.getTableViewerCreator()));
 }
Beispiel #3
0
  @Override
  protected void createColumns(
      TableViewerCreator<IMetadataColumn> tableViewerCreator, Table table) {
    super.createColumns(tableViewerCreator, table);

    configureIndexColumn(tableViewerCreator);
    configureRelationshipColumn(tableViewerCreator);
    configureAutoIndexColumn(tableViewerCreator, table);
  }
  private static void updateToolBarButtonsOnSelection(
      ISelection currentSelection,
      MetadataTableEditorView tableEditorView,
      IMetadataTable table,
      final MetadataTableEditorView linkedTableEditorView,
      final IMetadataTable linkedTable,
      boolean readOnly) {
    IStructuredSelection selection = (IStructuredSelection) currentSelection;

    boolean isThereCustom = false;
    boolean isThereReadOnly = false;
    for (Iterator iter = selection.iterator(); iter.hasNext(); ) {
      IMetadataColumn column = (IMetadataColumn) iter.next();
      if (column.isCustom()) {
        isThereCustom = true;
      }
      if (column.isReadOnly()) {
        isThereReadOnly = true;
      }
    }

    if (isThereReadOnly) {
      tableEditorView.getToolBar().getRemoveButton().getButton().setEnabled(false);
    }

    if (isThereCustom || table.isReadOnly()) {
      tableEditorView.getToolBar().getMoveDownButton().getButton().setEnabled(false);
      tableEditorView.getToolBar().getMoveUpButton().getButton().setEnabled(false);
      tableEditorView.getToolBar().getRemoveButton().getButton().setEnabled(false);
      tableEditorView.getToolBar().getPasteButton().getButton().setEnabled(false);
      ResetDBTypesPushButton resetDBTypesButton =
          tableEditorView.getToolBar().getResetDBTypesButton();
      if (resetDBTypesButton != null) {
        resetDBTypesButton.getButton().setEnabled(false);
      }
    }
    if (linkedTable != null) {
      if (linkedTable.isReadOnly() && linkedTableEditorView != null) {
        linkedTableEditorView.getToolBar().getPasteButton().getButton().setEnabled(false);
      }
    }
  }
  public static void addCustomManagementToToolBar(
      final MetadataTableEditorView tableEditorView,
      final IMetadataTable table,
      final boolean readOnly,
      final MetadataTableEditorView linkedTableEditorView,
      final IMetadataTable linkedTable,
      final boolean toPropagate) {
    tableEditorView
        .getTableViewerCreator()
        .getTableViewer()
        .addPostSelectionChangedListener(
            new ISelectionChangedListener() {

              public void selectionChanged(SelectionChangedEvent event) {
                updateToolBarButtonsOnSelection(
                    event.getSelection(),
                    tableEditorView,
                    table,
                    linkedTableEditorView,
                    linkedTable,
                    readOnly);
              }
            });
    boolean isThereCustom = false;
    for (IMetadataColumn column : table.getListColumns()) {
      if (column.isCustom()) {
        isThereCustom = true;
      }
    }
    if (isThereCustom) {
      tableEditorView.getToolBar().getImportButton().getButton().setEnabled(false);
    }
    if (table.isReadOnly()) {
      tableEditorView.getToolBar().getAddButton().getButton().setEnabled(false);
      tableEditorView.getToolBar().getMoveDownButton().getButton().setEnabled(false);
      tableEditorView.getToolBar().getMoveUpButton().getButton().setEnabled(false);
      tableEditorView.getToolBar().getRemoveButton().getButton().setEnabled(false);
      tableEditorView.getToolBar().getPasteButton().getButton().setEnabled(false);
      ResetDBTypesPushButton resetDBTypesButton =
          tableEditorView.getToolBar().getResetDBTypesButton();
      if (resetDBTypesButton != null) {
        resetDBTypesButton.getButton().setEnabled(false);
      }
    } else {
      tableEditorView
          .getToolBar()
          .getAddButton()
          .getButton()
          .addSelectionListener(
              new SelectionListener() {

                public void widgetDefaultSelected(SelectionEvent e) {}

                public void widgetSelected(SelectionEvent e) {
                  table.sortCustomColumns();
                  tableEditorView.getTableViewerCreator().getTableViewer().refresh();
                }
              });
    }
    SelectionListener customListener =
        new SelectionListener() {

          public void widgetDefaultSelected(SelectionEvent e) {}

          public void widgetSelected(SelectionEvent e) {
            updateToolBarButtonsOnSelection(
                tableEditorView.getTableViewerCreator().getTableViewer().getSelection(),
                tableEditorView,
                table,
                linkedTableEditorView,
                linkedTable,
                readOnly);
          }
        };
    tableEditorView.getToolBar().getRemoveButton().getButton().addSelectionListener(customListener);
    tableEditorView.getToolBar().getCopyButton().getButton().addSelectionListener(customListener);

    if (toPropagate) {
      if (linkedTable.isReadOnly()) {
        SelectionListener updateLinkedTableListener =
            new SelectionListener() {

              public void widgetDefaultSelected(SelectionEvent e) {}

              public void widgetSelected(SelectionEvent e) {
                MetadataToolHelper.copyTable(table, linkedTable);
                linkedTableEditorView.getTableViewerCreator().refresh();
                if (linkedTableEditorView != null) {
                  linkedTableEditorView.getTableViewerCreator().getTableViewer().refresh();
                }
              }
            };
        tableEditorView.getToolBar().getButtons();
        for (Object element2 : tableEditorView.getToolBar().getButtons()) {
          ExtendedPushButton element = (ExtendedPushButton) element2;
          element.getButton().addSelectionListener(updateLinkedTableListener);
        }
      }
    }
  }
 public CustomTableLabelProvider(
     final MetadataTableEditorView tableEditorView, final boolean readOnly) {
   super(tableEditorView.getTableViewerCreator());
   this.readOnly = readOnly;
   this.tableEditorView = tableEditorView;
 }
  @Override
  public void addComponents(boolean forceRedraw) {
    if (conSchema()) {
      disposeChildren();
      curRowSize = 0;

      List<? extends IElementParameter> listParam =
          ((Connection) elem).getSource().getElementParameters();

      generator.initController(this);
      for (IElementParameter cur : listParam) {
        if ((cur.getFieldType() == EParameterFieldType.SCHEMA_TYPE)
            && (cur.getContext().equals(((Connection) elem).getConnectorName()))) {
          AbstractElementPropertySectionController contorller =
              generator.getController(EParameterFieldType.SCHEMA_TYPE, this);
          contorller.createControl(composite, cur, 0, 0, 0, null);
        }
      }

      FormData data = new FormData();
      data.left = new FormAttachment(0, ITabbedPropertyConstants.HSPACE);
      data.right = new FormAttachment(100, -ITabbedPropertyConstants.HSPACE);
      data.top = new FormAttachment(0, curRowSize + ITabbedPropertyConstants.VSPACE);
      data.width = 300; // to correct bug of table growing indefinitly

      IMetadataTable outputMetaTable = ((Connection) elem).getMetadataTable();
      if (outputMetaTable != null) {
        // Composite compositeEditorView = new Composite(composite, SWT.BORDER);
        // compositeEditorView.setLayoutData(data);

        metadataTableEditor =
            new MetadataTableEditor(
                outputMetaTable,
                "Schema from " //$NON-NLS-1$
                    + ((Connection) elem).getSource().getElementName()
                    + " output "); //$NON-NLS-1$
        metadataTableEditorView =
            new MetadataTableEditorView(
                composite, SWT.NONE, metadataTableEditor, true, false, true, false);
        MetadataDialog.initializeMetadataTableView(
            metadataTableEditorView, ((Connection) elem).getSource(), outputMetaTable);
        metadataTableEditorView.initGraphicComponents();
        metadataTableEditorView.getExtendedTableViewer().setCommandStack(getCommandStack());
        CustomTableManager.addCustomManagementToTable(metadataTableEditorView, true);
        Composite compositeEditorView = metadataTableEditorView.getMainComposite();
        compositeEditorView.setLayoutData(data);
        // compositeEditorView.getParent().layout();

        Table table = metadataTableEditorView.getTable();
        int currentHeightEditor =
            table.getHeaderHeight()
                + outputMetaTable.getListColumns().size() * table.getItemHeight()
                + table.getItemHeight()
                + 50;
        curRowSize = currentHeightEditor + ITabbedPropertyConstants.VSPACE + curRowSize;
      }
      super.addComponents(forceRedraw, false);
    } else if (conIf()) {
      super.addComponents(forceRedraw);
    } else {
      disposeChildren();
    }
  }
Beispiel #8
0
 @Override
 protected void setTableViewerCreatorOptions(
     TableViewerCreator<IMetadataColumn> newTableViewerCreator) {
   super.setTableViewerCreatorOptions(newTableViewerCreator);
   newTableViewerCreator.setLayoutMode(LAYOUT_MODE.DEFAULT);
 }