1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ide.eclipse.adt.internal.editors.binaryxml; 18 19 import org.eclipse.core.resources.IStorage; 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.jface.resource.ImageDescriptor; 22 import org.eclipse.ui.IPersistableElement; 23 import org.eclipse.ui.IStorageEditorInput; 24 25 /** 26 * An editor input for a local file. 27 */ 28 public class XmlStorageEditorInput implements IStorageEditorInput { 29 30 /** 31 * Storage associated with this editor input 32 */ 33 IStorage mStorage = null; 34 35 /** 36 * Constructs an editor input on the given storage 37 * 38 * @param storage 39 */ 40 public XmlStorageEditorInput(IStorage storage) { 41 mStorage = storage; 42 } 43 44 /* (non-Javadoc) 45 * @see IStorageEditorInput#getStorage() 46 */ 47 @Override 48 public IStorage getStorage() throws CoreException { 49 return mStorage; 50 } 51 52 /* (non-Javadoc) 53 * @see IInput#getStorage() 54 */ 55 @Override 56 public boolean exists() { 57 return mStorage != null; 58 } 59 60 /* (non-Javadoc) 61 * @see IEditorInput#getImageDescriptor() 62 */ 63 @Override 64 public ImageDescriptor getImageDescriptor() { 65 return null; 66 } 67 68 /* (non-Javadoc) 69 * @see IEditorInput#getName() 70 */ 71 @Override 72 public String getName() { 73 return mStorage.getName(); 74 } 75 76 /* (non-Javadoc) 77 * @see IEditorInput#getPersistable() 78 */ 79 @Override 80 public IPersistableElement getPersistable() { 81 return null; 82 } 83 84 /* (non-Javadoc) 85 * @see IEditorInput#getToolTipText() 86 */ 87 @Override 88 public String getToolTipText() { 89 return mStorage.getFullPath() != null ? mStorage.getFullPath().toString() : mStorage 90 .getName(); 91 } 92 93 /* (non-Javadoc) 94 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) 95 */ 96 @Override 97 public Object getAdapter(Class adapter) { 98 return null; 99 } 100 101 /* (non-Javadoc) 102 * @see java.lang.Object#equals(java.lang.Object) 103 */ 104 @Override 105 public boolean equals(Object obj) { 106 if (obj instanceof XmlStorageEditorInput) { 107 return mStorage.equals(((XmlStorageEditorInput) obj).mStorage); 108 } 109 return super.equals(obj); 110 } 111 112 /* (non-Javadoc) 113 * @see java.lang.Object#hashCode() 114 */ 115 @Override 116 public int hashCode() { 117 return mStorage.hashCode(); 118 } 119 } 120