X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.nattable%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fnattable%2FNatTableGraphExplorer.java;h=9d12fd9b592f70e44bf842819cee245f2b596beb;hb=d7ce5ab37a70cf207e3bfe0045c0df3f1fb98415;hp=3bb05553dc7456e073d52b44e526688c2beffdc0;hpb=e84008c029ef2336cf55ad371256c9a12a889e98;p=simantics%2Fplatform.git 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 3bb05553d..9d12fd9b5 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 @@ -26,7 +26,6 @@ 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; @@ -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; @@ -198,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; @@ -580,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); } } } @@ -993,11 +993,15 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap // we have to remove all references here to reduce memory consumption. // // Proper fix would be to remove references between QueryCache and GENodeQueryManagers. + + // Clearing explorerContext replaces GECache with dummy implementation, which makes node disposal much faster. + explorerContext.close(); if (rootNode != null) { - rootNode.dispose(); + // Using fastDispose bypasses item removal from nodeMap, which is cleared later. + rootNode.fastDispose(); rootNode = null; } - explorerContext.dispose(); + explorerContext.dispose(); explorerContext = null; processors.clear(); detachPrimitiveProcessors(); @@ -1026,8 +1030,7 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap } resourceManager.dispose(); resourceManager = null; - - contextToNodeMap.clear(); // should be empty at this point. + contextToNodeMap.clear(); contextToNodeMap = null; if (postSelectionProvider != null) { postSelectionProvider.dispose(); @@ -1313,6 +1316,7 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap // } else { // viewer.refresh(element,true); // } + element.initData(); natTable.redraw(); } @@ -1505,7 +1509,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; } @@ -1858,10 +1862,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); } } @@ -2394,6 +2397,13 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap } }; + public void close() { + cache.dispose(); + cache = new DummyCache(); + scheduleList.clear(); + autoExpanded.clear(); + } + @Override public void dispose() { cache.dispose(); @@ -2605,6 +2615,7 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap final HashMap entries = new HashMap(); final HashMap> treeReferences = new HashMap>(); final HashMap> keyRefs = new HashMap>(); + private TObjectIntHashMap references = new TObjectIntHashMap(); /** * This single instance is used for all get operations from the cache. This @@ -2731,7 +2742,7 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap return references.get(context) > 0; } - private TObjectIntHashMap references = new TObjectIntHashMap(); + @Override public void incRef(NodeContext context) {