1 package org.simantics.document.linking.ge;
3 import java.util.ArrayList;
6 import org.eclipse.jface.viewers.ISelectionProvider;
7 import org.eclipse.swt.widgets.Composite;
8 import org.eclipse.ui.IWorkbenchSite;
9 import org.simantics.browsing.ui.NodeContext;
10 import org.simantics.browsing.ui.common.ErrorLogger;
11 import org.simantics.browsing.ui.model.InvalidContribution;
12 import org.simantics.browsing.ui.model.dnd.DndBrowseContext;
13 import org.simantics.browsing.ui.swt.DefaultExplorerSelectionListener;
14 import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;
15 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Resource;
18 import org.simantics.db.common.request.ReadRequest;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.procedure.Procedure;
21 import org.simantics.db.request.Read;
22 import org.simantics.ui.SimanticsUI;
24 public class SourceLinkExplorerComposite extends GraphExplorerComposite {
26 volatile DndBrowseContext dndBrowseContext;
27 private IWorkbenchSite site;
28 private MultiSelectionProvider provider;
30 public SourceLinkExplorerComposite(Map<String, Object> args, MultiSelectionProvider provider, IWorkbenchSite site, Composite parent, WidgetSupport support, int style) {
31 super(args, site, parent, support, style);
33 this.provider = provider;
38 public SourceLinkExplorerComposite(Map<String, Object> args, MultiSelectionProvider provider, IWorkbenchSite site, Composite parent, WidgetSupport support, boolean useDND, int style) {
39 super(args, site, parent, support, style);
41 this.provider = provider;
46 private void attachDND() {
47 SimanticsUI.getSession().asyncRequest(new ReadRequest() {
49 public void run(ReadGraph graph) throws DatabaseException {
50 ArrayList<Resource> browseContexts = new ArrayList<Resource>();
51 for (String uri : getBrowseContexts()) {
52 Resource browseContext = graph.getPossibleResource(uri);
53 if (browseContext != null)
54 browseContexts.add(browseContext);
57 dndBrowseContext = DndBrowseContext.create(graph, browseContexts);
58 } catch (InvalidContribution e) {
59 ErrorLogger.defaultLogError(e);
66 protected void handleDrop(final Object data, final NodeContext target) {
70 SimanticsUI.getSession().asyncRequest(new Read<Runnable>() {
72 public Runnable perform(ReadGraph graph) throws DatabaseException {
73 if (dndBrowseContext == null)
75 return dndBrowseContext.getAction(graph, target, data);
77 }, new Procedure<Runnable>() {
79 public void execute(Runnable result) {
85 public void exception(Throwable t) {
86 ErrorLogger.defaultLogError(t);
91 public void setWorkbenchListeners() {
92 if (workbenchSelectionListener == null && site != null) {
93 ISelectionProvider selectionProvider = (ISelectionProvider) explorer.getAdapter(ISelectionProvider.class);
94 //site.setSelectionProvider(selectionProvider);
95 provider.addSelectionProvider(selectionProvider);
97 // Listen to the workbench selection also to propagate it to
99 workbenchSelectionListener = new DefaultExplorerSelectionListener(site.getPage().getActivePart(), explorer);
100 //System.out.println("ADD WORKBENCH SELECTION LISTENER: " + workbenchSelectionListener);
101 site.getWorkbenchWindow().getSelectionService().addPostSelectionListener(workbenchSelectionListener);