From: lempinen Date: Thu, 6 Oct 2011 10:17:56 +0000 (+0000) Subject: Drafts for both polarities in dependencies and issue view X-Git-Tag: simantics-1.5~18 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=9746e3e0da7d6ca5a9c101f442509eaee6a209aa;p=simantics%2Fsysdyn.git Drafts for both polarities in dependencies and issue view git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@22551 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/META-INF/MANIFEST.MF b/org.simantics.sysdyn.ontology/META-INF/MANIFEST.MF index d9f12151..08acfa9f 100644 --- a/org.simantics.sysdyn.ontology/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn.ontology/META-INF/MANIFEST.MF @@ -10,7 +10,8 @@ Require-Bundle: org.simantics.layer0, org.simantics.g2d.ontology;bundle-version="1.0.0", org.simantics.project.ontology;bundle-version="1.0.0", org.simantics.viewpoint.ontology;bundle-version="1.0.0", - org.simantics.layer0x.ontology;bundle-version="1.0.0" + org.simantics.layer0x.ontology;bundle-version="1.0.0", + org.simantics.issues.ontology;bundle-version="1.1.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Export-Package: org.simantics.sysdyn Bundle-Vendor: VTT Technical Reserarch Centre of Finland diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 601e29b7..bb64744d 100644 Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/org.simantics.sysdyn.ontology/graph/GeneralSymbols.pgraph b/org.simantics.sysdyn.ontology/graph/GeneralSymbols.pgraph new file mode 100644 index 00000000..3a55dd73 --- /dev/null +++ b/org.simantics.sysdyn.ontology/graph/GeneralSymbols.pgraph @@ -0,0 +1,14 @@ +L0 = +G2D = +DIA = +SYSDYN = + +GENERAL = SYSDYN.SymbolReferences.GeneralSymbols : DIA.SymbolReferenceLibrary + L0.HasDescription "General graphical components" + +SYSDYN.AdditionalSymbols : L0.Library + +SYSDYN.AdditionalSymbols.Text """ : L0.String diff --git a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph index 84c4f19c..5be5fa7c 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph @@ -65,6 +65,7 @@ SYSDYN.ConfigurationDiagram +ISSUE = +SYSDYN = + +VALIDATIONS = SYSDYN.Validations : L0.Library + +SYSDYN.SysdynIssue - none 0 fill 1 + none 0 fill 1 \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 16bcbc7a..f6fb712b 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -167,6 +167,12 @@ relationship="stack" relative="org.simantics.sysdyn.ui.trend.view"> + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyConnectionFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyConnectionFactory.java index 9ef4fa9f..e7bb25f4 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyConnectionFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyConnectionFactory.java @@ -30,6 +30,8 @@ import org.simantics.g2d.element.ElementClass; import org.simantics.g2d.element.IElement; import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.editor.routing.DependencyRouter; import org.simantics.utils.datastructures.Pair; @@ -79,8 +81,10 @@ public class DependencyConnectionFactory extends ElementFactoryAdapter { ready.incrementAndGet(); Layer0 l0; + ModelingResources mr; try { l0 = Layer0.getInstance(graph.getSession()); + mr = ModelingResources.getInstance(graph.getSession()); } catch (DatabaseException e) { e.printStackTrace(); return; @@ -154,6 +158,48 @@ public class DependencyConnectionFactory extends ElementFactoryAdapter { }); + +// graph.forPossibleObject(elementResource, mr.DiagramConnectionToConnection, new AsyncProcedure() { +// +// @Override +// public void execute(AsyncReadGraph graph, Resource result) { +// SysdynResource sr; +// try { +// sr = SysdynResource.getInstance(graph.getSession()); +// } catch (DatabaseException e) { +// e.printStackTrace(); +// return; +// } +// graph.forPossibleRelatedValue(result, sr.Polarity, Bindings.STRING, new AsyncProcedure() { +// +// @Override +// public void exception(AsyncReadGraph graph, Throwable throwable) { +// throwable.printStackTrace(); +// } +// +// @Override +// public void execute(AsyncReadGraph graph, String name) { +// +// properties.put("polarity", Pair.make(property, (Object)name)); +//// System.out.println("load properties " + name + " => " + value); +// if(ready.decrementAndGet() == 0) { +// element.setHint(DiagramHints.PROPERTIES, new HashMap>(properties)); +// procedure.execute(graph, element); +// } +// +// } +// +// }); +// +// } +// +// @Override +// public void exception(AsyncReadGraph graph, Throwable throwable) { +// throwable.printStackTrace(); +// } +// +// }); + } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyEdgeClass.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyEdgeClass.java index 284a7bd4..e527e0a4 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyEdgeClass.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyEdgeClass.java @@ -13,12 +13,14 @@ package org.simantics.sysdyn.ui.elements2.connections; import java.awt.BasicStroke; import java.awt.Color; +import java.awt.Font; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Path2D; import java.awt.geom.Rectangle2D; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.util.HashMap; import java.util.Map; import org.simantics.db.Resource; @@ -30,6 +32,7 @@ import org.simantics.g2d.diagram.handler.PickRequest.PickPolicy; import org.simantics.g2d.diagram.handler.Topology; import org.simantics.g2d.diagram.handler.Topology.Connection; import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementHints; import org.simantics.g2d.element.ElementUtils; import org.simantics.g2d.element.IElement; import org.simantics.g2d.element.SceneGraphNodeKey; @@ -44,8 +47,12 @@ import org.simantics.g2d.element.handler.impl.ConnectionSelectionOutline; import org.simantics.g2d.element.handler.impl.FillColorImpl; import org.simantics.g2d.element.handler.impl.ParentImpl; import org.simantics.g2d.element.handler.impl.SimpleElementLayers; +import org.simantics.g2d.element.handler.impl.TextColorImpl; +import org.simantics.g2d.element.handler.impl.TextFontImpl; +import org.simantics.g2d.element.handler.impl.TextImpl; import org.simantics.g2d.elementclass.connection.EdgeClass.EdgeHandler; import org.simantics.g2d.elementclass.connection.EdgeClass.FixedTransform; +import org.simantics.g2d.utils.Alignment; import org.simantics.scenegraph.g2d.G2DParentNode; import org.simantics.scenegraph.utils.NodeUtil; import org.simantics.sysdyn.ui.editor.routing.DependencyRouter; @@ -87,6 +94,9 @@ public class DependencyEdgeClass { ConfigurableEdgeVisuals.DEFAULT, FillColorImpl.BLACK, FixedTransform.INSTANCE, + TextImpl.INSTANCE, + TextColorImpl.BLACK, + TextFontImpl.DEFAULT, new NodePick(), ConnectionSelectionOutline.INSTANCE, SimpleElementLayers.INSTANCE, @@ -102,11 +112,18 @@ public class DependencyEdgeClass { public static final Stroke ARROW_STROKE = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); public static final Key KEY_SG_NODE = new SceneGraphNodeKey(DependencyNode.class, "EDGE_NODE"); - + @Override public void init(IElement e, G2DParentNode parent) { DependencyNode node = ElementUtils.getOrCreateNode(e, parent, KEY_SG_NODE, "edge_" + e.hashCode(), DependencyNode.class); - node.setAngle(0.1); + + Font font = ElementUtils.getTextFont(e); + Color color = ElementUtils.getTextColor(e); + + HashMap properties = e.getHint(DiagramHints.PROPERTIES); + Pair polarityPair = (Pair)properties.get("Polarity"); + if(polarityPair != null) + node.init((String) polarityPair.second, font, color, 0, 0, 0.235); update(e); } @@ -146,9 +163,7 @@ public class DependencyEdgeClass { }); - EdgeVisuals vh = e.getElementClass().getSingleItem(EdgeVisuals.class); - Stroke stroke = vh.getStroke(e); - Color c = ElementUtils.getFillColor(e, Color.BLACK); + Shape beginTerminalShape = null; Shape endTerminalShape = null; @@ -164,10 +179,26 @@ public class DependencyEdgeClass { if(beginTerminalShape == null || endTerminalShape == null) return; + EdgeVisuals vh = e.getElementClass().getSingleItem(EdgeVisuals.class); + Stroke stroke = vh.getStroke(e); + Font font = ElementUtils.getTextFont(e); + Color color = ElementUtils.getTextColor(e); +// Color fillColor = ElementUtils.getFillColor(e); + Color borderColor = ElementUtils.getBorderColor(e, Color.BLACK); +// String text = ElementUtils.getText(e); + Alignment hAlign = ElementUtils.getHintOrDefault(e, ElementHints.KEY_HORIZONTAL_ALIGN, Alignment.CENTER); + node.setBackgroundColor(null); + node.setBorderColor(borderColor); + node.setHorizontalAlignment((byte) hAlign.ordinal()); + node.setPadding(0, 0); + node.setBorderWidth((float) 0); + node.setEditable(false); + node.setFont(font); + node.setBeginBounds(beginTerminalShape.getBounds2D()); node.setEndBounds(endTerminalShape.getBounds2D()); node.setStroke(stroke); - node.setColor(c); + node.setColor(color); node.setShapes(DependencyRouter.createArrowShape(node.getShapes(), node.getBeginBounds(), node.getEndBounds(), node.getAngle())); Map> properties = e.getHint(DiagramHints.PROPERTIES); @@ -207,5 +238,5 @@ public class DependencyEdgeClass { } } - + } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyNode.java index 04fc95bb..780d8f1a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyNode.java @@ -20,18 +20,19 @@ import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.geom.Arc2D; import java.awt.geom.Path2D; +import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import org.simantics.diagram.elements.TextNode; import org.simantics.scenegraph.ISelectionPainterNode; -import org.simantics.scenegraph.g2d.G2DNode; import org.simantics.scenegraph.g2d.events.ISGMouseEvent; import org.simantics.scenegraph.utils.NodeUtil; import org.simantics.sysdyn.ui.editor.routing.DependencyRouter; import org.simantics.utils.datastructures.Pair; -public class DependencyNode extends G2DNode implements ISelectionPainterNode, MouseListener, MouseMotionListener { +public class DependencyNode extends TextNode implements ISelectionPainterNode, MouseListener, MouseMotionListener { private static final long serialVersionUID = 1294351381209071074L; @@ -102,13 +103,13 @@ public class DependencyNode extends G2DNode implements ISelectionPainterNode, Mo public void setAngle(Double angle) { this.angle = angle.doubleValue(); if(this.beginBounds != null && this.endBounds != null) - this.shapes = DependencyRouter.createArrowShape(this.shapes, this.beginBounds, this.endBounds, this.angle); + this.shapes = DependencyRouter.createArrowShape(this.shapes, this.beginBounds, this.endBounds, this.angle); } - + @PropertySetter("shapes") @SyncField("shapes") public void setShapes(Pair shapes) { - this.shapes = shapes; + this.shapes = shapes; } public Color getColor() { @@ -130,13 +131,13 @@ public class DependencyNode extends G2DNode implements ISelectionPainterNode, Mo public double getAngle() { return angle; } - + public Pair getShapes() { return shapes; } - - + + @Override public void render(Graphics2D g) { if(beginBounds == null || endBounds == null) return; @@ -170,6 +171,26 @@ public class DependencyNode extends G2DNode implements ISelectionPainterNode, Mo g.fill(shapes.second); } + + double angleRad = angle > 0 ? + Math.toRadians(shapes.first.getAngleStart() + shapes.first.getAngleExtent()) : + Math.toRadians(shapes.first.getAngleStart()); + Point2D point = angle > 0 ? shapes.first.getEndPoint() : shapes.first.getStartPoint(); + + double a = Math.toRadians(angle < 0 ? 255 : -75); + double s = Math.sin(a) * 2; + double c = Math.cos(a) * 3; + + g.translate(point.getX(), point.getY()); + g.rotate(-angleRad); + g.translate(s, c); + g.rotate(angleRad); + super.render(g); + g.rotate(-angleRad); + g.translate(-s, -c); + g.rotate(angleRad); + g.translate(-point.getX(), -point.getY()); + } boolean pressHit = false; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java index a4c3175d..f073d5d8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java @@ -12,8 +12,9 @@ package org.simantics.sysdyn.ui.project; import java.io.File; +import java.util.Collection; import java.util.HashMap; -import java.util.UUID; +import java.util.Map; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.preferences.IEclipsePreferences; @@ -21,54 +22,45 @@ import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PartInitException; import org.osgi.service.prefs.BackingStoreException; -import org.simantics.databoard.Bindings; import org.simantics.databoard.accessor.Accessor; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.WriteGraph; +import org.simantics.db.common.procedure.single.SingleSetSyncListener; import org.simantics.db.common.request.Queries; import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.IssueSource; import org.simantics.db.layer0.adapter.RuntimeValuations; -import org.simantics.db.layer0.adapter.Template; import org.simantics.db.layer0.adapter.TrendVariable; import org.simantics.db.layer0.service.ActivationManager; +import org.simantics.db.procedure.AsyncListener; import org.simantics.db.request.Read; import org.simantics.db.service.GraphChangeListenerSupport; import org.simantics.db.service.LifecycleSupport; import org.simantics.db.service.VirtualGraphSupport; -import org.simantics.document.DocumentResource; import org.simantics.layer0.Layer0; -import org.simantics.layer0.utils.direct.GraphUtils; -import org.simantics.modeling.ModelingResources; -import org.simantics.modeling.ModelingUtils; import org.simantics.modeling.services.CaseInsensitiveComponentNamingStrategy2; import org.simantics.modeling.services.ComponentNamingStrategy; -import org.simantics.operation.Layer0X; import org.simantics.project.IProject; import org.simantics.project.ProjectElementType; import org.simantics.project.ProjectElements; import org.simantics.project.ProjectKeys; import org.simantics.project.exception.ProjectException; import org.simantics.project.features.AbstractProjectFeature; -import org.simantics.project.ontology.ProjectResource; import org.simantics.simulation.experiment.IExperiment; import org.simantics.simulation.ontology.SimulationResource; import org.simantics.simulation.project.IExperimentManager; -import org.simantics.spreadsheet.resource.SpreadsheetResource; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.Activator; import org.simantics.sysdyn.ui.editor.SysdynEditorNamingService; -import org.simantics.sysdyn.ui.utils.SheetUtils; -import org.simantics.ui.SimanticsUI; +import org.simantics.sysdyn.ui.validation.ActiveIssueSources; import org.simantics.ui.workbench.IEditorNamingService; import org.simantics.ui.workbench.action.ChooseActionRequest; import org.simantics.ui.workbench.project.UIModelManager; import org.simantics.ui.workbench.project.UIModelManagerBase; -import org.simantics.ui.workbench.project.UIModelManagerBase.WriteRunnable; -import org.simantics.utils.datastructures.ArrayMap; import org.simantics.utils.datastructures.Callback; import org.simantics.utils.ui.ErrorLogger; import org.simantics.utils.ui.workbench.WorkbenchUtils; @@ -84,7 +76,8 @@ public class SysdynProject extends AbstractProjectFeature { Callback callback, Callback errorCallback) { if (ProjectElements.MODEL.equals(kind)) { - request(session, container, callback, errorCallback, CREATE_MODEL); + //FIXME: Should not be needed anymore +// request(session, container, callback, errorCallback, CREATE_MODEL); return; } @@ -108,92 +101,7 @@ public class SysdynProject extends AbstractProjectFeature { } } - private final WriteRunnable CREATE_MODEL = new WriteRunnable() { - - @Override - public void run(WriteGraph g, Resource library, Callback callback, Callback errorCallback) { - try { - Layer0 l0 = Layer0.getInstance(g); - Layer0X L0X = Layer0X.getInstance(g); - SysdynResource sr = SysdynResource.getInstance(g); - SpreadsheetResource SHEET = SpreadsheetResource.getInstance(g); - ModelingUtils mu = new ModelingUtils(g); - DocumentResource DOC = DocumentResource.getInstance(g); - - String modelName = NameUtils.findFreshName(g, "Model", SimanticsUI.getProject().get(), l0.ConsistsOf, "%s%d"); - - Resource model = g.newResource(); - g.claimLiteral(model, l0.HasName, modelName); - g.claimLiteral(model, l0.HasLabel, modelName); - g.claim(model, l0.InstanceOf, sr.SysdynModel); - g.claim(model, l0.PartOf, SimanticsUI.getProject().get()); - - Resource conf = GraphUtils.create2(g, - sr.Configuration, - l0.PartOf, model, - L0X.IsBaseRealizationOf, model, - l0.HasName, modelName - ); - - Resource diagram = g.newResource(); - g.adapt(sr.ConfigurationDiagramTemplate, Template.class).apply(g, - ArrayMap - .keys("", "diagram", "name") - .values(conf, diagram, "Diagrammi") - ); - - g.claim(model, mu.SIMU.HasConfiguration, conf); - - Resource book = g.newResource(); - g.claim(book, l0.InstanceOf, null, SHEET.Book); - g.addLiteral(book, l0.HasName, l0.NameOf, l0.String, "Book" + UUID.randomUUID().toString(), Bindings.STRING); - g.claim(conf, l0.ConsistsOf, l0.PartOf, book); - - SheetUtils.createSheet(g, book, "Sheet1", new String[] { }, new int[] { 50 }); - - - - ModelingResources mr = ModelingResources.getInstance(g); - // Remove default mapping and add sysdyn mapping - for(Resource trigger : g.getObjects(diagram, L0X.HasTrigger)) { - if(g.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) { - g.deny(diagram, L0X.HasTrigger, trigger); - } - } - Resource mapping = g.newResource(); - g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping); - g.claim(diagram, L0X.HasTrigger, mapping); - - Resource report = GraphUtils.create2(g, DOC.Report, DOC.HasDocumentation, "===Report==="); - - GraphUtils.create2(g, mu.SIMU.Experiment, - l0.HasName, "Experiment", - l0.HasLabel, "Experiment", - DOC.HasReportFactory, report, - l0.PartOf, model); - - ProjectResource PROJ = ProjectResource.getInstance(g); - for(Resource dep : g.getObjects(library, l0.IsLinkedTo)) { - if(g.isInstanceOf(dep, PROJ.NamespaceRequirement)) { - for(Resource req : g.getObjects(dep, PROJ.RequiresNamespace)) { - String uri = g.getPossibleValue(req, Bindings.STRING); - if(uri != null) { - Resource target = g.getResource(uri); - if(target != null) { - g.claim(model, l0.IsLinkedTo, null, target); - } - } - } - } - } - - - callback.run(model); - } catch(Exception e) { - errorCallback.run(e); - } - } - }; + ModelManager mm; @@ -287,6 +195,79 @@ public class SysdynProject extends AbstractProjectFeature { ErrorLogger.defaultLogError(e); } } + + + // Issues + + try { + + session.syncRequest(new ActiveIssueSources(project.get()), new SingleSetSyncListener() { + + Map sources = new HashMap(); + Map listeners = new HashMap(); + + @Override + public void add(ReadGraph graph, final Resource source) throws DatabaseException { + final IssueSource is = graph.adapt(source, IssueSource.class); + if(is != null) { + + Runnable listener = new Runnable() { + + @Override + public void run() { + + project.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + is.update(graph); + } + + }); + + } + + }; + + is.addDirtyListener(listener); + sources.put(source, is); + listeners.put(source, listener); + + } else { + + System.err.println("Issue source " + source + " does not have adapter!"); + + } + + } + + @Override + public void remove(ReadGraph graph, final Resource source) throws DatabaseException { + + IssueSource is = sources.get(source); + Runnable listener = listeners.get(source); + if(is != null && listener != null) { + is.removeDirtyListener(listener); + } + sources.remove(source); + + } + + @Override + public void exception(ReadGraph graph, Throwable t) { + Logger.defaultLogError(t); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java index 1119f941..6b72b35c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java @@ -21,7 +21,7 @@ import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; import org.simantics.browsing.ui.swt.widgets.TrackedText; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.db.management.ISessionContext; -import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; public class DependencyTab extends LabelPropertyTabContributor { @@ -31,8 +31,8 @@ public class DependencyTab extends LabelPropertyTabContributor { GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(6).applyTo(composite); TrackedText nameText = new TrackedText(composite, support, SWT.BORDER); - nameText.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasName)); - nameText.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasName)); + nameText.setTextFactory(new StringPropertyFactory(SysdynResource.URIs.Polarity)); + nameText.addModifyListener(new StringPropertyModifier(context, SysdynResource.URIs.Polarity)); GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText.getWidget()); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java index 79af5b12..058d265a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java @@ -226,13 +226,15 @@ public class ResourceSelectionProcessor implements SelectionProcessor> { + + Resource project; + + public ActiveIssueSources(Resource project) { + super(project); + this.project = project; + } + + @Override + public Set perform(ReadGraph graph) throws DatabaseException { + + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Layer0X l0X = Layer0X.getInstance(graph); + IssueResource ISSUE = IssueResource.getInstance(graph); + + HashSet result = new HashSet(); + + for(Resource model : graph.syncRequest(new ObjectsWithType(project, l0.ConsistsOf, sr.SysdynModel))) { + result.addAll(graph.syncRequest(new ObjectsWithType(model, l0X.Activates, ISSUE.IssueSource))); + } + + return result; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyIssueSource.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyIssueSource.java new file mode 100644 index 00000000..a72218c5 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyIssueSource.java @@ -0,0 +1,79 @@ +package org.simantics.sysdyn.ui.validation; + +import java.util.concurrent.CopyOnWriteArraySet; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.changeset.GenericChangeListener; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.IssueSource; +import org.simantics.db.layer0.genericrelation.DependenciesRelation.DependencyChangesRequest; +import org.simantics.db.layer0.genericrelation.DependencyChanges; +import org.simantics.db.layer0.util.Simantics; +import org.simantics.db.service.GraphChangeListenerSupport; +import org.simantics.issues.common.IssueSourceUtils; +import org.simantics.operation.Layer0X; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; + +public class DependencyIssueSource implements IssueSource { + + private Resource source; + private Resource model; + private Resource baseRealization; + + private CopyOnWriteArraySet listeners = new CopyOnWriteArraySet(); + private boolean tracking = false; + + public DependencyIssueSource(ReadGraph graph, Resource source) throws DatabaseException { + Layer0X L0X = Layer0X.getInstance(graph); + this.source = source; + this.model = graph.getSingleObject(source, L0X.IsActivatedBy); + this.baseRealization = graph.getSingleObject(model, L0X.HasBaseRealization); + } + + @Override + public void addDirtyListener(Runnable runnable) { + + boolean added = listeners.add(runnable); + if(added && !tracking) { + + GraphChangeListenerSupport changeSupport = Simantics.getSession().getService(GraphChangeListenerSupport.class); + changeSupport.addMetadataListener(new GenericChangeListener() { + + @Override + public void onEvent(ReadGraph graph, DependencyChanges event) throws DatabaseException { + if(IssueSourceUtils.hasChanges(graph, event, model, baseRealization)) { + for(Runnable r : listeners) { + r.run(); + } + } + + } + + }); + + } + + } + + @Override + public void removeDirtyListener(Runnable runnable) { + listeners.remove(runnable); + } + + @Override + public void update(WriteGraph graph) throws DatabaseException { + + SysdynResource sr = SysdynResource.getInstance(graph); + + for(Resource unit : IssueSourceUtils.getChangedDependencies(graph, source, model, baseRealization, sr.Variable)) { + if(!graph.syncRequest(new DependencyValidator(unit, model))) new DependencySynchronizer(unit, model).perform(graph); + } + + IssueSourceUtils.claimUpdated(graph, source); + + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyIssues.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyIssues.java new file mode 100644 index 00000000..3ed195ab --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyIssues.java @@ -0,0 +1,30 @@ +package org.simantics.sysdyn.ui.validation; + +import java.util.HashSet; +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.issues.common.AllVisibleIssues; +import org.simantics.issues.ontology.IssueResource; + +public class DependencyIssues extends ResourceRead>{ + + public DependencyIssues(Resource resource) { + super(resource); + } + + @Override + public Set perform(ReadGraph graph) throws DatabaseException { + IssueResource ISSUE = IssueResource.getInstance(graph); + HashSet result = new HashSet(); + for (Resource issue : graph.syncRequest(new AllVisibleIssues(resource))) { + if (ISSUE.Severity_Error.equals(graph.getPossibleObject(issue, ISSUE.HasSeverity))) + result.add(issue); + } + return result; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencySynchronizer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencySynchronizer.java new file mode 100644 index 00000000..84be096b --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencySynchronizer.java @@ -0,0 +1,111 @@ +package org.simantics.sysdyn.ui.validation; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.issues.ontology.IssueResource; +import org.simantics.layer0.Layer0; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.utils.datastructures.Pair; + +public class DependencySynchronizer extends WriteRequest { + public static final boolean DEBUG = true; + + final private Resource unit; + final private Resource model; + + public DependencySynchronizer(Resource unit, Resource model) { + this.unit = unit; + this.model = model; + } + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + + StructuralResource2 sr = StructuralResource2.getInstance(graph); + IssueResource ISSUE = IssueResource.getInstance(graph); + + if(DEBUG) System.out.println("Running DependencySynchronizer for " + unit); + + Set set = graph.syncRequest(new DependencyIssues(model)); + + if(DEBUG) System.out.println(set.size() + " issues"); + + /* + Collection removed = new HashSet(); + + boolean unitExists = graph.hasStatement(unit); + if(unitExists) { + + removed.addAll(map.values()); + + for(Resource predicate : graph.getPredicates(unit)) { + if(graph.isSubrelationOf(predicate, FB.Parameter)) { + boolean hasIssue = false; + Resource literal = graph.getPossibleObject(unit, predicate); + Boolean required = graph.getPossibleRelatedValue(literal, FB.IsRequired, Bindings.BOOLEAN); + if(required != null && required && !DependencyValidator.excluded(graph, unit)) { + Boolean def = graph.getPossibleRelatedValue(literal, FB.IsDefault, Bindings.BOOLEAN); + if(def != null && def) { + hasIssue = true; + } + } + Resource issue = map.get(Pair.make(unit, predicate)); + if(hasIssue != (issue != null)) { + + if(hasIssue) { + + issue = graph.newResource(); + graph.claim(issue, L0.InstanceOf, null, FB.ParameterIssue); + graph.claim(issue, ISSUE.HasIssueContext, null, unit); + graph.claim(issue, ISSUE.HasIssueContext, null, predicate); + graph.claim(issue, ISSUE.HasSeverity, ISSUE.Severity_Error); + graph.claimValue(issue, L0.HasDescription, "= Missing connection =", Bindings.STRING); + graph.claimValue(issue, L0.HasName, UUID.randomUUID().toString(), Bindings.STRING); + DateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); + String created = format.format(Calendar.getInstance().getTime()); + graph.claimValue(issue, ISSUE.HasCreationTime, created, Bindings.STRING); + graph.claim(model, L0.ConsistsOf, issue); + + } else { + + graph.deny(issue, L0.PartOf); + + } + + } + + } + } + + } else { + + for(Map.Entry, Resource> entry : map.entrySet()) { +// System.err.println("entry " + entry.getKey()); + if(entry.getKey().first.equals(unit)) { + graph.deny(entry.getValue(), L0.PartOf); + } + if(entry.getKey().first == null) { + graph.deny(entry.getValue(), L0.PartOf); + } + } + + } +*/ + + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyValidator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyValidator.java new file mode 100644 index 00000000..ffac712a --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyValidator.java @@ -0,0 +1,69 @@ +package org.simantics.sysdyn.ui.validation; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ResourceRead2; +import org.simantics.db.exception.DatabaseException; +import org.simantics.issues.common.impl.DependencyIssue; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.utils.datastructures.Pair; + +public class DependencyValidator extends ResourceRead2 { + + public static final boolean DEBUG = true; + + public DependencyValidator(Resource resource, Resource resource2) { + super(resource, resource2); + } + + static boolean excluded(ReadGraph graph, Resource component) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + return !graph.isInstanceOf(component, sr.Variable); + } + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + + if(DEBUG) System.out.println("Running DependencyValidator for " + resource); + + //if(!graph.hasStatement(resource, L0.Represents)) return false; + + if(!graph.hasStatement(resource)) return false; + + Set resources = graph.syncRequest(new DependencyIssues(resource2)); + if(DEBUG) System.out.println(resources.size() + " resources"); + + /* + Set resources = graph.syncRequest(new DependencyIssues(resource2)); + HashMap, Resource> existing = new HashMap, Resource>(existing_); + + for(Resource predicate : graph.getPredicates(resource)) { + if(graph.isSubrelationOf(predicate, FB.Parameter)) { + boolean hasIssue = false; + Resource literal = graph.getPossibleObject(resource, predicate); + Boolean required = graph.getPossibleRelatedValue(literal, FB.IsRequired, Bindings.BOOLEAN); + if(required != null && required && !excluded(graph, resource)) { + Boolean def = graph.getPossibleRelatedValue(literal, FB.IsDefault, Bindings.BOOLEAN); + if(def != null && def) { + hasIssue = true; + return false; + } + } + if(hasIssue != existing.containsKey(Pair.make(resource, predicate))) return false; + } + } + */ + + return true; + + } + +}