1 /*******************************************************************************
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.swt;
14 import java.util.HashSet;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.widgets.Control;
18 import org.eclipse.swt.widgets.TreeItem;
19 import org.simantics.browsing.ui.BuiltinKeys;
20 import org.simantics.browsing.ui.CheckedState;
21 import org.simantics.browsing.ui.NodeContext;
22 import org.simantics.browsing.ui.NodeQueryManager;
23 import org.simantics.browsing.ui.common.internal.GENodeQueryManager;
24 import org.simantics.browsing.ui.common.internal.IGraphExplorerContext;
25 import org.simantics.browsing.ui.content.PrunedChildrenResult;
28 * This class is responsible for updating the {@link TreeItem}s contained by the
29 * SWT Tree in {@link GraphExplorerImpl}.
31 * It will reschedule itself for as long as there are UI items to update in the
32 * explorer. This class is not responsible for performing any throttling of
33 * <code>UpdateRunner</code> executions.
35 * @author Antti Villberg
37 class UpdateRunner implements Runnable {
39 final GraphExplorerImpl ge;
40 //final IGraphExplorerContext geContext;
42 UpdateRunner(GraphExplorerImpl ge, IGraphExplorerContext geContext) {
44 // this.geContext = geContext;
50 } catch (Throwable t) {
61 HashSet<TreeItem> items = new HashSet<TreeItem>();
64 synchronized (ge.pendingItems) {
66 doRoot = ge.pendingRoot;
68 for (TreeItem item : ge.pendingItems) {
69 //if(item.isDisposed()) continue;
70 //if(item.getParentItem() == null) doRoot = true;
71 //else items.add(item.getParentItem());
75 if(item.isDisposed()) continue;
80 ge.pendingItems = new HashSet<TreeItem>();
81 ge.pendingRoot = false;
87 NodeQueryManager manager = new GENodeQueryManager(ge.explorerContext, null, null, TreeItemReference.create(null));
89 PrunedChildrenResult children = manager.query(ge.rootContext, BuiltinKeys.PRUNED_CHILDREN);
90 int maxChildren = ge.getMaxChildren(manager, ge.rootContext);
91 int childCount = Math.min(children.getPrunedChildren().length, maxChildren);
92 ge.tree.clearAll(true);
93 ge.tree.setItemCount(childCount);
98 for (TreeItem item : items) {
99 if (item.isDisposed())
102 final NodeContext context = (NodeContext)item.getData();
103 assert(context != null);
105 NodeQueryManager manager = new GENodeQueryManager(ge.explorerContext, null, null, TreeItemReference.create(item));
107 PrunedChildrenResult children = manager.query(context, BuiltinKeys.PRUNED_CHILDREN);
109 int maxChildren = ge.getMaxChildren(manager, context);
110 item.setItemCount(Math.min(children.getPrunedChildren().length, maxChildren));
112 ge.setTextAndImage(item, manager, context, itemIndex);
116 boolean isExpanded = manager.query(context, BuiltinKeys.IS_EXPANDED);
117 item.setExpanded(isExpanded);
119 if ((((Control) ge.getControl()).getStyle() & SWT.CHECK) != 0) {
120 CheckedState checked = manager.query(context, BuiltinKeys.IS_CHECKED);
121 item.setChecked(CheckedState.CHECKED_STATES.contains(checked));
122 item.setGrayed(CheckedState.GRAYED == checked);
129 synchronized (ge.pendingItems) {
130 if (!ge.scheduleUpdater())