From 2ec7418891ad6ff5ffe0ac1c845f7059840f991e Mon Sep 17 00:00:00 2001 From: lempinen Date: Wed, 17 Oct 2012 09:29:17 +0000 Subject: [PATCH] issue decorations to old sysdyn model browser (fixes #3789) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26063 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../icons/error_decoration.png | Bin 0 -> 403 bytes .../icons/fatal_decoration.png | Bin 0 -> 381 bytes .../icons/warning_decoration.png | Bin 0 -> 474 bytes .../org/simantics/sysdyn/ui/Activator.java | 21 +++ .../contributions/AbstractNodeImager.java | 131 +++++++++++++++++- .../sysdyn/ui/editor/DiagramViewer.java | 45 +++--- 6 files changed, 167 insertions(+), 30 deletions(-) create mode 100644 org.simantics.sysdyn.ui/icons/error_decoration.png create mode 100644 org.simantics.sysdyn.ui/icons/fatal_decoration.png create mode 100644 org.simantics.sysdyn.ui/icons/warning_decoration.png diff --git a/org.simantics.sysdyn.ui/icons/error_decoration.png b/org.simantics.sysdyn.ui/icons/error_decoration.png new file mode 100644 index 0000000000000000000000000000000000000000..688ad22ab8d21c027f81d77f894be23e81ef22f6 GIT binary patch literal 403 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|*pj^6U4S$Y z{B+)352QE?JR*x37`TN&n2}-D90{Nxdx@v7EBkF`0TB*W>omIuKvRT0T^vIsE;Dj4 ze*ee#qbZ$%qi!a{|JqoQpMMyVfB*i?!1&|qT%IYL-#p0)VqgTC!SK5(CiaJn+9GCd zplcWz8NR>!%<%R6u{gPf`xZ0)Ee#X-s-X3n^~d}F?D@Tn|9}5t_|{+c|1$#{@k_^AU|7BqL{g>g}x33IL-`~BO^WpJR1_mxc2Hw2Qg#@(3mW o{_~6B{j*ndqn|On+3Tpz5NKGw@sr)*MjqQ5O7ys_L`uI{vK(CcK-!|CkFSr_)%+lP#?iB4jy{61 zZ<3OB1o-o=G<*K&J7>ek(}kC}o!#@H?7Z*vr}zECPEYFF?7E*R;e5y3-3OoOR9hJ2 zSFO}vKHL3McWndLfs?L6(Bta;gF?eBf(f8FYm=ykKPx#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2ipS> z6gnJ<6XKZw00CM_L_t&-({+qJNE>k+K;I?7j|gXw41UDHK~M_?i-d|F6gQ!zo6teT zk5t92xVSku=xAGmqJx98A`}I+g+eJ-1jSM(bB4B{HX)u-licNh_j6DLp}zG!9^8@G zYy}_{EpISq%IW}4K81M{bK`CLd@U0DuRL9UetVs+9;n+G@^EY&;} zLwgb*CG3CN)uR<;@wjQoOV7r6*nz;+PySDsv)sK5b;e6{^mov{_erz+c{nztC034%UM z=`$~)9Gq+(mCoYv2dE5%qT1;M1&07*qoM6N<$f*0t;Z~y=R literal 0 HcmV?d00001 diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/Activator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/Activator.java index cb2d6dd3..5e1333d7 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/Activator.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/Activator.java @@ -18,6 +18,8 @@ import org.apache.log4j.ConsoleAppender; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.LocalResourceManager; import org.eclipse.jface.resource.ResourceManager; @@ -25,6 +27,7 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; +import org.simantics.issues.Severity; import org.simantics.utils.FileUtils; public class Activator extends AbstractUIPlugin { @@ -40,6 +43,9 @@ public class Activator extends AbstractUIPlugin { public static String FATAL_SVG_TEXT; public static String ERROR_SVG_TEXT; public static String WARNING_SVG_TEXT; + public static ImageDescriptor FATAL_DECORATION_ICON; + public static ImageDescriptor ERROR_DECORATION_ICON; + public static ImageDescriptor WARNING_DECORATION_ICON; @Override public void start(BundleContext context) throws Exception { @@ -56,6 +62,9 @@ public class Activator extends AbstractUIPlugin { FATAL_SVG_TEXT = FileUtils.getContents(bundle.getResource("icons/fatal.svg")); ERROR_SVG_TEXT = FileUtils.getContents(bundle.getResource("icons/error.svg")); WARNING_SVG_TEXT = FileUtils.getContents(bundle.getResource("icons/warning.svg")); + FATAL_DECORATION_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/fatal_decoration.png")); + ERROR_DECORATION_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/error_decoration.png")); + WARNING_DECORATION_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/warning_decoration.png")); } @Override @@ -68,6 +77,18 @@ public class Activator extends AbstractUIPlugin { return plugin; } + @Override + protected ImageRegistry createImageRegistry() { + return super.createImageRegistry(); + } + + @Override + protected void initializeImageRegistry(ImageRegistry reg) { + reg.put(Severity.FATAL.toString(), FATAL_DECORATION_ICON); + reg.put(Severity.ERROR.toString(), ERROR_DECORATION_ICON); + reg.put(Severity.WARNING.toString(), WARNING_DECORATION_ICON); + } + public static ResourceManager initializeResourceManager(Display display) { if (resourceManager == null) { resourceManager = new LocalResourceManager(JFaceResources.getResources(display)); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java index f149c236..202b8b81 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java @@ -11,12 +11,24 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.browser.contributions; +import java.util.Collection; +import java.util.HashSet; + import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IDecoration; import org.simantics.browsing.ui.common.node.AbstractNode; import org.simantics.browsing.ui.swt.ImagerContributor; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.issues.Severity; +import org.simantics.issues.common.MaxIssueSeverityRecursive; +import org.simantics.issues.ontology.IssueResource; +import org.simantics.layer0.Layer0; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.structural.stubs.StructuralResource2; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.Activator; import org.simantics.sysdyn.ui.browser.nodes.BookNode; @@ -34,15 +46,21 @@ import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode; import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder; import org.simantics.sysdyn.ui.browser.nodes.SheetNode; import org.simantics.sysdyn.ui.browser.nodes.VariableNode; +import org.simantics.utils.ui.gfx.DecorationOverlayIcon; +/** + * Imager for nodes in old sysdyn model browser + * @author Teemu Lempinen + * + */ public class AbstractNodeImager extends ImagerContributor> { @Override public ImageDescriptor getDescriptor(ReadGraph graph, AbstractNode node) throws DatabaseException { - + String image = null; if (node instanceof SharedFunctionsFolder) - image = "icons/folder_link.png"; + image = "icons/folder_link.png"; else if (node instanceof ExperimentsFolder || node instanceof ModulesNode || node instanceof FunctionsFolder || @@ -56,7 +74,7 @@ public class AbstractNodeImager extends ImagerContributor if(graph.isInstanceOf(node.data, sr.PlaybackExperiment)) image = "icons/timeline_marker.png"; else if(graph.isInstanceOf(node.data, sr.GameExperiment)) - image = "icons/time_go.png"; + image = "icons/time_go.png"; else image = "icons/time.png"; } else if (node instanceof InputNode) @@ -69,10 +87,111 @@ public class AbstractNodeImager extends ImagerContributor image = "icons/table_multiple.png"; else if (node instanceof SheetNode) image = "icons/table.png"; - - if (image != null) - return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource(image)); + + if (image != null) { + + ImageDescriptor id = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource(image)); + + Severity maxSeverity = getMaxSeverity(graph, node); + + if (maxSeverity == null) + return id; + else + return getDecoration(id, maxSeverity); + } return null; } + + /** + * + * @param graph + * @param node + * @return + * @throws DatabaseException + */ + private Severity getMaxSeverity(ReadGraph graph, AbstractNode node) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + IssueResource.getInstance(graph); + SysdynResource SR = SysdynResource.getInstance(graph); + + HashSet issueTypes = new HashSet(); + issueTypes.add(SR.Variable); + issueTypes.add(SR.Configuration); + issueTypes.add(SR.Module); + + Resource data = node.data; + if(node instanceof ModuleTypeNode) { + Resource symbol = node.data; + Resource moduleType = graph.getPossibleObject(symbol, L0.PartOf); + data = graph.getPossibleObject(moduleType, StructuralResource2.getInstance(graph).IsDefinedBy); + } else if(node instanceof ModuleNode) { + Resource moduleType = graph.getPossibleObject(node.data, L0.InstanceOf); + data = graph.getPossibleObject(moduleType, StructuralResource2.getInstance(graph).IsDefinedBy); + } else if(node instanceof ModelNode) { + data = graph.getPossibleObject(node.data, SimulationResource.getInstance(graph).HasConfiguration); + } + + Severity maxSeverity = getMaxSeverityStructural(graph, data, issueTypes, null); + return maxSeverity; + } + + /** + * Recursive function for obtaining maximum severity of a configuration and its module + * children + * + * @param graph readGraph + * @param resource Resource from which issues are searched for. If the resource is configuraiton, issues are searched also from its module children. + * @param issueTypes Issue type resources + * @param severity Maximum current severity + * @return + * @throws DatabaseException + */ + private Severity getMaxSeverityStructural(ReadGraph graph, Resource resource, HashSet issueTypes, Severity severity) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + SysdynResource SR = SysdynResource.getInstance(graph); + + Resource data = resource; + Severity maxSeverity = graph.syncRequest(new MaxIssueSeverityRecursive(data, L0.ConsistsOf, issueTypes)); + + // Try structural + if(graph.isInstanceOf(data, SR.Configuration)) { + Collection moduleChildren = graph.syncRequest(new ModuleChildren(data)); + for(Resource r : moduleChildren) { + Resource moduleType = graph.getPossibleObject(r, L0.InstanceOf); + Resource configuration = graph.getPossibleObject(moduleType, StructuralResource2.getInstance(graph).IsDefinedBy); + if(configuration != null) + maxSeverity = getMaxSeverityStructural(graph, configuration, issueTypes, maxSeverity); + } + } + + return Severity.moreSevere(maxSeverity, severity); + } + + /** + * Request for obtaining all module children of a configuration + * @author Teemu Lempinen + * + */ + private class ModuleChildren implements Read> { + + Resource configuration; + + public ModuleChildren(Resource configuration) { + this.configuration = configuration; + } + + @Override + public Collection perform(ReadGraph graph) throws DatabaseException { + return graph.syncRequest(new ObjectsWithType(configuration, Layer0.getInstance(graph).ConsistsOf, SysdynResource.getInstance(graph).Module)); + } + } + + private ImageDescriptor getDecoration(ImageDescriptor original, Severity severity) { + ImageDescriptor img = Activator.getDefault().getImageRegistry().getDescriptor(severity.toString()); + if (original == null || original.getImageData() == null) + return img; + else + return new DecorationOverlayIcon(original, img, IDecoration.BOTTOM_LEFT); + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java index a3ea5059..b379b3ea 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java @@ -19,7 +19,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IWorkbenchPartSite; import org.simantics.db.ReadGraph; import org.simantics.db.Session; -import org.simantics.diagram.handler.CopyPasteHandler; import org.simantics.diagram.handler.DeleteHandler; import org.simantics.diagram.synchronization.IModifiableSynchronizationContext; import org.simantics.diagram.synchronization.SynchronizationHints; @@ -72,27 +71,6 @@ public class DiagramViewer extends org.simantics.modeling.ui.diagramEditor.Diagr @Override public void createPartControl(Composite parent) { super.createPartControl(parent); - - - ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() { - - @Override - public void run() { - if (isDisposed()) { - return; - } else { - if(canvasContext != null && sourceDiagram != null) { - ElementPainter ep = canvasContext.getSingleItem(ElementPainter.class); - for(IElement e : sourceDiagram.getElements()) { - if(e.getElementClass().getId().contains("Connection")){ - ep.update(e); - } - } - } - //scheduleZoomToFit(); - } - } - }); } @Override @@ -135,8 +113,27 @@ public class DiagramViewer extends org.simantics.modeling.ui.diagramEditor.Diagr @Override protected void onCreated() { - sourceDiagram.setHint(DiagramHints.KEY_ALLOW_ROUTE_POINTS, Boolean.FALSE); - sourceDiagram.setHint(SynchronizationHints.COPY_ADVISOR, new MappedElementCopyAdvisor(new ElementCopyAdvisor(), new SysdynComponentCopyAdvisor())); + sourceDiagram.setHint(DiagramHints.KEY_ALLOW_ROUTE_POINTS, Boolean.FALSE); + sourceDiagram.setHint(SynchronizationHints.COPY_ADVISOR, new MappedElementCopyAdvisor(new ElementCopyAdvisor(), new SysdynComponentCopyAdvisor())); + + ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() { + + @Override + public void run() { + if (isDisposed()) { + return; + } else { + if(canvasContext != null && sourceDiagram != null) { + ElementPainter ep = canvasContext.getSingleItem(ElementPainter.class); + for(IElement e : sourceDiagram.getElements()) { + if(e.getElementClass().getId().contains("Connection")){ + ep.update(e); + } + } + } + } + } + }); } @Override -- 2.47.1