X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=inline;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FGraphExplorerImpl.java;h=e90ae5eeecf78dee9d9bd0f6a74084e116d83af9;hb=da1d266392c3fe2f1ad1541c0f401763c3802f01;hp=3cf5f7478cd7af3dc23ff412db75eac0628f87c1;hpb=b844ca924d129072e11f7e4c18918dd388a37e8c;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 3cf5f7478..e90ae5eee 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 @@ -39,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; @@ -51,6 +50,7 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.LocalResourceManager; import org.eclipse.jface.resource.ResourceManager; +import org.eclipse.jface.util.OpenStrategy; import org.eclipse.jface.viewers.IPostSelectionProvider; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; @@ -69,7 +69,6 @@ import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; @@ -145,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; @@ -169,9 +169,12 @@ 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; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import gnu.trove.map.hash.THashMap; import gnu.trove.procedure.TObjectProcedure; @@ -184,6 +187,8 @@ import gnu.trove.set.hash.THashSet; */ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, GraphExplorer /*, IPostSelectionProvider*/ { + private static final Logger LOGGER = LoggerFactory.getLogger(GraphExplorerImpl.class); + private static class GraphExplorerPostSelectionProvider implements IPostSelectionProvider { private GraphExplorerImpl ge; @@ -288,24 +293,6 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph public static final int DEFAULT_MAX_CHILDREN = 1000; - private static final long POST_SELECTION_DELAY = 300; - - /** - * The time in milliseconds that must elapse between consecutive - * {@link Tree} {@link SelectionListener#widgetSelected(SelectionEvent)} - * invocations in order for this class to construct a new selection. - * - *
- * This is done because selection construction can be very expensive as the
- * selected set grows larger when the user is pressing shift+arrow keys.
- * GraphExplorerImpl will naturally listen to all changes in the tree
- * selection, but as an optimization will not construct new
- * StructuredSelection instances for every selection change event. A new
- * selection will be constructed and set only if the selection hasn't
- * changed for the amount of milliseconds specified by this constant.
- */
- private static final long SELECTION_CHANGE_QUIET_TIME = 150;
-
private final IThreadWorkQueue thread;
/**
@@ -327,11 +314,11 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph
Tree tree;
@SuppressWarnings({ "rawtypes" })
- final HashMap
true
if delayed selection runnable is current scheduled or
- * running.
+ * @return the new selection if it was different from the old selection in
+ * {@link #selectionProvider}
*/
- boolean delayedSelectionScheduled = false;
-
- Runnable SELECTION_DELAY = new Runnable() {
- @Override
- public void run() {
- if (tree.isDisposed())
- return;
- long now = System.currentTimeMillis();
- long waitTimeLeft = selectionSetTargetTime - now;
- if (waitTimeLeft > 0) {
- // Not enough quiet time, reschedule.
- delayedSelectionScheduled = true;
- tree.getDisplay().timerExec((int) waitTimeLeft, this);
- } else {
- // Time to perform selection, stop rescheduling.
- delayedSelectionScheduled = false;
- resetSelection();
- }
- }
- };
-
- private void widgetSelectionChanged(boolean forceSelectionChange) {
- long modTime = System.currentTimeMillis();
- long delta = modTime - lastSelectionModTime;
- lastSelectionModTime = modTime;
- if (!forceSelectionChange && delta < SELECTION_CHANGE_QUIET_TIME) {
- long msToWait = SELECTION_CHANGE_QUIET_TIME - delta;
- selectionSetTargetTime = modTime + msToWait;
- if (!delayedSelectionScheduled) {
- delayedSelectionScheduled = true;
- tree.getDisplay().timerExec((int) msToWait, SELECTION_DELAY);
- }
- // Make sure that post selection change events do not fire.
- ++postSelectionModCount;
- return;
+ private boolean resetSelectionFromWidgetAndFirePostSelection(boolean force) {
+ ISelection s = resetSelectionFromWidget();
+ boolean fire = s != null || force;
+ if (fire) {
+ //System.out.println("FIRING POST-SELECTION: " + selectionProvider.getSelection());
+ selectionProvider.firePostSelection(selectionProvider.getSelection());
}
-
- // Immediate selection reconstruction.
- resetSelection();
+ return fire;
}
- private void resetSelection() {
- final ISelection selection = getWidgetSelection();
-
- //System.out.println("resetSelection(" + postSelectionModCount + ")");
- //System.out.println(" provider selection: " + selectionProvider.getSelection());
- //System.out.println(" widget selection: " + selection);
-
- selectionProvider.setAndFireNonEqualSelection(selection);
-
- // Implement deferred firing of post selection events
- final int count = ++postSelectionModCount;
- //System.out.println("[" + System.currentTimeMillis() + "] scheduling postSelectionChanged " + count + ": " + selection);
- ThreadUtils.getNonBlockingWorkExecutor().schedule(new Runnable() {
- @Override
- public void run() {
- int newCount = postSelectionModCount;
- // Don't publish selection yet, there's another change incoming.
- //System.out.println("[" + System.currentTimeMillis() + "] checking post selection publish: " + count + " vs. " + newCount + ": " + selection);
- if (newCount != count)
- return;
- //System.out.println("[" + System.currentTimeMillis() + "] " + count + " count equals, firing post selection listeners: " + selection);
-
- if (tree.isDisposed())
- return;
-
- //System.out.println("scheduling fire post selection changed: " + selection);
- tree.getDisplay().asyncExec(new Runnable() {
- @Override
- public void run() {
- if (tree.isDisposed() || selectionProvider == null)
- return;
- //System.out.println("firing post selection changed: " + selection);
- selectionProvider.firePostSelection(selection);
- }
- });
- }
- }, POST_SELECTION_DELAY, TimeUnit.MILLISECONDS);
- }
-
protected void setDefaultProcessors() {
// Add a simple IMAGER query processor that always returns null.
// With this processor no images will ever be shown.
@@ -1883,15 +1787,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;
@@ -1902,7 +1806,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);
}
}
}
@@ -1947,7 +1851,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));
}
@@ -2426,7 +2330,7 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph
// System.out.println("MODCOUNT: " + modCount + " vs. " + count);
if (modCount != count)
return;
- widgetSelectionChanged(true);
+ resetSelectionFromWidgetAndFirePostSelection(false);
}
});
}
@@ -3251,13 +3155,16 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph
*/
private void doSetColumns(Column[] cols, Consumer