-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.browsing.ui.swt;\r
-\r
-import org.eclipse.core.runtime.IStatus;\r
-import org.eclipse.core.runtime.Status;\r
-import org.eclipse.jface.viewers.IPostSelectionProvider;\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.KeyAdapter;\r
-import org.eclipse.swt.events.KeyEvent;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.simantics.Simantics;\r
-import org.simantics.browsing.ui.GraphExplorer;\r
-import org.simantics.browsing.ui.NodeContext;\r
-import org.simantics.browsing.ui.model.queries.IsNodeContextModifiable;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.management.ISessionContext;\r
-import org.simantics.db.management.ISessionContextProvider;\r
-import org.simantics.ui.workbench.action.ChooseActionRequest;\r
-import org.simantics.utils.datastructures.Function;\r
-import org.simantics.utils.ui.ISelectionUtils;\r
-import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
-\r
-/**\r
- * The default keyboard handler for {@link GraphExplorer}.\r
- * \r
- * <p>\r
- * Carriage return presses are handled similarly to mouse double clicks. F2\r
- * initiates in-line editing of the selection when possible.\r
- * </p>\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class DefaultKeyListener extends KeyAdapter {\r
-\r
- private final ISessionContextProvider contextProvider;\r
- private final GraphExplorer explorer;\r
- private final Function<String[]> editingColumnResolver;\r
-\r
- /**\r
- * @param contextProvider\r
- * @param explorer\r
- * @param editingColumnResolver\r
- */\r
- public DefaultKeyListener(ISessionContextProvider contextProvider, GraphExplorer explorer, Function<String[]> editingColumnResolver) {\r
- assert contextProvider != null;\r
- assert explorer != null;\r
- assert editingColumnResolver != null;\r
-\r
- this.contextProvider = contextProvider;\r
- this.explorer = explorer;\r
- this.editingColumnResolver = editingColumnResolver;\r
- }\r
-\r
- @Override\r
- public void keyPressed(KeyEvent e) {\r
- if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {\r
- if (explorer.isDisposed())\r
- return;\r
-\r
- ISessionContext sessionContext = contextProvider.getSessionContext();\r
- if (sessionContext == null)\r
- return;\r
-\r
- IPostSelectionProvider selectionProvider = (IPostSelectionProvider)explorer.getAdapter(IPostSelectionProvider.class);\r
-\r
- ISelection input = selectionProvider.getSelection();\r
- if (input.isEmpty())\r
- return;\r
-// Resource resource = ResourceAdaptionUtils.toSingleResource(selectionProvider.getSelection());\r
-// if (resource == null)\r
-// return;\r
- final String perspectiveId = WorkbenchUtils.getCurrentPerspectiveId();\r
- Control control = explorer.getControl();\r
- Shell shell = control.getShell();\r
-\r
- // Try the doubleClick-extensions\r
- sessionContext.getSession().asyncRequest(new ChooseActionRequest(shell, explorer, input, perspectiveId));\r
- } else if (e.keyCode == SWT.F2) {\r
-\r
- IPostSelectionProvider selectionProvider = (IPostSelectionProvider)explorer.getAdapter(IPostSelectionProvider.class);\r
- NodeContext context = ISelectionUtils.filterSingleSelection(selectionProvider.getSelection(), NodeContext.class);\r
- if (context == null || !isEditable(context))\r
- return;\r
-\r
- for (String column : editingColumnResolver.execute(context)) {\r
- // Prefix column key with '#' to indicate that\r
- // textual editing is preferred if supported.\r
- String error = explorer.startEditing(context, "#" + column); \r
- if (error == null)\r
- return;\r
- }\r
- return;\r
- }\r
- }\r
-\r
- private boolean isEditable(NodeContext context) {\r
- try {\r
- return Simantics.getSession().syncRequest(new IsNodeContextModifiable(context));\r
- } catch (DatabaseException e) {\r
- Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,\r
- "Failed to check node context modifiability, see exception for details.", e));\r
- return false;\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.IPostSelectionProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.simantics.Simantics;
+import org.simantics.browsing.ui.GraphExplorer;
+import org.simantics.browsing.ui.NodeContext;
+import org.simantics.browsing.ui.model.queries.IsNodeContextModifiable;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.management.ISessionContext;
+import org.simantics.db.management.ISessionContextProvider;
+import org.simantics.ui.workbench.action.ChooseActionRequest;
+import org.simantics.utils.datastructures.Function;
+import org.simantics.utils.ui.ISelectionUtils;
+import org.simantics.utils.ui.workbench.WorkbenchUtils;
+
+/**
+ * The default keyboard handler for {@link GraphExplorer}.
+ *
+ * <p>
+ * Carriage return presses are handled similarly to mouse double clicks. F2
+ * initiates in-line editing of the selection when possible.
+ * </p>
+ *
+ * @author Tuukka Lehtonen
+ */
+public class DefaultKeyListener extends KeyAdapter {
+
+ private final ISessionContextProvider contextProvider;
+ private final GraphExplorer explorer;
+ private final Function<String[]> editingColumnResolver;
+
+ /**
+ * @param contextProvider
+ * @param explorer
+ * @param editingColumnResolver
+ */
+ public DefaultKeyListener(ISessionContextProvider contextProvider, GraphExplorer explorer, Function<String[]> editingColumnResolver) {
+ assert contextProvider != null;
+ assert explorer != null;
+ assert editingColumnResolver != null;
+
+ this.contextProvider = contextProvider;
+ this.explorer = explorer;
+ this.editingColumnResolver = editingColumnResolver;
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
+ if (explorer.isDisposed())
+ return;
+
+ ISessionContext sessionContext = contextProvider.getSessionContext();
+ if (sessionContext == null)
+ return;
+
+ IPostSelectionProvider selectionProvider = (IPostSelectionProvider)explorer.getAdapter(IPostSelectionProvider.class);
+
+ ISelection input = selectionProvider.getSelection();
+ if (input.isEmpty())
+ return;
+// Resource resource = ResourceAdaptionUtils.toSingleResource(selectionProvider.getSelection());
+// if (resource == null)
+// return;
+ final String perspectiveId = WorkbenchUtils.getCurrentPerspectiveId();
+ Control control = explorer.getControl();
+ Shell shell = control.getShell();
+
+ // Try the doubleClick-extensions
+ sessionContext.getSession().asyncRequest(new ChooseActionRequest(shell, explorer, input, perspectiveId));
+ } else if (e.keyCode == SWT.F2) {
+
+ IPostSelectionProvider selectionProvider = (IPostSelectionProvider)explorer.getAdapter(IPostSelectionProvider.class);
+ NodeContext context = ISelectionUtils.filterSingleSelection(selectionProvider.getSelection(), NodeContext.class);
+ if (context == null || !isEditable(context))
+ return;
+
+ for (String column : editingColumnResolver.execute(context)) {
+ // Prefix column key with '#' to indicate that
+ // textual editing is preferred if supported.
+ String error = explorer.startEditing(context, "#" + column);
+ if (error == null)
+ return;
+ }
+ return;
+ }
+ }
+
+ private boolean isEditable(NodeContext context) {
+ try {
+ return Simantics.getSession().syncRequest(new IsNodeContextModifiable(context));
+ } catch (DatabaseException e) {
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ "Failed to check node context modifiability, see exception for details.", e));
+ return false;
+ }
+ }
+
+}