1 /*******************************************************************************
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.swt.widgets.impl;
14 import org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.swt.events.MouseEvent;
16 import org.eclipse.swt.events.MouseListener;
17 import org.simantics.db.WriteGraph;
18 import org.simantics.db.common.request.WriteRequest;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.management.ISessionContext;
21 import org.simantics.utils.ReflectionUtils;
22 import org.simantics.utils.ui.ISelectionUtils;
24 abstract public class MouseListenerImpl<T> implements MouseListener, Widget {
26 private ISessionContext context;
27 private Object lastInput = null;
29 final private Class<?> clazz;
31 public MouseListenerImpl(ISessionContext context) {
32 this.context = context;
33 clazz = ReflectionUtils.getSingleParameterType(getClass());
37 public void mouseDown(MouseEvent e) {
41 public void mouseUp(MouseEvent e) {
45 public void mouseDoubleClick(MouseEvent e) {
47 final Object input = lastInput;
52 single = (T) ISelectionUtils.filterSingleSelection((ISelection)input, clazz);
56 context.getSession().syncRequest(new WriteRequest() {
58 @SuppressWarnings("unchecked")
60 public void perform(WriteGraph graph) throws DatabaseException {
62 // T single = (T) ISelectionUtils.filterSingleSelection((ISelection)input, clazz);
63 doubleClick(graph, single);
68 } catch (DatabaseException e1) {
74 public void setInput(ISessionContext context, Object parameter) {
75 this.context = context;
76 lastInput = parameter;
79 public void beforeApply(T input) {
83 abstract public void doubleClick(WriteGraph graph, T input) throws DatabaseException;