]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "JsonNode support with Data/Json"
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Fri, 28 Jul 2017 10:00:11 +0000 (13:00 +0300)
committerGerrit Code Review <gerrit2@www.simantics.org>
Fri, 28 Jul 2017 10:00:11 +0000 (13:00 +0300)
25 files changed:
bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/NodeRequest.java
bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerManager.java
bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java
bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/AWTImage.java
bundles/org.simantics.g2d/src/org/simantics/g2d/participant/RulerPainter.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/e4/ImportSVGPNG.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewer.java
bundles/org.simantics.modeling/scl/Simantics/Diagram.scl
bundles/org.simantics.modeling/src/org/simantics/modeling/ComponentTypeScriptRequest.java
bundles/org.simantics.modeling/src/org/simantics/modeling/svg/CreateSVGElement.java
bundles/org.simantics.platform.ui.ontology/graph/PlatformUIViews.pgraph
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/ImageNode.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/RulerNode.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/Environments.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorLog.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorSeverity.java
bundles/org.simantics.scl.runtime/scl/SetUtils.scl [new file with mode: 0644]
bundles/org.simantics.scl.runtime/scl/StandardLibrary.scl
bundles/org.simantics.scl.ui/icons/import_error.png [new file with mode: 0644]
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/Activator.java
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLCompletionProposal.java
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenDeclaration.java
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesView.java
bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java

index a6f2e0a77f4f354c146f98d52e38072a0f1cb7fd..198b4b341114616aa75137b7a719f8162ccaf40d 100644 (file)
@@ -11,6 +11,8 @@
  *******************************************************************************/
 package org.simantics.diagram.adapter;
 
+import java.util.List;
+
 import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.primitiverequest.Adapter;
@@ -20,6 +22,7 @@ import org.simantics.db.procedure.Listener;
 import org.simantics.diagram.synchronization.ErrorHandler;
 import org.simantics.g2d.canvas.ICanvasContext;
 import org.simantics.g2d.diagram.IDiagram;
+import org.simantics.g2d.diagram.handler.SubstituteElementClass;
 import org.simantics.g2d.element.ElementClass;
 import org.simantics.g2d.element.IElement;
 import org.slf4j.Logger;
@@ -110,8 +113,12 @@ public class NodeRequest extends BaseRequest2<Resource, IElement> {
                             }
 
                             @Override
-                            public void execute(AsyncReadGraph graph, final ElementClass clazz) {
-
+                            public void execute(AsyncReadGraph graph, ElementClass mutableClazz) {
+                                List<SubstituteElementClass> substitutes = diagram.getDiagramClass().getItemsByClass(SubstituteElementClass.class);
+                                for (SubstituteElementClass subs : substitutes) {
+                                    mutableClazz = subs.substitute(diagram, mutableClazz);
+                                }
+                                final ElementClass clazz = mutableClazz;
                                 graph.asyncRequest(new SpawnRequest(canvas, clazz, data), new TransientCacheAsyncListener<IElement>() {
 
                                     @Override
index 41947ef993c49bc937b39eedddb0a0cbf3d25460..e92ce1b41da779df96b1d08359241a7b959fa6b1 100644 (file)
@@ -433,8 +433,10 @@ public class GraphLayerManager {
                 graph.forHasStatement(element, gl.getVisible(), element, new AsyncProcedureAdapter<Boolean>() {
                     @Override
                     public void execute(AsyncReadGraph graph, Boolean result) {
-                        synchronized (visible) {
-                            visible.add(l);
+                        if (result) {
+                            synchronized (visible) {
+                                visible.add(l);
+                            }
                         }
                         if (DEBUG_LAYERS)
                             System.out.println("    Visible on layer '" + gl.getName() + "'");
@@ -452,8 +454,10 @@ public class GraphLayerManager {
                 graph.forHasStatement(element, gl.getFocusable(), element, new AsyncProcedureAdapter<Boolean>() {
                     @Override
                     public void execute(AsyncReadGraph graph, Boolean result) {
-                        synchronized (focusable) {
-                            focusable.add(l);
+                        if (result) {
+                            synchronized (focusable) {
+                                focusable.add(l);
+                            }
                         }
                         if (DEBUG_LAYERS)
                             System.out.println("    Focusable on layer '" + gl.getName() + "'");
index d69ef69c69fadec257a3e07e2fc31a600cd5ed15..eb9e33607d5500197cc7c4fd8d0c061036d835c3 100644 (file)
@@ -1012,8 +1012,9 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos
         Shape shape = ElementUtils.getElementShapeOrBounds(e);
         Rectangle2D bounds = shape.getBounds2D();
         //System.out.println("selection bounds: "+bounds);
-        final double margin = 1;
-        bounds.setFrame(bounds.getMinX() - margin, bounds.getMinY() - margin, bounds.getWidth() + 2*margin, bounds.getHeight() + 2*margin);
+        final double marginX = 1 / selectionTransform.getScaleX();
+        final double marginY = 1 / selectionTransform.getScaleY();
+        bounds.setFrame(bounds.getMinX() - marginX, bounds.getMinY() - marginY, bounds.getWidth() + 2*marginX, bounds.getHeight() + 2*marginY);
 
         List<SelectionSpecification> ss = e.getElementClass().getItemsByClass(SelectionSpecification.class);
         if (!ss.isEmpty()) {
index e547a663e8e8844024f110485ee85ba81d7ee302..0fbe895be551d6a75650db1decf5f5651ad56db1 100644 (file)
@@ -34,13 +34,19 @@ public class AWTImage extends AbstractImage implements Image {
 
     BufferedImage bi;
     Rectangle2D rect;
+    float alpha;
 
-    public AWTImage(BufferedImage bi) {
+    public AWTImage(BufferedImage bi, float alpha) {
         assert(bi!=null);
         this.bi = bi;
+        this.alpha = alpha;
         rect = new Rectangle2D.Double(bi.getMinX(),bi.getMinY(),bi.getWidth(), bi.getHeight());
     }
 
+    public AWTImage(BufferedImage bi) {
+        this(bi, 1.0f);
+    }
+
     @Override
     public Rectangle2D getBounds() {
         return rect;
@@ -55,6 +61,8 @@ public class AWTImage extends AbstractImage implements Image {
     public Node init(G2DParentNode parent) {
         ImageNode node = parent.getOrCreateNode("image", ImageNode.class);
         node.setImage(bi);
+        node.setAlpha(alpha);
+        node.setZIndex(-100);
         return node;
     }
 
index e4f90791e2123b8fa1c01bf1566ae82de90ac0f7..bffe0c9df4862a160f95ac0e61610dffb1d2a1e1 100644 (file)
@@ -102,17 +102,21 @@ public class RulerPainter extends AbstractCanvasParticipant {
 
     @SGInit
     public void initSG(G2DParentNode parent) {
-        node = parent.addNode("ruler", RulerNode.class);
+        node = parent.addNode("ruler", getNodeClass());
         node.setZIndex(PAINT_PRIORITY);
         updateNode();
     }
 
+    protected Class<? extends RulerNode> getNodeClass() {
+        return RulerNode.class;
+    }
+
     @SGCleanup
     public void cleanupSG() {
         node.remove();
     }
 
-    void updateNode() {
+    protected void updateNode() {
         node.setEnabled(isPaintingEnabled());
         node.setGridSize(getGridSize());
     }
index 931bfdf3d60d073c0b63c271dbda2c163f060c41..b864c4bcf56b3eff3b9d5a30e7338d5d60645018 100644 (file)
@@ -36,7 +36,12 @@ import org.simantics.db.common.request.IndexRoot;
 import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.request.Read;
+import org.simantics.diagram.synchronization.IModifiableSynchronizationContext;
+import org.simantics.diagram.synchronization.SynchronizationHints;
+import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints;
+import org.simantics.diagram.synchronization.graph.layer.GraphLayerManager;
 import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.g2d.diagram.IDiagram;
 import org.simantics.g2d.participant.MouseUtil;
 import org.simantics.g2d.participant.MouseUtil.MouseInfo;
 import org.simantics.modeling.ModelingResources;
@@ -112,10 +117,12 @@ public class ImportSVGPNG {
         IResourceEditorInput input = (IResourceEditorInput)viewer.getEditorInput();
         Resource composite = input.getResource();
 
-        addSVG(mpos.getX(), mpos.getY(), composite);
+        IDiagram idiagram = viewer.getAdapter(IDiagram.class);
+
+        addSVG(mpos.getX(), mpos.getY(), composite, idiagram);
     }
 
-    public static void addSVG(final double mposX, final double mposY, final Resource composite) {
+    public static void addSVG(final double mposX, final double mposY, final Resource composite, IDiagram idiagram) {
 
         Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
 
@@ -135,9 +142,20 @@ public class ImportSVGPNG {
 
                 @Override
                 public void perform(WriteGraph g) throws DatabaseException {
-                    Commands.get(g, "Simantics/Diagram/createSVGElement")
+                    Object svg = Commands.get(g, "Simantics/Diagram/createSVGElementR")
                             .execute(g, g.syncRequest(new IndexRoot(composite)),
                                      composite, suffix(filename), data, mposX, mposY);
+
+                    if (svg != null && svg instanceof Resource) {
+                        Resource resource = (Resource) svg;
+                        // 7. Put the element on all the currently active layers if possible.
+                        IModifiableSynchronizationContext context = idiagram.getHint(SynchronizationHints.CONTEXT);
+                        GraphLayerManager glm = context.get(GraphSynchronizationHints.GRAPH_LAYER_MANAGER);
+                        if (glm != null) {
+                            glm.removeFromAllLayers(g, resource);
+                            glm.putElementOnVisibleLayers(idiagram, g, resource);
+                        }
+                    }
                 }
 
             });
index b5381917d4b8acd3dd2e03f571b8a334d273e6de..1762dea7f6108d34b0a265731387adc9325cb002 100644 (file)
@@ -727,9 +727,7 @@ public class DiagramViewer
         addKeyBindingParticipants(ctx);
 
         // Grid & Ruler & Background
-        ctx.add(new GridPainter());
-        ctx.add(new RulerPainter());
-        ctx.add(new BackgroundPainter());
+        addGridRulerBackgroundParticipants(ctx);
 
         h.setHint(Hints.KEY_DISPLAY_PAGE, diagramPreferences.get(DiagramPreferences.P_DISPLAY_PAGE_SIZE));
         h.setHint(Hints.KEY_DISPLAY_MARGINS, diagramPreferences.get(DiagramPreferences.P_DISPLAY_MARGINS));
@@ -776,6 +774,12 @@ public class DiagramViewer
         ctx.setLocked(false);
     }
 
+    protected void addGridRulerBackgroundParticipants(CanvasContext ctx) {
+        ctx.add(new GridPainter());
+        ctx.add(new RulerPainter());
+        ctx.add(new BackgroundPainter());
+    }
+
     protected void loadPageSettings(ICanvasContext ctx) {
         DiagramDesc diagramDesc = null;
 
index bf5c589e85f8f2a248d55a71c5244bc1332b2fae..554a25edad081a50f4388688d19820b359440942 100644 (file)
@@ -805,8 +805,10 @@ setTransform element transform = claimRelatedValueWithType element DIA.HasTransf
     
 importJava "org.simantics.modeling.svg.CreateSVGElement" where
     createSVGElement :: Resource -> String -> ByteArray -> Double -> Double -> <WriteGraph> ()
+    createSVGElementR :: Resource -> String -> ByteArray -> Double -> Double -> <WriteGraph> Resource
     
     importSVGElement :: Resource -> File -> Double -> Double -> <WriteGraph> ()
+    importSVGElementR :: Resource -> File -> Double -> Double -> <WriteGraph> Resource
     
 importJava "org.simantics.diagram.synchronization.graph.RemoveElement" where
     removeElement :: Resource -> Resource -> <WriteGraph> ()
index 53b601fa2820ea91c640a42d643daff539ca343d..e5ae639355b1087ff16aa48fdfe095a99f408ad7 100644 (file)
@@ -13,6 +13,7 @@ import org.simantics.db.request.Read;
 import org.simantics.scl.compiler.environment.LocalEnvironment;
 import org.simantics.scl.compiler.environment.specification.EnvironmentSpecification;
 import org.simantics.scl.compiler.errors.CompilationError;
+import org.simantics.scl.compiler.errors.ErrorSeverity;
 import org.simantics.scl.compiler.module.repository.ImportFailure;
 import org.simantics.scl.compiler.module.repository.ImportFailureException;
 import org.simantics.scl.compiler.runtime.RuntimeEnvironment;
@@ -47,7 +48,7 @@ public class ComponentTypeScriptRequest implements Read<ComponentTypeScriptResul
                 // at the very start of the editor
                 List<CompilationError> errors = new ArrayList<CompilationError>();
                 for (ImportFailure failure : cause.failures) {
-                    errors.add(new CompilationError(0, failure.toString()));
+                    errors.add(new CompilationError(0, failure.toString(), ErrorSeverity.IMPORT_ERROR));
                 }
                 return new ComponentTypeScriptResult(errors, null);
             }
index 994d417c99b815ba4c3deae54511777a84e8fc05..1f302a64db4c2b7262339366bdb438123e7b3d11 100644 (file)
@@ -19,6 +19,10 @@ import org.simantics.utils.FileUtils;
 public class CreateSVGElement {
 
     public static void createSVGElement(WriteGraph g, Resource diagram, String suffix, byte[] data, double mposX, double mposY) throws DatabaseException {
+        createSVGElement(g, diagram, suffix, data, mposX, mposY);
+    }
+
+    public static Resource createSVGElementR(WriteGraph g, Resource diagram, String suffix, byte[] data, double mposX, double mposY) throws DatabaseException {
 
         Layer0 L0 = Layer0.getInstance(g);
         DiagramResource DIA = DiagramResource.getInstance(g);
@@ -50,19 +54,22 @@ public class CreateSVGElement {
             throw new DatabaseException("Unknown image format " + suffix);
         OrderedSetUtils.addFirst(g, diagram, element);
         g.claim(diagram, L0.ConsistsOf, element);
-
+        return element;
     }
-    
+
     public static void importSVGElement(WriteGraph graph, Resource diagram, File file, double posX, double posY) throws DatabaseException, IOException {
-        
+        importSVGElementR(graph, diagram, file, posX, posY);
+    }
+
+    public static Resource importSVGElementR(WriteGraph graph, Resource diagram, File file, double posX, double posY) throws DatabaseException, IOException {
         final byte[] data = FileUtils.readFile(file);
-        createSVGElement(graph, diagram, suffix(file.getName()), data, posX, posY);
+        return createSVGElementR(graph, diagram, suffix(file.getName()), data, posX, posY);
     }
-    
+
     private static String suffix(String fileName) {
         int len = fileName.length();
         if(len < 3) return null;
         else return fileName.substring(len-3,len).toLowerCase();
     }
-    
+
 }
index a265df8b136b86e9711d84843e5b8417d3e9cba3..eeab91d816030948d4c98212a87b9dcca30915eb 100644 (file)
@@ -101,7 +101,7 @@ VIEWS.SharedLibraryContribution : SWT.TypedVariableTabContribution
 
 //VIEWS.SharedLibraryContribution2 : SWT.TypedVariableTabContribution
 //    SEL.AbstractVariableTabContribution.HasPriority 1
-//    SEL.AbstractTypedVariableTabContribution.HasType L0.SharedOntology
+//    SEL.AbstractTypedTabContribution.HasType L0.SharedOntology
 //    SWT.TypedVariableTabContribution.HasView SharedLibraries
 //    L0.HasLabel "Shared Libraries"
 
index df35e968ef41501bd537425e97a513759719d747..43cf64eb0a2159f9d1fce6f12b4ed6351dfe6dd3 100644 (file)
@@ -11,6 +11,8 @@
  *******************************************************************************/
 package org.simantics.scenegraph.g2d.nodes;
 
+import java.awt.AlphaComposite;
+import java.awt.Composite;
 import java.awt.Graphics2D;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
@@ -28,6 +30,7 @@ public class ImageNode extends G2DNode {
 
     protected Boolean visible = Boolean.TRUE;
     protected BufferedImage img = null;
+    protected float alpha = 1.0f;
 
     @SyncField("visible")
     public void setVisible(Boolean visible) {
@@ -50,6 +53,10 @@ public class ImageNode extends G2DNode {
         img = src;
     }
 
+    public void setAlpha(float alpha) {
+        this.alpha = Math.max(0.0f, Math.min(alpha, 1.0f));
+    }
+
     @Override
     public void render(Graphics2D g) {
         if (!visible || img == null) return;
@@ -65,8 +72,17 @@ public class ImageNode extends G2DNode {
 //            Rectangle2D b = parent.getBoundsInLocal();
 //            g.drawImage(img, (int)b.getMinX(), (int)b.getMinY(), (int)b.getWidth()+(int)b.getMinX(), (int)b.getHeight()+(int)b.getMinY(), 0, 0, img.getWidth(), img.getHeight(), null);
 //        }
+
+        Composite old = null;
+        if (alpha < 1.0f) {
+            old = g.getComposite();
+            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
+        }
+
         g.drawImage(img, 0, 0, null);
 
+        if (old != null)
+            g.setComposite(old);
         if (ot != null)
             g.setTransform(ot);
     }
index f7e0d1e5c6b5cb05d280b9a5ae514758723b2370..27c1c1fd2bae4c1d2469ea24af1d0259647b152c 100644 (file)
@@ -57,7 +57,7 @@ public class RulerNode extends G2DNode {
     public void render(Graphics2D g) {
         if (!enabled)
             return;
-
+        
         AffineTransform tr = g.getTransform();
         double scaleX = Math.abs(tr.getScaleX());
         double scaleY = Math.abs(tr.getScaleY());
@@ -109,7 +109,9 @@ public class RulerNode extends G2DNode {
         // Vertical ruler
         for(double x = offsetX%stepX-stepX; x < bounds.getMaxX(); x+=stepX) {
             if(x > 20) {
-                String str = formatValue((x-offsetX)/scaleX);
+                double val = (x-offsetX)/scaleX / getTransform().getScaleX();
+                double modifiedValue = modifyHorizontalValue(val);
+                String str = formatValue(modifiedValue);
                 FontMetrics fm = g.getFontMetrics();
                 Rectangle2D r = fm.getStringBounds(str, g);
                 if((x-r.getWidth()/2) > previousText) {
@@ -140,10 +142,9 @@ public class RulerNode extends G2DNode {
         previousText = -100;
         for(double y = offsetY%stepY-stepY; y < bounds.getMaxY(); y+=stepY) {
             if(y > 20) {
-                double val = (y-offsetY)/scaleY;
-                if (MAP_Y_SCALING)
-                    val = Math.toDegrees(Math.atan(Math.sinh(Math.toRadians(val))));
-                String str = formatValue(val);
+                double val = (y-offsetY)/scaleY / getTransform().getScaleY();
+                double modifiedValue = modifyVerticalValue(val);
+                String str = formatValue(modifiedValue);
                 FontMetrics fm = g.getFontMetrics();
                 Rectangle2D r = fm.getStringBounds(str, g);
                 if(y-1+r.getHeight()/2 > previousText) {
@@ -175,6 +176,26 @@ public class RulerNode extends G2DNode {
         g.setTransform(tr);
     }
 
+    /**
+     * A method for subclasses to alter the actual X-value of the ruler 
+     * 
+     * @param value
+     * @return possibly modified X-value 
+     */
+    protected double modifyHorizontalValue(double value) {
+        return value;
+    }
+
+    /**
+     * A method for subclasses to alter the actual Y-value of the ruler 
+     * 
+     * @param value
+     * @return possibly modified Y-value 
+     */
+    protected double modifyVerticalValue(double value) {
+        return value;
+    }
+
     private static final transient int    MAX_DIGITS = 5;
     private static final transient double EPSILON    = 0.01;
     private static final transient double TRIM_THRESHOLD_MAX_VALUE = Math.pow(10, 4);
index fccf2681507466ef7f4c9b6f44dc6aab04f76b04..ff5ee3b2902fa0384258f246776d534dbed0d617 100644 (file)
@@ -61,7 +61,9 @@ import org.simantics.scl.compiler.environment.AmbiguousNameException;
 import org.simantics.scl.compiler.environment.Environment;
 import org.simantics.scl.compiler.environment.EnvironmentFactory;
 import org.simantics.scl.compiler.environment.Environments;
+import org.simantics.scl.compiler.errors.CompilationError;
 import org.simantics.scl.compiler.errors.ErrorLog;
+import org.simantics.scl.compiler.errors.ErrorSeverity;
 import org.simantics.scl.compiler.errors.Locations;
 import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor;
 import org.simantics.scl.compiler.internal.codegen.effects.ThreadLocalVariable;
@@ -179,7 +181,7 @@ public class Elaboration {
             compilationContext.environment = new EnvironmentOfModule(importedEnvironment, module);
         } catch (ImportFailureException e) {
             for(ImportFailure failure : e.failures)
-                errorLog.log(failure.location, failure.toString());
+                errorLog.log(new CompilationError(failure.location, failure.toString(), ErrorSeverity.IMPORT_ERROR));
             return;
         }
         for(ImportDeclaration importAst : importsAst)
@@ -1113,6 +1115,7 @@ public class Elaboration {
             int constructorTag = 0;
             for(Constructor constructor : dataType.constructors) {
                 SCLValue value = new SCLValue(constructor.name);
+                value.definitionLocation = constructor.loc;
                 SCLConstructor sclConstructor = 
                         new SCLConstructor(
                                 constructor.name.name,
index 3be214d2d6bd69f66aa4ae59347adeba2b5cb572..2ce0ced5bd5e46438a93a54b3c7651fab130cba9 100644 (file)
@@ -241,6 +241,8 @@ public class Environments {
             Namespace childNamespace = namespace.getNamespace(prefix.substring(0, p));
             if(childNamespace != null)
                 findValuesForPrefix(childNamespace, prefix.substring(p+1), proc);
+            else
+                namespace.findValuesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, proc);
         }
         else
             namespace.findValuesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, proc);
index 62d5d8c3de021defc1648d90c15f8ad55998440d..0e61a1644ef961bd99b9ae4a770eda46ffadf87e 100644 (file)
@@ -16,7 +16,7 @@ public class ErrorLog {
     
     public void log(CompilationError error) {
         errors.add(error);
-        if(error.severity == ErrorSeverity.ERROR)
+        if(error.severity != ErrorSeverity.WARNING)
                ++errorCount;
     }
     
index 9f65cb3e8662c739d36db66ba175fe8a6c511f58..101e0f9e5cdb04bbcd26f21aea7f3e9a3e33cb02 100644 (file)
@@ -1,6 +1,7 @@
 package org.simantics.scl.compiler.errors;
 
 public enum ErrorSeverity {
-       ERROR,
-       WARNING
+    ERROR,
+    IMPORT_ERROR,
+    WARNING
 }
diff --git a/bundles/org.simantics.scl.runtime/scl/SetUtils.scl b/bundles/org.simantics.scl.runtime/scl/SetUtils.scl
new file mode 100644 (file)
index 0000000..00fa752
--- /dev/null
@@ -0,0 +1,13 @@
+import "Prelude"
+import "Set" as Set
+import "MSet" as MSet
+import "MList" as MList
+
+fromList :: [a] -> Set.T a
+fromList l = runProc (MSet.freeze $ MSet.fromList l)
+
+toList :: Set.T a -> [a]
+toList s = runProc do
+    result = MList.createC (Set.size s)
+    Set.iter (MList.add result) s
+    MList.freeze result
\ No newline at end of file
index 122fcd02b99dc8e943f72c08776c955890e45454..7234b70be861c80806d752140cb575f5453b153c 100644 (file)
@@ -10,6 +10,7 @@ include "Lazy" as Lazy
 include "File" as File
 include "Serialization" as Serialization
 include "Set" as Set
+include "SetUtils" as Set
 //include "Map" as Map
 include "MMap" as MMap
 include "MSet" as MSet
diff --git a/bundles/org.simantics.scl.ui/icons/import_error.png b/bundles/org.simantics.scl.ui/icons/import_error.png
new file mode 100644 (file)
index 0000000..caa1838
Binary files /dev/null and b/bundles/org.simantics.scl.ui/icons/import_error.png differ
index a408e7f30ae3b745fd72ad7f3bd476933cb4ba67..768682fa3ef8a056f0b1fc73e7765a1e1390d034 100644 (file)
@@ -33,6 +33,7 @@ public class Activator extends AbstractUIPlugin {
         reg.put("find", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/find.png") );
         reg.put("disk", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/disk.png") );
         reg.put("error", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/error.png") );
+        reg.put("import_error", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/import_error.png") );
         reg.put("warning", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/warning.png") );
     }
     
index 4c429e7fdda6ced8d40a94b7f77a9467d42f7aa6..11749a4b2b24eef1c717eec74e9129731da58ce6 100644 (file)
@@ -37,8 +37,15 @@ public class SCLCompletionProposal implements ICompletionProposal, ICompletionPr
     private final SCLCompletionType completionType;
     
     public SCLCompletionProposal(SCLValue value, int replacementOffset, String prefix) {
-        this.name = value.getName().name;
-        this.module = value.getName().module;
+        String tempName = value.getName().name;
+        String tempModule = value.getName().module;
+        int p = tempName.lastIndexOf('.');
+        if(p >= 0) {
+            tempModule = tempModule + "." + tempName.substring(0, p);
+            tempName = tempName.substring(p+1);
+        }
+        this.name = tempName;
+        this.module = tempModule;
         this.documentation = value.getDocumentation();
         this.content = name + " :: " + value.getType() + "  (" + module + ")";
         this.replacementOffset = replacementOffset;
index 4b6818ab7b805587bfe6306a9f1154e48ac0e3ad..378840397759e1fbdbdc3714b2c3c930c01fa32b 100644 (file)
@@ -9,6 +9,7 @@ import org.eclipse.swt.widgets.Control;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.PlatformUI;
 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
+import org.simantics.scl.compiler.errors.Locations;
 import org.simantics.scl.compiler.module.InvalidModulePathException;
 import org.simantics.scl.compiler.module.ModuleUtils;
 import org.simantics.scl.compiler.source.ModuleSource;
@@ -106,6 +107,7 @@ public class OpenDeclaration extends AbstractHandler {
             SCLTextEditorEnvironment editorEnvironment = moduleEditor.getSCLTextEditorEnvironment();
             editorEnvironment.updateEnvironment(moduleEditor.getDocument());
             SCLValue value = editorEnvironment.getValue(identifierAtCaret);
+            System.out.println("identifierAtCaret = " + identifierAtCaret + " [" + Locations.beginOf(value.definitionLocation) + ", " + Locations.endOf(value.definitionLocation) + "]");
             if(value != null)
                 OpenSCLDefinition.openDefinition(value);
         }
index b4fd1edd8a1c8fdad594ff86e6a6b610f8b5abcb..3e0cc3120bd8c163c62158b4e5f0661ef8e0d74f 100644 (file)
@@ -90,6 +90,8 @@ public class SCLIssuesView extends ViewPart {
                 SCLIssuesTableEntry entry = (SCLIssuesTableEntry)element;
                 return entry.error.severity == ErrorSeverity.ERROR
                         ? imageRegistry.get("error")
+                        : entry.error.severity == ErrorSeverity.IMPORT_ERROR
+                        ? imageRegistry.get("import_error")
                         : imageRegistry.get("warning");
             }
         });
index 3c1888a0112c2c2f382e82c05915372ce51d440d..6d7daeb3c6ff191f8e04e444240bf99776f699d3 100644 (file)
@@ -5,6 +5,7 @@ import java.util.Map;
 
 import org.eclipse.e4.core.contexts.IEclipseContext;
 import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.commands.MCommand;
 import org.eclipse.e4.ui.model.application.ui.MUIElement;
 import org.eclipse.e4.ui.model.application.ui.advanced.MArea;
 import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
@@ -14,9 +15,12 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
 import org.eclipse.e4.ui.workbench.modeling.EModelService;
 import org.eclipse.e4.ui.workbench.modeling.EPartService;
 import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
+import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;
 import org.simantics.db.Resource;
 import org.simantics.utils.datastructures.ArrayMap;
+import org.simantics.utils.ui.workbench.WorkbenchUtils;
 
 /**
  * @author Tuukka Lehtonen
@@ -166,5 +170,32 @@ public class E4WorkbenchUtils {
             part = partService.createPart(partId);
         return part;
     }
+    
+    public static MCommand getMCommandById(String id) {
+        IEclipseContext context = PlatformUI.getWorkbench().getService(IEclipseContext.class);
+        MApplication application = context.get(MApplication.class);
+        for (MCommand command : application.getCommands()) {
+            if (id.equals(command.getElementId())) {
+                return command;
+            }
+        }
+        return null;
+    }
 
+    @SuppressWarnings("restriction")
+    public static IEditorPart getActiveIEditorPart(MPart mActiveEditorPart) {
+        // TODO: Fix this when we get rid of CompatibilityEditors
+        IEditorPart activeEditor = null;
+        if (mActiveEditorPart != null) {
+            Object editor = mActiveEditorPart.getObject();
+            if (editor instanceof CompatibilityEditor) {
+                CompatibilityEditor compEditor = (CompatibilityEditor) editor;
+                activeEditor = compEditor.getEditor();
+            } else {
+                // TODO: This is not good practice with E4 but an OK fallback for now
+                activeEditor = WorkbenchUtils.getActiveEditor();
+            }
+        }
+        return activeEditor;
+    }
 }