|
From: Matthias K <mat...@us...> - 2006-03-26 12:15:58
|
Update of /cvsroot/jcommander/incubator/matthias_kue/difftest/src/org/jcommander/ui/filepanel/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7890/matthias_kue/difftest/src/org/jcommander/ui/filepanel/actions Modified Files: CompareAction.java Log Message: editable Index: CompareAction.java =================================================================== RCS file: /cvsroot/jcommander/incubator/matthias_kue/difftest/src/org/jcommander/ui/filepanel/actions/CompareAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CompareAction.java 25 Mar 2006 12:14:27 -0000 1.1 --- CompareAction.java 26 Mar 2006 12:15:51 -0000 1.2 *************** *** 7,13 **** --- 7,15 ---- import java.io.FileInputStream; import java.io.FileNotFoundException; + import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; + import org.apache.commons.vfs.*; import org.eclipse.compare.*; import org.eclipse.compare.structuremergeviewer.Differencer; *************** *** 27,33 **** --- 29,39 ---- import org.eclipse.ui.WorkbenchException; import org.jcommander.compare.ComparePlugin; + import org.jcommander.compare.CompareTest; import org.jcommander.compare.perspective.ComparePerspectiveFactory; + import org.jcommander.ui.filepanel.FilePanelManagerProvider; + import org.jcommander.ui.filepanel.controls.FileTab; import org.jcommander.ui.utils.EclipseBroker; import org.jcommander.ui.utils.ImageBroker; + import org.jcommander.ui.utils.MessageDisplayer; /** *************** *** 45,55 **** } ! private static class FileInput implements IStructureComparator, ITypedElement, IStreamContentAccessor { - private File file; /** ! * ! */ ! public String base; --- 51,220 ---- } ! // private static class FileInput implements IStructureComparator, ITypedElement, IStreamContentAccessor, IEditableContent { ! // ! // private File file; ! // /** ! // * ! // */ ! // ! // 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(File file, String base) { ! // // TODO Auto-generated constructor stub ! // System.out.println(file.getName()); ! // this.file=file; ! // this.base=base; ! // } ! // ! // /* (non-Javadoc) ! // * @see org.eclipse.compare.structuremergeviewer.IStructureComparator#getChildren() ! // */ ! // public Object[] getChildren() { ! // //System.out.println("getchildren"); ! // if (file.listFiles()==null) ! // { ! // //System.out.println("Keine Kinder"); ! // return null; ! // ! // } ! // //System.out.println("Kinder->"); ! // //ArrayList list = new ArrayList(); ! // Object[] children= new Object[file.listFiles().length]; ! // File[] filelist = file.listFiles(); ! // ! // for (int i = 0; i < filelist.length; i++) { ! // //list.add(new FileInput(filelist[i])); ! // children[i]=new FileInput(filelist[i],base); ! // } ! // return children;//list.toArray(); ! // } ! // ! // /* (non-Javadoc) ! // * @see org.eclipse.compare.ITypedElement#getName() ! // */ ! // public String getName() { ! // //return file.getAbsolutePath().substring(base.length()); ! // return file.getName(); ! // } ! // ! // public 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; ! // if (file.isDirectory()) return ImageBroker.FOLDER_ICON; ! // int dot = file.getName().lastIndexOf('.'); ! // if (dot != -1) { ! // String extension = file.getName().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 ! // if (file.isDirectory()){ ! // System.out.println(FOLDER_TYPE); ! // return FOLDER_TYPE; ! // } ! // else { ! // String name=file.getName(); ! // int dot=name.lastIndexOf('.'); ! // String type=name.substring(dot+1); ! // System.out.println(type); ! // return type; ! // } ! // //System.out.println((file.isDirectory())?FOLDER_TYPE:TEXT_TYPE); ! // //return (file.isDirectory())?FOLDER_TYPE:TEXT_TYPE; ! // } ! // ! // /* (non-Javadoc) ! // * @see org.eclipse.compare.IStreamContentAccessor#getContents() ! // */ ! // public InputStream getContents() throws CoreException { ! // // TODO Auto-generated method stub ! // if (file.isDirectory()) return null; ! // try { ! // return new FileInputStream(file); ! // } catch (FileNotFoundException e) { ! // // TODO Auto-generated catch block ! // e.printStackTrace(); ! // } ! // return null; ! // } ! // ! // public boolean isEditable() { ! // // TODO Auto-generated method stub ! // return true; ! // } ! // ! // public void setContent(byte[] newContent) { ! // // TODO Auto-generated method stub ! // ! // } ! // ! // public ITypedElement replace(ITypedElement dest, ITypedElement src) { ! // // TODO Auto-generated method stub ! // return null; ! // } ! // ! // } ! ! /** ! * ! * @author MatthiasK ! * FileInput encapsulates an FileObject into an class the ! * eclipse comparefunctions are able to use. ! */ ! private static class FileInput implements IStructureComparator, ! ITypedElement, IStreamContentAccessor, IEditableContent { /** ! * 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; *************** *** 66,76 **** } ! public FileInput(File file, String base) { ! // TODO Auto-generated constructor stub ! System.out.println(file.getName()); this.file=file; this.base=base; } ! /* (non-Javadoc) * @see org.eclipse.compare.structuremergeviewer.IStructureComparator#getChildren() --- 231,246 ---- } ! 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() *************** *** 78,97 **** public Object[] getChildren() { //System.out.println("getchildren"); ! if (file.listFiles()==null) ! { ! //System.out.println("Keine Kinder"); ! return null; ! ! } ! //System.out.println("Kinder->"); ! //ArrayList list = new ArrayList(); ! Object[] children= new Object[file.listFiles().length]; ! File[] filelist = file.listFiles(); for (int i = 0; i < filelist.length; i++) { - //list.add(new FileInput(filelist[i])); children[i]=new FileInput(filelist[i],base); } ! return children;//list.toArray(); } --- 248,273 ---- 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; } *************** *** 101,108 **** public String getName() { //return file.getAbsolutePath().substring(base.length()); ! return file.getName(); } ! public Image getIconFromProgram(Program program) { Image image;// = (Image) imgRegistry.get(program.getName()); //if (image == null) { --- 277,284 ---- 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) { *************** *** 123,130 **** public Image getImage() { Image iconImage = null; ! if (file.isDirectory()) return ImageBroker.FOLDER_ICON; ! int dot = file.getName().lastIndexOf('.'); if (dot != -1) { ! String extension = file.getName().substring(dot); Program program = Program.findProgram(extension); if (program != null) { --- 299,311 ---- 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) { *************** *** 146,151 **** public String getType() { // TODO Auto-generated method stub ! System.out.println((file.isDirectory())?FOLDER_TYPE:TEXT_TYPE); ! return (file.isDirectory())?FOLDER_TYPE:TEXT_TYPE; } --- 327,345 ---- public String getType() { // TODO Auto-generated method stub ! try { ! if (file.getType()==FileType.FOLDER) { ! return FOLDER_TYPE; ! } else { ! String name=file.getName().getBaseName(); ! int dot=name.lastIndexOf('.'); ! return name.substring(dot+1); ! } ! //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; } *************** *** 155,171 **** public InputStream getContents() throws CoreException { // TODO Auto-generated method stub - if (file.isDirectory()) return null; try { ! return new FileInputStream(file); ! } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } ! ! } ! /* (non-Javadoc) --- 349,389 ---- 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; ! } ! ! public boolean isEditable() { ! // TODO Auto-generated method stub ! return true; ! } ! ! public void setContent(byte[] newContent) { ! // TODO Auto-generated method stub ! try { ! System.out.println("setContent"); ! file.getContent().getOutputStream().write(newContent); ! } catch (FileSystemException e) { ! // TODO Auto-generated catch block ! e.printStackTrace(); ! } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } + } + + public ITypedElement replace(ITypedElement dest, ITypedElement src) { + // TODO Implement! + System.out.println("replace"); return null; } ! ! } /* (non-Javadoc) *************** *** 181,232 **** */ public void run(IAction action) { ! // TODO Auto-generated method stub ! System.out.println("ddd"); ! // ComparePlugin c=ComparePlugin.getDefault(); ! // ! // try { ! // IWorkbenchPage page = PlatformUI.getWorkbench().showPerspective(ComparePlugin.COMPARE_PERSPECTIVE_ID, EclipseBroker.getWorkbenchWindow()); ! // } catch (WorkbenchException e) { ! // // TODO Auto-generated catch block ! // e.printStackTrace(); ! // } ! // ! // Shell shell = new Shell(); ! // CompareConfiguration cc = new CompareConfiguration(); ! // CompareEditorInput input = new CompareEditorInput(cc) { ! // protected Object prepareInput(IProgressMonitor monitor) throws ! // InvocationTargetException, InterruptedException { ! // Object fRoot; ! // Differencer d = new Differencer(); ! // System.out.println("Finding diffs"); ! // fRoot = d.findDifferences(false,monitor,null,null, ! // new FileInput(new File("D:\\Matthias\\Comp\\d1"),"D:\\Matthias\\Comp\\d1"), ! // new FileInput(new File("D:\\Matthias\\Comp\\d2"),"D:\\Matthias\\Comp\\d2")); ! // //r1, ! // //r2); ! // System.out.println("found diffs"); ! // ! // return fRoot; ! // /*return new DiffNode( ! // new ByteInput("left", ! // //"these\nare\nthe\ncontents"), ! // "c:\\Programm"), ! // new ByteInput("right", ! // //"theasdse\nare\nthe\ncontednts")); ! // "c:\\Programme"));*/ ! // } ! // }; ! // CompareUI.openCompareEditor(input); ! // /*TextEditor t = new TextEditor(); ! // try { ! // window.getActivePage().openEditor(null,"test"); ! // } catch (WorkbenchException e) { ! // // TODO Auto-generated catch block ! // e.printStackTrace(); ! // }*/ ! // ! // //CompareUI.openCompareEditor(input) ! // ! ComparePlugin.getDefault().compare(null, null); } --- 399,480 ---- */ public void run(IAction action) { ! /* ! * Code below copied from CompareByContentAction ! */ ! ! boolean error = true; ! ! FileTab tab = FilePanelManagerProvider ! .getTabManager() ! .getActiveTabMediator() ! .getFileTab(); ! ! /* Try to find a two file selection in the active panel */ ! ! FileObject leftFile = null; ! FileObject rightFile = null; ! ! FileObject[] selectedFiles = tab.getActiveFilePanel() ! .getPanelMediator() ! .getFilePanel() ! .getFileControl() ! .getSelectedFiles(); ! ! if(selectedFiles.length == 2) { ! error = false; ! ! // We have found an exact selection in the active panel ! leftFile = selectedFiles[0]; ! rightFile = selectedFiles[1]; ! } else ! if(selectedFiles.length == 1){ ! // Try to find a matching file in the other panel ! ! FileObject[] otherSelectedFiles = tab.getInactiveFilePanel() ! .getPanelMediator() ! .getFilePanel() ! .getFileControl() ! .getSelectedFiles(); ! ! if(otherSelectedFiles.length ==1) { ! error = false; ! ! leftFile = selectedFiles[0]; ! rightFile = otherSelectedFiles[0]; ! } ! } ! ! final FileObject fLeftFile=leftFile; ! final FileObject fRightFile=rightFile; ! if(!error) { ! ! try { ! IWorkbenchPage page = PlatformUI.getWorkbench().showPerspective(ComparePlugin.COMPARE_PERSPECTIVE_ID, EclipseBroker.getWorkbenchWindow()); ! } catch (WorkbenchException e) { ! // TODO Auto-generated catch block ! e.printStackTrace(); ! } ! ! CompareConfiguration cc = new CompareConfiguration(); ! cc.setLeftEditable(true); ! cc.setRightEditable(true); ! CompareEditorInput input = new CompareEditorInput(cc) { ! protected Object prepareInput(IProgressMonitor monitor) throws ! InvocationTargetException, InterruptedException { ! Object fRoot; ! Differencer d = new Differencer(); ! //System.out.println("Finding diffs"); ! fRoot = d.findDifferences(false,monitor,null,null, ! new FileInput(fLeftFile), ! new FileInput(fRightFile)); ! //System.out.println("found diffs"); ! ! return fRoot; ! } ! }; ! CompareUI.openCompareEditor(input); ! } else { ! MessageDisplayer.setStatusErrorMessage("Could not find suitable selections for performing diff"); ! } } |