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