From: Marko Luukkainen Date: Tue, 30 Jun 2020 08:38:34 +0000 (+0300) Subject: Simple implementation for Issues property tab X-Git-Tag: v1.43.0~8 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F31%2F4331%2F2;p=simantics%2Fplatform.git Simple implementation for Issues property tab gitlab #567 Change-Id: If675e438e23229347c9fe5e47748ffcb7bb8fc05 --- diff --git a/bundles/org.simantics.issues.ui/META-INF/MANIFEST.MF b/bundles/org.simantics.issues.ui/META-INF/MANIFEST.MF index da218152b..8d346bbb4 100644 --- a/bundles/org.simantics.issues.ui/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.issues.ui/META-INF/MANIFEST.MF @@ -24,6 +24,7 @@ Bundle-ActivationPolicy: lazy Bundle-Activator: org.simantics.issues.ui.internal.Activator Export-Package: org.simantics.issues.ui, org.simantics.issues.ui.contribution, - org.simantics.issues.ui.handler + org.simantics.issues.ui.handler, + org.simantics.issues.ui.property Bundle-Vendor: VTT Technical Research Centre of Finland Automatic-Module-Name: org.simantics.issues.ui diff --git a/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/property/IssuesTab.java b/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/property/IssuesTab.java new file mode 100644 index 000000000..fb1e0a977 --- /dev/null +++ b/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/property/IssuesTab.java @@ -0,0 +1,172 @@ +package org.simantics.issues.ui.property; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.CellLabelProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.ViewerCell; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.procedure.adapter.TransientCacheListener; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.request.Read; +import org.simantics.issues.Severity; +import org.simantics.issues.common.IssueResourceContexts; +import org.simantics.issues.common.ListModelIssuesBySeverity; +import org.simantics.issues.common.SimpleIssue; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.selectionview.PropertyTabContributorImpl; + +/** + * A very simple property tab for listing issues of a selected object. + * + * @author luukkainen + * + */ +public class IssuesTab extends PropertyTabContributorImpl{ + + + private TableViewer viewer; + private Resource model; + private Resource element; + + private List result; + + public IssuesTab(ReadGraph graph, Resource model, Resource element) throws DatabaseException { + this.model = model; + this.element = element; + + Layer0 L0 = Layer0.getInstance(graph); + List contexts = getContexts(graph, element); + Map> issuesBySeverity = graph.syncRequest( + new ListModelIssuesBySeverity(model, true, true, Severity.NOTE), + TransientCacheListener.>>instance()); + + result = new ArrayList<>(); + for (Severity severity : Severity.values()) { + List issues = issuesBySeverity.get(severity); + if (issues != null) { + for (Resource issue : issues) { + Set issueContexts = graph.syncRequest(new IssueResourceContexts(issue)); + if (!Collections.disjoint(issueContexts, contexts)) { + SimpleIssue si = new SimpleIssue((String) graph.getRelatedValue(issue, L0.HasLabel, Bindings.STRING), + severity, issue); + result.add(si); + System.out.println(si.label + " " + si.severity); + } + } + } + } + } + + + /** + * @see org.simantics.modeling.ui.diagram.style.IssueDecorationStyle + * + * @param graph + * @param element + * @return + * @throws DatabaseException + */ + protected List getContexts(ReadGraph graph, Resource element) throws DatabaseException { + + ModelingResources MOD = ModelingResources.getInstance(graph); + List result = new ArrayList(3); + result.add(element); + Resource config = graph.getPossibleObject(element, MOD.ElementToComponent); + if (config != null && result.indexOf(config) == -1) result.add(config); + config = graph.getPossibleObject(element, MOD.DiagramConnectionToConnection); + if (config != null && result.indexOf(config) == -1) result.add(config); + // For diagram reference element support + config = graph.getPossibleObject(element, MOD.HasParentComponent); + if (config != null && result.indexOf(config) == -1) result.add(config); + return result; + + } + + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + GridLayoutFactory.fillDefaults().numColumns(2).spacing(0, 0).applyTo(body); + + viewer = new TableViewer(body); + + TableViewerColumn issueColumn = new TableViewerColumn(viewer, SWT.LEFT); + TableViewerColumn severityColumn = new TableViewerColumn(viewer, SWT.LEFT); + + issueColumn.setLabelProvider(new CellLabelProvider() { + + @Override + public void update(ViewerCell cell) { + SimpleIssue issue = (SimpleIssue)cell.getElement(); + cell.setText(issue.label); + + } + }); + severityColumn.setLabelProvider(new CellLabelProvider() { + + @Override + public void update(ViewerCell cell) { + SimpleIssue issue = (SimpleIssue)cell.getElement(); + cell.setText(issue.severity.name()); + } + }); + + issueColumn.getColumn().setWidth(300); + issueColumn.getColumn().setText("Issue"); + + severityColumn.getColumn().setWidth(100); + severityColumn.getColumn().setText("Severity"); + + viewer.getTable().setHeaderVisible(true); + viewer.getTable().setLinesVisible(true); + + viewer.setContentProvider(new IStructuredContentProvider() { + + @Override + public Object[] getElements(Object inputElement) { + List list = (List)inputElement; + return list.toArray(); + } + }); + + viewer.setInput(result); + GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getControl()); + + } + + @Override + public Read getPartNameReadRequest(ISelection forSelection) { + return new ObjectTitleRead(element); + } + + public static class ObjectTitleRead extends ResourceRead { + public ObjectTitleRead(Resource resource) { + super(resource); + } + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + return NameUtils.getSafeName(graph, resource); + } + } + +}