X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FcomponentTypeEditor%2FDerivedPropertiesSection.java;h=23777604d35e43e6d221a60f7b2908e01566f777;hp=0f7bff3969dbf649e2a4740de2c586312a80a0a2;hb=0475b9e2a9331ef8f3dcd61567e5d071ae8ef561;hpb=e6e555f4c17e686c44d0681a01eab17d0ec6f2aa diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/DerivedPropertiesSection.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/DerivedPropertiesSection.java index 0f7bff396..23777604d 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/DerivedPropertiesSection.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/DerivedPropertiesSection.java @@ -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; @@ -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: @@ -330,12 +334,7 @@ public class DerivedPropertiesSection implements ComponentTypeViewerSection { 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; - } - }; + CompileSCLMonitorRequest compileSCLMonitorRequest = new ValidationCompilationRequest(graph, context, expression); Function1 exp = graph.syncRequest(compileSCLMonitorRequest); sclContext.put("graph", graph); //return exp.apply(context.getParent(graph)); @@ -380,6 +379,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 +390,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(); @@ -422,4 +447,29 @@ public class DerivedPropertiesSection implements ComponentTypeViewerSection { return 100.0; } + private static final class ValidationCompilationRequest extends CompileSCLMonitorRequest { + private final String expression; + + private ValidationCompilationRequest(ReadGraph graph, Variable context, String expression) + throws DatabaseException { + super(graph, context); + this.expression = expression; + } + + @Override + protected String getExpressionText(ReadGraph graph) throws DatabaseException { + return expression; + } + + @Override + public int hashCode() { + return super.hashCode() + 37 * expression.hashCode(); + } + + @Override + public boolean equals(Object obj) { + return super.equals(obj) && ((ValidationCompilationRequest)obj).expression.equals(expression); + } + } + } \ No newline at end of file