1   package com.stateofflow.eclipse.metrics.properties.exclusions.table;
2   
3   import org.eclipse.jface.viewers.ColumnWeightData;
4   import org.eclipse.jface.viewers.TableLayout;
5   import org.eclipse.jface.viewers.TableViewer;
6   import org.eclipse.swt.SWT;
7   import org.eclipse.swt.layout.GridData;
8   import org.eclipse.swt.widgets.Composite;
9   import org.eclipse.swt.widgets.Table;
10  import org.eclipse.swt.widgets.TableColumn;
11  
12  import com.stateofflow.eclipse.metrics.properties.exclusions.ExcludedResources;
13  
14  public final class TableViewerBuilder {
15      public TableViewer create(final Composite parent, final ExcludedResources excludedResources) {
16          final Table table = new Table(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
17          table.setHeaderVisible(true);
18          table.setLinesVisible(false);
19  
20          initialiseTableLayout(table);
21          return initialiseTableViewer(table, excludedResources);
22      }
23  
24      private void initialiseTableLayout(final Table table) {
25          final TableLayout tableLayout = new TableLayout();
26          tableLayout.addColumnData(new ColumnWeightData(1000));
27          table.setLayout(tableLayout);
28          table.setLayoutData(new GridData(GridData.FILL_BOTH));
29  
30          final TableColumn column = new TableColumn(table, SWT.NULL);
31          column.setText("Excluded Resources");
32          column.setResizable(false);
33      }
34  
35      private TableViewer initialiseTableViewer(final Table table, final ExcludedResources excludedResources) {
36          final TableViewer viewer = new TableViewer(table);
37          viewer.setContentProvider(new ContentProvider());
38          viewer.setInput(excludedResources);
39          viewer.setSorter(new Sorter());
40          viewer.setLabelProvider(new LabelProvider());
41          return viewer;
42      }
43  }
44