コード例 #1
0
  @Override
  public void createPartControl(Composite parent) {
    super.createPartControl(parent);
    final TreeViewer viewer = getNavigatorViewer();
    assert viewer != null;
    viewer.getTree().setHeaderVisible(true);
    createColumns(viewer);
    UIUtils.setHelp(parent, IHelpContextIds.CTX_PROJECT_EXPLORER);

    viewer.addFilter(
        new ViewerFilter() {
          @Override
          public boolean select(Viewer viewer, Object parentElement, Object element) {
            return !(element instanceof DBNProjectDatabases);
          }
        });
    updateTitle();
  }
コード例 #2
0
  private void createColumns(final TreeViewer viewer) {
    final Color shadowColor =
        viewer.getControl().getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);

    final ILabelProvider mainLabelProvider = (ILabelProvider) viewer.getLabelProvider();
    columnController = new ViewerColumnController("projectExplorer", viewer);
    columnController.addColumn(
        "Name",
        "Resource name",
        SWT.LEFT,
        true,
        true,
        new TreeColumnViewerLabelProvider(
            new LabelProvider() {
              @Override
              public String getText(Object element) {
                return mainLabelProvider.getText(element);
              }

              @Override
              public Image getImage(Object element) {
                return mainLabelProvider.getImage(element);
              }
            }));

    columnController.addColumn(
        "DataSource",
        "Datasource(s) associated with resource",
        SWT.LEFT,
        true,
        false,
        new TreeColumnViewerLabelProvider(
            new LabelProvider() {
              @Override
              public String getText(Object element) {
                DBNNode node = (DBNNode) element;
                if (node instanceof DBNDatabaseNode) {
                  return ((DBNDatabaseNode) node).getDataSourceContainer().getName();
                } else if (node instanceof DBNResource) {
                  Collection<DBPDataSourceContainer> containers =
                      ((DBNResource) node).getAssociatedDataSources();
                  if (!CommonUtils.isEmpty(containers)) {
                    StringBuilder text = new StringBuilder();
                    for (DBPDataSourceContainer container : containers) {
                      if (text.length() > 0) {
                        text.append(", ");
                      }
                      text.append(container.getName());
                    }
                    return text.toString();
                  }
                }
                return "";
              }

              @Override
              public Image getImage(Object element) {
                /*
                                DBNNode node = (DBNNode) element;
                                if (node instanceof DBNDatabaseNode) {
                                    return DBeaverIcons.getImage(((DBNDatabaseNode) node).getDataSourceContainer().getDriver().getIcon());
                                } else if (node instanceof DBNResource) {
                                    Collection<DBPDataSourceContainer> containers = ((DBNResource) node).getAssociatedDataSources();
                                    if (containers != null && containers.size() == 1) {
                                        return DBeaverIcons.getImage((containers.iterator().next().getDriver().getIcon()));
                                    }
                                }
                */
                return null;
              }
            }));
    columnController.addColumn(
        "Preview",
        "Script content preview",
        SWT.LEFT,
        false,
        false,
        new LazyLabelProvider(shadowColor) {
          @Override
          public String getLazyText(Object element) {
            if (element instanceof DBNNode) {
              return ((DBNNode) element).getNodeDescription();
            } else {
              return null;
            }
          }
        });
    columnController.addColumn(
        "Size",
        "File size",
        SWT.LEFT,
        false,
        false,
        new TreeColumnViewerLabelProvider(
            new LabelProvider() {
              @Override
              public String getText(Object element) {
                DBNNode node = (DBNNode) element;
                if (node instanceof DBNResource) {
                  IResource resource = ((DBNResource) node).getResource();
                  if (resource instanceof IFile) {
                    return String.valueOf(resource.getLocation().toFile().length());
                  }
                }
                return "";
              }
            }));
    columnController.addColumn(
        "Modified",
        "Time the file was last modified",
        SWT.LEFT,
        false,
        false,
        new TreeColumnViewerLabelProvider(
            new LabelProvider() {
              private SimpleDateFormat sdf =
                  new SimpleDateFormat(DBConstants.DEFAULT_TIMESTAMP_FORMAT);

              @Override
              public String getText(Object element) {
                DBNNode node = (DBNNode) element;
                if (node instanceof DBNResource) {
                  IResource resource = ((DBNResource) node).getResource();
                  if (resource instanceof IFile || resource instanceof IFolder) {
                    return sdf.format(new Date(resource.getLocation().toFile().lastModified()));
                  }
                }
                return "";
              }
            }));
    columnController.addColumn(
        "Type",
        "Resource type",
        SWT.LEFT,
        false,
        false,
        new TreeColumnViewerLabelProvider(
            new LabelProvider() {
              @Override
              public String getText(Object element) {
                DBNNode node = (DBNNode) element;
                if (node instanceof DBNResource) {
                  IResource resource = ((DBNResource) node).getResource();
                  ProgramInfo program = ProgramInfo.getProgram(resource);
                  if (program != null) {
                    return program.getProgram().getName();
                  }
                }
                return "";
              }
            }));
    columnController.createColumns();
  }