|
From: Matthias K <mat...@us...> - 2006-03-28 13:49:25
|
Update of /cvsroot/jcommander/plugins/org.jcommander.eclipsepatch.compare/compare/org/eclipse/ui/part In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5127/compare/org/eclipse/ui/part Added Files: FileEditorInput.java FileEditorInputFactory.java Log Message: org.eclipse.compare, extracted from the Eclipse CVS. Now independent of org.eclipse.ui.ide etc. --- NEW FILE: FileEditorInputFactory.java --- /******************************************************************************* * Copyright (c) 2000, 2004 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.ui.part; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.Path; import org.eclipse.ui.IElementFactory; import org.eclipse.ui.IMemento; /** * Factory for saving and restoring a <code>FileEditorInput</code>. * The stored representation of a <code>FileEditorInput</code> remembers * the full path of the file (that is, <code>IFile.getFullPath</code>). * <p> * The workbench will automatically create instances of this class as required. * It is not intended to be instantiated or subclassed by the client. * </p> */ public class FileEditorInputFactory implements IElementFactory { /** * Factory id. The workbench plug-in registers a factory by this name * with the "org.eclipse.ui.elementFactories" extension point. */ private static final String ID_FACTORY = "org.eclipse.ui.part.FileEditorInputFactory"; //$NON-NLS-1$ /** * Tag for the IFile.fullPath of the file resource. */ private static final String TAG_PATH = "path"; //$NON-NLS-1$ /** * Creates a new factory. */ public FileEditorInputFactory() { } /* (non-Javadoc) * Method declared on IElementFactory. */ public IAdaptable createElement(IMemento memento) { // Get the file name. String fileName = memento.getString(TAG_PATH); if (fileName == null) return null; // Get a handle to the IFile...which can be a handle // to a resource that does not exist in workspace IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile( new Path(fileName)); if (file != null) return new FileEditorInput(file); else return null; } /** * Returns the element factory id for this class. * * @return the element factory id */ public static String getFactoryId() { return ID_FACTORY; } /** * Saves the state of the given file editor input into the given memento. * * @param memento the storage area for element state * @param input the file editor input */ public static void saveState(IMemento memento, FileEditorInput input) { IFile file = input.getFile(); memento.putString(TAG_PATH, file.getFullPath().toString()); } } --- NEW FILE: FileEditorInput.java --- /******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.ui.part; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IStorage; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; //import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.IMemento; import org.eclipse.ui.IPathEditorInput; import org.eclipse.ui.IPersistableElement; import org.eclipse.ui.PlatformUI; //import org.eclipse.ui.ide.IDE; /** * Adapter for making a file resource a suitable input for an editor. * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> */ public class FileEditorInput implements IFileEditorInput, IPathEditorInput, IPersistableElement { private IFile file; /** * Creates an editor input based of the given file resource. * * @param file the file resource */ public FileEditorInput(IFile file) { if (file == null) { throw new IllegalArgumentException(); } this.file = file; } /* (non-Javadoc) * Method declared on Object. */ public int hashCode() { return file.hashCode(); } /* (non-Javadoc) * Method declared on Object. * * The <code>FileEditorInput</code> implementation of this <code>Object</code> * method bases the equality of two <code>FileEditorInput</code> objects on the * equality of their underlying <code>IFile</code> resources. */ public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof IFileEditorInput)) return false; IFileEditorInput other = (IFileEditorInput) obj; return file.equals(other.getFile()); } /* (non-Javadoc) * Method declared on IEditorInput. */ public boolean exists() { return file.exists(); } /* (non-Javadoc) * Method declared on IAdaptable. */ public Object getAdapter(Class adapter) { if (adapter == IFile.class) return file; return file.getAdapter(adapter); } /* (non-Javadoc) * Method declared on IPersistableElement. */ public String getFactoryId() { return FileEditorInputFactory.getFactoryId(); } /* (non-Javadoc) * Method declared on IFileEditorInput. */ public IFile getFile() { return file; } /* (non-Javadoc) * Method declared on IEditorInput. */ public ImageDescriptor getImageDescriptor() { //IContentType contentType = IDE.getContentType(file); return PlatformUI.getWorkbench().getEditorRegistry() .getImageDescriptor(file.getName(), null); } /* (non-Javadoc) * Method declared on IEditorInput. */ public String getName() { return file.getName(); } /* (non-Javadoc) * Method declared on IEditorInput. */ public IPersistableElement getPersistable() { return this; } /* (non-Javadoc) * Method declared on IStorageEditorInput. */ public IStorage getStorage() throws CoreException { return file; } /* (non-Javadoc) * Method declared on IEditorInput. */ public String getToolTipText() { return file.getFullPath().makeRelative().toString(); } /* (non-Javadoc) * Method declared on IPersistableElement. */ public void saveState(IMemento memento) { FileEditorInputFactory.saveState(memento, this); } /* (non-Javadoc) * Method declared on IPathEditorInput * @since 3.0 * @issue consider using an internal adapter for IPathEditorInput rather than adding this as API */ public IPath getPath() { return file.getLocation(); } /* (non-Javadoc) * @see java.lang.Object#toString() */ public String toString() { return getClass().getName() + "(" + getFile().getFullPath() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } } |