1
/*******************************************************************************
2
* Copyright (c) 2000, 2009 QNX Software Systems and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* QNX Software Systems - Initial API and implementation
10
* Anton Leherbauer (Wind River Systems)
11
*******************************************************************************/
12
package org.eclipse.cdt.internal.ui.util;
17
import org.eclipse.core.filesystem.EFS;
18
import org.eclipse.core.filesystem.IFileStore;
19
import org.eclipse.core.filesystem.URIUtil;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.runtime.Assert;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.IPath;
24
import org.eclipse.ui.IMemento;
25
import org.eclipse.ui.ide.FileStoreEditorInput;
27
import org.eclipse.cdt.core.model.ITranslationUnit;
28
import org.eclipse.cdt.ui.CUIPlugin;
30
import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
34
* An EditorInput for an external (non-workspace) file.
36
public final class ExternalEditorInput extends FileStoreEditorInput implements ITranslationUnitEditorInput {
38
private final IPath location;
39
private final IResource markerResource;
40
private ITranslationUnit unit;
43
* Create an editor input for an external translation unit.
45
* @param unit the translation unit
47
public ExternalEditorInput(ITranslationUnit unit) {
48
this(unit.getLocationURI(), unit.getCProject().getProject());
49
Assert.isNotNull(unit);
54
* Create an editor input for an external file of the local file system.
56
* @param location the file system location
58
public ExternalEditorInput(IPath location) {
59
this(URIUtil.toURI(location), null);
63
* Create an editor input for an external file of the local file system.
65
* @param location the file system location
66
* @param markerResource the associated marker resource, may be <code>null</code>
68
public ExternalEditorInput(IPath location, IResource markerResource) {
69
this(URIUtil.toURI(location), markerResource);
73
* Create an editor input for a location URI.
75
* @param locationURI the location URI
77
public ExternalEditorInput(URI locationURI) {
78
this(locationURI, null);
82
* Create an editor input for a location URI.
84
* @param locationURI the location URI
85
* @param markerResource the associated marker resource, may be <code>null</code>
87
public ExternalEditorInput(URI locationURI, IResource markerResource) {
88
super(getFileStore(locationURI));
89
this.location = URIUtil.toPath(locationURI);
90
this.markerResource = markerResource;
93
private static IFileStore getFileStore(URI locationURI) {
95
return EFS.getStore(locationURI);
96
} catch (CoreException exc) {
103
* @see org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput#getTranslationUnit()
105
public ITranslationUnit getTranslationUnit() {
110
* @see org.eclipse.ui.ide.FileStoreEditorInput#getAdapter(java.lang.Class)
112
@SuppressWarnings("unchecked")
114
public Object getAdapter(Class adapter) {
115
if (adapter.isAssignableFrom(ITranslationUnit.class) && unit != null) {
118
return super.getAdapter(adapter);
122
* Return the resource where markers for this external editor input are stored
124
public IResource getMarkerResource() {
125
return markerResource;
129
* @see org.eclipse.ui.IPersistableElement#getFactoryId()
132
public String getFactoryId() {
133
if (getPath() != null) {
134
return ExternalEditorInputFactory.ID;
136
return super.getFactoryId();
140
* @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
143
public void saveState(IMemento memento) {
144
if (getPath() != null) {
145
ExternalEditorInputFactory.saveState(memento, this);
147
super.saveState(memento);
152
* @see org.eclipse.ui.IPathEditorInput#getPath()
153
* Note: ExternalEditorInput must not implement IPathEditorInput!
155
public IPath getPath() {