Red background color & tooltip for invalid derived property expression 55/2955/3
authorJaniSimomaa <JaniSimomaa@mongodb-primary>
Wed, 19 Jun 2019 09:14:42 +0000 (12:14 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 19 Jun 2019 22:43:19 +0000 (22:43 +0000)
gitlab #309

Change-Id: I7a494c50f8cb1566043599cdeca49c51c9cee2eb

bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/DerivedPropertiesSection.java

index 1abe8434897ee8bc3071ff528baf45b41e76bbee..23777604d35e43e6d221a60f7b2908e01566f777 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;
@@ -375,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);
@@ -383,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();