]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/ExplorerMouseListenerImpl.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / widgets / ExplorerMouseListenerImpl.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.widgets;
13
14 import org.eclipse.jface.viewers.IPostSelectionProvider;
15 import org.eclipse.jface.viewers.ISelection;
16 import org.simantics.browsing.ui.GraphExplorer;
17 import org.simantics.browsing.ui.swt.widgets.impl.MouseListenerImpl;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.management.ISessionContext;
21
22 abstract public class ExplorerMouseListenerImpl<T> extends MouseListenerImpl<T> {
23
24         private GraphExplorer explorer = null;
25         private ISelection selection;
26         
27         public ExplorerMouseListenerImpl(ISessionContext context) {
28                 super(context);
29         }
30         
31         void register(GraphExplorer explorer) {
32                 this.explorer = explorer;
33         }
34         
35         public void doubleClick(WriteGraph graph, T input) throws DatabaseException {
36
37                 if(explorer == null) return;
38                 
39                 doubleClick(graph, input, selection);
40                         
41         }
42         
43         @Override
44         public void beforeApply(T input) {
45                 
46                 if(explorer == null) return;
47                 
48                 IPostSelectionProvider selectionProvider = (IPostSelectionProvider)explorer.getAdapter(IPostSelectionProvider.class);
49                 selection = selectionProvider.getSelection();
50                 
51         }
52
53         abstract public void doubleClick(WriteGraph graph, T input, ISelection selection) throws DatabaseException;
54         
55 }
56