]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/DerivedPropertiesSection.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / componentTypeEditor / DerivedPropertiesSection.java
index 0f7bff3969dbf649e2a4740de2c586312a80a0a2..9ef0b31cd24082a5f5a75aa6aee77db67f066235 100644 (file)
@@ -9,6 +9,8 @@ import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.jface.layout.TableColumnLayout;
 import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.window.DefaultToolTip;
+import org.eclipse.jface.window.ToolTip;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.TableEditor;
 import org.eclipse.swt.events.MouseAdapter;
@@ -16,11 +18,13 @@ import org.eclipse.swt.events.MouseEvent;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.TableItem;
@@ -43,10 +47,10 @@ import org.simantics.db.layer0.variable.StandardGraphPropertyVariable;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.layer0.Layer0;
 import org.simantics.modeling.scl.CompileProceduralSCLMonitorRequest;
-import org.simantics.modeling.scl.CompileSCLMonitorRequest;
 import org.simantics.modeling.userComponent.ComponentTypeCommands;
-import org.simantics.scl.runtime.SCLContext;
-import org.simantics.scl.runtime.function.Function1;
+import org.simantics.modeling.utils.ComponentTypePropertiesResult;
+import org.simantics.modeling.utils.ComponentTypeViewerPropertyInfo;
+import org.simantics.modeling.utils.HeadlessComponentTypePropertiesResultRequest;
 import org.simantics.scl.runtime.function.Function4;
 import org.simantics.structural.stubs.StructuralResource2;
 import org.slf4j.Logger;
@@ -162,7 +166,7 @@ public class DerivedPropertiesSection implements ComponentTypeViewerSection {
                     break;
 
                 case 1:
-                    data.editType(table, editor, propertyInfo, selectedItem, column, false);
+                    data.editType(table, editor, propertyInfo, selectedItem, column, null, false);
                     break;
 
                 case 2:
@@ -306,7 +310,7 @@ public class DerivedPropertiesSection implements ComponentTypeViewerSection {
                             if(graph.isInstanceOf(componentType, STR.ProceduralComponentType)) {
                                 CompileProceduralSCLMonitorRequest.compileAndEvaluate(graph, context);
                             } else {
-                                compileAndEvaluate(graph, context, expression);
+                                HeadlessComponentTypePropertiesResultRequest.compileAndEvaluate(graph, context, expression);
                             }
                             
                         } catch (Exception e) {
@@ -326,28 +330,6 @@ public class DerivedPropertiesSection implements ComponentTypeViewerSection {
         return null;
     }
 
-    public static void compileAndEvaluate(ReadGraph graph, Variable context, String expression) throws DatabaseException {
-        SCLContext sclContext = SCLContext.getCurrent();
-        Object oldGraph = sclContext.get("graph");
-        try {
-            CompileSCLMonitorRequest compileSCLMonitorRequest = new CompileSCLMonitorRequest(graph, context) {
-                @Override
-                protected String getExpressionText(ReadGraph graph) throws DatabaseException {
-                    return expression;
-                }
-            };
-            Function1<Variable,Object> exp = graph.syncRequest(compileSCLMonitorRequest);
-            sclContext.put("graph", graph);
-            //return exp.apply(context.getParent(graph));
-        } catch (DatabaseException e) {
-            throw (DatabaseException)e;
-        } catch (Throwable t) {
-            throw new DatabaseException(t);
-        } finally {
-            sclContext.put("graph", oldGraph);
-        }
-    }
-    
     @Override
     public void update(ComponentTypePropertiesResult result) {
         if (table.isDisposed())
@@ -380,6 +362,9 @@ public class DerivedPropertiesSection implements ComponentTypeViewerSection {
             item.setText(4, info.label);
             item.setText(5, info.description);
 
+            if (info.valid != null)
+                item.setBackground(table.getDisplay().getSystemColor(SWT.COLOR_RED));
+            
             item.setForeground(fg);
 
             item.setData(info);
@@ -388,6 +373,29 @@ public class DerivedPropertiesSection implements ComponentTypeViewerSection {
                 selectedItems.add(item);
         }
         
+        new DefaultToolTip(table, ToolTip.NO_RECREATE, false) {
+
+            @Override
+            protected boolean shouldCreateToolTip(Event event) {
+                TableItem item = table.getItem(new Point(event.x, event.y));
+                if (item != null) {
+                    ComponentTypeViewerPropertyInfo info = (ComponentTypeViewerPropertyInfo) item.getData();
+                    return info.valid != null;
+                }
+                return false;
+            }
+
+            @Override
+            protected String getText(Event event) {
+                TableItem item = table.getItem(new Point(event.x, event.y));
+                if (item != null) {
+                    ComponentTypeViewerPropertyInfo info = (ComponentTypeViewerPropertyInfo) item.getData();
+                    return info.valid.replaceAll("\n", "");
+                }
+                return super.getText(event);
+            }
+        };
+        
         table.setTopIndex(topIndex);
         table.setSelection(selectedItems.toArray(new TableItem[selectedItems.size()]));
         table.redraw();