From: <zh...@us...> - 2008-01-28 22:54:43
|
Revision: 607 http://cishell.svn.sourceforge.net/cishell/?rev=607&view=rev Author: zhang45 Date: 2008-01-28 14:54:39 -0800 (Mon, 28 Jan 2008) Log Message: ----------- Ticket181 view CSV file with Excel Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWithFactory.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java 2008-01-25 15:29:43 UTC (rev 606) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java 2008-01-28 22:54:39 UTC (rev 607) @@ -63,9 +63,28 @@ } return tempFile; } + + public File getTempFileCSV(){ //TC181 + File tempFile; + + String tempPath = System.getProperty("java.io.tmpdir"); + File tempDir = new File(tempPath+File.separator+"temp"); + if(!tempDir.exists()) + tempDir.mkdir(); + try{ + tempFile = File.createTempFile("xxx-Session-", ".csv", tempDir); + + }catch (IOException e){ + logger.log(LogService.LOG_ERROR, e.toString()); + tempFile = new File (tempPath+File.separator+"temp"+File.separator+"temp.csv"); + } + return tempFile; + } + public Data[] execute() { boolean lastSaveSuccessful = false; + boolean isCSVFile = false;//TC181 String format; Display display; @@ -78,19 +97,34 @@ } parentShell = windows[0].getShell(); display = PlatformUI.getWorkbench().getDisplay(); - tempFile = getTempFile(); + //tempFile = getTempFile(); TC181 for (int i = 0; i < data.length; i++){ Object theData = data[i].getData(); format = data[i].getFormat(); + if (theData instanceof File || format.startsWith("file:text/") || format.startsWith("file-ext:")){ - copy((File)data[i].getData(), tempFile); - lastSaveSuccessful = true; + + if (format.startsWith("file:text/csv") || format.startsWith("file-ext:csv")) + { + tempFile = getTempFileCSV(); + isCSVFile = true; + + } + else + { + tempFile = getTempFile(); + } + copy((File)data[i].getData(), tempFile); + lastSaveSuccessful = true; + + + }else{ final Converter[] converters = conversionManager.findConverters(data[i], "file-ext:*"); - + if (converters.length < 1) { guiBuilder.showError("No Converters", "No valid converters for data type: " + @@ -100,8 +134,18 @@ else if (converters.length == 1){ //If length=1, use the unique path to save it directly //and bring the text editor. - Data newData = converters[0].convert(data[i]); - copy((File)newData.getData(), tempFile); + Data newData = converters[0].convert(data[i]); + if (format.startsWith("prefuse.data.Table")) + { + tempFile = getTempFileCSV(); + isCSVFile = true; + } + else + { + tempFile = getTempFile(); + + } + copy((File)newData.getData(), tempFile); lastSaveSuccessful = true; } else { @@ -113,12 +157,21 @@ } } } - - - Display.getDefault().syncExec(new Runnable() { - public void run() { - program = Program.findProgram("txt"); - }}); + if (isCSVFile){//TC181 + Display.getDefault().syncExec(new Runnable() { + public void run() { + program = Program.findProgram("csv"); + }}); + + }else + { + Display.getDefault().syncExec(new Runnable() { + public void run() { + program = Program.findProgram("txt"); + }}); + + } + /* Display.getDefault().syncExec(new Runnable() { public void run() { Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java 2008-01-25 15:29:43 UTC (rev 606) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java 2008-01-28 22:54:39 UTC (rev 607) @@ -33,6 +33,7 @@ Program program; Program programTwo; Program programThree; + Program programFour; //TC181 File tempFile; public FileViewWith(Data[] data, Dictionary parameters, CIShellContext context) { @@ -132,9 +133,14 @@ public void run() { programThree = Program.findProgram("htm"); }}); + //TC181 + Display.getDefault().syncExec(new Runnable() { + public void run() { + programFour = Program.findProgram("csv"); + }}); - - if (program == null && programTwo == null && programThree == null) { + //TC181 + if (program == null && programTwo == null && programThree == null && programThree == null) { guiBuilder.showError("No Viewers for TXT, DOC, or HTM", "No valid viewers for .txt, .doc, or .htm files. " + "The file is located at: "+tempFile.getAbsolutePath(), @@ -158,6 +164,12 @@ public void run() { programThree.execute(tempFile.getAbsolutePath()); }}); + //TC181 + } else if (viewWith.equals("csv")) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + programFour.execute(tempFile.getAbsolutePath()); + }}); } else { // Try to run it with txt viewer... Display.getDefault().syncExec(new Runnable() { Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWithFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWithFactory.java 2008-01-25 15:29:43 UTC (rev 606) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWithFactory.java 2008-01-28 22:54:39 UTC (rev 607) @@ -30,6 +30,7 @@ Program programTxt; Program programDoc; Program programHtml; + Program programCsv; //TS181 private MetaTypeProvider provider; protected void activate(ComponentContext ctxt) { @@ -65,6 +66,12 @@ programHtml = Program.findProgram("htm"); }}); + //TC181 + Display.getDefault().syncExec(new Runnable() { + public void run() { + programCsv = Program.findProgram("csv"); + + }}); System.err.println(definition.getID()); @@ -83,6 +90,9 @@ if (programTxt != null) { possiblePrograms++; } + if (programCsv != null) { + possiblePrograms++; + } String[] myOptionLabels = new String[possiblePrograms]; String[] myOptionValues = new String[possiblePrograms]; @@ -98,6 +108,11 @@ myOptionLabels[counter] = programTxt.getName(); myOptionValues[counter++] = "txt"; } + //TC181 + if (programTxt != null) { + myOptionLabels[counter] = programCsv.getName(); + myOptionValues[counter++] = "csv"; + } AttributeDefinition ad = new BasicAttributeDefinition("viewWith", "View file as", "Type of viewer", AttributeDefinition.STRING /*string*/, 0, defValStringArray/*String[] defaultValue*/, null /*validator*/, myOptionLabels, myOptionValues); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |