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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.ui.workbench.editor;
\r
14 import org.eclipse.jface.resource.ImageDescriptor;
\r
15 import org.simantics.db.ReadGraph;
\r
16 import org.simantics.db.exception.DatabaseException;
\r
19 * The purpose of an {@link EditorAdapter} is two-fold:
\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
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
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
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
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
52 * @author Tuukka Lehtonen
\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
62 public interface EditorAdapter {
\r
73 ImageDescriptor getIcon();
\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
85 boolean canHandle(ReadGraph g, Object input) throws DatabaseException;
\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
92 void openEditor(Object input) throws Exception;
\r