1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.ui.workbench.editor;
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.exception.DatabaseException;
19 * The purpose of an {@link EditorAdapter} is two-fold:
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>
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.
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.
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)}.
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.
52 * @author Tuukka Lehtonen
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
62 public interface EditorAdapter {
73 ImageDescriptor getIcon();
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
85 boolean canHandle(ReadGraph g, Object input) throws DatabaseException;
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
92 void openEditor(Object input) throws Exception;
95 * Returns id of the editor.
96 * @return id of the editor or null.