KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > model > LocationProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation 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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ant.internal.ui.model;
12
13 import org.eclipse.core.resources.IFile;
14 import org.eclipse.core.runtime.IPath;
15 import org.eclipse.ui.IEditorInput;
16 import org.eclipse.ui.IFileEditorInput;
17 import org.eclipse.ui.editors.text.ILocationProvider;
18
19 public class LocationProvider {
20     private IEditorInput fEditorInput;
21     
22     public LocationProvider(IEditorInput input) {
23         fEditorInput= input;
24     }
25
26     public IPath getLocation() {
27         if (fEditorInput instanceof IFileEditorInput) {
28             return ((IFileEditorInput)fEditorInput).getFile().getLocation();
29         }
30         ILocationProvider locationProvider= (ILocationProvider)fEditorInput.getAdapter(ILocationProvider.class);
31         if (locationProvider != null) {
32             return locationProvider.getPath(fEditorInput);
33         }
34         return null;
35     }
36     
37     public IFile getFile() {
38         if(fEditorInput instanceof IFileEditorInput) {
39             return ((IFileEditorInput)fEditorInput).getFile();
40         }
41         return null;
42     }
43 }
44
Popular Tags