1 /*******************************************************************************
2 * Copyright (c) 2017 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 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.ui.scl.scriptEditor;
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.ui.IEditorInput;
16 import org.eclipse.ui.IMemento;
17 import org.eclipse.ui.IPersistableElement;
18 import org.simantics.Simantics;
19 import org.simantics.db.exception.DatabaseException;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * @author Tuukka Lehtonen
27 public class SCLScriptEditorInput implements IEditorInput, IPersistableElement {
29 private static final Logger LOGGER = LoggerFactory.getLogger(SCLScriptEditorInput.class);
31 private final String scriptURI;
33 public SCLScriptEditorInput(String scriptURI) {
34 this.scriptURI = scriptURI;
37 public String getScriptURI() {
42 public boolean exists() {
43 // Not worth it testing this from the database.
47 @SuppressWarnings("unchecked")
49 public <T> T getAdapter(Class<T> adapter) {
50 if (adapter.equals(SCLScriptSource.class)) {
52 return (T) Simantics.getSession().syncRequest(new ReadSCLScriptSource(scriptURI));
53 } catch (DatabaseException e) {
54 LOGGER.error("Failed to read SCL script source", e);
57 if (adapter.equals(IPersistableElement.class))
63 public String getFactoryId() {
64 return "org.simantics.modeling.ui.scl.scriptEditor.inputFactory";
68 public String getName() {
69 int p = scriptURI.lastIndexOf('/');
71 return scriptURI.substring(p+1);
77 public String getToolTipText() {
82 public ImageDescriptor getImageDescriptor() {
87 public IPersistableElement getPersistable() {
92 public int hashCode() {
95 result = prime * result + ((scriptURI == null) ? 0 : scriptURI.hashCode());
100 public boolean equals(Object obj) {
103 if (obj == null || getClass() != obj.getClass())
105 SCLScriptEditorInput other = (SCLScriptEditorInput) obj;
106 return scriptURI.equals(other.scriptURI);
110 public void saveState(IMemento memento) {
111 memento.putTextData(scriptURI);