1 package org.simantics.scl.ui.issues;
3 import java.util.ArrayList;
4 import java.util.Collections;
6 import java.util.concurrent.atomic.AtomicBoolean;
7 import java.util.stream.Collectors;
9 import org.eclipse.jface.viewers.IStructuredContentProvider;
10 import org.eclipse.jface.viewers.Viewer;
11 import org.eclipse.swt.widgets.Control;
12 import org.simantics.scl.osgi.issues.SCLIssueFactoryProvider;
13 import org.simantics.scl.osgi.issues.SCLIssueProviderFactory.SCLIssueProvider;
14 import org.simantics.scl.osgi.issues.SCLIssuesTableEntry;
16 public class SCLIssuesContentProvider implements IStructuredContentProvider {
18 public static final int MAX_ISSUE_COUNT = 1000;
20 private Viewer viewer;
21 boolean disposed = false;
22 private AtomicBoolean refreshInProgress = new AtomicBoolean(false);
23 private List<SCLIssueProvider> issueProviders = new ArrayList<>();
26 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
28 if (!issueProviders.isEmpty()) {
29 issueProviders.forEach(p -> p.dispose());
30 issueProviders.clear();
32 if(newInput != null) {
33 issueProviders = SCLIssueFactoryProvider.getSCLIssueProviderFactories().stream().map(f -> f.getSCLIssueProvider()).collect(Collectors.toList());
34 issueProviders.forEach(p -> p.listenIssues(() -> refresh()));
38 private void refresh() {
39 if(!refreshInProgress.compareAndSet(false, true))
43 Control control = viewer.getControl();
44 if(control.isDisposed() || disposed)
46 control.getDisplay().asyncExec(new Runnable() {
49 if(control.isDisposed() || disposed)
51 refreshInProgress.set(false);
57 public void dispose() {
60 issueProviders.forEach(p -> p.dispose());
61 issueProviders.clear();
66 public Object[] getElements(Object inputElement) {
67 ArrayList<SCLIssuesTableEntry> result = new ArrayList<>();
68 issueProviders.forEach(p -> result.addAll(p.getIssues()));
69 Collections.sort(result);
70 return result.toArray();