]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java
Fix column width issues on HiDPI displays. KeyTiSelection fixes.
[simantics/platform.git] / bundles / org.simantics.browsing.ui.nattable / src / org / simantics / browsing / ui / nattable / NatTableGraphExplorer.java
index 5726b51303879cf301b94ad1b3256dfad2938b18..6765f65ead2e0a87877ee52c73f969b452bac0d6 100644 (file)
@@ -19,6 +19,7 @@ import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiFunction;
 import java.util.function.Consumer;
 
 import org.eclipse.core.runtime.Assert;
@@ -89,7 +90,6 @@ import org.eclipse.nebula.widgets.nattable.painter.NatTableBorderOverlayPainter;
 import org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer;
 import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
 import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
-import org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand;
 import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
 import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
 import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
@@ -190,7 +190,6 @@ import org.simantics.browsing.ui.swt.ViewerCellReference;
 import org.simantics.browsing.ui.swt.ViewerRowReference;
 import org.simantics.browsing.ui.swt.internal.Threads;
 import org.simantics.db.layer0.SelectionHints;
-import org.simantics.utils.datastructures.BinaryFunction;
 import org.simantics.utils.datastructures.MapList;
 import org.simantics.utils.datastructures.disposable.AbstractDisposable;
 import org.simantics.utils.datastructures.hints.IHintContext;
@@ -297,10 +296,10 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
     private boolean expand;
     private boolean verticalBarVisible = false;
     
-    private BinaryFunction<Object[], GraphExplorer, Object[]>  selectionTransformation = new BinaryFunction<Object[], GraphExplorer, Object[]>() {
+    private BiFunction<GraphExplorer, Object[], Object[]>  selectionTransformation = new BiFunction<GraphExplorer, Object[], Object[]>() {
 
         @Override
-        public Object[] call(GraphExplorer explorer, Object[] objects) {
+        public Object[] apply(GraphExplorer explorer, Object[] objects) {
             Object[] result = new Object[objects.length];
             for (int i = 0; i < objects.length; i++) {
                 IHintContext context = new AdaptableHintContext(SelectionHints.KEY_MAIN);
@@ -846,7 +845,7 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
     }
     
     protected Object[] transformSelection(Object[] objects) {
-        return selectionTransformation.call(this, objects);
+        return selectionTransformation.apply(this, objects);
     }
     
     protected static Object[] filter(SelectionFilter filter, NodeContext[] contexts) {
@@ -859,7 +858,7 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
 
        @Override
        public void setSelectionTransformation(
-                       BinaryFunction<Object[], GraphExplorer, Object[]> f) {
+                       BiFunction<GraphExplorer, Object[], Object[]> f) {
                this.selectionTransformation = f;
        }
        
@@ -1314,6 +1313,7 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
 //                             } else {
 //                                     viewer.refresh(element,true);
 //                             }
+                               element.initData();
                                natTable.redraw();
                        }
                        
@@ -1506,7 +1506,7 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
     final ExecutorService                        queryUpdateScheduler = Threads.getExecutor();
     
     
-       private double getDisplayScale() {
+    public static double getDisplayScale() {
                Point dpi = Display.getCurrent().getDPI();
                return (double)dpi.x/96.0;
        }
@@ -1517,10 +1517,14 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
                columnAccessor = new GEColumnAccessor(this);
                
                IDataProvider dataProvider = new ListDataProvider<TreeNode>(list, columnAccessor);
-               
-               int defaultFontSize = 12;
-               int height = (int)Math.ceil(((double)(defaultFontSize))*getDisplayScale()) + DataLayer.DEFAULT_ROW_HEIGHT-defaultFontSize;
-               dataLayer = new DataLayer(dataProvider, DataLayer.DEFAULT_COLUMN_WIDTH, height);
+
+//      FIXME: NatTable 1.0 required help to work with custom display scaling (Windows 7 display scaling). 
+//             It seems that NatTable 1.4 breaks with the same code in Windows 7, so now the code is disabled.
+//             More testing with different hardware is required...             
+//             int defaultFontSize = 12;
+//             int height = (int)Math.ceil(((double)(defaultFontSize))*getDisplayScale()) + DataLayer.DEFAULT_ROW_HEIGHT-defaultFontSize;
+//             dataLayer = new DataLayer(dataProvider, DataLayer.DEFAULT_COLUMN_WIDTH, height);
+               dataLayer = new DataLayer(dataProvider);
                
                // resizable rows are unnecessary in Sulca report.
                dataLayer.setRowsResizableByDefault(false);
@@ -1535,7 +1539,7 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
                // Column header layer
                columnHeaderDataProvider = new GEColumnHeaderDataProvider(this, dataLayer); 
                columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
-               columnHeaderDataLayer.setDefaultRowHeight(height);
+               //columnHeaderDataLayer.setDefaultRowHeight(height);
                columnHeaderDataProvider.updateColumnSizes();
                
                //ISortModel sortModel = new EcoSortModel(this, generator,dataLayer);
@@ -1855,10 +1859,9 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
                        if (modifier == null)
                                return false;
                        
-                       String err =  modifier.isValid(newValue.toString());
+                       String err =  modifier.isValid(newValue != null ? newValue.toString() : "");
                        if (err == null)
                                return true;
-                       modifier.isValid(newValue.toString());
                        throw new ValidationFailedException(err);
        }
     }