예제 #1
0
  protected void createColumns(TreeViewer viewer) {

    final TreeViewer treeViewer = (TreeViewer) viewer;
    // 用于一般的列
    EObjectColumnViewerProblemView problemView = new EObjectColumnViewerProblemView(treeViewer);
    // 用于扩展列
    EObjectColumnViewerProblemView exProblemView =
        new ExtensibleModelColumnViewerProblemView(treeViewer);

    // 标记列
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_INDEX__MARK;

      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(80);
      tvColumn.getColumn().setText("标记");

      EObjectColumnLabelProvider provider = new TableColumnLabelProvider(attribute, resource);
      provider.setDiagnosticProvider(problemView);
      tvColumn.setLabelProvider(provider);
      tvColumn.getColumn().setMoveable(true);
    }

    // 索引名
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_INDEX__NAME;

      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(130);
      tvColumn.getColumn().setText("索引名");

      EObjectColumnLabelProvider provider = new TableColumnLabelProvider(attribute, resource);
      provider.setDiagnosticProvider(problemView);
      tvColumn.setLabelProvider(provider);
    }
    //		// 索引字段列表
    {
      EStructuralFeature feature = DatabasePackage.Literals.TABLE_INDEX__COLUMNS;

      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(150);
      tvColumn.getColumn().setText("索引字段列表");

      IndexColumnLabelProvider provider =
          new IndexColumnLabelProvider(feature) {
            @Override
            public Color getBackground(Object element) {
              if (resource.isReadOnly()) {
                return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
              }
              return super.getBackground(element);
            }
          };
      provider.setDiagnosticProvider(problemView);
      tvColumn.setLabelProvider(provider);

      tvColumn.getColumn().setMoveable(true);
    }
    // 是否唯一
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_INDEX__UNIQUE;

      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(80);
      tvColumn.getColumn().setText("唯一");

      CheckBoxColumnLabelProvider provider = new CheckBoxColumnLabelProvider(attribute, resource);
      tvColumn.setLabelProvider(provider);

      tvColumn.getColumn().setMoveable(true);
    }

    // 聚簇列
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_INDEX__CLUSTER;

      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(80);
      tvColumn.getColumn().setText("聚簇");

      CheckBoxColumnLabelProvider provider = new CheckBoxColumnLabelProvider(attribute, resource);
      tvColumn.setLabelProvider(provider);

      tvColumn.setEditingSupport(new BooleanEditingSupport(treeViewer, attribute));
      tvColumn.getColumn().setMoveable(true);
    }

    // 扩展信息
    ExtensibleModelUtils.createExtensibleModelTreeViewerColumns(
        treeViewer, resource, DatabasePackage.Literals.TABLE_INDEX, exProblemView);
  }
  protected void createColumns(TreeViewer viewer) {
    final TreeViewer treeViewer = (TreeViewer) viewer;
    // 用于一般的列
    EObjectColumnViewerProblemView problemView = new EObjectColumnViewerProblemView(treeViewer);
    // 用于扩展列
    EObjectColumnViewerProblemView exProblemView =
        new ExtensibleModelColumnViewerProblemView(treeViewer);

    // 标记
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_COLUMN__MARK;

      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(90);
      tvColumn.getColumn().setText("标记");

      EObjectColumnLabelProvider provider = new TableColumnLabelProvider(attribute, resource);
      provider.setDiagnosticProvider(problemView);
      tvColumn.setLabelProvider(provider);

      tvColumn.getColumn().setMoveable(true);
    }

    // 引用的标准字段
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_COLUMN__FIELD_NAME;

      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(130);
      tvColumn.getColumn().setText("字段名");

      EObjectColumnLabelProvider provider = new TableColumnLabelProvider(attribute, getResource());
      provider.setDiagnosticProvider(problemView);
      tvColumn.setLabelProvider(provider);
    }

    // 中文名
    {
      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(100);
      tvColumn.getColumn().setText("中文名");

      TableColumnRefLabelProvider provider =
          new TableColumnRefLabelProvider(
              resource.getBundle(), TableColumnRefLabelProvider.TYPE.ChineseName) {
            @Override
            public Color getBackground(Object element) {
              if (getResource().isReadOnly()) {
                return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
              }
              return super.getBackground(element);
            }
          };
      tvColumn.setLabelProvider(provider);
      tvColumn.getColumn().setMoveable(true);
    }
    // 字段类型
    {
      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(100);
      tvColumn.getColumn().setText("字段类型");

      TableColumnRefLabelProvider provider =
          new TableColumnRefLabelProvider(
              resource.getBundle(), TableColumnRefLabelProvider.TYPE.Type) {
            @Override
            public Color getBackground(Object element) {
              if (getResource().isReadOnly()) {
                return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
              }
              return super.getBackground(element);
            }
          };
      tvColumn.setLabelProvider(provider);
      tvColumn.getColumn().setMoveable(true);
    }

    // 字段说明
    {
      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(150);
      tvColumn.getColumn().setText("字段说明");

      TableColumnRefLabelProvider provider =
          new TableColumnRefLabelProvider(
              resource.getBundle(), TableColumnRefLabelProvider.TYPE.Desciption) {
            @Override
            public String getToolTipText(Object element) {
              return getText(element);
            }

            @Override
            public Color getBackground(Object element) {
              if (getResource().isReadOnly()) {
                return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
              }
              return super.getBackground(element);
            }
          };
      tvColumn.setLabelProvider(provider);
      tvColumn.getColumn().setMoveable(true);
    }

    // 默认值
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_COLUMN__DEFAULT_VALUE;

      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(100);
      tvColumn.getColumn().setText("默认值");

      EObjectColumnLabelProvider provider = new TableColumnLabelProvider(attribute, getResource());
      provider.setDiagnosticProvider(problemView);
      tvColumn.setLabelProvider(provider);

      tvColumn.getColumn().setMoveable(true);
    }

    // 是否为空
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_COLUMN__NULLABLE;

      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(80);
      tvColumn.getColumn().setText("允许空");

      CheckBoxColumnLabelProvider provider =
          new CheckBoxColumnLabelProvider(attribute, getResource()) {
            @Override
            public Color getBackground(Object element) {
              TableColumn tc = (TableColumn) element;
              // if (tc.isPrimaryKey()) {
              if (DatabaseUtils.isPrimaryKey(tc)) {
                return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
              }
              return super.getBackground(element);
            }

            @Override
            public Image getImage(Object element) {
              TableColumn tc = (TableColumn) element;
              //					if (tc.isPrimaryKey()) {
              if (DatabaseUtils.isPrimaryKey(tc)) {
                return null;
              }
              return super.getImage(element);
            }
          };
      tvColumn.setLabelProvider(provider);
      tvColumn.getColumn().setMoveable(true);
    }

    // 备注
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_COLUMN__COMMENTS;

      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(150);
      tvColumn.getColumn().setText("备注");

      EObjectColumnLabelProvider provider =
          new TableColumnLabelProvider(attribute, getResource()) {

            @Override
            public String getToolTipText(Object element) {
              String text = super.getToolTipText(element);
              if (StringUtils.isBlank(text)) {
                return getText(element);
              }
              return text;
            }
          };
      provider.setDiagnosticProvider(problemView);
      tvColumn.setLabelProvider(provider);
      tvColumn.getColumn().setMoveable(true);
    }

    // 扩展信息
    ExtensibleModelUtils.createExtensibleModelTreeViewerColumns(
        treeViewer, getResource(), DatabasePackage.Literals.TABLE_COLUMN, exProblemView);
  }