/******************************************************************************* * Copyright (c) 2008, 2015 IBM Corporation and others. * 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: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.wst.jsdt.web.ui.tests.translation; import java.io.InputStream; import org.eclipse.core.resources.IStorage; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.text.Document; import org.eclipse.ui.IPersistableElement; import org.eclipse.ui.IStorageEditorInput; import org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation; import org.eclipse.wst.sse.core.internal.util.DocumentInputStream; /** * @author nitin * */ public class JSTranslationEditorInput implements IStorageEditorInput { private class JSTranslationStorage implements IStorage { private final IJsTranslation fTranslation; final String fBaseLocation; public JSTranslationStorage(IJsTranslation translation, String baseLocation) { fTranslation = translation; fBaseLocation = baseLocation; } /* * (non-Javadoc) * * @see * org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) */ public Object getAdapter(Class adapter) { return null; } /* * (non-Javadoc) * * @see org.eclipse.core.resources.IStorage#getContents() */ public InputStream getContents() throws CoreException { return new DocumentInputStream(new Document(fTranslation.getJsText())); } /* * (non-Javadoc) * * @see org.eclipse.core.resources.IStorage#getFullPath() */ public IPath getFullPath() { return new Path(fBaseLocation + ".js"); //$NON-NLS-1$ } /* * (non-Javadoc) * * @see org.eclipse.core.resources.IStorage#getName() */ public String getName() { return new Path(fBaseLocation + ".js").lastSegment(); //$NON-NLS-1$ } /* * (non-Javadoc) * * @see org.eclipse.core.resources.IStorage#isReadOnly() */ public boolean isReadOnly() { return true; } } private JSTranslationStorage fStorage; /** * */ public JSTranslationEditorInput(IJsTranslation translation, String baseLocation) { fStorage = new JSTranslationStorage(translation, baseLocation); } /* * (non-Javadoc) * * @see org.eclipse.ui.IEditorInput#exists() */ public boolean exists() { return false; } /* * (non-Javadoc) * * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) */ public Object getAdapter(Class adapter) { return null; } /* * (non-Javadoc) * * @see org.eclipse.ui.IEditorInput#getImageDescriptor() */ public ImageDescriptor getImageDescriptor() { return null; } /* * (non-Javadoc) * * @see org.eclipse.ui.IEditorInput#getName() */ public String getName() { return fStorage.getName(); } /* * (non-Javadoc) * * @see org.eclipse.ui.IEditorInput#getPersistable() */ public IPersistableElement getPersistable() { return null; } /* * (non-Javadoc) * * @see org.eclipse.ui.IStorageEditorInput#getStorage() */ public IStorage getStorage() throws CoreException { return fStorage; } /* * (non-Javadoc) * * @see org.eclipse.ui.IEditorInput#getToolTipText() */ public String getToolTipText() { return fStorage.fBaseLocation; } }