1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 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.graph.impl;
14 import java.util.Collection;
15 import java.util.function.Consumer;
17 import org.simantics.browsing.ui.BuiltinKeys;
18 import org.simantics.browsing.ui.BuiltinKeys.ViewpointKey;
19 import org.simantics.browsing.ui.DataSource;
20 import org.simantics.browsing.ui.NodeContext;
21 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
22 import org.simantics.browsing.ui.common.NodeContextUtil;
23 import org.simantics.browsing.ui.common.viewpoints.LazyContainerViewpoint;
24 import org.simantics.browsing.ui.content.Viewpoint;
25 import org.simantics.browsing.ui.content.ViewpointFactory;
26 import org.simantics.db.ReadGraph;
27 import org.simantics.db.Resource;
28 import org.simantics.db.common.utils.OrderedSetUtils;
29 import org.simantics.db.exception.DatabaseException;
31 public class OrderedSetViewpointFactory implements ViewpointFactory {
34 public Viewpoint create(final PrimitiveQueryUpdater updater, final NodeContext context, final ViewpointKey key) {
35 assert updater != null;
36 assert context != null;
38 final LazyContainerViewpoint result = new LazyContainerViewpoint();
40 DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
44 final Resource inputResource = (Resource) context.getConstant(BuiltinKeys.INPUT);
45 assert inputResource != null;
47 source.schedule(new Consumer<ReadGraph>() {
49 public void accept(ReadGraph source) {
51 Collection<Resource> children = OrderedSetUtils.toList(source, inputResource);
52 NodeContext[] resultContexts = NodeContextUtil.toContextsWithInput(children);
53 result.setChildren(updater, resultContexts);
54 result.setHasChildren(resultContexts.length > 0);
56 updater.scheduleReplace(context, key, result);
57 } catch (DatabaseException e) {
67 public String toString() {