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;
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;
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;
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;
});
}
}
-
+
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;
if (processor instanceof DefaultIsExpandedProcessor) {
DefaultIsExpandedProcessor isExpandedProcessor = (DefaultIsExpandedProcessor)processor;
for(NodeContext expanded : state.expandedNodes) {
- isExpandedProcessor.setExpanded(expanded, true);
+ isExpandedProcessor.replaceExpanded(expanded, true);
}
}
}
}
persistor.serialize(
- Platform.getStateLocation(Activator.getDefault().getBundle()).toFile(),
+ ExplorerStates.explorerStateLocation(),
getRoot(),
new ExplorerState(topNodePath, topNodePathChildIndex, expandedNodes, columnWidths));
}
//System.out.println("NodeContext path : " + contexts);
NodeContext head = tryFind(contexts[position]);
-
+ // tryFind may return null for positions, that actually have NodeContext.
+ if (head == null)
+ return false;
+
if(position == contexts.length-1) {
return select(head);
*/
private void doSetColumns(Column[] cols, Consumer<Map<Column, Object>> callback) {
// Attempt to keep previous column widths.
- Map<String, Integer> prevWidths = new HashMap<String, Integer>();
+ Map<String, Integer> 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<String, Integer> keyToIndex = new HashMap<String, Integer>();
+ HashMap<String, Integer> keyToIndex = new HashMap<>();
for (int i = 0; i < cols.length; ++i) {
keyToIndex.put(cols[i].getKey(), i);
}
this.columnImageArray = new Image[cols.length];
this.columnDescOrImageArray = new Object[cols.length];
- Map<Column, Object> map = new HashMap<Column, Object>();
+ Map<Column, Object> map = new HashMap<>();
tree.setHeaderVisible(columnsAreVisible);
for (Column column : columns) {
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)
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();
- }
});
}