-/*******************************************************************************\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.eclipse.jface.action.IAction;\r
-import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.eclipse.ui.WorkbenchException;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.utils.ResourceAdaptionUtils;\r
-import org.simantics.ui.workbench.ResourceViewPartUtils;\r
-import org.simantics.ui.workbench.action.ResourceEditorAdapterAction;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-import org.simantics.utils.ui.action.IPriorityAction;\r
-import org.simantics.utils.ui.action.PriorityActionAdapter;\r
-import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
-\r
-/**\r
- * A base implementation for {@link EditorAdapter} that adapts\r
- * {@link #canHandle(ReadGraph, Object)} into\r
- * {@link #canHandle(ReadGraph, Resource)} and {@link #openEditor(Object)} into\r
- * {@link #openEditor(Resource)}.\r
- * \r
- * If you only plan to support {@link Resource} or {@link Resource}-adaptable\r
- * editor inputs, this class is a bit easier to use than\r
- * {@link AbstractEditorAdapter}.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public abstract class AbstractResourceEditorAdapter extends AbstractEditorAdapter {\r
-\r
- public AbstractResourceEditorAdapter(String name) {\r
- super(name, null, 0);\r
- }\r
-\r
- public AbstractResourceEditorAdapter(String name, ImageDescriptor icon) {\r
- super(name, icon, 0);\r
- }\r
-\r
- public AbstractResourceEditorAdapter(String name, ImageDescriptor icon, int priority) {\r
- super(name, icon, priority);\r
- }\r
-\r
- /**\r
- * Override to perform the can handle check based on a single resource\r
- * adapted from the Object input using default mechanisms provided by\r
- * {@link ResourceAdaptionUtils}.\r
- * \r
- * Returns <code>false</code> by default.\r
- * \r
- * @param g\r
- * @param input\r
- * @return\r
- * @throws DatabaseException\r
- */\r
- protected boolean canHandle(ReadGraph g, Resource input) throws DatabaseException {\r
- return false;\r
- }\r
-\r
- /**\r
- * Override to open an editor based on a single resource adapted from the\r
- * Object input using default mechanisms provided by\r
- * {@link ResourceAdaptionUtils}.\r
- * \r
- * @param input\r
- * @throws Exception\r
- */\r
- protected void openEditor(Resource input) throws Exception {\r
- }\r
-\r
- @Override\r
- public boolean canHandle(ReadGraph g, Object input) throws DatabaseException {\r
- Resource r = ResourceAdaptionUtils.toSingleResource(input);\r
- if (r == null)\r
- return false;\r
- return canHandle(g, r);\r
- }\r
-\r
- @Override\r
- public void openEditor(Object input) throws Exception {\r
- Resource r = ResourceAdaptionUtils.toSingleResource(input);\r
- if (r != null)\r
- openEditor(r);\r
- }\r
-\r
- protected void openViewWithId(String viewId, Resource id, String suffix) throws Exception {\r
- Session ls = SimanticsUI.getSession();\r
- ResourceViewPartUtils.activateViewForResource(viewId, ls, id, null);\r
- }\r
-\r
- protected void openViewWithId(String viewId, Resource id) throws Exception {\r
- openViewWithId(viewId, id, null);\r
- }\r
-\r
- protected void openViewWithIdInPerspective(String viewId, Resource id, String perspectiveId) throws Exception {\r
- try {\r
- WorkbenchUtils.showPerspective(perspectiveId);\r
- } catch (WorkbenchException e) {\r
- ErrorLogger.getDefault().logError("Could not open perspective with ID'" + perspectiveId + "'.", e);\r
- }\r
-\r
- openViewWithId(viewId, id);\r
- }\r
-\r
- public IAction toAction(Resource r) {\r
- return new ResourceEditorAdapterAction(this, r);\r
- }\r
-\r
- public IPriorityAction toPriorityAction(int priority, Resource r) {\r
- return new PriorityActionAdapter(priority, toAction(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.eclipse.jface.action.IAction;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.WorkbenchException;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.ui.SimanticsUI;
+import org.simantics.ui.utils.ResourceAdaptionUtils;
+import org.simantics.ui.workbench.ResourceViewPartUtils;
+import org.simantics.ui.workbench.action.ResourceEditorAdapterAction;
+import org.simantics.utils.ui.ErrorLogger;
+import org.simantics.utils.ui.action.IPriorityAction;
+import org.simantics.utils.ui.action.PriorityActionAdapter;
+import org.simantics.utils.ui.workbench.WorkbenchUtils;
+
+/**
+ * A base implementation for {@link EditorAdapter} that adapts
+ * {@link #canHandle(ReadGraph, Object)} into
+ * {@link #canHandle(ReadGraph, Resource)} and {@link #openEditor(Object)} into
+ * {@link #openEditor(Resource)}.
+ *
+ * If you only plan to support {@link Resource} or {@link Resource}-adaptable
+ * editor inputs, this class is a bit easier to use than
+ * {@link AbstractEditorAdapter}.
+ *
+ * @author Tuukka Lehtonen
+ */
+public abstract class AbstractResourceEditorAdapter extends AbstractEditorAdapter {
+
+ public AbstractResourceEditorAdapter(String name) {
+ super(name, null, 0);
+ }
+
+ public AbstractResourceEditorAdapter(String name, ImageDescriptor icon) {
+ super(name, icon, 0);
+ }
+
+ public AbstractResourceEditorAdapter(String name, ImageDescriptor icon, int priority) {
+ super(name, icon, priority);
+ }
+
+ /**
+ * Override to perform the can handle check based on a single resource
+ * adapted from the Object input using default mechanisms provided by
+ * {@link ResourceAdaptionUtils}.
+ *
+ * Returns <code>false</code> by default.
+ *
+ * @param g
+ * @param input
+ * @return
+ * @throws DatabaseException
+ */
+ protected boolean canHandle(ReadGraph g, Resource input) throws DatabaseException {
+ return false;
+ }
+
+ /**
+ * Override to open an editor based on a single resource adapted from the
+ * Object input using default mechanisms provided by
+ * {@link ResourceAdaptionUtils}.
+ *
+ * @param input
+ * @throws Exception
+ */
+ protected void openEditor(Resource input) throws Exception {
+ }
+
+ @Override
+ public boolean canHandle(ReadGraph g, Object input) throws DatabaseException {
+ Resource r = ResourceAdaptionUtils.toSingleResource(input);
+ if (r == null)
+ return false;
+ return canHandle(g, r);
+ }
+
+ @Override
+ public void openEditor(Object input) throws Exception {
+ Resource r = ResourceAdaptionUtils.toSingleResource(input);
+ if (r != null)
+ openEditor(r);
+ }
+
+ protected void openViewWithId(String viewId, Resource id, String suffix) throws Exception {
+ Session ls = SimanticsUI.getSession();
+ ResourceViewPartUtils.activateViewForResource(viewId, ls, id, null);
+ }
+
+ protected void openViewWithId(String viewId, Resource id) throws Exception {
+ openViewWithId(viewId, id, null);
+ }
+
+ protected void openViewWithIdInPerspective(String viewId, Resource id, String perspectiveId) throws Exception {
+ try {
+ WorkbenchUtils.showPerspective(perspectiveId);
+ } catch (WorkbenchException e) {
+ ErrorLogger.getDefault().logError("Could not open perspective with ID'" + perspectiveId + "'.", e);
+ }
+
+ openViewWithId(viewId, id);
+ }
+
+ public IAction toAction(Resource r) {
+ return new ResourceEditorAdapterAction(this, r);
+ }
+
+ public IPriorityAction toPriorityAction(int priority, Resource r) {
+ return new PriorityActionAdapter(priority, toAction(r));
+ }
+
}
\ No newline at end of file