-/*******************************************************************************\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.resource.ImageDescriptor;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.ui.workbench.ResourceEditorInput;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-\r
-/**\r
- * A very simple and limited implementation of ResourceEditorAdapter.\r
- * \r
- * <p>\r
- * Easy to use because all necessary information can be given as constructor\r
- * parameters.\r
- * </p>\r
- * \r
- * <p>\r
- * Example:\r
- * \r
- * <pre>\r
- * class MyEditorAdapter extends SimpleEditorAdapter {\r
- * MyEditorAdapter() {\r
- * super("My Editor", "My.Editor.Id",\r
- * new String[] { Builtins.URIs.Entity },\r
- * new String[] { Builtins.URIs.Entity });\r
- * }\r
- * }\r
- * </pre>\r
- * \r
- * allows opening the editor "My.Editor.Id" for a resource if it is\r
- * inherited from the type Object or is an instance of Object.\r
- * </p>\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class SimpleEditorAdapter extends AbstractResourceEditorAdapter {\r
-\r
- private final String editorViewId;\r
- private final String perspectiveId;\r
- private final String[] inherits;\r
- private final String[] instanceOf;\r
-\r
- /**\r
- * @param name\r
- * @param editorViewId\r
- * @param inherits\r
- * @param instanceOf\r
- */\r
- public SimpleEditorAdapter(String name, String editorViewId,\r
- String[] inherits, String[] instanceOf)\r
- {\r
- this(name, (ImageDescriptor) null, editorViewId, inherits, instanceOf);\r
- }\r
-\r
- /**\r
- * @param name\r
- * @param icon\r
- * @param editorViewId\r
- * @param inherits\r
- * @param instanceOf\r
- */\r
- public SimpleEditorAdapter(String name, ImageDescriptor icon,\r
- String editorViewId,\r
- String[] inherits, String[] instanceOf)\r
- {\r
- this(name, icon, editorViewId, null, inherits, instanceOf);\r
- }\r
-\r
- /**\r
- * @param name\r
- * @param icon\r
- * @param editorViewId\r
- * @param perspectiveId\r
- * @param inherits\r
- * @param instanceOf\r
- */\r
- public SimpleEditorAdapter(String name, ImageDescriptor icon,\r
- String editorViewId, String perspectiveId,\r
- String[] inherits, String[] instanceOf)\r
- {\r
- super(name, icon);\r
- this.editorViewId = editorViewId;\r
- this.perspectiveId = perspectiveId;\r
- this.inherits = inherits;\r
- this.instanceOf = instanceOf;\r
- }\r
-\r
- @Override\r
- public boolean canHandle(ReadGraph g, Resource r) throws DatabaseException {\r
- //System.out.println("canHandle: " + this.getClass().getCanonicalName());\r
-\r
- // If not filters are defined, allow anything.\r
- if ((inherits == null || inherits.length == 0)\r
- && (instanceOf == null || instanceOf.length == 0))\r
- return true;\r
-\r
- if (inherits != null) {\r
- for (String type : inherits) {\r
- //System.out.println("type: " + type);\r
- try {\r
- if (g.isInheritedFrom(r, g.getResource(type)))\r
- return true;\r
- } catch (DatabaseException e) {\r
- ErrorLogger.defaultLogError("BUG: SimpleEditorAdapter " + getClass().getName()\r
- + " checked for inheritance of '" + type + "' but resource was not found", e);\r
- }\r
- }\r
- }\r
- if (instanceOf != null) {\r
- for (String instance : instanceOf) {\r
- //System.out.println("instance: " + instance);\r
- try {\r
- //System.out.println(instance);\r
- if (g.isInstanceOf(r, g.getResource(instance)))\r
- return true;\r
- } catch (DatabaseException e) {\r
- ErrorLogger.defaultLogError("BUG: SimpleEditorAdapter " + getClass().getName()\r
- + " checked for instanceOf '" + instance + "' but the type was not found", e);\r
- }\r
- }\r
- }\r
- return false;\r
- }\r
-\r
-\r
- @Override\r
- protected void openEditor(Resource r) throws Exception {\r
- assert(editorViewId != null);\r
-\r
- if (perspectiveId != null) {\r
- openEditorWithIdInPerspective(editorViewId, new ResourceEditorInput(editorViewId, r), perspectiveId);\r
- } else {\r
- openEditorWithId(editorViewId, new ResourceEditorInput(editorViewId, r));\r
- }\r
- }\r
-\r
- protected void openView(Resource r) throws Exception {\r
- assert(editorViewId != null);\r
-\r
- if (perspectiveId != null) {\r
- openViewWithIdInPerspective(editorViewId, r, perspectiveId);\r
- } else {\r
- openViewWithId(editorViewId, 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.eclipse.jface.resource.ImageDescriptor;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.ui.workbench.ResourceEditorInput;
+import org.simantics.utils.ui.ErrorLogger;
+
+/**
+ * A very simple and limited implementation of ResourceEditorAdapter.
+ *
+ * <p>
+ * Easy to use because all necessary information can be given as constructor
+ * parameters.
+ * </p>
+ *
+ * <p>
+ * Example:
+ *
+ * <pre>
+ * class MyEditorAdapter extends SimpleEditorAdapter {
+ * MyEditorAdapter() {
+ * super("My Editor", "My.Editor.Id",
+ * new String[] { Builtins.URIs.Entity },
+ * new String[] { Builtins.URIs.Entity });
+ * }
+ * }
+ * </pre>
+ *
+ * allows opening the editor "My.Editor.Id" for a resource if it is
+ * inherited from the type Object or is an instance of Object.
+ * </p>
+ *
+ * @author Tuukka Lehtonen
+ */
+public class SimpleEditorAdapter extends AbstractResourceEditorAdapter {
+
+ private final String editorViewId;
+ private final String perspectiveId;
+ private final String[] inherits;
+ private final String[] instanceOf;
+
+ /**
+ * @param name
+ * @param editorViewId
+ * @param inherits
+ * @param instanceOf
+ */
+ public SimpleEditorAdapter(String name, String editorViewId,
+ String[] inherits, String[] instanceOf)
+ {
+ this(name, (ImageDescriptor) null, editorViewId, inherits, instanceOf);
+ }
+
+ /**
+ * @param name
+ * @param icon
+ * @param editorViewId
+ * @param inherits
+ * @param instanceOf
+ */
+ public SimpleEditorAdapter(String name, ImageDescriptor icon,
+ String editorViewId,
+ String[] inherits, String[] instanceOf)
+ {
+ this(name, icon, editorViewId, null, inherits, instanceOf);
+ }
+
+ /**
+ * @param name
+ * @param icon
+ * @param editorViewId
+ * @param perspectiveId
+ * @param inherits
+ * @param instanceOf
+ */
+ public SimpleEditorAdapter(String name, ImageDescriptor icon,
+ String editorViewId, String perspectiveId,
+ String[] inherits, String[] instanceOf)
+ {
+ super(name, icon);
+ this.editorViewId = editorViewId;
+ this.perspectiveId = perspectiveId;
+ this.inherits = inherits;
+ this.instanceOf = instanceOf;
+ }
+
+ @Override
+ public boolean canHandle(ReadGraph g, Resource r) throws DatabaseException {
+ //System.out.println("canHandle: " + this.getClass().getCanonicalName());
+
+ // If not filters are defined, allow anything.
+ if ((inherits == null || inherits.length == 0)
+ && (instanceOf == null || instanceOf.length == 0))
+ return true;
+
+ if (inherits != null) {
+ for (String type : inherits) {
+ //System.out.println("type: " + type);
+ try {
+ if (g.isInheritedFrom(r, g.getResource(type)))
+ return true;
+ } catch (DatabaseException e) {
+ ErrorLogger.defaultLogError("BUG: SimpleEditorAdapter " + getClass().getName()
+ + " checked for inheritance of '" + type + "' but resource was not found", e);
+ }
+ }
+ }
+ if (instanceOf != null) {
+ for (String instance : instanceOf) {
+ //System.out.println("instance: " + instance);
+ try {
+ //System.out.println(instance);
+ if (g.isInstanceOf(r, g.getResource(instance)))
+ return true;
+ } catch (DatabaseException e) {
+ ErrorLogger.defaultLogError("BUG: SimpleEditorAdapter " + getClass().getName()
+ + " checked for instanceOf '" + instance + "' but the type was not found", e);
+ }
+ }
+ }
+ return false;
+ }
+
+
+ @Override
+ protected void openEditor(Resource r) throws Exception {
+ assert(editorViewId != null);
+
+ if (perspectiveId != null) {
+ openEditorWithIdInPerspective(editorViewId, new ResourceEditorInput(editorViewId, r), perspectiveId);
+ } else {
+ openEditorWithId(editorViewId, new ResourceEditorInput(editorViewId, r));
+ }
+ }
+
+ protected void openView(Resource r) throws Exception {
+ assert(editorViewId != null);
+
+ if (perspectiveId != null) {
+ openViewWithIdInPerspective(editorViewId, r, perspectiveId);
+ } else {
+ openViewWithId(editorViewId, r);
+ }
+ }
+
+}