-/*******************************************************************************\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.ui.workbench.editor;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.ui.DoubleClickEvent;\r
-import org.simantics.ui.IDoubleClickAction;\r
-import org.simantics.ui.workbench.action.IWorkbenchActionHints;\r
-import org.simantics.ui.workbench.action.ResourceEditorAdapterAction;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class OpenDefaultEditor implements IDoubleClickAction {\r
-\r
- @Override\r
- public void doubleClickEvent(DoubleClickEvent e) {\r
- ReadGraph g = e.getGraph();\r
- Object r = e.getResource();\r
-\r
- Boolean remember = e.getHintContext().getHint(IWorkbenchActionHints.KEY_REMEMBER);\r
- final boolean rememberChoice = remember != null ? remember : false;\r
-\r
- Boolean ask = e.getHintContext().getHint(IWorkbenchActionHints.KEY_ALWAYS_ASK);\r
- boolean alwaysAsk = ask != null ? ask : false;\r
-\r
- EditorAdapter primaryAdapter = EditorRegistry.getInstance().getMappings().get(r);\r
- if (!alwaysAsk && primaryAdapter != null) {\r
- e.add(new ResourceEditorAdapterAction(primaryAdapter, r));\r
- } else {\r
- try {\r
- EditorAdapter[] editorAdapters = EditorRegistry.getInstance().getAdaptersFor(g, r);\r
- for (final EditorAdapter a : editorAdapters) {\r
- e.add(new ResourceEditorAdapterAction(a, r) {\r
- @Override\r
- protected void safeRun() throws Exception {\r
- super.safeRun();\r
-\r
- if (rememberChoice) {\r
- // Make this choice the default for the next time.\r
- EditorRegistry.getInstance().getMappings().put(getResource(), getAdapter());\r
- }\r
- }\r
- });\r
- }\r
- } catch (DatabaseException ex) {\r
- }\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.ui.workbench.editor;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.ui.DoubleClickEvent;
+import org.simantics.ui.IDoubleClickAction;
+import org.simantics.ui.workbench.action.IWorkbenchActionHints;
+import org.simantics.ui.workbench.action.ResourceEditorAdapterAction;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class OpenDefaultEditor implements IDoubleClickAction {
+
+ @Override
+ public void doubleClickEvent(DoubleClickEvent e) {
+ ReadGraph g = e.getGraph();
+ Object r = e.getResource();
+
+ Boolean remember = e.getHintContext().getHint(IWorkbenchActionHints.KEY_REMEMBER);
+ final boolean rememberChoice = remember != null ? remember : false;
+
+ Boolean ask = e.getHintContext().getHint(IWorkbenchActionHints.KEY_ALWAYS_ASK);
+ boolean alwaysAsk = ask != null ? ask : false;
+
+ EditorAdapter primaryAdapter = EditorRegistry.getInstance().getMappings().get(r);
+ if (!alwaysAsk && primaryAdapter != null) {
+ e.add(new ResourceEditorAdapterAction(primaryAdapter, r));
+ } else {
+ try {
+ EditorAdapter[] editorAdapters = EditorRegistry.getInstance().getAdaptersFor(g, r);
+ for (final EditorAdapter a : editorAdapters) {
+ e.add(new ResourceEditorAdapterAction(a, r) {
+ @Override
+ protected void safeRun() throws Exception {
+ super.safeRun();
+
+ if (rememberChoice) {
+ // Make this choice the default for the next time.
+ EditorRegistry.getInstance().getMappings().put(getResource(), getAdapter());
+ }
+ }
+ });
+ }
+ } catch (DatabaseException ex) {
+ }
+ }
+ }
+
+}