X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.nattable%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fnattable%2FNatTableGraphExplorer.java;h=37eafd4eb5e965e1e1811fc418576e8a37535b21;hp=cc978e7e8b6ce599957ff6fbb859c76ec96a0d96;hb=97e8b055b8ad16f1d799c81898fee075780a5a83;hpb=8cf8163295ffc6b25dfdebc3dc89467c56684da1 diff --git a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java index cc978e7e8..37eafd4eb 100644 --- a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java +++ b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java @@ -19,13 +19,13 @@ 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; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.resource.ColorDescriptor; @@ -89,7 +89,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; @@ -141,6 +140,7 @@ import org.simantics.browsing.ui.PrimitiveQueryUpdater; import org.simantics.browsing.ui.SelectionDataResolver; import org.simantics.browsing.ui.SelectionFilter; import org.simantics.browsing.ui.StatePersistor; +import org.simantics.browsing.ui.common.AdaptableHintContext; import org.simantics.browsing.ui.common.ColumnKeys; import org.simantics.browsing.ui.common.ErrorLogger; import org.simantics.browsing.ui.common.NodeContextBuilder; @@ -171,6 +171,7 @@ import org.simantics.browsing.ui.common.processors.DefaultViewpointProcessor; import org.simantics.browsing.ui.common.processors.IsExpandedProcessor; import org.simantics.browsing.ui.common.processors.NoSelectionRequestProcessor; import org.simantics.browsing.ui.common.processors.ProcessorLifecycle; +import org.simantics.browsing.ui.common.state.ExplorerStates; import org.simantics.browsing.ui.content.Labeler; import org.simantics.browsing.ui.content.Labeler.CustomModifier; import org.simantics.browsing.ui.content.Labeler.DialogModifier; @@ -178,7 +179,6 @@ import org.simantics.browsing.ui.content.Labeler.EnumerationModifier; import org.simantics.browsing.ui.content.Labeler.Modifier; import org.simantics.browsing.ui.nattable.override.DefaultTreeLayerConfiguration2; import org.simantics.browsing.ui.swt.Activator; -import org.simantics.browsing.ui.swt.AdaptableHintContext; import org.simantics.browsing.ui.swt.DefaultImageDecoratorsProcessor; import org.simantics.browsing.ui.swt.DefaultIsExpandedProcessor; import org.simantics.browsing.ui.swt.DefaultLabelDecoratorsProcessor; @@ -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; @@ -199,6 +198,7 @@ import org.simantics.utils.threads.SWTThread; import org.simantics.utils.threads.ThreadUtils; import org.simantics.utils.ui.AdaptionUtils; import org.simantics.utils.ui.ISelectionUtils; +import org.simantics.utils.ui.SWTUtils; import org.simantics.utils.ui.jface.BasePostSelectionProvider; import gnu.trove.map.hash.THashMap; @@ -297,10 +297,10 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap private boolean expand; private boolean verticalBarVisible = false; - private BinaryFunction selectionTransformation = new BinaryFunction() { + private BiFunction selectionTransformation = new BiFunction() { @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); @@ -581,17 +581,16 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap private void initializeState() { if (persistor == null) return; + ExplorerStates.scheduleRead(getRoot(), persistor) + .thenAccept(state -> SWTUtils.asyncExec(natTable, () -> restoreState(state))); + } - ExplorerState state = persistor.deserialize( - Platform.getStateLocation(Activator.getDefault().getBundle()).toFile(), - getRoot()); - - + private void restoreState(ExplorerState state) { Object processor = getPrimitiveProcessor(BuiltinKeys.IS_EXPANDED); if (processor instanceof DefaultIsExpandedProcessor) { DefaultIsExpandedProcessor isExpandedProcessor = (DefaultIsExpandedProcessor)processor; for(NodeContext expanded : state.expandedNodes) { - isExpandedProcessor.setExpanded(expanded, true); + isExpandedProcessor.replaceExpanded(expanded, true); } } } @@ -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 f) { + BiFunction 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; } @@ -1859,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); } }