X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FGraphExplorerMouseAdapter.java;h=f3e27f1be70dcffa8d9613d9ae49a05819bb407c;hb=HEAD;hp=77b1b1a5355294f4007c69a6b71ffb4995724f05;hpb=86e91ef31d25e4d5950cae130754846d15119c61;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerMouseAdapter.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerMouseAdapter.java index 77b1b1a53..f3e27f1be 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerMouseAdapter.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerMouseAdapter.java @@ -1,93 +1,93 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.browsing.ui.swt; - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.widgets.Control; -import org.simantics.browsing.ui.GraphExplorer; -import org.simantics.browsing.ui.NodeContext; -import org.simantics.utils.ui.AdaptionUtils; -import org.simantics.utils.ui.action.IPriorityAction; - -/** - * An abstract base class for implementing SWT mouse event handlers for - * SWT-based {@link GraphExplorer}. - * - *

- * Use {@link #getClickedContext(MouseEvent)} to find the possible NodeContext - * the user clicked. You may also reimplement - * {@link #handleContextDoubleClick(NodeContext)} for the easiest way to - * redefine double click handling. - * - * @author Tuukka Lehtonen - * - * @see IPriorityAction - */ -public class GraphExplorerMouseAdapter extends MouseAdapter { - - protected GraphExplorer ge; - - public GraphExplorerMouseAdapter(GraphExplorer ge) { - this.ge = ge; - } - - protected ISelection getClickedContext(MouseEvent e) { -// final Tree tree = (Tree) e.getSource(); -// Point point = new Point(e.x, e.y); -// TreeItem item = tree.getItem(point); -// -// // No selectable item at point? -// if (item == null) -// return null; -// -// Object data = item.getData(); - Object data = ge.getClicked(e); - if (data == null) - return null; - - NodeContext context = AdaptionUtils.adaptToSingle(data, NodeContext.class); - if (context == null) - return null; - //System.out.println("double clicked tree item data: " + data); - - ISelectionProvider sp = (ISelectionProvider) ge.getAdapter(ISelectionProvider.class); - ISelection selection = sp.getSelection(); - //System.out.println("double clicked tree selection: " + selection); - - // Validate that the selection matches the clicked data. - NodeContext selectionContext = AdaptionUtils.adaptToSingle(selection, NodeContext.class); - if (!context.equals(selectionContext)) { - //ErrorLogger.defaultLogWarning("GraphExplorer selection does not match clicked tree item's NodeContext", new Exception("stacktrace")); - return new StructuredSelection(context); - } - - return selection; - } - - @Override - public void mouseDoubleClick(MouseEvent e) { - ISelection context = getClickedContext(e); - if (context == null) - return; - - Control tree = (Control)e.getSource(); - handleContextDoubleClick(tree, context); - } - - protected void handleContextDoubleClick(Control tree, ISelection selection) { - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.browsing.ui.swt; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.widgets.Control; +import org.simantics.browsing.ui.GraphExplorer; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.utils.ui.AdaptionUtils; +import org.simantics.utils.ui.action.IPriorityAction; + +/** + * An abstract base class for implementing SWT mouse event handlers for + * SWT-based {@link GraphExplorer}. + * + *

+ * Use {@link #getClickedContext(MouseEvent)} to find the possible NodeContext + * the user clicked. You may also reimplement + * {@link #handleContextDoubleClick(NodeContext)} for the easiest way to + * redefine double click handling. + * + * @author Tuukka Lehtonen + * + * @see IPriorityAction + */ +public class GraphExplorerMouseAdapter extends MouseAdapter { + + protected GraphExplorer ge; + + public GraphExplorerMouseAdapter(GraphExplorer ge) { + this.ge = ge; + } + + protected ISelection getClickedContext(MouseEvent e) { +// final Tree tree = (Tree) e.getSource(); +// Point point = new Point(e.x, e.y); +// TreeItem item = tree.getItem(point); +// +// // No selectable item at point? +// if (item == null) +// return null; +// +// Object data = item.getData(); + Object data = ge.getClicked(e); + if (data == null) + return null; + + NodeContext context = AdaptionUtils.adaptToSingle(data, NodeContext.class); + if (context == null) + return null; + //System.out.println("double clicked tree item data: " + data); + + ISelectionProvider sp = (ISelectionProvider) ge.getAdapter(ISelectionProvider.class); + ISelection selection = sp.getSelection(); + //System.out.println("double clicked tree selection: " + selection); + + // Validate that the selection matches the clicked data. + NodeContext selectionContext = AdaptionUtils.adaptToSingle(selection, NodeContext.class); + if (!context.equals(selectionContext)) { + //ErrorLogger.defaultLogWarning("GraphExplorer selection does not match clicked tree item's NodeContext", new Exception("stacktrace")); + return new StructuredSelection(context); + } + + return selection; + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + ISelection context = getClickedContext(e); + if (context == null) + return; + + Control tree = (Control)e.getSource(); + handleContextDoubleClick(tree, context); + } + + protected void handleContextDoubleClick(Control tree, ISelection selection) { + } + +}