1 package org.simantics.scl.ui.issues;
3 import org.eclipse.jface.action.Action;
4 import org.eclipse.jface.action.IAction;
5 import org.eclipse.jface.resource.ImageRegistry;
6 import org.eclipse.jface.viewers.ColumnLabelProvider;
7 import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
8 import org.eclipse.jface.viewers.DoubleClickEvent;
9 import org.eclipse.jface.viewers.IDoubleClickListener;
10 import org.eclipse.jface.viewers.IStructuredSelection;
11 import org.eclipse.jface.viewers.TableViewer;
12 import org.eclipse.jface.viewers.TableViewerColumn;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.events.ControlAdapter;
15 import org.eclipse.swt.events.ControlEvent;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.swt.graphics.Point;
18 import org.eclipse.swt.graphics.Rectangle;
19 import org.eclipse.swt.layout.FillLayout;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.ScrollBar;
22 import org.eclipse.swt.widgets.Table;
23 import org.eclipse.ui.IMemento;
24 import org.eclipse.ui.IViewSite;
25 import org.eclipse.ui.PartInitException;
26 import org.eclipse.ui.part.ViewPart;
27 import org.simantics.scl.osgi.SCLOsgi;
28 import org.simantics.scl.ui.Activator;
29 import org.simantics.scl.ui.editor2.OpenSCLDefinition;
31 public class SCLIssuesView extends ViewPart {
33 private static final int COLUMN1_DEFAULT_WIDTH = 300;
34 private static final int COLUMN2_MIN_WIDTH = 100;
37 TableViewer tableViewer;
38 TableViewerColumn column1;
39 TableViewerColumn column2;
41 ImageRegistry imageRegistry;
43 SCLIssuesContentProvider issuesContentProvider = new SCLIssuesContentProvider();
45 public SCLIssuesView() {
47 imageRegistry = Activator.getInstance().getImageRegistry();
51 public void init(IViewSite site, IMemento memento)
52 throws PartInitException {
53 super.init(site, memento);
54 IAction action = new Action("Refresh") {
57 SCLOsgi.MODULE_REPOSITORY.getSourceRepository().checkUpdates();
60 action.setImageDescriptor(imageRegistry.getDescriptor("arrow_refresh"));
61 site.getActionBars().getToolBarManager().add(action);
65 public void createPartControl(Composite parent) {
67 parent.setLayout(new FillLayout());
68 tableViewer = new TableViewer(parent,
69 SWT.FULL_SELECTION | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
70 ColumnViewerToolTipSupport.enableFor(tableViewer);
71 tableViewer.setContentProvider(issuesContentProvider);
73 Table table = tableViewer.getTable();
74 table.setHeaderVisible(true);
75 table.setLinesVisible(true);
77 column1 = new TableViewerColumn(tableViewer, SWT.NONE);
78 column1.getColumn().setText("Module");
79 column1.getColumn().setWidth(COLUMN1_DEFAULT_WIDTH);
80 column1.getColumn().setResizable(true);
81 column1.setLabelProvider(new ColumnLabelProvider() {
83 public String getText(Object element) {
84 SCLIssuesTableEntry entry = (SCLIssuesTableEntry)element;
85 return entry.moduleName;
88 public Image getImage(Object element) {
89 return imageRegistry.get("error");
93 column2 = new TableViewerColumn(tableViewer, SWT.NONE);
94 column2.getColumn().setText("Description");
95 column2.getColumn().setResizable(false);
96 column2.setLabelProvider(new ColumnLabelProvider() {
98 public String getText(Object element) {
99 SCLIssuesTableEntry entry = (SCLIssuesTableEntry)element;
100 String description = entry.error.description;
101 int p = description.indexOf('\n');
105 return description.substring(0, p);
108 public String getToolTipText(Object element) {
109 SCLIssuesTableEntry entry = (SCLIssuesTableEntry)element;
110 return entry.error.description;
113 public int getToolTipTimeDisplayed(Object object) {
117 public int getToolTipDisplayDelayTime(Object object) {
121 public Point getToolTipShift(Object object) {
122 return new Point(0, 0);
126 ControlAdapter resizeListener = new ControlAdapter() {
128 public void controlResized(ControlEvent e) {
132 parent.addControlListener(resizeListener);
133 column1.getColumn().addControlListener(resizeListener);
135 tableViewer.setInput(SCLOsgi.MODULE_REPOSITORY);
136 tableViewer.addDoubleClickListener(new IDoubleClickListener() {
138 public void doubleClick(DoubleClickEvent event) {
139 IStructuredSelection selection = (IStructuredSelection)event.getSelection();
140 SCLIssuesTableEntry entry = (SCLIssuesTableEntry)selection.getFirstElement();
141 OpenSCLDefinition.openDefinition(entry.moduleName, entry.error.location);
146 private void resizeColumns() {
147 Table table = tableViewer.getTable();
148 Rectangle area = parent.getClientArea();
149 Point size = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
150 ScrollBar vBar = table.getVerticalBar();
151 int width = area.width;
152 if (size.y > area.height + table.getHeaderHeight()) {
153 Point vBarSize = vBar.getSize();
156 Point oldSize = table.getSize();
157 if (oldSize.x > area.width) {
158 column2.getColumn().setWidth(Math.max(COLUMN2_MIN_WIDTH, width - column1.getColumn().getWidth()));
159 table.setSize(area.width, area.height);
161 table.setSize(area.width, area.height);
162 column2.getColumn().setWidth(Math.max(COLUMN2_MIN_WIDTH, width - column1.getColumn().getWidth()));
167 public void setFocus() {
168 tableViewer.getControl().setFocus();
172 public void dispose() {
174 issuesContentProvider.dispose();