X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FGraphExplorerImpl.java;h=df736c1e6dc2603315bea23f47b46a2170a52f55;hb=b825d7a7aff95002f355878ec2767352411b5a43;hp=62b284858cd9893383719e5ec7b89632437335f9;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl.java index 62b284858..df736c1e6 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl.java @@ -31,6 +31,7 @@ import java.util.concurrent.ScheduledExecutorService; 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; @@ -38,7 +39,6 @@ import org.eclipse.core.runtime.AssertionFailedException; 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.action.IStatusLineManager; @@ -113,6 +113,7 @@ import org.simantics.browsing.ui.PrimitiveQueryProcessor; 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; @@ -143,6 +144,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.ImageDecorator; import org.simantics.browsing.ui.content.Imager; import org.simantics.browsing.ui.content.LabelDecorator; @@ -161,13 +163,13 @@ import org.simantics.browsing.ui.swt.internal.Threads; import org.simantics.db.layer0.SelectionHints; import org.simantics.utils.ObjectUtils; import org.simantics.utils.datastructures.BijectionMap; -import org.simantics.utils.datastructures.BinaryFunction; import org.simantics.utils.datastructures.disposable.AbstractDisposable; import org.simantics.utils.datastructures.hints.IHintContext; import org.simantics.utils.threads.IThreadWorkQueue; import org.simantics.utils.threads.SWTThread; import org.simantics.utils.threads.ThreadUtils; import org.simantics.utils.ui.ISelectionUtils; +import org.simantics.utils.ui.SWTUtils; import org.simantics.utils.ui.jface.BasePostSelectionProvider; import org.simantics.utils.ui.widgets.VetoingEventHandler; import org.simantics.utils.ui.workbench.WorkbenchUtils; @@ -544,10 +546,10 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph protected BasePostSelectionProvider selectionProvider = new BasePostSelectionProvider(); protected SelectionDataResolver selectionDataResolver; protected SelectionFilter selectionFilter; - protected BinaryFunction selectionTransformation = new BinaryFunction() { + protected 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); @@ -1812,7 +1814,7 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph } @Override - public void setSelectionTransformation(BinaryFunction f) { + public void setSelectionTransformation(BiFunction f) { this.selectionTransformation = f; } @@ -1882,15 +1884,15 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph }); } } - + private void initializeState() { if (persistor == null) return; + ExplorerStates.scheduleRead(getRoot(), persistor) + .thenAccept(state -> SWTUtils.asyncExec(tree, () -> restoreState(state))); + } - ExplorerState state = persistor.deserialize( - Platform.getStateLocation(Activator.getDefault().getBundle()).toFile(), - getRoot()); - + private void restoreState(ExplorerState state) { // topNodeToSet will be processed by #setData when it encounters a // NodeContext that matches this one. // topNodePath = state.topNodePath; @@ -1901,7 +1903,7 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph if (processor instanceof DefaultIsExpandedProcessor) { DefaultIsExpandedProcessor isExpandedProcessor = (DefaultIsExpandedProcessor)processor; for(NodeContext expanded : state.expandedNodes) { - isExpandedProcessor.setExpanded(expanded, true); + isExpandedProcessor.replaceExpanded(expanded, true); } } } @@ -1946,7 +1948,7 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph } persistor.serialize( - Platform.getStateLocation(Activator.getDefault().getBundle()).toFile(), + ExplorerStates.explorerStateLocation(), getRoot(), new ExplorerState(topNodePath, topNodePathChildIndex, expandedNodes, columnWidths)); } @@ -3168,7 +3170,7 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph } protected Object[] transformSelection(Object[] objects) { - return selectionTransformation.call(this, objects); + return selectionTransformation.apply(this, objects); } protected static Object[] filter(SelectionFilter filter, NodeContext[] contexts) { @@ -3250,13 +3252,16 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph */ private void doSetColumns(Column[] cols, Consumer> callback) { // Attempt to keep previous column widths. - Map prevWidths = new HashMap(); + Map prevWidths = new HashMap<>(); for (TreeColumn column : tree.getColumns()) { - prevWidths.put(column.getText(), column.getWidth()); - column.dispose(); + Column c = (Column) column.getData(); + if (c != null) { + prevWidths.put(c.getKey(), column.getWidth()); + column.dispose(); + } } - HashMap keyToIndex = new HashMap(); + HashMap keyToIndex = new HashMap<>(); for (int i = 0; i < cols.length; ++i) { keyToIndex.put(cols[i].getKey(), i); } @@ -3267,7 +3272,7 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph this.columnImageArray = new Image[cols.length]; this.columnDescOrImageArray = new Object[cols.length]; - Map map = new HashMap(); + Map map = new HashMap<>(); tree.setHeaderVisible(columnsAreVisible); for (Column column : columns) { @@ -3280,7 +3285,7 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph int cw = column.getWidth(); // Try to keep previous widths - Integer w = prevWidths.get(column); + Integer w = prevWidths.get(column.getKey()); if (w != null) c.setWidth(w); else if (cw != Column.DEFAULT_CONTROL_WIDTH) @@ -3305,13 +3310,9 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph if(callback != null) callback.accept(map); // Make sure the explorer fits the columns properly after initialization. - tree.getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - if (tree.isDisposed()) - return; + SWTUtils.asyncExec(tree, () -> { + if (!tree.isDisposed()) refreshColumnSizes(); - } }); }