X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.ui%2Fsrc%2Forg%2Fsimantics%2Fui%2Fworkbench%2Feditor%2FEditorAdapter.java;fp=bundles%2Forg.simantics.ui%2Fsrc%2Forg%2Fsimantics%2Fui%2Fworkbench%2Feditor%2FEditorAdapter.java;h=1343cd51630b0e0db7ef7c221d484522d2a8f2ee;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git 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 index 000000000..1343cd516 --- /dev/null +++ b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/editor/EditorAdapter.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.ui.workbench.editor; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; + +/** + * The purpose of an {@link EditorAdapter} is two-fold: + *
    + *
  1. Checking whether an action can be performed on an input object (see + * {@link #canHandle(ReadGraph, Object)}
  2. + *
  3. Performing the action on that input object (see + * {@link #openEditor(Object)}
  4. + *
+ * An action can be anything, but for the purposes this interface is intended + * for, the action is most often opening an editor. + * {@link #canHandle(ReadGraph, Object)} is performed within a graph database + * read transaction to make data model based decision making easier. + * + *

+ * #openEditor(Object) shall be called only if + * {@link #canHandle(ReadGraph, Object)} returns true for the same input. It is + * possible that the data model has changed between invocations of + * {@link #canHandle(ReadGraph, Object)} and {@link #openEditor(Object)} so + * {@link #openEditor(Object)} implementations should always check the input + * throughly instead of assuming that the data model state in + * {@link #canHandle(ReadGraph, Object)} still holds. + * + * Clients should extend at least {@link AbstractEditorAdapter} instead of + * implementing this interface. This allows the extension point handler to set + * the priority of the adapter according to what is described in extensions. The + * only things that really need to be implemented are + * {@link #canHandle(ReadGraph, Object)} and {@link #openEditor(Object)}. + * + *

+ * These classes are instantiated by {@link EditorRegistry} from Eclipse + * extensions so make sure that your implementations have a default constructor + * available, or no constructors at all. + *

+ * + * @author Tuukka Lehtonen + * + * @see AbstractEditorAdapter + * @see AbstractResourceEditorAdapter + * @see SimpleEditorAdapter + * @see IEditorRegistry the front-end interface for handling these classes + * @see EditorRegistry an Eclipse extension point implementation of + * IResourceEditorRegistry + * @see Prioritized + */ +public interface EditorAdapter { + + /** + * @return + */ + String getName(); + + /** + * @param r + * @return + */ + ImageDescriptor getIcon(); + + /** + * @return + */ + int getPriority(); + + /** + * @param input the input of the editor + * @return true if this adapter can open an editor for the + * specified input object + */ + boolean canHandle(ReadGraph g, Object input) throws DatabaseException; + + /** + * @param input the input object for the editor to be opened + * @throws Exception PartInitException, or anything else that may happen + * while performing the action may be thrown + */ + void openEditor(Object input) throws Exception; + +}