]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/PropertyTableUtil.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / PropertyTableUtil.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2012 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.browsing.ui.swt;
13
14 import org.eclipse.jface.viewers.ISelectionProvider;
15 import org.eclipse.swt.widgets.Control;
16 import org.simantics.browsing.ui.GraphExplorer;
17 import org.simantics.browsing.ui.common.views.PropertyTableConstants;
18 import org.simantics.db.Session;
19 import org.simantics.db.management.ISessionContext;
20 import org.simantics.ui.dnd.BasicDragSource;
21 import org.simantics.ui.dnd.SessionContainer;
22
23 public class PropertyTableUtil {
24
25     /**
26      * @param explorer
27      * @return the object representing the drag source. If the object implements
28      *         {@link SessionContainer}, its
29      *         {@link SessionContainer#setSession(Session)} will be invoked
30      *         every time the active database session changes.
31      */
32     public static Object createResourceDragSource(GraphExplorer explorer) {
33         ISelectionProvider selectionProvider = (ISelectionProvider)explorer.getAdapter(ISelectionProvider.class);
34         Control control = explorer.getControl();
35         return new BasicDragSource(selectionProvider, control, null, PropertyTableConstants.DND_PURPOSE_PROPERTY);
36     }
37
38     public static void setupDragSource(Object dragSource, ISessionContext sessionContext) {
39         if (dragSource instanceof SessionContainer) {
40             ((SessionContainer) dragSource).setSession(sessionContext != null ? sessionContext.getSession() : null);
41         }
42     }
43
44 }