private void setTreeInput(GradleProject project) {
   if (taskSelectionTreeViewer != null) {
     taskSelectionTreeViewer.setInput(project);
     Tree tree = taskSelectionTreeViewer.getTree();
     for (TreeColumn col : tree.getColumns()) {
       col.pack();
     }
   }
 }
예제 #2
0
  /**
   * **** The same version as {@link BaseScopeView.initTableColumns} but without worrying if the
   * tree has been disposed or not.
   *
   * @param tree
   * @param keepColumnStatus
   */
  private void initTableColumns(Tree tree, boolean keepColumnStatus) {
    final Experiment myExperiment = database.getExperiment();
    final int numMetric = myExperiment.getMetricCount();

    int iColCount = tree.getColumnCount();
    boolean status[] = new boolean[numMetric];

    if (iColCount > 1) {
      TreeColumn[] columns = tree.getColumns();

      // this is Eclipse Indigo bug: when a column is disposed, the next column will have
      //	zero as its width. Somehow they didn't preserve the width of the columns.
      // Hence, we have to retrieve the information of column width before the dispose action
      for (int i = 1; i < iColCount; i++) {
        // bug fix: for callers view activation, we have to reserve the current status
        if (keepColumnStatus && i - 1 < status.length) {
          int width = columns[i].getWidth();
          status[i - 1] = (width > 0);
        }
      }

      // remove the metric columns blindly
      // TODO we need to have a more elegant solution here
      for (int i = 1; i < iColCount; i++) {
        TreeColumn column = columns[i]; // treeViewer.getTree().getColumn(1);
        column.dispose();
      }
    }
    // prepare the data for the sorter class for tree
    sorterTreeColumn.setMetric(myExperiment.getMetric(0));

    // dirty solution to update titles
    TreeViewerColumn[] colMetrics = new TreeViewerColumn[numMetric];
    {
      // Update metric title labels
      String[] titles = new String[numMetric + 1];
      titles[0] = "Scope"; // unused element. Already defined
      // add table column for each metric
      for (int i = 0; i < numMetric; i++) {
        final BaseMetric metric = myExperiment.getMetric(i);
        if (metric != null) {
          titles[i + 1] = metric.getDisplayName(); // get the title
          colMetrics[i] = this.treeViewer.addTreeColumn(metric, (i == 0));

          // bug fix: for view initialization, we need to reset the status of hide/view
          if (!keepColumnStatus) {
            status[i] = metric.getDisplayed();
          }
        }
      }
      treeViewer.setColumnProperties(titles); // do we need this ??
    }
    // update the root scope of the actions !
    this.objViewActions.updateContent(myExperiment, this.myRootScope);
    this.objViewActions.objActionsGUI.setColumnsStatus(status);
  }
예제 #3
0
파일: UIUtils.java 프로젝트: ralic/dbeaver
 public static void packColumns(@NotNull Tree tree, boolean fit, @Nullable float[] ratios) {
   tree.setRedraw(false);
   try {
     // Check for disposed items
     // TODO: it looks like SWT error. Sometimes tree items are disposed and NPE is thrown from
     // column.pack
     for (TreeItem item : tree.getItems()) {
       if (item.isDisposed()) {
         return;
       }
     }
     int totalWidth = 0;
     final TreeColumn[] columns = tree.getColumns();
     for (TreeColumn column : columns) {
       column.pack();
       totalWidth += column.getWidth();
     }
     Rectangle clientArea = tree.getClientArea();
     if (clientArea.isEmpty()) {
       return;
     }
     if (fit) {
       int areaWidth = clientArea.width;
       if (tree.getVerticalBar() != null) {
         areaWidth -= tree.getVerticalBar().getSize().x;
       }
       if (totalWidth > areaWidth) {
         int extraSpace = totalWidth - areaWidth;
         for (TreeColumn tc : columns) {
           double ratio = (double) tc.getWidth() / totalWidth;
           tc.setWidth((int) (tc.getWidth() - extraSpace * ratio));
         }
       } else if (totalWidth < areaWidth) {
         float extraSpace = areaWidth - totalWidth;
         if (columns.length > 0) {
           if (ratios == null || ratios.length < columns.length) {
             extraSpace /= columns.length;
             extraSpace--;
             for (TreeColumn tc : columns) {
               tc.setWidth((int) (tc.getWidth() + extraSpace));
             }
           } else {
             for (int i = 0; i < columns.length; i++) {
               TreeColumn tc = columns[i];
               tc.setWidth((int) (tc.getWidth() + extraSpace * ratios[i]));
             }
           }
         }
       }
     }
   } finally {
     tree.setRedraw(true);
   }
 }