~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ExternalEditorInput.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
7
 
 *
8
 
 * Contributors:
9
 
 *     QNX Software Systems - Initial API and implementation
10
 
 *     Anton Leherbauer (Wind River Systems)
11
 
 *******************************************************************************/
12
 
package org.eclipse.cdt.internal.ui.util;
13
 
 
14
 
 
15
 
import java.net.URI;
16
 
 
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;
26
 
 
27
 
import org.eclipse.cdt.core.model.ITranslationUnit;
28
 
import org.eclipse.cdt.ui.CUIPlugin;
29
 
 
30
 
import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
31
 
 
32
 
 
33
 
/**
34
 
 * An EditorInput for an external (non-workspace) file.
35
 
 */
36
 
public final class ExternalEditorInput extends FileStoreEditorInput implements ITranslationUnitEditorInput {
37
 
           
38
 
        private final IPath location;
39
 
        private final IResource markerResource;
40
 
        private ITranslationUnit unit;
41
 
 
42
 
        /**
43
 
         * Create an editor input for an external translation unit.
44
 
         * 
45
 
         * @param unit  the translation unit
46
 
         */
47
 
        public ExternalEditorInput(ITranslationUnit unit) {
48
 
                this(unit.getLocationURI(), unit.getCProject().getProject());
49
 
                Assert.isNotNull(unit);
50
 
                this.unit = unit;
51
 
        }
52
 
 
53
 
        /**
54
 
         * Create an editor input for an external file of the local file system.
55
 
         * 
56
 
         * @param location  the file system location
57
 
         */
58
 
        public ExternalEditorInput(IPath location) {
59
 
                this(URIUtil.toURI(location), null);
60
 
        }
61
 
 
62
 
        /**
63
 
         * Create an editor input for an external file of the local file system.
64
 
         * 
65
 
         * @param location  the file system location
66
 
         * @param markerResource  the associated marker resource, may be <code>null</code>
67
 
         */
68
 
        public ExternalEditorInput(IPath location, IResource markerResource) {
69
 
                this(URIUtil.toURI(location), markerResource);
70
 
        }
71
 
 
72
 
        /**
73
 
         * Create an editor input for a location URI.
74
 
         * 
75
 
         * @param locationURI  the location URI
76
 
         */
77
 
        public ExternalEditorInput(URI locationURI) {
78
 
                this(locationURI, null);
79
 
        }
80
 
 
81
 
        /**
82
 
         * Create an editor input for a location URI.
83
 
         * 
84
 
         * @param locationURI  the location URI
85
 
         * @param markerResource  the associated marker resource, may be <code>null</code>
86
 
         */
87
 
        public ExternalEditorInput(URI locationURI, IResource markerResource) {
88
 
                super(getFileStore(locationURI));
89
 
                this.location = URIUtil.toPath(locationURI);
90
 
                this.markerResource = markerResource;
91
 
        }
92
 
 
93
 
        private static IFileStore getFileStore(URI locationURI) {
94
 
                try {
95
 
                        return EFS.getStore(locationURI);
96
 
                } catch (CoreException exc) {
97
 
                        CUIPlugin.log(exc);
98
 
                }
99
 
                return null;
100
 
        }
101
 
 
102
 
        /*
103
 
         * @see org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput#getTranslationUnit()
104
 
         */
105
 
        public ITranslationUnit getTranslationUnit() {
106
 
                return unit;
107
 
        }
108
 
 
109
 
        /*
110
 
         * @see org.eclipse.ui.ide.FileStoreEditorInput#getAdapter(java.lang.Class)
111
 
         */
112
 
        @SuppressWarnings("unchecked")
113
 
        @Override
114
 
        public Object getAdapter(Class adapter) {
115
 
                if (adapter.isAssignableFrom(ITranslationUnit.class) && unit != null) {
116
 
                        return unit;
117
 
                }
118
 
                return super.getAdapter(adapter);
119
 
        }
120
 
 
121
 
        /**
122
 
         * Return the resource where markers for this external editor input are stored
123
 
         */
124
 
        public IResource getMarkerResource() {
125
 
                return markerResource;
126
 
        }
127
 
 
128
 
        /*
129
 
         * @see org.eclipse.ui.IPersistableElement#getFactoryId()
130
 
         */
131
 
        @Override
132
 
        public String getFactoryId() {
133
 
                if (getPath() != null) {
134
 
                        return ExternalEditorInputFactory.ID;
135
 
                }
136
 
                return super.getFactoryId();
137
 
        }
138
 
 
139
 
        /*
140
 
         * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
141
 
         */
142
 
        @Override
143
 
        public void saveState(IMemento memento) {
144
 
                if (getPath() != null) {
145
 
                        ExternalEditorInputFactory.saveState(memento, this);
146
 
                } else {
147
 
                        super.saveState(memento);
148
 
                }
149
 
        }
150
 
 
151
 
        /*
152
 
         * @see org.eclipse.ui.IPathEditorInput#getPath()
153
 
         * Note: ExternalEditorInput must not implement IPathEditorInput!
154
 
         */
155
 
        public IPath getPath() {
156
 
                return location;
157
 
        }
158
 
        
159
 
}