Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9f03864c28d5bd7048d9a0db160fc252606a6e37 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/

package org.eclipse.osee.framework.ui.skynet;

import java.util.ArrayList;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.osee.framework.jdk.core.util.AHTML;
import org.eclipse.osee.framework.ui.skynet.results.XResultData;
import org.eclipse.osee.framework.ui.skynet.results.html.XResultPage.Manipulations;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;

public class TreeViewerReport {

   private final TreeViewer treeViewer;
   private ArrayList<Integer> ignoreCols = new ArrayList<Integer>();
   private final String title;

   public TreeViewerReport(String title, TreeViewer treeViewer) {
      this.title = title;
      this.treeViewer = treeViewer;
   }

   public TreeViewerReport(TreeViewer treeViewer) {
      this("Table View Report", treeViewer);
   }

   public void open() {
      open(treeViewer.getTree().getItems());
   }

   public void setIgnoreColumns(ArrayList<Integer> ignoreCols) {
      this.ignoreCols = ignoreCols;
   }

   public void open(TreeItem items[]) {
      String html = getHtml(items);
      XResultData xResultData = new XResultData();
      xResultData.addRaw(html);
      xResultData.report(title, Manipulations.RAW_HTML);
   }

   public String getHtml(TreeItem items[]) {
      String html = "<html><body>";
      if (!title.equals("WebDialog")) {
         html += AHTML.heading(3, title);
      }
      html += AHTML.beginMultiColumnTable(100, 1);
      TreeColumn cols[] = treeViewer.getTree().getColumns();
      Integer width[] = new Integer[cols.length - ignoreCols.size()];
      String colNames[] = new String[cols.length - ignoreCols.size()];
      int colNum = 0;
      for (int x = 0; x < cols.length; x++) {
         if (!ignoreCols.contains(x)) {
            TreeColumn col = cols[x];
            width[colNum] = col.getWidth();
            colNames[colNum++] = col.getText();
         }
      }
      html += AHTML.addHeaderRowMultiColumnTable(colNames, width);
      // Get column widths and column name and setup the columns
      ITableLabelProvider labelProv = (ITableLabelProvider) treeViewer.getLabelProvider();
      ArrayList<String[]> list = new ArrayList<String[]>();
      for (TreeItem item : items) {
         addRow(item, list, labelProv, cols.length, 1);
      }
      for (String[] strs : list) {
         html += AHTML.addRowMultiColumnTable(strs);
      }
      html += AHTML.endMultiColumnTable();
      html += "</body></html>";
      return html;
   }

   public void addRow(TreeItem item, ArrayList<String[]> list, ITableLabelProvider labelProv, int numCols, int level) {
      String str[] = new String[numCols - ignoreCols.size()];
      int colNum = 0;
      for (int x = 0; x < numCols; x++) {
         if (!ignoreCols.contains(x)) {
            str[colNum] = "";
            if (x == 0) {
               for (int y = 0; y < level; y++) {
                  str[colNum] += "&nbsp;&nbsp;&nbsp;&nbsp;";
               }
            }
            str[colNum++] += labelProv.getColumnText(item.getData(), x);
         }
      }
      list.add(str);
      if (item.getExpanded()) {
         for (TreeItem i : item.getItems()) {
            addRow(i, list, labelProv, numCols, level + 1);
         }
      }

   }

}

Back to the top