|
From: Matthias K <mat...@us...> - 2006-03-28 13:54:54
|
Update of /cvsroot/jcommander/plugins/org.jcommander.ui.compare/src/org/jcommander/compare In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9650/src/org/jcommander/compare Added Files: ComparePlugin.java CompareTest.java Log Message: JCommander compare support --- NEW FILE: ComparePlugin.java --- package org.jcommander.compare; import java.io.InputStream; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.program.Program; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.WorkbenchException; import org.eclipse.ui.plugin.*; import org.eclipse.compare.IStreamContentAccessor; import org.eclipse.compare.ITypedElement; import org.eclipse.compare.structuremergeviewer.IStructureComparator; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.resource.ImageDescriptor; import org.jcommander.ui.utils.EclipseBroker; import org.jcommander.ui.utils.ImageBroker; import org.osgi.framework.BundleContext; import org.apache.commons.vfs.*; /** * The main plugin class to be used in the desktop. */ public class ComparePlugin extends AbstractUIPlugin { //The shared instance. private static ComparePlugin plugin; public static final String COMPARE_PERSPECTIVE_ID = "org.jcommander.compare.Compare"; /** * * @author MatthiasK * FileInput encapsulates an FileObject into an class the * eclipse comparefunctions are able to use. */ private static class FileInput implements IStructureComparator, ITypedElement, IStreamContentAccessor { /** * The FileObject this FileInput represents */ private FileObject file; /** * The basedirectory from which we are comparing. * Not any longer needed, just not yet removed. */ public String base; //protected static final ImageRegistry imgRegistry = new ImageRegistry(); public boolean equals(Object other) { if (other instanceof ITypedElement) return getName().equals(((ITypedElement) other).getName()); return super.equals(other); } public int hashCode() { return getName().hashCode(); } public FileInput(FileObject file, String base) { //System.out.println(file.getName()); this.file=file; this.base=base; } public FileInput(FileObject file) { System.out.println(file.getName()); this.file=file; this.base=""; } /* (non-Javadoc) * @see org.eclipse.compare.structuremergeviewer.IStructureComparator#getChildren() */ public Object[] getChildren() { //System.out.println("getchildren"); try { if (file.getChildren()==null) { return null; } } catch (FileSystemException e) { return null; } Object[] children=null; FileObject[] filelist=null; try { children= new Object[file.getChildren().length]; filelist = file.getChildren(); } catch (FileSystemException e) { e.printStackTrace(); } for (int i = 0; i < filelist.length; i++) { children[i]=new FileInput(filelist[i],base); } return children; } /* (non-Javadoc) * @see org.eclipse.compare.ITypedElement#getName() */ public String getName() { //return file.getAbsolutePath().substring(base.length()); return file.getName().getBaseName(); } private Image getIconFromProgram(Program program) { Image image;// = (Image) imgRegistry.get(program.getName()); //if (image == null) { ImageData imageData = program.getImageData(); if (imageData != null) { image = new Image(null, imageData, imageData.getTransparencyMask()); //imgRegistry.put(program.getName(), image); } else { image = ImageBroker.FILE_ICON; } //} return image; } /* (non-Javadoc) * @see org.eclipse.compare.ITypedElement#getImage() */ public Image getImage() { Image iconImage = null; try { if (file.getType()==FileType.FOLDER) return ImageBroker.FOLDER_ICON; } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } int dot = file.getName().getBaseName().lastIndexOf('.'); if (dot != -1) { String extension = file.getName().getBaseName().substring(dot); Program program = Program.findProgram(extension); if (program != null) { //typeString = program.getName(); //typeString = extension.toUpperCase(); iconImage = getIconFromProgram(program); } else { iconImage = ImageBroker.FILE_ICON; } } else { iconImage = ImageBroker.FILE_ICON; } return iconImage; } /* (non-Javadoc) * @see org.eclipse.compare.ITypedElement#getType() */ public String getType() { // TODO Auto-generated method stub try { System.out.println((file.getType()==FileType.FOLDER)?FOLDER_TYPE:TEXT_TYPE); return (file.getType()==FileType.FOLDER)?FOLDER_TYPE:TEXT_TYPE; } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } /* (non-Javadoc) * @see org.eclipse.compare.IStreamContentAccessor#getContents() */ public InputStream getContents() throws CoreException { // TODO Auto-generated method stub try { if (file.getType()==FileType.FOLDER) return null; return file.getContent().getInputStream(); } catch (FileSystemException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return null; } } /** * The constructor. */ public ComparePlugin() { plugin = this; } /** * This method is called upon plug-in activation */ public void start(BundleContext context) throws Exception { super.start(context); } /** * This method is called when the plug-in is stopped */ public void stop(BundleContext context) throws Exception { super.stop(context); plugin = null; } /** * Returns the shared instance. * * @return the shared instance. */ public static ComparePlugin getDefault() { return plugin; } /** * Returns an image descriptor for the image file at the given * plug-in relative path. * * @param path the path * @return the image descriptor */ public static ImageDescriptor getImageDescriptor(String path) { return AbstractUIPlugin.imageDescriptorFromPlugin("org.jcommander.compare", path); } public void compare(FileObject left, FileObject right){ try { IWorkbenchPage page = PlatformUI.getWorkbench().showPerspective(COMPARE_PERSPECTIVE_ID, EclipseBroker.getWorkbenchWindow()); System.out.println("Compare!!!"); } catch (WorkbenchException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("ComparePlugin"); } } --- NEW FILE: CompareTest.java --- /** * */ package org.jcommander.compare; /** * @author MatthiasK * */ public class CompareTest { public static void compare(){ System.out.println("CompareTest"); } } |