]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.ui/src/org/simantics/ui/workbench/editor/EditorAdapter.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / workbench / editor / EditorAdapter.java
diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/editor/EditorAdapter.java b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/editor/EditorAdapter.java
new file mode 100644 (file)
index 0000000..1343cd5
--- /dev/null
@@ -0,0 +1,94 @@
+/*******************************************************************************\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.exception.DatabaseException;\r
+\r
+/**\r
+ * The purpose of an {@link EditorAdapter} is two-fold:\r
+ * <ol>\r
+ * <li>Checking whether an action can be performed on an input object (see\r
+ * {@link #canHandle(ReadGraph, Object)}</li>\r
+ * <li>Performing the action on that input object (see\r
+ * {@link #openEditor(Object)}</li>\r
+ * </ol>\r
+ * An action can be anything, but for the purposes this interface is intended\r
+ * for, the action is most often <em>opening an editor</em>.\r
+ * {@link #canHandle(ReadGraph, Object)} is performed within a graph database\r
+ * read transaction to make data model based decision making easier.\r
+ * \r
+ * <p>\r
+ * #openEditor(Object) shall be called only if\r
+ * {@link #canHandle(ReadGraph, Object)} returns true for the same input. It is\r
+ * possible that the data model has changed between invocations of\r
+ * {@link #canHandle(ReadGraph, Object)} and {@link #openEditor(Object)} so\r
+ * {@link #openEditor(Object)} implementations should always check the input\r
+ * throughly instead of assuming that the data model state in\r
+ * {@link #canHandle(ReadGraph, Object)} still holds.\r
+ * \r
+ * Clients should extend at least {@link AbstractEditorAdapter} instead of\r
+ * implementing this interface. This allows the extension point handler to set\r
+ * the priority of the adapter according to what is described in extensions. The\r
+ * only things that really need to be implemented are\r
+ * {@link #canHandle(ReadGraph, Object)} and {@link #openEditor(Object)}.\r
+ * \r
+ * <p>\r
+ * These classes are instantiated by {@link EditorRegistry} from Eclipse\r
+ * extensions so make sure that your implementations have a default constructor\r
+ * available, or no constructors at all.\r
+ * </p>\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ * \r
+ * @see AbstractEditorAdapter\r
+ * @see AbstractResourceEditorAdapter\r
+ * @see SimpleEditorAdapter\r
+ * @see IEditorRegistry the front-end interface for handling these classes\r
+ * @see EditorRegistry an Eclipse extension point implementation of\r
+ *      IResourceEditorRegistry\r
+ * @see Prioritized\r
+ */\r
+public interface EditorAdapter {\r
+\r
+    /**\r
+     * @return\r
+     */\r
+    String getName();\r
+\r
+    /**\r
+     * @param r\r
+     * @return\r
+     */\r
+    ImageDescriptor getIcon();\r
+\r
+    /**\r
+     * @return\r
+     */\r
+    int getPriority();\r
+\r
+    /**\r
+     * @param input the input of the editor\r
+     * @return <code>true</code> if this adapter can open an editor for the\r
+     *         specified input object\r
+     */\r
+    boolean canHandle(ReadGraph g, Object input) throws DatabaseException;\r
+\r
+    /**\r
+     * @param input the input object for the editor to be opened\r
+     * @throws Exception PartInitException, or anything else that may happen\r
+     *         while performing the action may be thrown\r
+     */\r
+    void openEditor(Object input) throws Exception;\r
+\r
+}\r