X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.ui%2Fsrc%2Forg%2Fsimantics%2Fui%2Fworkbench%2Feditor%2FSimpleEditorAdapter.java;h=a37ada7afd1c9eca7990aaa96398602d372b496b;hb=fbfec9e8c7d8d768d9c6327060d9333b2feaea81;hp=d6e9c849edf8314cf5517a1128e93195333eb744;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/editor/SimpleEditorAdapter.java b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/editor/SimpleEditorAdapter.java index d6e9c849e..a37ada7af 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/editor/SimpleEditorAdapter.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/editor/SimpleEditorAdapter.java @@ -1,159 +1,159 @@ -/******************************************************************************* - * 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.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.ui.workbench.ResourceEditorInput; -import org.simantics.utils.ui.ErrorLogger; - -/** - * A very simple and limited implementation of ResourceEditorAdapter. - * - *
- * Easy to use because all necessary information can be given as constructor - * parameters. - *
- * - *- * Example: - * - *
- * class MyEditorAdapter extends SimpleEditorAdapter { - * MyEditorAdapter() { - * super("My Editor", "My.Editor.Id", - * new String[] { Builtins.URIs.Entity }, - * new String[] { Builtins.URIs.Entity }); - * } - * } - *- * - * allows opening the editor "My.Editor.Id" for a resource if it is - * inherited from the type Object or is an instance of Object. - * - * - * @author Tuukka Lehtonen - */ -public class SimpleEditorAdapter extends AbstractResourceEditorAdapter { - - private final String editorViewId; - private final String perspectiveId; - private final String[] inherits; - private final String[] instanceOf; - - /** - * @param name - * @param editorViewId - * @param inherits - * @param instanceOf - */ - public SimpleEditorAdapter(String name, String editorViewId, - String[] inherits, String[] instanceOf) - { - this(name, (ImageDescriptor) null, editorViewId, inherits, instanceOf); - } - - /** - * @param name - * @param icon - * @param editorViewId - * @param inherits - * @param instanceOf - */ - public SimpleEditorAdapter(String name, ImageDescriptor icon, - String editorViewId, - String[] inherits, String[] instanceOf) - { - this(name, icon, editorViewId, null, inherits, instanceOf); - } - - /** - * @param name - * @param icon - * @param editorViewId - * @param perspectiveId - * @param inherits - * @param instanceOf - */ - public SimpleEditorAdapter(String name, ImageDescriptor icon, - String editorViewId, String perspectiveId, - String[] inherits, String[] instanceOf) - { - super(name, icon); - this.editorViewId = editorViewId; - this.perspectiveId = perspectiveId; - this.inherits = inherits; - this.instanceOf = instanceOf; - } - - @Override - public boolean canHandle(ReadGraph g, Resource r) throws DatabaseException { - //System.out.println("canHandle: " + this.getClass().getCanonicalName()); - - // If not filters are defined, allow anything. - if ((inherits == null || inherits.length == 0) - && (instanceOf == null || instanceOf.length == 0)) - return true; - - if (inherits != null) { - for (String type : inherits) { - //System.out.println("type: " + type); - try { - if (g.isInheritedFrom(r, g.getResource(type))) - return true; - } catch (DatabaseException e) { - ErrorLogger.defaultLogError("BUG: SimpleEditorAdapter " + getClass().getName() - + " checked for inheritance of '" + type + "' but resource was not found", e); - } - } - } - if (instanceOf != null) { - for (String instance : instanceOf) { - //System.out.println("instance: " + instance); - try { - //System.out.println(instance); - if (g.isInstanceOf(r, g.getResource(instance))) - return true; - } catch (DatabaseException e) { - ErrorLogger.defaultLogError("BUG: SimpleEditorAdapter " + getClass().getName() - + " checked for instanceOf '" + instance + "' but the type was not found", e); - } - } - } - return false; - } - - - @Override - protected void openEditor(Resource r) throws Exception { - assert(editorViewId != null); - - if (perspectiveId != null) { - openEditorWithIdInPerspective(editorViewId, new ResourceEditorInput(editorViewId, r), perspectiveId); - } else { - openEditorWithId(editorViewId, new ResourceEditorInput(editorViewId, r)); - } - } - - protected void openView(Resource r) throws Exception { - assert(editorViewId != null); - - if (perspectiveId != null) { - openViewWithIdInPerspective(editorViewId, r, perspectiveId); - } else { - openViewWithId(editorViewId, r); - } - } - -} +/******************************************************************************* + * 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.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.ui.workbench.ResourceEditorInput; +import org.simantics.utils.ui.ErrorLogger; + +/** + * A very simple and limited implementation of ResourceEditorAdapter. + * + *
+ * Easy to use because all necessary information can be given as constructor + * parameters. + *
+ * + *+ * Example: + * + *
+ * class MyEditorAdapter extends SimpleEditorAdapter { + * MyEditorAdapter() { + * super("My Editor", "My.Editor.Id", + * new String[] { Builtins.URIs.Entity }, + * new String[] { Builtins.URIs.Entity }); + * } + * } + *+ * + * allows opening the editor "My.Editor.Id" for a resource if it is + * inherited from the type Object or is an instance of Object. + * + * + * @author Tuukka Lehtonen + */ +public class SimpleEditorAdapter extends AbstractResourceEditorAdapter { + + private final String editorViewId; + private final String perspectiveId; + private final String[] inherits; + private final String[] instanceOf; + + /** + * @param name + * @param editorViewId + * @param inherits + * @param instanceOf + */ + public SimpleEditorAdapter(String name, String editorViewId, + String[] inherits, String[] instanceOf) + { + this(name, (ImageDescriptor) null, editorViewId, inherits, instanceOf); + } + + /** + * @param name + * @param icon + * @param editorViewId + * @param inherits + * @param instanceOf + */ + public SimpleEditorAdapter(String name, ImageDescriptor icon, + String editorViewId, + String[] inherits, String[] instanceOf) + { + this(name, icon, editorViewId, null, inherits, instanceOf); + } + + /** + * @param name + * @param icon + * @param editorViewId + * @param perspectiveId + * @param inherits + * @param instanceOf + */ + public SimpleEditorAdapter(String name, ImageDescriptor icon, + String editorViewId, String perspectiveId, + String[] inherits, String[] instanceOf) + { + super(name, icon); + this.editorViewId = editorViewId; + this.perspectiveId = perspectiveId; + this.inherits = inherits; + this.instanceOf = instanceOf; + } + + @Override + public boolean canHandle(ReadGraph g, Resource r) throws DatabaseException { + //System.out.println("canHandle: " + this.getClass().getCanonicalName()); + + // If not filters are defined, allow anything. + if ((inherits == null || inherits.length == 0) + && (instanceOf == null || instanceOf.length == 0)) + return true; + + if (inherits != null) { + for (String type : inherits) { + //System.out.println("type: " + type); + try { + if (g.isInheritedFrom(r, g.getResource(type))) + return true; + } catch (DatabaseException e) { + ErrorLogger.defaultLogError("BUG: SimpleEditorAdapter " + getClass().getName() + + " checked for inheritance of '" + type + "' but resource was not found", e); + } + } + } + if (instanceOf != null) { + for (String instance : instanceOf) { + //System.out.println("instance: " + instance); + try { + //System.out.println(instance); + if (g.isInstanceOf(r, g.getResource(instance))) + return true; + } catch (DatabaseException e) { + ErrorLogger.defaultLogError("BUG: SimpleEditorAdapter " + getClass().getName() + + " checked for instanceOf '" + instance + "' but the type was not found", e); + } + } + } + return false; + } + + + @Override + protected void openEditor(Resource r) throws Exception { + assert(editorViewId != null); + + if (perspectiveId != null) { + openEditorWithIdInPerspective(editorViewId, new ResourceEditorInput(editorViewId, r), perspectiveId); + } else { + openEditorWithId(editorViewId, new ResourceEditorInput(editorViewId, r)); + } + } + + protected void openView(Resource r) throws Exception { + assert(editorViewId != null); + + if (perspectiveId != null) { + openViewWithIdInPerspective(editorViewId, r, perspectiveId); + } else { + openViewWithId(editorViewId, r); + } + } + +}