View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: AbstractConfigurableView.java
13   * Created: 2007-02-02
14   * Author: fox
15   * $Id: FileEditorInput.java 3020 2009-07-17 14:41:19Z kpietak $
16   */
17  
18  package pl.edu.agh.cast.backward.resources;
19  
20  import org.eclipse.core.resources.IFile;
21  import org.eclipse.core.runtime.IPath;
22  import org.eclipse.jface.resource.ImageDescriptor;
23  import org.eclipse.ui.IEditorInput;
24  import org.eclipse.ui.IPathEditorInput;
25  import org.eclipse.ui.IPersistableElement;
26  
27  /**
28   * {@link IEditorInput} from {@link IFile}.
29   *
30   * @author AGH CAST Team
31   */
32  public class FileEditorInput implements IEditorInput, IPathEditorInput {
33  
34  	private IFile file;
35  
36  	public IPath getPath() {
37  		return file.getLocation();
38  	}
39  
40  	/**
41  	 * Creates new file editor input.
42  	 *
43  	 * @param file
44  	 *            file to use as input data source
45  	 */
46  	public FileEditorInput(IFile file) {
47  		this.file = file;
48  	}
49  
50  	public IFile getFile() {
51  		return file;
52  	}
53  
54  	/**
55  	 * {@inheritDoc}
56  	 *
57  	 * @see org.eclipse.ui.IEditorInput#exists()
58  	 */
59  	public boolean exists() {
60  		return file.exists();
61  	}
62  
63  	public ImageDescriptor getImageDescriptor() {
64  		return null;
65  	}
66  
67  	public String getName() {
68  		return file.getName();
69  	}
70  
71  	public IPersistableElement getPersistable() {
72  		return null;
73  	}
74  
75  	/**
76  	 * {@inheritDoc}
77  	 *
78  	 * @see org.eclipse.ui.IEditorInput#getToolTipText()
79  	 */
80  	public String getToolTipText() {
81  		return file.getLocation() == null ? "" : //$NON-NLS-1$
82  		        file.getLocation().toOSString();
83  	}
84  
85  	/**
86  	 * {@inheritDoc}
87  	 *
88  	 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
89  	 */
90  	@SuppressWarnings("unchecked")
91  	public Object getAdapter(Class adapter) {
92  		return null;
93  	}
94  
95  	/**
96  	 * {@inheritDoc}
97  	 *
98  	 * @see java.lang.Object#toString()
99  	 */
100 	@Override
101 	public String toString() {
102 		return file.getName();
103 	}
104 
105 	/**
106 	 * {@inheritDoc}
107 	 *
108 	 * @see java.lang.Object#equals(java.lang.Object)
109 	 */
110 	@Override
111 	public boolean equals(Object obj) {
112 		if (this == obj) {
113 			return true;
114 		}
115 		if (!(obj instanceof FileEditorInput)) {
116 			return false;
117 		}
118 
119 		FileEditorInput that = (FileEditorInput)obj;
120 		if (file == null) {
121 			if (that.file != null) {
122 				return false;
123 			}
124 		} else if (!file.equals(that.file)) {
125 			return false;
126 		}
127 		return true;
128 	}
129 
130 	/**
131 	 * {@inheritDoc}
132 	 *
133 	 * @see java.lang.Object#hashCode()
134 	 */
135 	@Override
136 	public int hashCode() {
137 		return file == null ? 1234 : file.hashCode();
138 	}
139 }