]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.ui.workbench.editor;\r
13 \r
14 import org.eclipse.jface.resource.ImageDescriptor;\r
15 import org.simantics.db.ReadGraph;\r
16 import org.simantics.db.exception.DatabaseException;\r
17 \r
18 /**\r
19  * The purpose of an {@link EditorAdapter} is two-fold:\r
20  * <ol>\r
21  * <li>Checking whether an action can be performed on an input object (see\r
22  * {@link #canHandle(ReadGraph, Object)}</li>\r
23  * <li>Performing the action on that input object (see\r
24  * {@link #openEditor(Object)}</li>\r
25  * </ol>\r
26  * An action can be anything, but for the purposes this interface is intended\r
27  * for, the action is most often <em>opening an editor</em>.\r
28  * {@link #canHandle(ReadGraph, Object)} is performed within a graph database\r
29  * read transaction to make data model based decision making easier.\r
30  * \r
31  * <p>\r
32  * #openEditor(Object) shall be called only if\r
33  * {@link #canHandle(ReadGraph, Object)} returns true for the same input. It is\r
34  * possible that the data model has changed between invocations of\r
35  * {@link #canHandle(ReadGraph, Object)} and {@link #openEditor(Object)} so\r
36  * {@link #openEditor(Object)} implementations should always check the input\r
37  * throughly instead of assuming that the data model state in\r
38  * {@link #canHandle(ReadGraph, Object)} still holds.\r
39  * \r
40  * Clients should extend at least {@link AbstractEditorAdapter} instead of\r
41  * implementing this interface. This allows the extension point handler to set\r
42  * the priority of the adapter according to what is described in extensions. The\r
43  * only things that really need to be implemented are\r
44  * {@link #canHandle(ReadGraph, Object)} and {@link #openEditor(Object)}.\r
45  * \r
46  * <p>\r
47  * These classes are instantiated by {@link EditorRegistry} from Eclipse\r
48  * extensions so make sure that your implementations have a default constructor\r
49  * available, or no constructors at all.\r
50  * </p>\r
51  * \r
52  * @author Tuukka Lehtonen\r
53  * \r
54  * @see AbstractEditorAdapter\r
55  * @see AbstractResourceEditorAdapter\r
56  * @see SimpleEditorAdapter\r
57  * @see IEditorRegistry the front-end interface for handling these classes\r
58  * @see EditorRegistry an Eclipse extension point implementation of\r
59  *      IResourceEditorRegistry\r
60  * @see Prioritized\r
61  */\r
62 public interface EditorAdapter {\r
63 \r
64     /**\r
65      * @return\r
66      */\r
67     String getName();\r
68 \r
69     /**\r
70      * @param r\r
71      * @return\r
72      */\r
73     ImageDescriptor getIcon();\r
74 \r
75     /**\r
76      * @return\r
77      */\r
78     int getPriority();\r
79 \r
80     /**\r
81      * @param input the input of the editor\r
82      * @return <code>true</code> if this adapter can open an editor for the\r
83      *         specified input object\r
84      */\r
85     boolean canHandle(ReadGraph g, Object input) throws DatabaseException;\r
86 \r
87     /**\r
88      * @param input the input object for the editor to be opened\r
89      * @throws Exception PartInitException, or anything else that may happen\r
90      *         while performing the action may be thrown\r
91      */\r
92     void openEditor(Object input) throws Exception;\r
93 \r
94 }\r