-/*******************************************************************************\r
- * Copyright (c) 2007, 2012 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.browsing.ui.swt;\r
-\r
-import java.util.HashSet;\r
-\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.TreeItem;\r
-import org.simantics.browsing.ui.BuiltinKeys;\r
-import org.simantics.browsing.ui.CheckedState;\r
-import org.simantics.browsing.ui.NodeContext;\r
-import org.simantics.browsing.ui.NodeQueryManager;\r
-import org.simantics.browsing.ui.common.internal.GENodeQueryManager;\r
-import org.simantics.browsing.ui.common.internal.IGraphExplorerContext;\r
-import org.simantics.browsing.ui.content.PrunedChildrenResult;\r
-\r
-/**\r
- * This class is responsible for updating the {@link TreeItem}s contained by the\r
- * SWT Tree in {@link GraphExplorerImpl}.\r
- * \r
- * It will reschedule itself for as long as there are UI items to update in the\r
- * explorer. This class is not responsible for performing any throttling of\r
- * <code>UpdateRunner</code> executions.\r
- * \r
- * @author Antti Villberg\r
- */\r
-class UpdateRunner implements Runnable {\r
-\r
- final GraphExplorerImpl ge;\r
- //final IGraphExplorerContext geContext;\r
-\r
- UpdateRunner(GraphExplorerImpl ge, IGraphExplorerContext geContext) {\r
- this.ge = ge;\r
- // this.geContext = geContext;\r
- }\r
-\r
- public void run() {\r
- try {\r
- doRun();\r
- } catch (Throwable t) {\r
- t.printStackTrace();\r
- }\r
- \r
- }\r
-\r
- public void doRun() {\r
- \r
- if (ge.isDisposed())\r
- return;\r
-\r
- HashSet<TreeItem> items = new HashSet<TreeItem>();\r
- boolean doRoot;\r
-\r
- synchronized (ge.pendingItems) {\r
-\r
- doRoot = ge.pendingRoot;\r
- \r
- for (TreeItem item : ge.pendingItems) {\r
- //if(item.isDisposed()) continue;\r
- //if(item.getParentItem() == null) doRoot = true;\r
- //else items.add(item.getParentItem());\r
- if (item == null) {\r
- doRoot = true;\r
- } else {\r
- if(item.isDisposed()) continue;\r
- items.add(item);\r
- }\r
- }\r
-\r
- ge.pendingItems = new HashSet<TreeItem>();\r
- ge.pendingRoot = false;\r
-\r
- }\r
-\r
- if (doRoot) {\r
-\r
- NodeQueryManager manager = new GENodeQueryManager(ge.explorerContext, null, null, TreeItemReference.create(null));\r
-\r
- PrunedChildrenResult children = manager.query(ge.rootContext, BuiltinKeys.PRUNED_CHILDREN);\r
- int maxChildren = ge.getMaxChildren(manager, ge.rootContext);\r
- int childCount = Math.min(children.getPrunedChildren().length, maxChildren);\r
- ge.tree.clearAll(true);\r
- ge.tree.setItemCount(childCount);\r
-\r
- } else {\r
-\r
- int itemIndex = 0;\r
- for (TreeItem item : items) {\r
- if (item.isDisposed())\r
- continue;\r
-\r
- final NodeContext context = (NodeContext)item.getData();\r
- assert(context != null);\r
-\r
- NodeQueryManager manager = new GENodeQueryManager(ge.explorerContext, null, null, TreeItemReference.create(item));\r
-\r
- PrunedChildrenResult children = manager.query(context, BuiltinKeys.PRUNED_CHILDREN);\r
-\r
- int maxChildren = ge.getMaxChildren(manager, context);\r
- item.setItemCount(Math.min(children.getPrunedChildren().length, maxChildren));\r
-\r
- ge.setTextAndImage(item, manager, context, itemIndex);\r
-\r
- item.clearAll(true);\r
-\r
- boolean isExpanded = manager.query(context, BuiltinKeys.IS_EXPANDED);\r
- item.setExpanded(isExpanded);\r
-\r
- if ((((Control) ge.getControl()).getStyle() & SWT.CHECK) != 0) {\r
- CheckedState checked = manager.query(context, BuiltinKeys.IS_CHECKED);\r
- item.setChecked(CheckedState.CHECKED_STATES.contains(checked));\r
- item.setGrayed(CheckedState.GRAYED == checked);\r
- }\r
-\r
- ++itemIndex;\r
- }\r
- }\r
-\r
- synchronized (ge.pendingItems) {\r
- if (!ge.scheduleUpdater())\r
- ge.updating = false;\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.browsing.ui.swt;
+
+import java.util.HashSet;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.TreeItem;
+import org.simantics.browsing.ui.BuiltinKeys;
+import org.simantics.browsing.ui.CheckedState;
+import org.simantics.browsing.ui.NodeContext;
+import org.simantics.browsing.ui.NodeQueryManager;
+import org.simantics.browsing.ui.common.internal.GENodeQueryManager;
+import org.simantics.browsing.ui.common.internal.IGraphExplorerContext;
+import org.simantics.browsing.ui.content.PrunedChildrenResult;
+
+/**
+ * This class is responsible for updating the {@link TreeItem}s contained by the
+ * SWT Tree in {@link GraphExplorerImpl}.
+ *
+ * It will reschedule itself for as long as there are UI items to update in the
+ * explorer. This class is not responsible for performing any throttling of
+ * <code>UpdateRunner</code> executions.
+ *
+ * @author Antti Villberg
+ */
+class UpdateRunner implements Runnable {
+
+ final GraphExplorerImpl ge;
+ //final IGraphExplorerContext geContext;
+
+ UpdateRunner(GraphExplorerImpl ge, IGraphExplorerContext geContext) {
+ this.ge = ge;
+ // this.geContext = geContext;
+ }
+
+ public void run() {
+ try {
+ doRun();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+
+ }
+
+ public void doRun() {
+
+ if (ge.isDisposed())
+ return;
+
+ HashSet<TreeItem> items = new HashSet<TreeItem>();
+ boolean doRoot;
+
+ synchronized (ge.pendingItems) {
+
+ doRoot = ge.pendingRoot;
+
+ for (TreeItem item : ge.pendingItems) {
+ //if(item.isDisposed()) continue;
+ //if(item.getParentItem() == null) doRoot = true;
+ //else items.add(item.getParentItem());
+ if (item == null) {
+ doRoot = true;
+ } else {
+ if(item.isDisposed()) continue;
+ items.add(item);
+ }
+ }
+
+ ge.pendingItems = new HashSet<TreeItem>();
+ ge.pendingRoot = false;
+
+ }
+
+ if (doRoot) {
+
+ NodeQueryManager manager = new GENodeQueryManager(ge.explorerContext, null, null, TreeItemReference.create(null));
+
+ PrunedChildrenResult children = manager.query(ge.rootContext, BuiltinKeys.PRUNED_CHILDREN);
+ int maxChildren = ge.getMaxChildren(manager, ge.rootContext);
+ int childCount = Math.min(children.getPrunedChildren().length, maxChildren);
+ ge.tree.clearAll(true);
+ ge.tree.setItemCount(childCount);
+
+ } else {
+
+ int itemIndex = 0;
+ for (TreeItem item : items) {
+ if (item.isDisposed())
+ continue;
+
+ final NodeContext context = (NodeContext)item.getData();
+ assert(context != null);
+
+ NodeQueryManager manager = new GENodeQueryManager(ge.explorerContext, null, null, TreeItemReference.create(item));
+
+ PrunedChildrenResult children = manager.query(context, BuiltinKeys.PRUNED_CHILDREN);
+
+ int maxChildren = ge.getMaxChildren(manager, context);
+ item.setItemCount(Math.min(children.getPrunedChildren().length, maxChildren));
+
+ ge.setTextAndImage(item, manager, context, itemIndex);
+
+ item.clearAll(true);
+
+ boolean isExpanded = manager.query(context, BuiltinKeys.IS_EXPANDED);
+ item.setExpanded(isExpanded);
+
+ if ((((Control) ge.getControl()).getStyle() & SWT.CHECK) != 0) {
+ CheckedState checked = manager.query(context, BuiltinKeys.IS_CHECKED);
+ item.setChecked(CheckedState.CHECKED_STATES.contains(checked));
+ item.setGrayed(CheckedState.GRAYED == checked);
+ }
+
+ ++itemIndex;
+ }
+ }
+
+ synchronized (ge.pendingItems) {
+ if (!ge.scheduleUpdater())
+ ge.updating = false;
+ }
+ }
+
+}