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.jfreechart.chart.properties.xyline;
\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.ui.SimanticsUI;
\r
34 * ExplorerComposite allowing ontology-based DnD definitions. DnD Copied from {@link ModelBrowser2}
\r
36 * @author Teemu Lempinen
\r
39 public class AxisAndVariablesExplorerComposite extends GraphExplorerComposite {
\r
41 volatile DndBrowseContext dndBrowseContext;
\r
43 public AxisAndVariablesExplorerComposite(Map<String, Object> args, IWorkbenchSite site, Composite parent,
\r
44 WidgetSupport support, int style) {
\r
45 super(args, site, parent, support, style);
\r
47 SimanticsUI.getSession().asyncRequest(new ReadRequest() {
\r
49 public void run(ReadGraph graph) throws DatabaseException {
\r
50 ArrayList<Resource> browseContexts = new ArrayList<Resource>();
\r
51 for (String uri : getBrowseContexts()) {
\r
52 Resource browseContext = graph.getPossibleResource(uri);
\r
53 if (browseContext != null)
\r
54 browseContexts.add(browseContext);
\r
57 dndBrowseContext = DndBrowseContext.create(graph, browseContexts);
\r
58 } catch (InvalidContribution e) {
\r
59 ErrorLogger.defaultLogError(e);
\r
66 protected void handleDrop(final Object data, final NodeContext target) {
\r
70 SimanticsUI.getSession().asyncRequest(new Read<Runnable>() {
\r
72 public Runnable perform(ReadGraph graph) throws DatabaseException {
\r
73 if (dndBrowseContext == null)
\r
75 return dndBrowseContext.getAction(graph, target, data);
\r
77 }, new Procedure<Runnable>() {
\r
79 public void execute(Runnable result) {
\r
85 public void exception(Throwable t) {
\r
86 ErrorLogger.defaultLogError(t);
\r