1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.trend.chart.properties;
\r
14 import java.util.ArrayList;
\r
15 import java.util.Map;
\r
17 import org.eclipse.swt.widgets.Composite;
\r
18 import org.eclipse.ui.IWorkbenchSite;
\r
19 import org.simantics.browsing.ui.NodeContext;
\r
20 import org.simantics.browsing.ui.common.ErrorLogger;
\r
21 import org.simantics.browsing.ui.model.InvalidContribution;
\r
22 import org.simantics.browsing.ui.model.dnd.DndBrowseContext;
\r
23 import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;
\r
24 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
\r
25 import org.simantics.db.ReadGraph;
\r
26 import org.simantics.db.Resource;
\r
27 import org.simantics.db.common.request.ReadRequest;
\r
28 import org.simantics.db.exception.DatabaseException;
\r
29 import org.simantics.db.procedure.Procedure;
\r
30 import org.simantics.db.request.Read;
\r
31 import org.simantics.structural.ui.modelBrowser.ModelBrowser2;
\r
32 import org.simantics.ui.SimanticsUI;
\r
35 * ExplorerComposite allowing ontology-based DnD definitions. DnD Copied from {@link ModelBrowser2}
\r
37 * @author Teemu Lempinen
\r
40 public class AxisAndVariablesExplorerComposite extends GraphExplorerComposite {
\r
42 volatile DndBrowseContext dndBrowseContext;
\r
44 public AxisAndVariablesExplorerComposite(Map<String, Object> args, IWorkbenchSite site, Composite parent,
\r
45 WidgetSupport support, int style) {
\r
46 super(args, site, parent, support, style);
\r
48 SimanticsUI.getSession().asyncRequest(new ReadRequest() {
\r
50 public void run(ReadGraph graph) throws DatabaseException {
\r
51 ArrayList<Resource> browseContexts = new ArrayList<Resource>();
\r
52 for (String uri : getBrowseContexts()) {
\r
53 Resource browseContext = graph.getPossibleResource(uri);
\r
54 if (browseContext != null)
\r
55 browseContexts.add(browseContext);
\r
58 dndBrowseContext = DndBrowseContext.create(graph, browseContexts);
\r
59 } catch (InvalidContribution e) {
\r
60 ErrorLogger.defaultLogError(e);
\r
67 protected void handleDrop(final Object data, final NodeContext target) {
\r
71 SimanticsUI.getSession().asyncRequest(new Read<Runnable>() {
\r
73 public Runnable perform(ReadGraph graph) throws DatabaseException {
\r
74 if (dndBrowseContext == null)
\r
76 return dndBrowseContext.getAction(graph, target, data);
\r
78 }, new Procedure<Runnable>() {
\r
80 public void execute(Runnable result) {
\r
86 public void exception(Throwable t) {
\r
87 ErrorLogger.defaultLogError(t);
\r