File Browser: initial version 00/4400/36
Calixte DENIZET [Tue, 5 Jul 2011 16:08:07 +0000 (18:08 +0200)]
See SEP #68 for more information

Change-Id: Ie371c797102b2299e6ceff9e77a1531f6606d6ef

76 files changed:
scilab/modules/commons/src/c/fileutils.c
scilab/modules/commons/src/jni/CommonFileUtils.i
scilab/modules/gui/Makefile.am
scilab/modules/gui/Makefile.in
scilab/modules/gui/etc/main_toolbar.xml
scilab/modules/gui/images/icons/16x16/filebrowser/application-pdf.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/binary.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/dynamic-blue-up.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/emblem-readonly.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/filter.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/folder-open.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/folder.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/go-next.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/go-previous.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/icon_scilab.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/image-x-generic.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/open-scilab-folder.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/open-user-home.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/scilab-folder.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/system-search.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/text-csv.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/text-html.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/text-x-generic.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/text-xml.png [new file with mode: 0644]
scilab/modules/gui/images/icons/16x16/filebrowser/user-home.png [new file with mode: 0644]
scilab/modules/localization/src/java/org/scilab/modules/localization/MessagesJNI.java
scilab/modules/shell/src/c/GetCommandLine.c
scilab/modules/shell/src/c/fileio_Import.def
scilab/modules/shell/src/c/ui_data_Import.def
scilab/modules/ui_data/Makefile.am
scilab/modules/ui_data/Makefile.in
scilab/modules/ui_data/includes/FileBrowserChDir.h [new file with mode: 0644]
scilab/modules/ui_data/includes/gw_ui_data.h
scilab/modules/ui_data/sci_gateway/c/gw_ui_data.c
scilab/modules/ui_data/sci_gateway/cpp/sci_filebrowser.cpp [new file with mode: 0644]
scilab/modules/ui_data/sci_gateway/ui_data_gateway.xml
scilab/modules/ui_data/src/c/ui_data.vcxproj
scilab/modules/ui_data/src/c/ui_data.vcxproj.filters
scilab/modules/ui_data/src/cpp/FileBrowserChDir.cpp [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/FileBrowser.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/AbstractScilabTreeTableModel.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/FileBrowserRowSorter.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/FileNode.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/FileUtils.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileBrowser.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileBrowserComponent.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileBrowserHistory.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileBrowserModel.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileSelectorComboBox.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileSelectorFilter.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileSelectorPanel.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabTreeTableCellRenderer.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabTreeTableModel.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabTreeTableModelAdapter.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/SwingScilabFileBrowser.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/SwingScilabTreeTable.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/ChangeCWDAction.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/CloseAction.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/EditFileWithDefaultAppAction.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/ExecuteCommandAction.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/ExecuteFileInConsoleAction.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/ExecuteFileInXcosAction.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/GoToHomeAction.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/GoToSCIAction.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/LoadFileAsGraphAction.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/LoadFileInScilabAction.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/OpenFileInSciNotesAction.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/OpenFileWithDefaultAppAction.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/ValidateAction.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/tabfactory/FileBrowserTab.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/tabfactory/FileBrowserTabFactory.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/utils/UiDataMessages.java
scilab/modules/ui_data/src/jni/FileBrowser.cpp [new file with mode: 0644]
scilab/modules/ui_data/src/jni/FileBrowser.giws.xml [new file with mode: 0644]
scilab/modules/ui_data/src/jni/FileBrowser.hxx [new file with mode: 0644]
scilab/modules/ui_data/src/noui_data/noui_data.c

index a74f17b..2591647 100644 (file)
 
 #ifdef _MSC_VER
 #include <Windows.h>
+#include <stdio.h>
 #include "charEncoding.h"
 #else
 #include <sys/types.h>
 #include <dirent.h>
-#include "PATH_MAX.h"
 #endif
 
+#include "PATH_MAX.h"
 #include <string.h>
 #include "fileutils.h"
 #include "MALLOC.h"
 
+/*--------------------------------------------------------------------------*/
 #ifdef _MSC_VER
 int isEmptyDirectory(char * dirName)
 {
     wchar_t *wcpath = NULL;
+       wchar_t wdirpath[PATH_MAX + FILENAME_MAX + 1];
     HANDLE hFile;
     WIN32_FIND_DATAW FileInformation;
     int ret = 1;
 
     wcpath = to_wide_string(dirName);
+       swprintf(wdirpath, wcslen(wcpath) + 2 + 1, L"%s\\*", wcpath);
+       FREE(wcpath);
 
-    hFile = FindFirstFileW(wcpath, &FileInformation);
-
-    if (hFile != INVALID_HANDLE_VALUE)
+    hFile = FindFirstFileW(wdirpath, &FileInformation);
+    
+    if (hFile == INVALID_HANDLE_VALUE)
     {
-        FREE(wcpath);
         return 0;
     }
 
@@ -52,18 +56,19 @@ int isEmptyDirectory(char * dirName)
         break;
     } while (FindNextFileW(hFile, &FileInformation) == TRUE);
 
-    FREE(wcpath);
     FindClose(hFile);
-
+       
     return ret;
 }
+/*--------------------------------------------------------------------------*/
 #else
+/*--------------------------------------------------------------------------*/
 int isEmptyDirectory(char * dirName)
 {
     DIR *dir = NULL;
 #ifdef __APPLE__
-  struct dirent *ptr;
-  struct dirent *result;
+    struct dirent *ptr;
+    struct dirent *result;
 #else
     struct dirent64 *ptr;
     struct dirent64 *result;
@@ -90,17 +95,17 @@ int isEmptyDirectory(char * dirName)
 #ifdef __APPLE__
     while ((readdir_r(dir, ptr, &result) == 0)  && (result != NULL))
 #else
-    while ((readdir64_r(dir, ptr, &result) == 0)  && (result != NULL))
+        while ((readdir64_r(dir, ptr, &result) == 0)  && (result != NULL))
 #endif
-    {
-        if (!strcmp(ptr->d_name, ".") || !strcmp(ptr->d_name, ".."))
         {
-            continue;
-        }
+            if (!strcmp(ptr->d_name, ".") || !strcmp(ptr->d_name, ".."))
+            {
+                continue;
+            }
 
-        ret = 0;
-        break;
-    }
+            ret = 0;
+            break;
+        }
 
     FREE(ptr);
     closedir(dir);
index 945e25a..de444a2 100644 (file)
@@ -83,7 +83,7 @@ public class";
  }";
 
 /* JavaDoc */
-%javamethodmodifiers getSCIHOME() "
+%javamethodmodifiers isEmptyDirectory(String dirName) "
  /**
    * Test if a directory is empty or not
    * @param dirName the directory name
index 11447c9..772c85e 100644 (file)
@@ -315,6 +315,26 @@ images/icons/16x16/search/file.png \
 images/icons/16x16/search/line-found.png \
 images/icons/16x16/search/scilab-file.png \
 images/icons/16x16/actions/save-and-execute.png \
+images/icons/16x16/filebrowser/application-pdf.png \
+images/icons/16x16/filebrowser/binary.png \
+images/icons/16x16/filebrowser/dynamic-blue-up.png \
+images/icons/16x16/filebrowser/emblem-readonly.png \
+images/icons/16x16/filebrowser/filter.png \
+images/icons/16x16/filebrowser/folder-open.png \
+images/icons/16x16/filebrowser/folder.png \
+images/icons/16x16/filebrowser/go-next.png \
+images/icons/16x16/filebrowser/go-previous.png \
+images/icons/16x16/filebrowser/icon_scilab.png \
+images/icons/16x16/filebrowser/image-x-generic.png \
+images/icons/16x16/filebrowser/open-scilab-folder.png \
+images/icons/16x16/filebrowser/open-user-home.png \
+images/icons/16x16/filebrowser/scilab-folder.png \
+images/icons/16x16/filebrowser/system-search.png \
+images/icons/16x16/filebrowser/text-csv.png \
+images/icons/16x16/filebrowser/text-html.png \
+images/icons/16x16/filebrowser/text-x-generic.png \
+images/icons/16x16/filebrowser/text-xml.png \
+images/icons/16x16/filebrowser/user-home.png \
 images/icons/aboutscilab.png \
 images/icons/accessories-text-editor.png \
 images/icons/applications-system.png \
index dbfb9b2..c4cf52e 100644 (file)
@@ -888,6 +888,26 @@ images/icons/16x16/search/file.png \
 images/icons/16x16/search/line-found.png \
 images/icons/16x16/search/scilab-file.png \
 images/icons/16x16/actions/save-and-execute.png \
+images/icons/16x16/filebrowser/application-pdf.png \
+images/icons/16x16/filebrowser/binary.png \
+images/icons/16x16/filebrowser/dynamic-blue-up.png \
+images/icons/16x16/filebrowser/emblem-readonly.png \
+images/icons/16x16/filebrowser/filter.png \
+images/icons/16x16/filebrowser/folder-open.png \
+images/icons/16x16/filebrowser/folder.png \
+images/icons/16x16/filebrowser/go-next.png \
+images/icons/16x16/filebrowser/go-previous.png \
+images/icons/16x16/filebrowser/icon_scilab.png \
+images/icons/16x16/filebrowser/image-x-generic.png \
+images/icons/16x16/filebrowser/open-scilab-folder.png \
+images/icons/16x16/filebrowser/open-user-home.png \
+images/icons/16x16/filebrowser/scilab-folder.png \
+images/icons/16x16/filebrowser/system-search.png \
+images/icons/16x16/filebrowser/text-csv.png \
+images/icons/16x16/filebrowser/text-html.png \
+images/icons/16x16/filebrowser/text-x-generic.png \
+images/icons/16x16/filebrowser/text-xml.png \
+images/icons/16x16/filebrowser/user-home.png \
 images/icons/aboutscilab.png \
 images/icons/accessories-text-editor.png \
 images/icons/applications-system.png \
index 3ba8142..d4e0dda 100644 (file)
 
     <separator/>
 
-    <!-- Change current directory -->
-    <button icon="folder.png" tooltiptext="Change Current Directory">
-        <callback 
-        instruction='
-          %newDir = uigetdir(pwd(), gettext("Select a directory"));
-          if ~(%newDir == "") then 
-            cd(%newDir);
-          end
-          clear("%newDir");'
-        type="0"/>
-    </button> 
-
-    <separator/>
-
     <!-- Change font -->
     <button icon="format-text-bold.png" tooltiptext="Choose Font...">
         <callback instruction='org.scilab.modules.gui.bridge.CallScilabBridge.changeConsoleFont' type="3"/>
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/application-pdf.png b/scilab/modules/gui/images/icons/16x16/filebrowser/application-pdf.png
new file mode 100644 (file)
index 0000000..ec2c8c9
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/application-pdf.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/binary.png b/scilab/modules/gui/images/icons/16x16/filebrowser/binary.png
new file mode 100644 (file)
index 0000000..1103016
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/binary.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/dynamic-blue-up.png b/scilab/modules/gui/images/icons/16x16/filebrowser/dynamic-blue-up.png
new file mode 100644 (file)
index 0000000..9f2cce8
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/dynamic-blue-up.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/emblem-readonly.png b/scilab/modules/gui/images/icons/16x16/filebrowser/emblem-readonly.png
new file mode 100644 (file)
index 0000000..0466619
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/emblem-readonly.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/filter.png b/scilab/modules/gui/images/icons/16x16/filebrowser/filter.png
new file mode 100644 (file)
index 0000000..709636c
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/filter.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/folder-open.png b/scilab/modules/gui/images/icons/16x16/filebrowser/folder-open.png
new file mode 100644 (file)
index 0000000..b67403d
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/folder-open.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/folder.png b/scilab/modules/gui/images/icons/16x16/filebrowser/folder.png
new file mode 100644 (file)
index 0000000..65bd0bb
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/folder.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/go-next.png b/scilab/modules/gui/images/icons/16x16/filebrowser/go-next.png
new file mode 100644 (file)
index 0000000..6ef8de7
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/go-next.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/go-previous.png b/scilab/modules/gui/images/icons/16x16/filebrowser/go-previous.png
new file mode 100644 (file)
index 0000000..659cd90
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/go-previous.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/icon_scilab.png b/scilab/modules/gui/images/icons/16x16/filebrowser/icon_scilab.png
new file mode 100644 (file)
index 0000000..8b4927c
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/icon_scilab.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/image-x-generic.png b/scilab/modules/gui/images/icons/16x16/filebrowser/image-x-generic.png
new file mode 100644 (file)
index 0000000..68da502
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/image-x-generic.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/open-scilab-folder.png b/scilab/modules/gui/images/icons/16x16/filebrowser/open-scilab-folder.png
new file mode 100644 (file)
index 0000000..742a9d5
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/open-scilab-folder.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/open-user-home.png b/scilab/modules/gui/images/icons/16x16/filebrowser/open-user-home.png
new file mode 100644 (file)
index 0000000..79570d5
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/open-user-home.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/scilab-folder.png b/scilab/modules/gui/images/icons/16x16/filebrowser/scilab-folder.png
new file mode 100644 (file)
index 0000000..93ee4ff
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/scilab-folder.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/system-search.png b/scilab/modules/gui/images/icons/16x16/filebrowser/system-search.png
new file mode 100644 (file)
index 0000000..fd7f0b0
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/system-search.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/text-csv.png b/scilab/modules/gui/images/icons/16x16/filebrowser/text-csv.png
new file mode 100644 (file)
index 0000000..b1e79bc
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/text-csv.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/text-html.png b/scilab/modules/gui/images/icons/16x16/filebrowser/text-html.png
new file mode 100644 (file)
index 0000000..53014ab
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/text-html.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/text-x-generic.png b/scilab/modules/gui/images/icons/16x16/filebrowser/text-x-generic.png
new file mode 100644 (file)
index 0000000..2383a3b
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/text-x-generic.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/text-xml.png b/scilab/modules/gui/images/icons/16x16/filebrowser/text-xml.png
new file mode 100644 (file)
index 0000000..2ae96f2
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/text-xml.png differ
diff --git a/scilab/modules/gui/images/icons/16x16/filebrowser/user-home.png b/scilab/modules/gui/images/icons/16x16/filebrowser/user-home.png
new file mode 100644 (file)
index 0000000..7b9110d
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/filebrowser/user-home.png differ
index a48b589..b33d47c 100644 (file)
@@ -27,12 +27,11 @@ public class MessagesJNI {
 
   static {
     try {
-
-         if (System.getProperty("os.name").toLowerCase().contains("windows") != true) {
-             if (System.getProperty("testngTests")!=null) {
-                 System.loadLibrary("scilab");
-             }
-         }
+        if (System.getProperty("os.name").toLowerCase().contains("windows") != true) {
+            if (System.getProperty("testngTests")!=null) {
+                System.loadLibrary("scilab");
+            }
+        }
         System.loadLibrary("scilocalization");
     } catch (SecurityException e) {
         System.err.println("A security manager exists and does not allow the loading of the specified dynamic library.");
index 1aefd40..5b21dd3 100644 (file)
@@ -33,6 +33,8 @@
 #include "TermReadAndProcess.h"
 #include "../../../jvm/includes/InitializeJVM.h"
 #include "UpdateBrowseVar.h"
+#include "scicurdir.h"
+#include "FileBrowserChDir.h"
 #ifdef _MSC_VER
 
 #include "mmapWindows.h"
@@ -239,7 +241,16 @@ void C2F(zzledt)(char *buffer,int *buf_size,int *len_line,int * eof,
           }
          if (getScilabMode() != SCILAB_NWNI)
          {
+             char *cwd = NULL;
+             int err = 0;
+
               UpdateBrowseVar(TRUE);
+             cwd = scigetcwd(&err);
+             if (cwd)
+             {
+                 FileBrowserChDir(cwd);
+                 FREE(cwd);
+             }
          }
           __CreateThread(&WatchGetCmdLineThread, &watchGetCommandLine);
           WatchGetCmdLineThreadAlive = TRUE;
index 23c307b..270b17a 100644 (file)
@@ -1,3 +1,4 @@
        LIBRARY    fileio.dll
 
 EXPORTS 
+scigetcwd
\ No newline at end of file
index d5cf008..d804ae9 100644 (file)
@@ -2,4 +2,5 @@ LIBRARY    sciui_data.dll
 
 
 EXPORTS
-UpdateBrowseVar
\ No newline at end of file
+UpdateBrowseVar
+FileBrowserChDir
\ No newline at end of file
index 8c394f7..ccea264 100644 (file)
@@ -28,15 +28,18 @@ libsciui_data_la_etc_DATA = etc/ui_data.quit \
 include $(top_srcdir)/Makefile.incl.am
 
 UI_DATA_JNI_SOURCES = src/jni/BrowseVar.cpp \
-                                         src/jni/EditVar.cpp
+                     src/jni/EditVar.cpp \
+                     src/jni/FileBrowser.cpp
 
 UI_DATA_C_SOURCES = 
 
-UI_DATA_CPP_SOURCES = src/cpp/UpdateBrowseVar.cpp
+UI_DATA_CPP_SOURCES = src/cpp/UpdateBrowseVar.cpp \
+                     src/cpp/FileBrowserChDir.cpp
 
 GIWS_WRAPPERS = \
 src/jni/BrowseVar.giws.xml \
-src/jni/EditVar.giws.xml
+src/jni/EditVar.giws.xml \
+src/jni/FileBrowser.giws.xml
 
 if GIWS
 BUILT_SOURCES=giws
@@ -45,8 +48,9 @@ endif
 
 GATEWAY_C_SOURCES = sci_gateway/c/gw_ui_data.c
 
-GATEWAY_CPP_SOURCES =  sci_gateway/cpp/sci_editvar.cpp \
-                                               sci_gateway/cpp/sci_browsevar.cpp
+GATEWAY_CPP_SOURCES = sci_gateway/cpp/sci_editvar.cpp \
+                     sci_gateway/cpp/sci_browsevar.cpp \
+                     sci_gateway/cpp/sci_filebrowser.cpp
 
 libsciui_data_la_CFLAGS= $(JAVA_JNI_INCLUDE) \
                        -I$(top_srcdir)/libs/MALLOC/includes/ \
index 4691beb..ed63a0a 100644 (file)
@@ -119,8 +119,10 @@ LTLIBRARIES = $(noinst_LTLIBRARIES) $(pkglib_LTLIBRARIES)
 libsciui_data_algo_la_LIBADD =
 am__objects_1 =
 am__objects_2 = libsciui_data_algo_la-BrowseVar.lo \
-       libsciui_data_algo_la-EditVar.lo
-am__objects_3 = libsciui_data_algo_la-UpdateBrowseVar.lo
+       libsciui_data_algo_la-EditVar.lo \
+       libsciui_data_algo_la-FileBrowser.lo
+am__objects_3 = libsciui_data_algo_la-UpdateBrowseVar.lo \
+       libsciui_data_algo_la-FileBrowserChDir.lo
 am_libsciui_data_algo_la_OBJECTS = $(am__objects_1) $(am__objects_2) \
        $(am__objects_3)
 libsciui_data_algo_la_OBJECTS = $(am_libsciui_data_algo_la_OBJECTS)
@@ -140,7 +142,8 @@ libsciui_data_la_DEPENDENCIES = libsciui_data-algo.la \
        $(top_builddir)/modules/output_stream/libscioutput_stream.la
 am__objects_5 = libsciui_data_la-gw_ui_data.lo
 am__objects_6 = libsciui_data_la-sci_editvar.lo \
-       libsciui_data_la-sci_browsevar.lo
+       libsciui_data_la-sci_browsevar.lo \
+       libsciui_data_la-sci_filebrowser.lo
 am_libsciui_data_la_OBJECTS = $(am__objects_5) $(am__objects_6)
 libsciui_data_la_OBJECTS = $(am_libsciui_data_la_OBJECTS)
 libsciui_data_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
@@ -513,18 +516,23 @@ HELP_CHAPTERDIR = help/
 HELP_CHAPTERFILE = addchapter.sce
 HELP_CHAPTERLANG = en_US fr_FR pt_BR
 UI_DATA_JNI_SOURCES = src/jni/BrowseVar.cpp \
-                                         src/jni/EditVar.cpp
+                     src/jni/EditVar.cpp \
+                     src/jni/FileBrowser.cpp
 
 UI_DATA_C_SOURCES = 
-UI_DATA_CPP_SOURCES = src/cpp/UpdateBrowseVar.cpp
+UI_DATA_CPP_SOURCES = src/cpp/UpdateBrowseVar.cpp \
+                     src/cpp/FileBrowserChDir.cpp
+
 GIWS_WRAPPERS = \
 src/jni/BrowseVar.giws.xml \
-src/jni/EditVar.giws.xml
+src/jni/EditVar.giws.xml \
+src/jni/FileBrowser.giws.xml
 
 @GIWS_TRUE@BUILT_SOURCES = giws
 GATEWAY_C_SOURCES = sci_gateway/c/gw_ui_data.c
 GATEWAY_CPP_SOURCES = sci_gateway/cpp/sci_editvar.cpp \
-                                               sci_gateway/cpp/sci_browsevar.cpp
+                     sci_gateway/cpp/sci_browsevar.cpp \
+                     sci_gateway/cpp/sci_filebrowser.cpp
 
 libsciui_data_la_CFLAGS = $(JAVA_JNI_INCLUDE) \
                        -I$(top_srcdir)/libs/MALLOC/includes/ \
@@ -686,11 +694,14 @@ distclean-compile:
 
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_algo_la-BrowseVar.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_algo_la-EditVar.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_algo_la-FileBrowser.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_algo_la-FileBrowserChDir.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_algo_la-UpdateBrowseVar.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_disable_la-noui_data.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_la-gw_ui_data.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_la-sci_browsevar.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_la-sci_editvar.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_la-sci_filebrowser.Plo@am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@   $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -762,6 +773,13 @@ libsciui_data_algo_la-EditVar.lo: src/jni/EditVar.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsciui_data_algo_la-EditVar.lo `test -f 'src/jni/EditVar.cpp' || echo '$(srcdir)/'`src/jni/EditVar.cpp
 
+libsciui_data_algo_la-FileBrowser.lo: src/jni/FileBrowser.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libsciui_data_algo_la-FileBrowser.lo -MD -MP -MF $(DEPDIR)/libsciui_data_algo_la-FileBrowser.Tpo -c -o libsciui_data_algo_la-FileBrowser.lo `test -f 'src/jni/FileBrowser.cpp' || echo '$(srcdir)/'`src/jni/FileBrowser.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libsciui_data_algo_la-FileBrowser.Tpo $(DEPDIR)/libsciui_data_algo_la-FileBrowser.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='src/jni/FileBrowser.cpp' object='libsciui_data_algo_la-FileBrowser.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsciui_data_algo_la-FileBrowser.lo `test -f 'src/jni/FileBrowser.cpp' || echo '$(srcdir)/'`src/jni/FileBrowser.cpp
+
 libsciui_data_algo_la-UpdateBrowseVar.lo: src/cpp/UpdateBrowseVar.cpp
 @am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libsciui_data_algo_la-UpdateBrowseVar.lo -MD -MP -MF $(DEPDIR)/libsciui_data_algo_la-UpdateBrowseVar.Tpo -c -o libsciui_data_algo_la-UpdateBrowseVar.lo `test -f 'src/cpp/UpdateBrowseVar.cpp' || echo '$(srcdir)/'`src/cpp/UpdateBrowseVar.cpp
 @am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libsciui_data_algo_la-UpdateBrowseVar.Tpo $(DEPDIR)/libsciui_data_algo_la-UpdateBrowseVar.Plo
@@ -769,6 +787,13 @@ libsciui_data_algo_la-UpdateBrowseVar.lo: src/cpp/UpdateBrowseVar.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsciui_data_algo_la-UpdateBrowseVar.lo `test -f 'src/cpp/UpdateBrowseVar.cpp' || echo '$(srcdir)/'`src/cpp/UpdateBrowseVar.cpp
 
+libsciui_data_algo_la-FileBrowserChDir.lo: src/cpp/FileBrowserChDir.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libsciui_data_algo_la-FileBrowserChDir.lo -MD -MP -MF $(DEPDIR)/libsciui_data_algo_la-FileBrowserChDir.Tpo -c -o libsciui_data_algo_la-FileBrowserChDir.lo `test -f 'src/cpp/FileBrowserChDir.cpp' || echo '$(srcdir)/'`src/cpp/FileBrowserChDir.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libsciui_data_algo_la-FileBrowserChDir.Tpo $(DEPDIR)/libsciui_data_algo_la-FileBrowserChDir.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='src/cpp/FileBrowserChDir.cpp' object='libsciui_data_algo_la-FileBrowserChDir.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsciui_data_algo_la-FileBrowserChDir.lo `test -f 'src/cpp/FileBrowserChDir.cpp' || echo '$(srcdir)/'`src/cpp/FileBrowserChDir.cpp
+
 libsciui_data_la-sci_editvar.lo: sci_gateway/cpp/sci_editvar.cpp
 @am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libsciui_data_la-sci_editvar.lo -MD -MP -MF $(DEPDIR)/libsciui_data_la-sci_editvar.Tpo -c -o libsciui_data_la-sci_editvar.lo `test -f 'sci_gateway/cpp/sci_editvar.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_editvar.cpp
 @am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libsciui_data_la-sci_editvar.Tpo $(DEPDIR)/libsciui_data_la-sci_editvar.Plo
@@ -783,6 +808,13 @@ libsciui_data_la-sci_browsevar.lo: sci_gateway/cpp/sci_browsevar.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsciui_data_la-sci_browsevar.lo `test -f 'sci_gateway/cpp/sci_browsevar.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_browsevar.cpp
 
+libsciui_data_la-sci_filebrowser.lo: sci_gateway/cpp/sci_filebrowser.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libsciui_data_la-sci_filebrowser.lo -MD -MP -MF $(DEPDIR)/libsciui_data_la-sci_filebrowser.Tpo -c -o libsciui_data_la-sci_filebrowser.lo `test -f 'sci_gateway/cpp/sci_filebrowser.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_filebrowser.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libsciui_data_la-sci_filebrowser.Tpo $(DEPDIR)/libsciui_data_la-sci_filebrowser.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_filebrowser.cpp' object='libsciui_data_la-sci_filebrowser.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsciui_data_la-sci_filebrowser.lo `test -f 'sci_gateway/cpp/sci_filebrowser.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_filebrowser.cpp
+
 mostlyclean-libtool:
        -rm -f *.lo
 
diff --git a/scilab/modules/ui_data/includes/FileBrowserChDir.h b/scilab/modules/ui_data/includes/FileBrowserChDir.h
new file mode 100644 (file)
index 0000000..ef5f09e
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#ifndef __FILEBROWSERCHDIR_H__
+#define __FILEBROWSERCHDIR_H__
+/*--------------------------------------------------------------------------*/#
+#include "dynlib_ui_data.h"
+/**
+* FileBrowserChDir function
+* @param baseDir the current working directory
+*/
+UI_DATA_IMPEXP void FileBrowserChDir(char * baseDir);
+
+/*--------------------------------------------------------------------------*/
+#endif /* __FILEBROWSERCHDIR_H__ */
index fce5111..9a76279 100644 (file)
@@ -18,6 +18,7 @@
 UI_DATA_IMPEXP int gw_ui_data(void);
 UI_DATA_IMPEXP int sci_editvar(char* fname, unsigned long l);
 UI_DATA_IMPEXP int sci_browsevar(char* fname, unsigned long l);
+UI_DATA_IMPEXP int sci_filebrowser(char* fname, unsigned long l);
 /*--------------------------------------------------------------------------*/
 #endif /* __GW_UI_DATA__ */
 /*--------------------------------------------------------------------------*/
index f3a92eb..08cf8bc 100644 (file)
@@ -17,7 +17,6 @@
 #include "scilabmode.h"
 #include "localization.h"
 #include "Scierror.h"
-#include "BOOL.h"
 #include "loadOnUseClassPath.h"
 /*--------------------------------------------------------------------------*/
 /*static BOOL loadedDep = FALSE;*/
@@ -25,7 +24,8 @@
 static gw_generic_table Tab[]=
 {
     {sci_editvar, "editvar"},
-    {sci_browsevar, "browsevar"}
+    {sci_browsevar, "browsevar"},
+    {sci_filebrowser, "filebrowser"}
 };
 /*--------------------------------------------------------------------------*/
 int gw_ui_data(void)
diff --git a/scilab/modules/ui_data/sci_gateway/cpp/sci_filebrowser.cpp b/scilab/modules/ui_data/sci_gateway/cpp/sci_filebrowser.cpp
new file mode 100644 (file)
index 0000000..082d010
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "FileBrowser.hxx"
+
+extern "C"
+{
+#include "gw_ui_data.h"
+#include "getScilabJavaVM.h"
+#include "stack-c.h"
+}
+
+using namespace org_scilab_modules_ui_data;
+
+/*--------------------------------------------------------------------------*/
+int sci_filebrowser(char *fname, unsigned long fname_len)
+{
+    CheckRhs(0, 0);
+    CheckLhs(0, 1);
+
+    FileBrowser::openFileBrowser(getScilabJavaVM());
+
+    LhsVar(1) = 0;
+    PutLhsVar();
+
+    return 0;
+}
index e14c5be..dfb2169 100644 (file)
@@ -25,4 +25,5 @@
 
 <PRIMITIVE gatewayId="67" primitiveId="1" primitiveName="editvar" />
 <PRIMITIVE gatewayId="67" primitiveId="2" primitiveName="browsevar" />
+<PRIMITIVE gatewayId="67" primitiveId="3" primitiveName="filebrowser" />
 </GATEWAY>
index 8d59398..18a04a5 100644 (file)
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_filebrowser.cpp" />
+    <ClCompile Include="..\cpp\FileBrowserChDir.cpp" />
     <ClCompile Include="..\cpp\UpdateBrowseVar.cpp" />
     <ClCompile Include="..\jni\BrowseVar.cpp" />
+    <ClCompile Include="..\jni\FileBrowser.cpp" />
     <ClCompile Include="DllmainUi_data.c" />
     <ClCompile Include="..\jni\EditVar.cpp" />
     <ClCompile Include="..\jni\GiwsException.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_editvar.cpp" />
   </ItemGroup>
   <ItemGroup>
+    <ClInclude Include="..\..\includes\FileBrowserChDir.h" />
     <ClInclude Include="..\..\includes\UpdateBrowseVar.h" />
     <ClInclude Include="..\jni\BrowseVar.hxx" />
     <ClInclude Include="..\..\includes\dynlib_ui_data.h" />
     <ClInclude Include="..\jni\EditVar.hxx" />
+    <ClInclude Include="..\jni\FileBrowser.hxx" />
     <ClInclude Include="..\jni\GiwsException.hxx" />
     <ClInclude Include="..\..\includes\gw_ui_data.h" />
   </ItemGroup>
index d9558ec..fa34f05 100644 (file)
     <ClCompile Include="..\cpp\UpdateBrowseVar.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\jni\FileBrowser.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\cpp\FileBrowserChDir.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_filebrowser.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\jni\BrowseVar.hxx">
     <ClInclude Include="..\..\includes\UpdateBrowseVar.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\includes\FileBrowserChDir.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="..\jni\FileBrowser.hxx">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="LibScilab_Import.def">
diff --git a/scilab/modules/ui_data/src/cpp/FileBrowserChDir.cpp b/scilab/modules/ui_data/src/cpp/FileBrowserChDir.cpp
new file mode 100644 (file)
index 0000000..6b760f4
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "FileBrowser.hxx"
+
+extern "C"
+{
+#include "FileBrowserChDir.h"
+#include "getScilabJavaVM.h"
+}
+using namespace org_scilab_modules_ui_data;
+
+/*--------------------------------------------------------------------------*/
+void FileBrowserChDir(char * baseDir)
+{
+    if (getScilabJavaVM())
+    {
+       FileBrowser::setBaseDir(getScilabJavaVM(), baseDir);
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/FileBrowser.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/FileBrowser.java
new file mode 100644 (file)
index 0000000..25f9ba8
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data;
+
+import org.scilab.modules.ui_data.filebrowser.ScilabFileBrowser;
+
+/**
+ * Main class used in the GIWS interface
+ * @author Calixte DENIZET
+ */
+public final class FileBrowser {
+
+    /**
+     * Open the file browser
+     */
+    public static void openFileBrowser() {
+        ScilabFileBrowser.getFileBrowser();
+    }
+
+    /**
+     * Set the base directory
+     * @param baseDir the base directory
+     */
+    public static void setBaseDir(String baseDir) {
+        ScilabFileBrowser.setBaseDir(baseDir);
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/AbstractScilabTreeTableModel.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/AbstractScilabTreeTableModel.java
new file mode 100644 (file)
index 0000000..98625f1
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser;
+
+import javax.swing.tree.TreePath;
+import javax.swing.event.EventListenerList;
+import javax.swing.event.TreeModelEvent;
+import javax.swing.event.TreeModelListener;
+
+/**
+ * The tree table model abstract implementation
+ * @author Calixte DENIZET
+ */
+public abstract class AbstractScilabTreeTableModel implements ScilabTreeTableModel {
+
+    protected Object root;
+    protected Object parent;
+    protected EventListenerList listenerList = new EventListenerList();
+
+    /**
+     * Default constructor
+     * @param root the root element
+     */
+    public AbstractScilabTreeTableModel(Object root) {
+        this.root = root;
+    }
+
+    /**
+     * Default constructor
+     */
+    public AbstractScilabTreeTableModel() { }
+
+    /**
+     * Set the root element
+     * @param root the root
+     */
+    public void setRoot(Object root) {
+        this.root = root;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public Object getRoot() {
+        return root;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public boolean isLeaf(Object node) {
+        return ((FileNode) node).isLeaf();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public void valueForPathChanged(TreePath path, Object newValue) { }
+
+    /**
+     * {@inheritdoc}
+     */
+    public int getIndexOfChild(Object parent, Object child) {
+        if (parent == root && this.parent != null) {
+            return ((FileNode) child).getPosition() + 1;
+        } else {
+            return ((FileNode) child).getPosition();
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public void addTreeModelListener(TreeModelListener l) {
+        listenerList.add(TreeModelListener.class, l);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public void removeTreeModelListener(TreeModelListener l) {
+        listenerList.remove(TreeModelListener.class, l);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected void fireTreeNodesChanged(Object source, Object[] path, int[] childIndices, Object[] children) {
+        Object[] listeners = listenerList.getListenerList();
+        TreeModelEvent e = null;
+        for (int i = listeners.length - 2; i >= 0; i -= 2) {
+            if (listeners[i] == TreeModelListener.class) {
+                if (e == null) {
+                    e = new TreeModelEvent(source, path, childIndices, children);
+                }
+                ((TreeModelListener) listeners[i + 1]).treeNodesChanged(e);
+            }
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected void fireTreeNodesInserted(Object source, Object[] path, int[] childIndices, Object[] children) {
+        Object[] listeners = listenerList.getListenerList();
+        TreeModelEvent e = null;
+        for (int i = listeners.length - 2; i >= 0; i -= 2) {
+            if (listeners[i] == TreeModelListener.class) {
+                if (e == null) {
+                    e = new TreeModelEvent(source, path, childIndices, children);
+                }
+                ((TreeModelListener) listeners[i + 1]).treeNodesInserted(e);
+            }
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected void fireTreeNodesRemoved(Object source, Object[] path, int[] childIndices, Object[] children) {
+        Object[] listeners = listenerList.getListenerList();
+        TreeModelEvent e = null;
+        for (int i = listeners.length - 2; i >= 0; i -= 2) {
+            if (listeners[i] == TreeModelListener.class) {
+                if (e == null) {
+                    e = new TreeModelEvent(source, path, childIndices, children);
+                }
+                ((TreeModelListener) listeners[i + 1]).treeNodesRemoved(e);
+            }
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected void fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children) {
+        Object[] listeners = listenerList.getListenerList();
+        TreeModelEvent e = null;
+        for (int i = listeners.length - 2; i >= 0; i -= 2) {
+            if (listeners[i] == TreeModelListener.class) {
+                if (e == null) {
+                    e = new TreeModelEvent(source, path, childIndices, children);
+                }
+                ((TreeModelListener) listeners[i + 1]).treeStructureChanged(e);
+            }
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public Class getColumnClass(int column) {
+        return Object.class;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public boolean isCellEditable(Object node, int column) {
+        return false;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public void setValueAt(Object aValue, Object node, int column) { }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/FileBrowserRowSorter.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/FileBrowserRowSorter.java
new file mode 100644 (file)
index 0000000..1c54c2a
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser;
+
+import java.awt.Cursor;
+import java.util.Enumeration;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.swing.JTable;
+import javax.swing.JTree;
+import javax.swing.RowSorter;
+import javax.swing.SortOrder;
+import javax.swing.SwingUtilities;
+import javax.swing.table.TableModel;
+import javax.swing.tree.TreePath;
+
+import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
+
+/**
+ * A RowSorter to sort the files in the view
+ * @author Calixte DENIZET
+ */
+public class FileBrowserRowSorter extends RowSorter<TableModel> {
+
+    private JTree tree;
+    private JTable table;
+    private List<RowSorter.SortKey> sortKeys;
+
+    /**
+     * Default constructor
+     * @param tree the associated JTree
+     * @param table the associated JTable
+     */
+    public FileBrowserRowSorter(JTree tree, JTable table) {
+        this.tree = tree;
+        this.table = table;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void allRowsChanged() { }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int convertRowIndexToModel(int index) {
+        return index;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int convertRowIndexToView(int index) {
+        return index;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public TableModel getModel() {
+        return table.getModel();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getModelRowCount() {
+        return tree.getRowCount();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<RowSorter.SortKey> getSortKeys() {
+        if (sortKeys == null) {
+            List<RowSorter.SortKey> list = new ArrayList<RowSorter.SortKey>();
+            list.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
+            setSortKeys(list);
+        }
+
+        return sortKeys;
+    }
+
+    public int getViewRowCount() {
+        return getModelRowCount();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void modelStructureChanged() { }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void rowsDeleted(int firstRow, int endRow) { }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void rowsInserted(int firstRow, int endRow) { }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void rowsUpdated(int firstRow, int endRow) { }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void rowsUpdated(int firstRow, int endRow, int column) { }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setSortKeys(List<? extends RowSorter.SortKey> keys) {
+        this.sortKeys = Collections.unmodifiableList(new ArrayList<SortKey>(keys));
+        fireSortOrderChanged();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void toggleSortOrder(int column) {
+        SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, table).setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+
+        ScilabFileBrowserModel model = (ScilabFileBrowserModel) tree.getModel();
+        FileNode root = (FileNode) model.getRoot();
+        Enumeration<TreePath> en = tree.getExpandedDescendants(new TreePath(model.getRoot()));
+        root.toggleSortOrder(table.getColumnName(column));
+
+        root.resetChildren();
+        for (int i = 0; i < tree.getRowCount(); i++) {
+            FileNode fn = (FileNode) tree.getPathForRow(i).getLastPathComponent();
+            fn.resetChildren();
+        }
+
+        model.fireTreeStructureChanged(model, new TreePath(root).getPath(), null, null);
+        if (en != null) {
+            while (en.hasMoreElements()) {
+                tree.expandPath(en.nextElement());
+            }
+        }
+
+        SortOrder order = root.getOrder();
+        List<RowSorter.SortKey> list = new ArrayList<RowSorter.SortKey>();
+        list.add(new RowSorter.SortKey(column, order));
+        setSortKeys(list);
+
+        table.repaint();
+
+        SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, table).setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+    }
+}
\ No newline at end of file
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/FileNode.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/FileNode.java
new file mode 100644 (file)
index 0000000..3fe0dcd
--- /dev/null
@@ -0,0 +1,385 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.regex.Pattern;
+
+import javax.swing.Icon;
+import javax.swing.SortOrder;
+
+import org.scilab.modules.commons.CommonFileUtils;
+import org.scilab.modules.commons.ScilabConstants;
+import org.scilab.modules.core.Scilab;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+
+/**
+ * Handle a File as a node in the JTree
+ * @author Calixte DENIZET
+ */
+public class FileNode {
+
+    public static final int NAMEORDER = 1;
+    public static final int SIZEORDER = 2;
+    public static final int DATEORDER = 3;
+    public static final int TYPEORDER = 4;
+
+    private final FileFilter FILTER = new FileFilter() {
+            public boolean accept(File f) {
+                return !f.isHidden() && f.canRead() && (f.isFile() || f.isDirectory()) && (pat == null || pat.matcher(f.getName()).matches());
+            }
+        };
+
+    private static final File userHomeDir = new File(ScilabConstants.USERHOME);
+    private static final File SCIDIR = new File(System.getenv("SCI"));
+    private static boolean isWindows = Scilab.isWindowsPlateform();
+
+    protected File file;
+    protected Icon icon;
+    protected Object[] children;
+    protected File[] childrenFiles;
+    protected long lastModified;
+    protected boolean isFile;
+    protected boolean canRead;
+    protected boolean canWrite;
+    protected boolean isEmpty;
+    private boolean userHome;
+    private boolean sci;
+    private int order = 1;
+    private Pattern pat;
+    private int position;
+
+    /**
+     * Default constructor
+     * @param file the file in this node
+     */
+    public FileNode(File file, int position) {
+        this.file = file;
+        this.position = position;
+        init();
+    }
+
+    public int getPosition() {
+        return position;
+    }
+
+    /**
+     * @param pat the pattern to filter the files
+     */
+    public void setFilter(Pattern pat) {
+        this.pat = pat;
+        reset();
+    }
+
+    /**
+     * @param order the order to use to sort the file. If order is positive, then ascending order is used.
+     */
+    public void setOrder(int order) {
+        this.order = order;
+    }
+
+    /**
+     * @param order the order to use to sort the file.
+     * @param ascending if true, the ascending order is used
+     */
+    public void setOrder(int order, boolean ascending) {
+        int sign = ascending ? +1 : -1;
+        setOrder(sign * order);
+    }
+
+    /**
+     * @return the used order
+     */
+    public SortOrder getOrder() {
+        return order > 0 ? SortOrder.ASCENDING : SortOrder.DESCENDING;
+    }
+
+    /**
+     * Sort a column according to the natural order for its.
+     * @param nameColumn the column name
+     */
+    public void toggleSortOrder(String nameColumn) {
+        if (nameColumn.equals(UiDataMessages.NAME_COLUMN)) {
+            if (Math.abs(order) == NAMEORDER) {
+                setOrder(-order);
+            } else {
+                setOrder(NAMEORDER);
+            }
+        } else if (nameColumn.equals(UiDataMessages.TYPE_COLUMN)) {
+            if (Math.abs(order) == TYPEORDER) {
+                setOrder(-order);
+            } else {
+                setOrder(TYPEORDER);
+            }
+        } else if (nameColumn.equals(UiDataMessages.SIZE_COLUMN)) {
+            if (Math.abs(order) == SIZEORDER) {
+                setOrder(-order);
+            } else {
+                setOrder(SIZEORDER);
+            }
+        } else if (nameColumn.equals(UiDataMessages.LASTMODIF_COLUMN)) {
+            if (Math.abs(order) == DATEORDER) {
+                setOrder(-order);
+            } else {
+                setOrder(DATEORDER);
+            }
+        }
+    }
+
+    /**
+     * Sort the files
+     * @param order the order to use
+     * @param files the files to order
+     * @return the ordered FileNodes
+     */
+    protected static FileNode[] orderFiles(int order, File[] files) {
+        final Comparator alpha;
+        if (isWindows) {
+            alpha = new Comparator<File>() {
+                public int compare(File f1, File f2) {
+                    if ((f1.isFile() && f2.isFile()) || (f1.isDirectory() && f2.isDirectory())) {
+                        int diff = f1.getName().compareToIgnoreCase(f2.getName());
+                        if (diff == 0) {
+                            diff = f1.getName().compareTo(f2.getName());
+                        }
+                        return diff;
+                    } else if (f1.isFile()) {
+                        return 1;
+                    }
+                    return -1;
+                }
+
+                public boolean equals(Object obj) {
+                    return false;
+                }
+            };
+        } else {
+            alpha = new Comparator<File>() {
+                public int compare(File f1, File f2) {
+                    if ((f1.isFile() && f2.isFile()) || (f1.isDirectory() && f2.isDirectory())) {
+                        return f1.getName().compareTo(f2.getName());
+                    } else if (f1.isFile()) {
+                        return 1;
+                    }
+                    return -1;
+                }
+
+                public boolean equals(Object obj) {
+                    return false;
+                }
+            };
+        }
+
+        switch (Math.abs(order)) {
+        case SIZEORDER :
+            Arrays.sort(files, new Comparator<File>() {
+                    public int compare(File f1, File f2) {
+                        int diff = new Long(f1.length()).compareTo(f2.length());
+                        if (diff == 0 || f1.isDirectory() || f2.isDirectory()) {
+                            return alpha.compare(f1, f2);
+                        } else {
+                            return diff;
+                        }
+                    }
+
+                    public boolean equals(Object obj) {
+                        return false;
+                    }
+                });
+            break;
+        case DATEORDER :
+            Arrays.sort(files, new Comparator<File>() {
+                    public int compare(File f1, File f2) {
+                        int diff = new Long(f1.lastModified()).compareTo(f2.lastModified());
+                        if (diff == 0) {
+                            return alpha.compare(f1, f2);
+                        } else {
+                            return diff;
+                        }
+                    }
+
+                    public boolean equals(Object obj) {
+                        return false;
+                    }
+                });
+            break;
+        case TYPEORDER :
+            Arrays.sort(files, new Comparator<File>() {
+                    public int compare(File f1, File f2) {
+                        int diff = FileUtils.getFileExtension(f1).compareTo(FileUtils.getFileExtension(f2));
+                        if (diff == 0) {
+                            return alpha.compare(f1, f2);
+                        } else {
+                            return diff;
+                        }
+                    }
+
+                    public boolean equals(Object obj) {
+                        return false;
+                    }
+                });
+            break;
+        default :
+            Arrays.sort(files, alpha);
+        }
+
+        FileNode[] nodes = new FileNode[files.length];
+        if (order > 0) {
+            for (int i = 0; i < files.length; i++) {
+                nodes[i] = new FileNode(files[i], i);
+            }
+        } else {
+            for (int i = 0; i < files.length; i++) {
+                nodes[i] = new FileNode(files[files.length - 1 - i], i);
+            }
+        }
+
+        return nodes;
+    }
+
+    /**
+     * Returns the the string to be used to display this leaf in the JTree.
+     */
+    public String toString() {
+        String name = file.getName();
+        if (name.isEmpty()) {
+            name = "/";
+        }
+        return name;
+    }
+
+    /**
+     * @return the file associated with this node
+     */
+    public File getFile() {
+        return file;
+    }
+
+    /**
+     * @return true if this represents the user-home directory
+     */
+    public boolean isUserHome() {
+        return userHome;
+    }
+
+    /**
+     * @return true if this represents the SCI directory
+     */
+    public boolean isSCI() {
+        return sci;
+    }
+
+    /**
+     * @return the last modified time for this file
+     */
+    public long getLastModified() {
+        return lastModified;
+    }
+
+    /**
+     * @return the icon associated with this file
+     */
+    public Icon getIcon() {
+        if (icon == null) {
+            icon = FileUtils.getIconForFile(file);
+        }
+
+        return icon;
+    }
+
+    /**
+     * @return true if the file is not a directory or if it is an empty one
+     */
+    public boolean isLeaf() {
+        return isEmpty;
+    }
+
+    /**
+     * @return the number of files in the directory representated by this file
+     */
+    public int getChildrenCount() {
+        if (childrenFiles == null && !isEmpty) {
+            synchronized(file) {
+                if (childrenFiles == null) {
+                    childrenFiles = file.listFiles(FILTER);
+                }
+            }
+        }
+
+        if (childrenFiles != null) {
+            return childrenFiles.length;
+        }
+
+        return 0;
+    }
+
+    /**
+     * @return the children FileNode of this FileNode
+     */
+    protected Object[] getChildren() {
+        if (children == null && !isEmpty) {
+            try {
+                children = orderFiles(order, childrenFiles);
+            } catch (SecurityException se) { }
+        }
+
+        return children;
+    }
+
+    /**
+     * Reset this FileNode
+     */
+    public void reset() {
+        children = null;
+        icon = null;
+        childrenFiles = null;
+        init();
+    }
+
+    /**
+     * Reset children only
+     */
+    public void resetChildren() {
+        children = null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean equals(Object o) {
+        return (o instanceof FileNode) && ((FileNode) o).file.equals(file);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int hashCode() {
+        return file.hashCode();
+    }
+
+    /**
+     * Init
+     */
+    private void init() {
+        isFile = file.isFile();
+        lastModified = file.lastModified();
+        canRead = file.canRead();
+        canWrite = file.canWrite();
+        userHome = file.equals(userHomeDir);
+        sci = file.equals(SCIDIR);
+        isEmpty = isFile || CommonFileUtils.isEmptyDirectory(file.getAbsolutePath()) == 1;
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/FileUtils.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/FileUtils.java
new file mode 100644 (file)
index 0000000..0fa1745
--- /dev/null
@@ -0,0 +1,189 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+
+/**
+ * Few file tools
+ * @author Calixte DENIZET
+ */
+public final class FileUtils {
+
+    private static final Icon SCILABICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/icon_scilab.png");
+    private static final Icon PDFICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/application-pdf.png");
+    private static final Icon BINARYICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/binary.png");
+    private static final Icon IMAGEICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/image-x-generic.png");
+    private static final Icon TEXTICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/text-x-generic.png");
+    private static final Icon HTMLICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/text-html.png");
+    private static final Icon XMLICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/text-xml.png");
+    private static final Icon CSVICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/text-csv.png");
+    private static final Icon DIRICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/folder.png");
+    private static final Icon OPENDIRICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/folder-open.png");
+    private static final Icon READONLYICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/emblem-readonly.png");
+    private static final Icon CLOSEDUSERHOMEICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/user-home.png");
+    private static final Icon OPENUSERHOMEICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/open-user-home.png");
+    private static final Icon UPICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/dynamic-blue-up.png");
+    private static final Icon SCIICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/scilab-folder.png");
+    private static final Icon OPENSCIICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/open-scilab-folder.png");
+
+    private static final int CHARTOREAD = 128;
+
+    private static final Map<String, Icon> extToIcon = new HashMap<String, Icon>();
+
+    static {
+        extToIcon.put("sce", SCILABICON);
+        extToIcon.put("sci", SCILABICON);
+        extToIcon.put("scg", SCILABICON);
+        extToIcon.put("xcos", SCILABICON);
+        extToIcon.put("bin", SCILABICON);
+        extToIcon.put("cos", SCILABICON);
+        extToIcon.put("cosf", SCILABICON);
+        extToIcon.put("dem", SCILABICON);
+        extToIcon.put("graph", SCILABICON);
+        extToIcon.put("sav", SCILABICON);
+        extToIcon.put("tst", SCILABICON);
+        extToIcon.put("pdf", PDFICON);
+        extToIcon.put("png", IMAGEICON);
+        extToIcon.put("gif", IMAGEICON);
+        extToIcon.put("jpg", IMAGEICON);
+        extToIcon.put("jpeg", IMAGEICON);
+        extToIcon.put("html", HTMLICON);
+        extToIcon.put("htm", HTMLICON);
+        extToIcon.put("xml", XMLICON);
+        extToIcon.put("csv", CSVICON);
+    }
+
+    /**
+     * @param f the file
+     * @return the extension of f
+     */
+    public static String getFileExtension(File f) {
+        if (f.isFile()) {
+            String name = f.getName();
+            int pos = name.lastIndexOf(".");
+            if (pos != -1) {
+                return name.substring(pos + 1, name.length());
+            }
+        }
+
+        return "";
+    }
+
+    /**
+     * @param file the file to test
+     * @return true if it is a binary file
+     */
+    public static boolean isBinaryFile(File f) {
+        if (f.isFile() && f.canRead()) {
+            try {
+                BufferedReader reader = new BufferedReader(new FileReader(f));
+                char[] buffer = new char[CHARTOREAD];
+                int len = reader.read(buffer, 0, CHARTOREAD);
+                reader.close();
+                int i = 0;
+                if (len != -1) {
+                    for (;i < len && buffer[i] != '\0'; i++);
+                }
+
+                return len != -1 && i != len;
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return false;
+    }
+
+    /**
+     * @return the up icon
+     */
+    public static Icon getUpDirIcon() {
+        return UPICON;
+    }
+
+    /**
+     * @return the SCI icon
+     */
+    public static Icon getSCIIcon() {
+        return SCIICON;
+    }
+
+    /**
+     * @return the open SCI icon
+     */
+    public static Icon getOpenSCIIcon() {
+        return OPENSCIICON;
+    }
+
+    /**
+     * @return the open dir icon
+     */
+    public static Icon getOpenDirIcon() {
+        return OPENDIRICON;
+    }
+
+    /**
+     * @return the closed dir icon
+     */
+    public static Icon getClosedDirIcon() {
+        return DIRICON;
+    }
+
+    /**
+     * @return the closed user-home dir icon
+     */
+    public static Icon getClosedUserHomeIcon() {
+        return CLOSEDUSERHOMEICON;
+    }
+
+    /**
+     * @return the open user-home dir icon
+     */
+    public static Icon getOpenUserHomeIcon() {
+        return OPENUSERHOMEICON;
+    }
+
+    /**
+     * @param f the file
+     * @return an icon according to its extension
+     */
+    public static Icon getIconForFile(File f) {
+        if (f.isDirectory()) {
+            return DIRICON;
+        }
+
+        if (f.canRead() && !f.canWrite()) {
+            return READONLYICON;
+        }
+
+        String ext = getFileExtension(f).toLowerCase();
+        Icon icon = extToIcon.get(ext);
+        if (icon != null) {
+            return icon;
+        }
+
+        if (f.isFile() && isBinaryFile(f)) {
+            return BINARYICON;
+        }
+
+        return TEXTICON;
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileBrowser.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileBrowser.java
new file mode 100644 (file)
index 0000000..526aa27
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser;
+
+import javax.swing.SwingUtilities;
+
+import org.scilab.modules.gui.textbox.ScilabTextBox;
+import org.scilab.modules.gui.textbox.TextBox;
+import org.scilab.modules.gui.tabfactory.ScilabTabFactory;
+import org.scilab.modules.gui.utils.UIElementMapper;
+import org.scilab.modules.gui.utils.WindowsConfigurationManager;
+import org.scilab.modules.gui.window.ScilabWindow;
+import org.scilab.modules.gui.window.Window;
+import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
+import org.scilab.modules.ui_data.tabfactory.FileBrowserTab;
+import org.scilab.modules.ui_data.tabfactory.FileBrowserTabFactory;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+
+/**
+ * The file browser
+ * @author Calixte DENIZET
+ */
+public final class ScilabFileBrowser {
+
+    private static SwingScilabFileBrowser instance;
+
+    static {
+        ScilabTabFactory.getInstance().addTabFactory(FileBrowserTabFactory.getInstance());
+    }
+
+    /**
+     * Constructor
+     */
+    private ScilabFileBrowser() {
+        TextBox infobar = ScilabTextBox.createTextBox();
+        instance = new SwingScilabFileBrowser();
+        instance.addInfoBar(infobar);
+        instance.setTitle(UiDataMessages.FILE_BROWSER);
+    }
+
+    /**
+     * Create a file browser (as tab) instance
+     * @return the instance
+     */
+    public static SwingScilabFileBrowser createFileBrowserTab() {
+        if (instance == null) {
+            new ScilabFileBrowser();
+        }
+
+        return instance;
+    }
+
+    /**
+     * @return true if an instance of BrowseVar already exists.
+     */
+    public static boolean isFileBrowserOpened() {
+        return instance != null;
+    }
+
+    /**
+     * Set the base directory
+     * @param dir the base directory
+     */
+    public static void setBaseDir(String dir) {
+        if (instance != null) {
+            instance.setBaseDir(dir);
+        }
+    }
+
+    /**
+     * Get the variable browser singleton with specified columns title.
+     * @return the File Browser
+     */
+    public static SwingScilabFileBrowser getFileBrowser() {
+        if (instance == null) {
+            boolean success = WindowsConfigurationManager.restoreUUID(SwingScilabFileBrowser.FILEBROWSERUUID);
+            if (!success) {
+                FileBrowserTab.getFileBrowserInstance();
+                SwingScilabWindow window = (SwingScilabWindow) ScilabWindow.createWindow().getAsSimpleWindow();
+                window.addTab(instance);
+                window.setLocation(0, 0);
+                window.setSize(500, 500);
+                window.setVisible(true);
+            }
+        } else {
+            SwingScilabWindow window = (SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, instance);
+            window.setVisible(true);
+            window.toFront();
+        }
+
+        return instance;
+    }
+
+    /**
+     * Close File Browser
+     */
+    public static void closeFileBrowser() {
+        if (instance != null) {
+            instance.close();
+            instance = null;
+        }
+    }
+
+    /**
+     * Close File Browser
+     */
+    public void close() {
+        instance = null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setVisible(boolean status) {
+        instance.setVisible(status);
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileBrowserComponent.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileBrowserComponent.java
new file mode 100644 (file)
index 0000000..3bff74e
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+
+import javax.swing.BoxLayout;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JViewport;
+import javax.swing.SwingUtilities;
+import javax.swing.border.EmptyBorder;
+
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.ui_data.filebrowser.actions.ChangeCWDAction;
+
+/**
+ * A JPanel containing the different elements composing the File Browser
+ * @author Calixte DENIZET
+ */
+public class ScilabFileBrowserComponent extends JPanel {
+
+    private static final int GAP = 3;
+
+    private SwingScilabFileBrowser filebrowser;
+    private SwingScilabTreeTable stt;
+
+    /**
+     * Default constructor
+     */
+    public ScilabFileBrowserComponent() {
+        super(new BorderLayout());
+        setBorder(new EmptyBorder(GAP, GAP, GAP, GAP));
+        ScilabFileSelectorComboBox combobox = new ScilabFileSelectorComboBox();
+        stt = new SwingScilabTreeTable(new ScilabFileBrowserModel(), combobox);
+        Color bg = Color.WHITE;
+        stt.setBackground(bg);
+
+        add(new ScilabFileSelectorPanel(stt), BorderLayout.PAGE_START);
+        add(new ScilabFileSelectorFilter(stt), BorderLayout.PAGE_END);
+
+        JScrollPane jsp = new JScrollPane(stt);
+        jsp.getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE);
+        jsp.getViewport().setBackground(bg);
+        add(jsp, BorderLayout.CENTER);
+    }
+
+    /**
+     * Set the base directory
+     * @param baseDir the base directory
+     */
+    public void setBaseDir(final String baseDir) {
+        SwingUtilities.invokeLater(new Runnable() {
+                public void run() {
+                    stt.setBaseDir(baseDir);
+                }
+            });
+    }
+
+    /**
+     * @return the file browser (as Tab) instance
+     */
+    public SwingScilabFileBrowser getFileBrowser() {
+        return filebrowser;
+    }
+
+    /**
+     * @return the next button in the history
+     */
+    public PushButton getNextButton() {
+        return stt.getNextButton();
+    }
+
+    /**
+     * @return the previous button in the history
+     */
+    public PushButton getPreviousButton() {
+        return stt.getPreviousButton();
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileBrowserHistory.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileBrowserHistory.java
new file mode 100644 (file)
index 0000000..ae19989
--- /dev/null
@@ -0,0 +1,218 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser;
+
+import java.awt.Rectangle;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JComboBox;
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
+import javax.swing.SwingUtilities;
+
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+
+/**
+ * The File Browser history
+ * @author Calixte DENIZET
+ */
+public class ScilabFileBrowserHistory {
+
+    private static final String PREVIOUSICON = System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/go-previous.png";
+    private static final String NEXTICON = System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/go-next.png";
+
+    private SwingScilabTreeTable stt;
+    private List<String> history = new ArrayList<String>();
+    private int position = -1;
+    private PushButton previous;
+    private PushButton next;
+    private JPopupMenu popup;
+    private Timer timer;
+
+    /**
+     * Default constructor
+     * @param stt the treetable associated with this history
+     */
+    public ScilabFileBrowserHistory(SwingScilabTreeTable stt) {
+        this.stt = stt;
+        this.popup = new JPopupMenu();
+        this.popup.setBorderPainted(true);
+
+        previous = ScilabPushButton.createPushButton();
+        previous.setIcon(PREVIOUSICON);
+
+        final SwingScilabPushButton swingPrevious = (SwingScilabPushButton) previous.getAsSimplePushButton();
+        swingPrevious.addMouseListener(new MouseAdapter() {
+                public void mousePressed(MouseEvent e) {
+                    if (timer == null) {
+                        timer = new Timer();
+                        timer.schedule(new TimerTask() {
+                                public void run() {
+                                    if (!popup.isVisible() || popup.getInvoker() != next) {
+                                        showPopup(true);
+                                    }
+                                }
+                            }, 1000);
+                    }
+                }
+
+                public void mouseReleased(MouseEvent e) {
+                    if (timer != null) {
+                        timer.cancel();
+                        timer = null;
+                    }
+                }
+
+                public void mouseClicked(MouseEvent e) {
+                    if (SwingUtilities.isRightMouseButton(e) && previous.isEnabled() && (!popup.isVisible() || popup.getInvoker() != swingPrevious)) {
+                        showPopup(true);
+                    } else if (SwingUtilities.isLeftMouseButton(e) && !popup.isVisible() && previous.isEnabled()) {
+                        ScilabFileBrowserHistory.this.stt.setBaseDir(history.get(position - 1), false);
+                        setPositionInHistory(position - 1);
+                    }
+                }
+            });
+
+        next = ScilabPushButton.createPushButton();
+        next.setIcon(NEXTICON);
+
+        final SwingScilabPushButton swingNext = (SwingScilabPushButton) next.getAsSimplePushButton();
+        swingNext.addMouseListener(new MouseAdapter() {
+                public void mousePressed(MouseEvent e) {
+                    if (timer == null) {
+                        timer = new Timer();
+                        timer.schedule(new TimerTask() {
+                                public void run() {
+                                    if (!popup.isVisible() || popup.getInvoker() != next) {
+                                        showPopup(false);
+                                    }
+                                }
+                            }, 1000);
+                    }
+                }
+
+                public void mouseReleased(MouseEvent e) {
+                    if (timer != null) {
+                        timer.cancel();
+                        timer = null;
+                    }
+                }
+
+                public void mouseClicked(MouseEvent e) {
+                    if (SwingUtilities.isRightMouseButton(e) && next.isEnabled() && (!popup.isVisible() || popup.getInvoker() != swingNext)) {
+                        showPopup(false);
+                    } else if (SwingUtilities.isLeftMouseButton(e) && !popup.isVisible() && next.isEnabled()) {
+                        ScilabFileBrowserHistory.this.stt.setBaseDir(history.get(position + 1), false);
+                        setPositionInHistory(position + 1);
+                    }
+                }
+            });
+
+        updateButton(0);
+    }
+
+    /**
+     * Show the popup under the button
+     * @param prev if true, the popup is show under the previous button
+     */
+    private void showPopup(boolean prev) {
+        popup.removeAll();
+        if (prev) {
+            for (int i = position - 1; i >= 0; i--) {
+                JMenuItem item = new JMenuItem(history.get(i));
+                final int j = i;
+                item.addActionListener(new CallBack(null) {
+                        public void callBack() {
+                            ScilabFileBrowserHistory.this.stt.setBaseDir(history.get(j), false);
+                            setPositionInHistory(j);
+                        }
+                    });
+                popup.add(item);
+            }
+        } else {
+            for (int i = position + 1; i < history.size(); i++) {
+                JMenuItem item = new JMenuItem(history.get(i));
+                final int j = i;
+                item.addActionListener(new CallBack(null) {
+                        public void callBack() {
+                            ScilabFileBrowserHistory.this.stt.setBaseDir(history.get(j), false);
+                            setPositionInHistory(j);
+                        }
+                    });
+                popup.add(item);
+            }
+        }
+        popup.pack();
+
+        SwingScilabPushButton button;
+        if (prev) {
+            button = (SwingScilabPushButton) previous.getAsSimplePushButton();
+        } else {
+            button = (SwingScilabPushButton) next.getAsSimplePushButton();
+        }
+
+        popup.show(button, 0, button.getBounds(null).height);
+    }
+
+    /**
+     * Add a path in the history
+     * @param path the path to add
+     */
+    public void addPathInHistory(String path) {
+        history.add(path);
+        setPositionInHistory(position + 1);
+    }
+
+    /**
+     * @return the previous button
+     */
+    public PushButton getPreviousButton() {
+        return previous;
+    }
+
+    /**
+     * @return the next button
+     */
+    public PushButton getNextButton() {
+        return next;
+    }
+
+    /**
+     * Set the current position in the history
+     * @param pos the new position
+     */
+    private void setPositionInHistory(int pos) {
+        position = pos;
+        updateButton(pos);
+    }
+
+    /**
+     * Update the buttons state according to the position
+     * @param pos the position
+     */
+    private void updateButton(int pos) {
+        previous.setEnabled(history.size() >= 2 && pos != 0);
+        next.setEnabled(history.size() >= 2 && pos != history.size() - 1);
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileBrowserModel.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileBrowserModel.java
new file mode 100644 (file)
index 0000000..dd0b310
--- /dev/null
@@ -0,0 +1,299 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser;
+
+import java.io.File;
+import java.text.DecimalFormat;
+import java.util.Date;
+import java.util.regex.Pattern;
+
+import javax.swing.SwingWorker;
+import javax.swing.tree.TreePath;
+
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+
+/**
+ * The tree table model abstract implementation
+ * @author Calixte DENIZET
+ */
+public class ScilabFileBrowserModel extends AbstractScilabTreeTableModel implements ScilabTreeTableModel {
+
+    private static final String[] names = {UiDataMessages.NAME_COLUMN,
+                                           UiDataMessages.SIZE_COLUMN,
+                                           UiDataMessages.TYPE_COLUMN,
+                                           UiDataMessages.LASTMODIF_COLUMN};
+
+    private static final Class[] types = {ScilabTreeTableModel.class,
+                                          FileSize.class,
+                                          String.class,
+                                          Date.class};
+
+    private static final FileSize MINUSONE = new FileSize(-1);
+
+    private int order = 1;
+    private String baseDir = "";
+
+    /**
+     * Default constructor
+     */
+    public ScilabFileBrowserModel() {
+        super();
+        setRoot(new RootNode());
+    }
+
+    /**
+     * Set the base directory
+     * @param baseDir the base directory
+     * @param stt the associated treetable component
+     */
+    public void setBaseDir(final String baseDir, final SwingScilabTreeTable stt) {
+        this.baseDir = baseDir;
+        SwingWorker worker = new SwingWorker<Void, Void>() {
+            protected Void doInBackground() throws Exception {
+                File f = new File(baseDir);
+                setRoot(new FileNode(f, -1));
+                File parentFile = f.getParentFile();
+                if (parentFile != null) {
+                    parent = new ParentNode(parentFile);
+                } else {
+                    parent = null;
+                }
+
+                return null;
+            }
+
+            protected void done() {
+                stt.reload(ScilabFileBrowserModel.this);
+            }
+        };
+        worker.execute();
+    }
+
+    /**
+     * @return the base directory of this model
+     */
+    public String getBaseDir() {
+        return baseDir;
+    }
+
+    /**
+     * Set the filter pattern
+     * @pat the pattern
+     */
+    public void setFilter(Pattern pat) {
+        ((FileNode) root).setFilter(pat);
+    }
+
+    /**
+     * @param node the node
+     * @return the file associated with the node
+     */
+    protected File getFile(Object node) {
+        FileNode fileNode = (FileNode) node;
+        return fileNode.getFile();
+    }
+
+    /**
+     * @param node the node
+     * @return the children of this node
+     */
+    protected Object[] getChildren(Object node) {
+        FileNode fileNode = (FileNode) node;
+        return fileNode.getChildren();
+    }
+
+    /**
+     * @param node the node
+     * @return the number of children of this node
+     */
+    public int getChildCount(Object node) {
+        int count = ((FileNode) node).getChildrenCount();
+        if (parent == null || node != getRoot()) {
+            return count;
+        }
+        return count + 1;
+    }
+
+    /**
+     * @param node the node
+     * @param i the child number
+     * @return the child at position i
+     */
+    public Object getChild(Object node, int i) {
+        Object ret;
+        if (node == getRoot()) {
+            if (parent == null) {
+                ret = getChildren(node)[i];
+            } else {
+                if (i == 0) {
+                    ret = parent;
+                } else {
+                    ret = getChildren(node)[i - 1];
+                }
+            }
+        } else {
+            ret = getChildren(node)[i];
+        }
+
+        return ret;
+    }
+
+    /**
+     * @param node the node
+     * @return true is this node is a leaf
+     */
+    public boolean isLeaf(Object node) {
+        return node != getRoot() && ((FileNode) node).isLeaf();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getColumnCount() {
+        return names.length;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getColumnName(int column) {
+        return names[column];
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Class getColumnClass(int column) {
+        return types[column];
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object getValueAt(Object node, int column) {
+        File file = getFile(node);
+        try {
+            switch(column) {
+            case 0:
+                return file.getName();
+            case 1:
+                return file.isFile() ? new FileSize((int) file.length()) : MINUSONE;
+            case 2:
+                if (file.isFile()) {
+                    String ext = FileUtils.getFileExtension(file);
+                    if (ext.isEmpty()) {
+                        return UiDataMessages.FILE;
+                    } else {
+                        return String.format(UiDataMessages.FILETYPE, FileUtils.getFileExtension(file));
+                    }
+                } else {
+                    return UiDataMessages.DIRECTORY;
+                }
+            case 3:
+                return new Date(file.lastModified());
+            }
+        }
+        catch (SecurityException se) { }
+
+        return null;
+    }
+
+    /**
+     * Inner class to represent a root
+     */
+    public class RootNode extends FileNode {
+
+        /**
+         * {@inheritDoc}
+         */
+        public RootNode() {
+            super(new File(""), -1);
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        protected Object[] getChildren() {
+            if (children == null) {
+                try {
+                    File[] files = File.listRoots();
+                    if (files != null) {
+                        children = orderFiles(order, files);
+                    }
+                } catch (SecurityException se) { }
+            }
+
+            return children;
+        }
+    }
+
+    /**
+     * Inner class to represent the parent node of a file node
+     */
+    public class ParentNode extends FileNode {
+
+        /**
+         * {@inheritDoc}
+         */
+        public ParentNode(File f) {
+            super(f, -1);
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public boolean isLeaf() {
+            return true;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public String toString() {
+            return "..";
+        }
+    }
+
+    /**
+     * Inner class to represent the size of file
+     */
+    public static class FileSize {
+
+        int size;
+
+        FileSize(int size) {
+            this.size = size;
+        }
+
+        public String toString() {
+            if (size < 0) {
+                return "";
+            }
+
+            if (size >= 0 && size < 1000) {
+                return size + " B";
+            }
+
+            DecimalFormat df = new DecimalFormat("#.#");
+            if (size >= 1000 && size < 1000000) {
+                return df.format(((float) size) / 1000f).toString() + " KB";
+            }
+
+            if (size >= 1000000 && size < 1000000000) {
+                return df.format(((float) size) / 1000000f).toString() + " MB";
+            }
+
+            return df.format(((float) size) / 1000000000f).toString() + " GB";
+        }
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileSelectorComboBox.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileSelectorComboBox.java
new file mode 100644 (file)
index 0000000..25f8ddc
--- /dev/null
@@ -0,0 +1,556 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser;
+
+import java.awt.AWTEvent;
+import java.awt.Color;
+import java.awt.Toolkit;
+import java.awt.KeyboardFocusManager;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.AWTEventListener;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.TreeSet;
+
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
+import javax.swing.JRootPane;
+import javax.swing.KeyStroke;
+import javax.swing.SwingUtilities;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultEditorKit;
+import javax.swing.text.JTextComponent;
+
+import org.scilab.modules.commons.ScilabConstants;
+import org.scilab.modules.core.Scilab;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+
+/**
+ *
+ * @author Calixte DENIZET
+ */
+public class ScilabFileSelectorComboBox extends JComboBox implements DocumentListener {
+
+    private static final FileFilter DIRFILTER = new FileFilter() {
+            public boolean accept(File f) {
+                return f.isDirectory();
+            }
+        };
+
+    private static boolean isWindows = Scilab.isWindowsPlateform();
+
+    private int lastSize = -1;
+    private String oldName = "";
+    private TreeSet<String> currentSet;
+    private JTextComponent textComponent;
+    private boolean disableUpdateCombo;
+    private boolean disableShowPopup;
+    private boolean isValidate;
+    private CallBack validation;
+    private SwingScilabTreeTable stt;
+    private Color defaultFg;
+
+    /**
+     * Default constructor
+     * @param baseDir the base directory to open
+     * @param validation the callback to execute when the user valids the directory
+     */
+    public ScilabFileSelectorComboBox() {
+        super();
+        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
+        textComponent = (JTextComponent) getEditor().getEditorComponent();
+        textComponent.getDocument().addDocumentListener(this);
+        defaultFg = textComponent.getForeground();
+
+        getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
+                public void keyReleased(KeyEvent e) {
+                    int code = e.getKeyCode();
+                    if (code != KeyEvent.VK_ESCAPE && code != KeyEvent.VK_ENTER) {
+                        showPopup();
+                    } else if (code == KeyEvent.VK_ENTER) {
+                        if (!isValidate) {
+                            updateComboBoxLater();
+                            if (!currentSet.isEmpty()) {
+                                showPopup();
+                            }
+                        } else {
+                            isValidate = false;
+                        }
+                    }
+                }
+
+                public void keyPressed(KeyEvent e) {
+                    int code = e.getKeyCode();
+                    if (code == KeyEvent.VK_DOWN || code == KeyEvent.VK_KP_DOWN || code == KeyEvent.VK_PAGE_DOWN
+                        || code == KeyEvent.VK_UP || code == KeyEvent.VK_KP_UP || code == KeyEvent.VK_PAGE_UP
+                        || code == KeyEvent.VK_END || code == KeyEvent.VK_BEGIN) {
+                        disableUpdateCombo = true;
+                    } else {
+                        disableUpdateCombo = false;
+                    }
+                }
+            });
+
+        /* Workaround to override the default behaviour of TAB key */
+        Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
+                public void eventDispatched(AWTEvent e) {
+                    KeyEvent ke = (KeyEvent) e;
+                    if (ke.getKeyCode() == KeyEvent.VK_TAB && ke.getID() == KeyEvent.KEY_RELEASED && ke.getSource() == textComponent) {
+                        updateComboBoxLater();
+                        String cp = getCommonPart();
+                        getEditor().setItem(cp);
+                        showPopup();
+                        ke.consume();
+                    }
+                }
+            }, AWTEvent.KEY_EVENT_MASK);
+
+        setEditable(true);
+
+        textComponent.setComponentPopupMenu(createPopup());
+    }
+
+    /**
+     * Set the treetable linked with this combobox
+     */
+    public void setTreeTable(SwingScilabTreeTable stt) {
+        this.stt = stt;
+    }
+
+    /**
+     * Set the action as CallBack
+     * @param validation the action to use when a path is validated
+     */
+    public void setAction(CallBack validation) {
+        this.validation = validation;
+        textComponent.addKeyListener(new KeyAdapter() {
+                public void keyPressed(KeyEvent e) {
+                    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
+                        isValidate = true;
+                        ScilabFileSelectorComboBox.this.validation.callBack();
+                        hidePopup();
+                        e.consume();
+                    }
+                }
+            });
+    }
+
+    /**
+     * Set the base directory and validate
+     * @param path the path to set
+     */
+    public void setBaseDirAndValidate(String path) {
+        disableUpdateCombo = true;
+        textComponent.getDocument().removeDocumentListener(this);
+        getEditor().setItem(path);
+        validation.callBack();
+        disableUpdateCombo = false;
+    }
+
+    /**
+     * @return the base directory
+     */
+    public void setBaseDir(String baseDir) {
+        if (!baseDir.endsWith(File.separator)) {
+            baseDir += File.separator;
+        }
+        disableShowPopup = true;
+        textComponent.setText(baseDir);
+        disableShowPopup = false;
+    }
+
+    /**
+     * @return the base directory
+     */
+    public String getBaseDir() {
+        return getTruePath(getText());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void changedUpdate(DocumentEvent e) { }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void insertUpdate(DocumentEvent e) {
+        testPathValidity();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void removeUpdate(DocumentEvent e) {
+        testPathValidity();
+    }
+
+    /**
+     * Test the path validity. If the path is invalid the color in the combo's textfield is set to RED
+     */
+    private void testPathValidity() {
+        File f = new File(getText());
+        if (f.exists() && f.isDirectory() && f.canRead()) {
+            textComponent.setForeground(defaultFg);
+            updateComboBox();
+        } else {
+            textComponent.setForeground(Color.RED);
+        }
+    }
+
+    /**
+     * @return the text in the textfield
+     */
+    private String getText() {
+        int len = textComponent.getDocument().getLength();
+        try {
+            return textComponent.getDocument().getText(0, len);
+        } catch (BadLocationException e) {
+            return "";
+        }
+    }
+
+    /**
+     * Get the path where the jokers such as ~, SCI or TMPDIR are replaced by their values
+     * @param path the path
+     * @return the true path
+     */
+    private static final String getTruePath(String path) {
+        if (path != null) {
+            if (path.startsWith("SCI\\") || path.startsWith("SCI/") || path.startsWith("SCI")) {
+                return path.replaceFirst("SCI", ScilabConstants.SCI.getAbsolutePath());
+            }
+            if (path.startsWith("~\\") || path.startsWith("~/") || path.startsWith("~")) {
+                return path.replaceFirst("~", ScilabConstants.USERHOME);
+            }
+            if (path.startsWith("TMPDIR\\") || path.startsWith("TMPDIR/") || path.startsWith("TMPDIR")) {
+                return path.replaceFirst("TMPDIR", ScilabConstants.TMPDIR.getAbsolutePath());
+            }
+        }
+
+        boolean failed = true;
+        for (int i = 0; i < 5 && failed; i++) {
+            try {
+                path = new File(path).getCanonicalPath();
+                failed = false;
+            } catch (IOException e) {
+                try {
+                    Thread.sleep(10);
+                } catch (InterruptedException ee) { }
+            }
+        }
+
+        return path;
+    }
+
+
+    /**
+     * Get the path where the jokers such as ~, SCI or TMPDIR are replaced by their values
+     * @param path the path
+     * @param joker the joker
+     * @return the true path
+     */
+    private static final String getTruePath(String path, String joker) {
+        if (path != null && joker != null) {
+            if (joker.equals("SCI")) {
+                return path.replaceFirst("SCI", ScilabConstants.SCI.getAbsolutePath());
+            }
+            if (joker.equals("~")) {
+                return path.replaceFirst("~", ScilabConstants.USERHOME);
+            }
+            if (joker.equals("TMPDIR")) {
+                return path.replaceFirst("TMPDIR", ScilabConstants.TMPDIR.getAbsolutePath());
+            }
+        }
+
+        return path;
+    }
+
+    /**
+     * Get the joker, if one exists, in the path. Jokers can be ~, SCI or TMPDIR
+     * @param path the path to analyze
+     * @return the joker
+     */
+    private static final String getJoker(String path) {
+        if (path != null) {
+            if (path.startsWith("SCI\\") || path.startsWith("SCI/")) {
+                return "SCI";
+            }
+            if (path.startsWith("~\\") || path.startsWith("~/")) {
+                return "~";
+            }
+            if (path.startsWith("TMPDIR\\") || path.startsWith("TMPDIR/")) {
+                return "TMPDIR";
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Get a path where the value of SCI is replaced by the string "SCI" (or ~, TMPDIR)
+     * @param path the path
+     * @param joker the joker
+     * @return the fake path
+     */
+    private static final String getFakePath(String path, String joker) {
+        if (path != null && joker != null) {
+            if (joker.equals("SCI")) {
+                return path.replaceFirst(ScilabConstants.SCI.getAbsolutePath(), "SCI");
+            }
+            if (joker.equals("~")) {
+                return path.replaceFirst(ScilabConstants.USERHOME, "~");
+            }
+            if (joker.equals("TMPDIR")) {
+                return path.replaceFirst(ScilabConstants.TMPDIR.getAbsolutePath(), "TMPDIR");
+            }
+        }
+
+        return path;
+    }
+
+    /**
+     * Get the directory where to list the file
+     * @param name the directory name
+     * @return the directory
+     */
+    private static final File getFileDirectory(String name) {
+        File file = new File(name);
+
+        if (name.endsWith(File.separator) && file.isDirectory()) {
+            return file;
+        }
+
+        File parent = file.getParentFile();
+        if (parent != null && parent.isDirectory()) {
+            return parent;
+        }
+
+        return null;
+    }
+
+    /**
+     * Get the common part of the strings present in currentSet (in fine, the combobox content list)
+     * @return the common part
+     */
+    private String getCommonPart() {
+        if (currentSet != null && !currentSet.isEmpty()) {
+            if (currentSet.size() == 1) {
+                return currentSet.first();
+            }
+
+            String parent = new File(currentSet.first()).getParent();
+            int lenParent = 0;
+            if (parent != null) {
+                lenParent = parent.length();
+            }
+
+            int min = Integer.MAX_VALUE;
+            char[][] strs = new char[currentSet.size()][];
+            int i = 0;
+
+            for (String s : currentSet) {
+                strs[i] = s.substring(lenParent).toCharArray();
+                if (strs[i].length < min) {
+                    min = strs[i].length;
+                }
+                i++;
+            }
+
+            /* Now we get the common part */
+            int j = strs.length;
+            for (i = 0; i < min && j == strs.length; i++) {
+                if (isWindows) {
+                    char c = Character.toLowerCase(strs[0][i]);
+                    j = 1;
+                    for (;j < strs.length && Character.toLowerCase(strs[j][i]) == c; j++);
+                } else {
+                    char c = strs[0][i];
+                    j = 1;
+                    for (;j < strs.length && strs[j][i] == c; j++);
+                }
+            }
+
+            String common = new String(strs[0], 0, i - 1);
+            if (isWindows) {
+                int k = i - 1;
+                for (j = 1; j < strs.length && k == i - 1; j++) {
+                    for (k = 0; k < i - 1 && strs[j][k] == strs[0][k]; k++);
+                }
+
+                if (j != strs.length) {
+                    common = common.toLowerCase();
+                }
+            }
+
+            if (lenParent != 0) {
+                return parent + common;
+            }
+            return common;
+        }
+
+        return getText();
+    }
+
+    /**
+     * Update the combobox. Since this function is called from the DocumentListener and methods in JComboBox change the JTextComponent content
+     * (so the listener would try to write under a writeLock()... see DocumentListener javadoc), the update is called outside the main thread.
+     */
+    private void updateComboBox() {
+        final boolean b = disableShowPopup;
+        textComponent.getDocument().removeDocumentListener(this);
+        SwingUtilities.invokeLater(new Runnable() {
+                public void run() {
+                    if (!disableUpdateCombo) {
+                        updateComboBoxLater(b);
+                    }
+                    textComponent.getDocument().addDocumentListener(ScilabFileSelectorComboBox.this);
+                }
+            });
+    }
+
+    /**
+     * Update the comboBox with the possible completion of the name
+     * entered in the comboBox.
+     */
+    private void updateComboBoxLater() {
+        updateComboBoxLater(false);
+    }
+
+    /**
+     * Update the comboBox with the possible completion of the name
+     * entered in the comboBox.
+     */
+    private void updateComboBoxLater(final boolean hidepopup) {
+        String trueName = getText();
+        if (trueName != null && !trueName.equals(oldName)) {
+            String joker = getJoker(trueName);
+            String name = getTruePath(trueName, joker);
+            oldName = trueName;
+
+            TreeSet<String> set = null;
+            File[] files;
+
+            if (name.isEmpty()) {
+                files = File.listRoots();
+            } else {
+                File parent = getFileDirectory(name);
+
+                if (parent != null) {
+                    files = parent.listFiles(DIRFILTER);
+                } else {
+                    files = File.listRoots();
+                }
+            }
+
+            if (isWindows) {
+                set = new TreeSet<String>(new Comparator<String>() {
+                        public int compare(String s1, String s2) {
+                            int diff = s1.compareToIgnoreCase(s2);
+                            if (diff == 0) {
+                                diff = s1.compareTo(s2);
+                            }
+                            return diff;
+                        }
+
+                        public boolean equals(Object obj) {
+                            return false;
+                        }
+                    });
+            } else {
+                set = new TreeSet<String>();
+            }
+            for (File f : files) {
+                String extra = File.separator;
+                if (f.getParent() == null) {
+                    extra = "";
+                }
+                set.add(getFakePath(f.getAbsolutePath(), joker) + extra);
+            }
+
+            if (set != null) {
+                String bound = "";
+                int len = trueName.length();
+                if (len != 0) {
+                    if (len == 1) {
+                        bound = new String(new char[]{(char) (trueName.charAt(0) + 1)});
+                    } else {
+                        bound = trueName.substring(0, len - 1);
+                        bound += (char) (trueName.charAt(len - 1) + 1);
+                    }
+                    currentSet = (TreeSet) set.subSet(trueName, true, bound, false);
+                } else {
+                    currentSet = set;
+                }
+
+                if (currentSet != null && currentSet.size() != lastSize) {
+                    hidePopup();
+                    removeAllItems();
+                    for (String f : currentSet) {
+                        addItem(f);
+                    }
+                    lastSize = currentSet.size();
+                }
+            }
+
+            setSelectedIndex(-1);
+            getEditor().setItem(trueName);
+            textComponent.setSelectionStart(textComponent.getSelectionEnd());
+
+            if (isShowing()) {
+                setPopupVisible(!hidepopup);
+            }
+        }
+    }
+
+    /**
+     * @return the popup used in the combo's textfield
+     */
+    private JPopupMenu createPopup() {
+        JPopupMenu popup = new JPopupMenu();
+
+        JMenuItem item = new JMenuItem(UiDataMessages.CUT);
+        item.addActionListener(new DefaultEditorKit.CutAction());
+        popup.add(item);
+
+        item = new JMenuItem(UiDataMessages.COPY);
+        item.addActionListener(new DefaultEditorKit.CopyAction());
+        popup.add(item);
+
+        item = new JMenuItem(UiDataMessages.PASTE);
+        item.addActionListener(new DefaultEditorKit.PasteAction());
+        popup.add(item);
+
+        item = new JMenuItem(UiDataMessages.CLEAR);
+        item.addActionListener(new ActionListener() {
+                public void actionPerformed(ActionEvent e) {
+                    textComponent.setText("");
+                }
+            });
+        popup.add(item);
+
+        return popup;
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileSelectorFilter.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileSelectorFilter.java
new file mode 100644 (file)
index 0000000..424f5e9
--- /dev/null
@@ -0,0 +1,286 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser;
+
+import java.awt.Color;
+import java.awt.ContainerOrderFocusTraversalPolicy;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.KeyboardFocusManager;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.util.Collections;
+import java.util.regex.Pattern;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JLabel;
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JTextField;
+import javax.swing.KeyStroke;
+import javax.swing.border.EmptyBorder;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import javax.swing.text.DefaultEditorKit;
+
+import org.scilab.modules.core.Scilab;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+
+/**
+ * A panel with file filter and the combo to set the cwd.
+ * @author Calixte DENIZET
+ */
+public class ScilabFileSelectorFilter extends JPanel {
+
+    private static boolean isWindows = Scilab.isWindowsPlateform();
+    private static final int GAP = 3;
+    private static final Icon VALIDATE = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/filebrowser/filter.png");
+
+    private MyJTextField textfield;
+    private SwingScilabTreeTable stt;
+    private JCheckBox caseSensitive;
+    private JCheckBox regexp;
+    private JButton validate;
+
+    /**
+     * Default constructor
+     * @param stt the SwingScilabTree containing the cwd
+     * @param comboPath the combobox where to set the path
+     */
+    public ScilabFileSelectorFilter(SwingScilabTreeTable stt) {
+        super();
+        this.stt = stt;
+        initPanel();
+    }
+
+    /**
+     * Init the panel
+     */
+    private void initPanel() {
+        setBorder(new EmptyBorder(0, 0, GAP, 0));
+        setLayout(new GridBagLayout());
+        textfield = new MyJTextField();
+        setFocusCycleRoot(true);
+        setFocusTraversalPolicy(new ContainerOrderFocusTraversalPolicy());
+
+        validate = new JButton(new CallBack(null) {
+                public void callBack() {
+                    stt.setFilter(getPattern());
+                }
+            });
+        validate.setIcon(VALIDATE);
+
+        caseSensitive = new JCheckBox(UiDataMessages.CASESENSITIVE, !isWindows);
+        regexp = new JCheckBox(UiDataMessages.REGEXP, false);
+
+        GridBagConstraints gbc = new GridBagConstraints();
+
+        gbc.gridx = 0;
+        gbc.gridy = 0;
+        gbc.gridwidth = 2;
+        gbc.gridheight = 1;
+        gbc.weightx = 1;
+        gbc.fill = GridBagConstraints.HORIZONTAL;
+        gbc.anchor = gbc.LINE_START;
+        add(textfield, gbc);
+
+        gbc.gridx = 2;
+        gbc.gridwidth = gbc.gridheight = 1;
+        gbc.weightx = 0;
+        gbc.anchor = gbc.LINE_START;
+        add(validate, gbc);
+
+        gbc.gridx = 0;
+        gbc.gridy = 1;
+        gbc.gridwidth = gbc.gridheight = 1;
+        gbc.weightx = 0;
+        gbc.anchor = gbc.LINE_START;
+        add(caseSensitive, gbc);
+
+        gbc.gridx = 1;
+        gbc.gridwidth = gbc.gridheight = 1;
+        gbc.weightx = 0;
+        gbc.anchor = gbc.LINE_START;
+        add(regexp, gbc);
+    }
+
+    /**
+     * Test the pattern and change the color of the text in textfield if the pattern is invalid
+     */
+    private void testPattern() {
+        if (regexp.isSelected()) {
+            if (getPattern() == null) {
+                textfield.setForeground(Color.RED);
+            } else {
+                textfield.setForeground(textfield.defaultFg);
+            }
+        }
+    }
+
+    /**
+     * Get the pattern according to the textfield content
+     * @return the pattern
+     */
+    private Pattern getPattern() {
+        String text = textfield.getText();
+        if (text != null && !text.isEmpty()) {
+            if (!regexp.isSelected()) {
+                text = text.replaceAll("\\*", "\\\\E.*\\\\Q").replaceAll("\\?", "\\\\E.?\\\\Q");
+                text = "\\Q" + text + "\\E";
+            }
+            if (!caseSensitive.isSelected()) {
+                text = "(?i)" + text;
+            }
+
+            if (regexp.isSelected()) {
+                text = "(?m)" + text;
+            }
+
+            try {
+                return Pattern.compile(text);
+            } catch (Exception e) { }
+        }
+
+        return null;
+    }
+
+    /**
+     * Inner class to have the possibility to add a default text in the textfield but in this case the textfield is empty !
+     * It is a workaround for a GTK bug which avoids me to paint directly in the field.
+     */
+    private class MyJTextField extends JTextField implements DocumentListener, FocusListener {
+
+        boolean isEmpty = true;
+        Color defaultFg;
+
+        /**
+         * {@inheritDoc}
+         */
+        MyJTextField() {
+            super();
+            defaultFg = getForeground();
+            setEditable(true);
+            setComponentPopupMenu(createPopup());
+            addFocusListener(this);
+            getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ENTER");
+            getActionMap().put("ENTER", new CallBack(null) {
+                    public void callBack() {
+                        stt.setFilter(getPattern());
+                    }
+                });
+            toggleContents();
+        }
+
+        /**
+         * Toggle the contents
+         */
+        private void toggleContents() {
+            if (isEmpty) {
+                setForeground(Color.LIGHT_GRAY);
+                setText(UiDataMessages.FILEFILTER);
+            }
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public String getText() {
+            if (isEmpty) {
+                return "";
+            }
+
+            return super.getText();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public void focusGained(FocusEvent e) {
+            getDocument().addDocumentListener(this);
+            if (isEmpty) {
+                setForeground(defaultFg);
+                setText("");
+            }
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public void focusLost(FocusEvent e) {
+            getDocument().removeDocumentListener(this);
+            isEmpty = super.getText().isEmpty();
+            toggleContents();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public void insertUpdate(DocumentEvent e) {
+            isEmpty = super.getText().isEmpty();
+            testPattern();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public void removeUpdate(DocumentEvent e) {
+            isEmpty = super.getText().isEmpty();
+            testPattern();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public void changedUpdate(DocumentEvent e) { }
+
+        /**
+         * @return the popup menu used in this textfield
+         */
+        private JPopupMenu createPopup() {
+            JPopupMenu popup = new JPopupMenu();
+
+            JMenuItem item = new JMenuItem(UiDataMessages.CUT);
+            item.addActionListener(new DefaultEditorKit.CutAction());
+            popup.add(item);
+
+            item = new JMenuItem(UiDataMessages.COPY);
+            item.addActionListener(new DefaultEditorKit.CopyAction());
+            popup.add(item);
+
+            item = new JMenuItem(UiDataMessages.PASTE);
+            item.addActionListener(new DefaultEditorKit.PasteAction());
+            popup.add(item);
+
+            item = new JMenuItem(UiDataMessages.CLEAR);
+            item.addActionListener(new ActionListener() {
+                    public void actionPerformed(ActionEvent e) {
+                        MyJTextField.this.setText("");
+                    }
+                });
+            popup.add(item);
+
+            return popup;
+        }
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileSelectorPanel.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileSelectorPanel.java
new file mode 100644 (file)
index 0000000..cd2dcce
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JViewport;
+import javax.swing.SwingUtilities;
+import javax.swing.border.EmptyBorder;
+
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.ui_data.filebrowser.actions.ChangeCWDAction;
+
+/**
+ * The JPanel containing the combobox used to set the path and the two buttons
+ * @author Calixte DENIZET
+ */
+public class ScilabFileSelectorPanel extends JPanel {
+
+    private SwingScilabTreeTable table;
+
+    /**
+     * Default constructor
+     * @param table the table linked with the combobox
+     */
+    public ScilabFileSelectorPanel(SwingScilabTreeTable table) {
+        super();
+        this.table = table;
+        init();
+    }
+
+    /**
+     * Init the panel contents
+     */
+    private void init() {
+        setLayout(new GridBagLayout());
+        JButton changeDirButton = ((ChangeCWDAction) table.getActionMap().get("cwd")).createButton();
+        JButton upDirButton = ((ChangeCWDAction) table.getActionMap().get("cwd")).createParentDirButton();
+
+        GridBagConstraints gbc = new GridBagConstraints();
+
+        gbc.gridx = 0;
+        gbc.gridy = 0;
+        gbc.gridwidth = 1;
+        gbc.gridheight = 1;
+        gbc.weightx = 0;
+        gbc.anchor = gbc.LINE_START;
+        add(changeDirButton, gbc);
+
+        gbc.gridx = 1;
+        gbc.gridwidth = gbc.gridheight = 1;
+        gbc.weightx = 1;
+        gbc.fill = GridBagConstraints.HORIZONTAL;
+        gbc.anchor = gbc.LINE_START;
+        add(table.getComboBox(), gbc);
+
+        gbc.gridx = 2;
+        gbc.gridwidth = gbc.gridheight = 1;
+        gbc.weightx = 0;
+        gbc.anchor = gbc.LINE_START;
+        add(upDirButton, gbc);
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabTreeTableCellRenderer.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabTreeTableCellRenderer.java
new file mode 100644 (file)
index 0000000..2b5282d
--- /dev/null
@@ -0,0 +1,196 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser;
+
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Cursor;
+import java.awt.Graphics;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.JTable;
+import javax.swing.JTree;
+import javax.swing.SwingUtilities;
+import javax.swing.table.TableCellRenderer;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeCellRenderer;
+import javax.swing.tree.DefaultTreeSelectionModel;
+import javax.swing.tree.TreeModel;
+import javax.swing.tree.TreePath;
+import javax.swing.event.TreeExpansionEvent;
+import javax.swing.event.TreeExpansionListener;
+import javax.swing.event.TreeModelEvent;
+import javax.swing.event.TreeModelListener;
+import javax.swing.event.TreeWillExpandListener;
+
+import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
+import org.scilab.modules.gui.events.callback.CallBack;
+
+/**
+ * The table renderer to render the tree in the first column of the JTable
+ */
+public class ScilabTreeTableCellRenderer extends JTree implements TableCellRenderer {
+
+    private SwingScilabTreeTable table;
+    protected int visibleRow;
+
+    /**
+     * {@inheritdoc}
+     */
+    public ScilabTreeTableCellRenderer(SwingScilabTreeTable table, TreeModel model) {
+        super(model);
+        this.table = table;
+        DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {
+
+                public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
+                    FileNode fn = (FileNode) value;
+                    super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
+                    if (leaf) {
+                        if (fn instanceof ScilabFileBrowserModel.ParentNode) {
+                            this.setLeafIcon(FileUtils.getUpDirIcon());
+                        } else {
+                            this.setLeafIcon(fn.getIcon());
+                        }
+                    } else if (fn.isUserHome()) {
+                        this.setClosedIcon(FileUtils.getClosedUserHomeIcon());
+                        this.setOpenIcon(FileUtils.getOpenUserHomeIcon());
+                    } else if (fn.isSCI()) {
+                        this.setClosedIcon(FileUtils.getSCIIcon());
+                        this.setOpenIcon(FileUtils.getOpenSCIIcon());
+                    } else {
+                        this.setClosedIcon(FileUtils.getClosedDirIcon());
+                        this.setOpenIcon(FileUtils.getOpenDirIcon());
+                    }
+
+                    return this;
+                }
+            };
+
+        /* Force the JTable and JTree to share their row selection models.
+           And let the table to handle the selection rather than the tree; */
+        setSelectionModel(new DefaultTreeSelectionModel() {
+                    {
+                        ScilabTreeTableCellRenderer.this.table.setSelectionModel(listSelectionModel);
+                    }
+
+                public void setSelectionPaths(TreePath[] pPaths) { }
+
+                public void addSelectionPaths(TreePath[] paths) { }
+
+                public void removeSelectionPaths(TreePath[] paths) { }
+            });
+
+        setCellRenderer(renderer);
+        setRootVisible(true);
+        setRowHeight(table.getRowHeight());
+        setLargeModel(true);
+        setEditable(true);
+        setToggleClickCount(0);
+
+        addMouseListener(new MouseAdapter() {
+                public void mousePressed(MouseEvent e) {
+                    int selRow = getRowForLocation(e.getX(), e.getY());
+                    TreePath selPath = getPathForLocation(e.getX(), e.getY());
+                    if (selRow != -1) {
+                        switch (e.getClickCount()) {
+                        case 1 :
+                            /*int sel = SwingScilabTreeTable.this.getSelectedRow();
+                              System.out.println(sel+":::"+selRow+":::"+isEditable());
+                              if (sel == selRow) {
+                              System.out.println(getCellEditor().getTreeCellEditorComponent(ScilabTreeTableCellRenderer.this, getCellEditor().getCellEditorValue(), true, false, true, selRow));
+                              }
+                              e.consume();*/
+                            break;
+                        case 2:
+                            ((CallBack) ScilabTreeTableCellRenderer.this.table.getActionMap().get("validate")).callBack();
+                            e.consume();
+                        }
+                    }
+                }
+
+                public void mouseReleased(MouseEvent e) { }
+            });
+
+        addTreeWillExpandListener(new TreeWillExpandListener() {
+                public void treeWillCollapse(TreeExpansionEvent event) { }
+
+                public void treeWillExpand(TreeExpansionEvent event) {
+                    Container win = SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, ScilabTreeTableCellRenderer.this.table);
+                    if (win != null) {
+                        win.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+                    }
+                }
+            });
+        addTreeExpansionListener(new TreeExpansionListener() {
+                public void treeCollapsed(TreeExpansionEvent event) { }
+
+                public void treeExpanded(TreeExpansionEvent event) {
+                    Container win = SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, ScilabTreeTableCellRenderer.this.table);
+                    if (win != null) {
+                        win.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+                    }
+                }
+            });
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected TreeModelListener createTreeModelListener() {
+        return new TreeModelListener() {
+            public void treeNodesChanged(TreeModelEvent e) { }
+
+            public void treeNodesInserted(TreeModelEvent e) { }
+
+            public void treeStructureChanged(TreeModelEvent e) { }
+
+            public void treeNodesRemoved(TreeModelEvent e) { }
+        };
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public void setBounds(int x, int y, int w, int h) {
+        super.setBounds(x, 0, w, table.getHeight());
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public void paint(Graphics g) {
+        g.translate(0, -visibleRow * getRowHeight());
+        try {
+            ui.update(g, this);
+        } catch (NullPointerException e) {
+            // Occurs sometimes...
+            g.translate(0, visibleRow * getRowHeight());
+            paint(g);
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
+        if (isSelected) {
+            setBackground(table.getSelectionBackground());
+        } else {
+            setBackground(table.getBackground());
+        }
+        visibleRow = row;
+
+        return this;
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabTreeTableModel.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabTreeTableModel.java
new file mode 100644 (file)
index 0000000..635635e
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser;
+
+import javax.swing.tree.TreeModel;
+
+/**
+ * The tree table model interface
+ * @author Calixte DENIZET
+ */
+public interface ScilabTreeTableModel extends TreeModel {
+
+    /**
+     * @return the number of available columns.
+     */
+    public int getColumnCount();
+
+    /**
+     * @param column the column number
+     * @return the name for column number
+     */
+    public String getColumnName(int column);
+
+    /**
+     * @param column the column number
+     * @return the type for column number
+     */
+    public Class getColumnClass(int column);
+
+    /**
+     * @param node the node
+     * @param column the column number
+     * @return the value to be displayed for node at column number
+     */
+    public Object getValueAt(Object node, int column);
+
+    /**
+     * @param node the node
+     * @param column the column number
+     * @return true if the cell is editable
+     */
+    public boolean isCellEditable(Object node, int column);
+
+    /**
+     * @param value the value to set
+     * @param node the node
+     * @param column the column number
+     */
+    public void setValueAt(Object value, Object node, int column);
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabTreeTableModelAdapter.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabTreeTableModelAdapter.java
new file mode 100644 (file)
index 0000000..db38357
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser;
+
+import javax.swing.table.AbstractTableModel;
+import javax.swing.JTree;
+import javax.swing.tree.TreePath;
+import javax.swing.event.EventListenerList;
+import javax.swing.event.TreeExpansionEvent;
+import javax.swing.event.TreeExpansionListener;
+
+/**
+ * The tree table model abstract implementation
+ * @author Calixte DENIZET
+ */
+public class ScilabTreeTableModelAdapter extends AbstractTableModel {
+
+    private JTree tree;
+    private ScilabTreeTableModel treeTableModel;
+
+    /**
+     * Default constructor
+     * @param treeTableModel the table model
+     * @param tree the tree
+     */
+    public ScilabTreeTableModelAdapter(ScilabTreeTableModel treeTableModel, JTree tree) {
+        this.tree = tree;
+        this.treeTableModel = treeTableModel;
+        tree.addTreeExpansionListener(new TreeExpansionListener() {
+                public void treeExpanded(TreeExpansionEvent event) {
+                    fireTableDataChanged();
+                }
+                public void treeCollapsed(TreeExpansionEvent event) {
+                    fireTableDataChanged();
+                }
+            });
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public int getColumnCount() {
+        return treeTableModel.getColumnCount();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public String getColumnName(int column) {
+        return treeTableModel.getColumnName(column);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public Class getColumnClass(int column) {
+        return treeTableModel.getColumnClass(column);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public int getRowCount() {
+        return tree.getRowCount();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected Object nodeForRow(int row) {
+        TreePath treePath = tree.getPathForRow(row);
+        return treePath.getLastPathComponent();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public Object getValueAt(int row, int column) {
+        return treeTableModel.getValueAt(nodeForRow(row), column);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public boolean isCellEditable(int row, int column) {
+        return treeTableModel.isCellEditable(nodeForRow(row), column);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public void setValueAt(Object value, int row, int column) {
+        treeTableModel.setValueAt(value, nodeForRow(row), column);
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/SwingScilabFileBrowser.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/SwingScilabFileBrowser.java
new file mode 100644 (file)
index 0000000..ba62363
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser;
+
+import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.InterpreterException;
+import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
+import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
+import org.scilab.modules.gui.menu.Menu;
+import org.scilab.modules.gui.menu.ScilabMenu;
+import org.scilab.modules.gui.menubar.MenuBar;
+import org.scilab.modules.gui.menubar.ScilabMenuBar;
+import org.scilab.modules.gui.messagebox.ScilabModalDialog;
+import org.scilab.modules.gui.messagebox.ScilabModalDialog.IconType;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.tab.SimpleTab;
+import org.scilab.modules.gui.tab.Tab;
+import org.scilab.modules.gui.textbox.TextBox;
+import org.scilab.modules.gui.toolbar.ScilabToolBar;
+import org.scilab.modules.gui.toolbar.ToolBar;
+import org.scilab.modules.gui.utils.UIElementMapper;
+import org.scilab.modules.gui.utils.WindowsConfigurationManager;
+import org.scilab.modules.gui.window.Window;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+import org.scilab.modules.ui_data.filebrowser.actions.CloseAction;
+import org.scilab.modules.ui_data.filebrowser.actions.GoToHomeAction;
+import org.scilab.modules.ui_data.filebrowser.actions.GoToSCIAction;
+
+/**
+ * Swing implementation of Scilab Variable browser
+ * uses JTable
+ * @author Calixte DENIZET
+ */
+public final class SwingScilabFileBrowser extends SwingScilabTab implements Tab {
+
+    public static final String FILEBROWSERUUID = "3b649047-6a71-4998-bd8e-00d367a4793d";
+
+    private ScilabFileBrowserComponent filebrowser;
+
+    /**
+     * Create a JTable with data Model.
+     * @param columnsName : Titles of JTable columns.
+     */
+    public SwingScilabFileBrowser() {
+        super(UiDataMessages.FILE_BROWSER, FILEBROWSERUUID);
+        addMenuBar(createMenuBar());
+        filebrowser = new ScilabFileBrowserComponent();
+
+        ToolBar toolBar = ScilabToolBar.createToolBar();
+        toolBar.add(filebrowser.getPreviousButton());
+        toolBar.add(filebrowser.getNextButton());
+        toolBar.addSeparator();
+        toolBar.add(GoToHomeAction.createButton());
+        toolBar.add(GoToSCIAction.createButton());
+
+        addToolBar(toolBar);
+        setContentPane(filebrowser);
+    }
+
+    /**
+     * Set the base directory
+     * @param baseDir the base directory
+     */
+    public void setBaseDir(String baseDir) {
+        filebrowser.setBaseDir(baseDir);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public SimpleTab getAsSimpleTab() {
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Window getParentWindow() {
+        return (Window) UIElementMapper.getCorrespondingUIElement(getParentWindowId());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void addInfoBar(TextBox infoBarToAdd) {
+        setInfoBar(infoBarToAdd);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void addMenuBar(MenuBar menuBarToAdd) {
+        setMenuBar(menuBarToAdd);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void addToolBar(ToolBar toolBarToAdd) {
+        setToolBar(toolBarToAdd);
+    }
+
+    /**
+     * Create History Browser MenuBar
+     * @return the menu bar
+     */
+    private static MenuBar createMenuBar() {
+        MenuBar menuBar = ScilabMenuBar.createMenuBar();
+        Menu fileMenu = ScilabMenu.createMenu();
+        fileMenu.setText(UiDataMessages.FILE);
+        fileMenu.setMnemonic('F');
+
+        fileMenu.add(CloseAction.createMenu());
+
+        menuBar.add(fileMenu);
+
+        return menuBar;
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/SwingScilabTreeTable.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/SwingScilabTreeTable.java
new file mode 100644 (file)
index 0000000..6f2d109
--- /dev/null
@@ -0,0 +1,420 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.io.File;
+import java.lang.reflect.Method;
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.regex.Pattern;
+
+import javax.swing.AbstractCellEditor;
+import javax.swing.ActionMap;
+import javax.swing.InputMap;
+import javax.swing.JLabel;
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.JTree;
+import javax.swing.KeyStroke;
+import javax.swing.SwingUtilities;
+import javax.swing.border.AbstractBorder;
+import javax.swing.border.Border;
+import javax.swing.plaf.basic.BasicTreeUI;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.TableCellEditor;
+import javax.swing.table.TableCellRenderer;
+import javax.swing.table.TableColumn;
+import javax.swing.tree.TreePath;
+
+import org.scilab.modules.action_binding.InterpreterManagement;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.ui_data.filebrowser.actions.ChangeCWDAction;
+import org.scilab.modules.ui_data.filebrowser.actions.EditFileWithDefaultAppAction;
+import org.scilab.modules.ui_data.filebrowser.actions.ExecuteFileInConsoleAction;
+import org.scilab.modules.ui_data.filebrowser.actions.ExecuteFileInXcosAction;
+import org.scilab.modules.ui_data.filebrowser.actions.LoadFileAsGraphAction;
+import org.scilab.modules.ui_data.filebrowser.actions.LoadFileInScilabAction;
+import org.scilab.modules.ui_data.filebrowser.actions.OpenFileInSciNotesAction;
+import org.scilab.modules.ui_data.filebrowser.actions.OpenFileWithDefaultAppAction;
+import org.scilab.modules.ui_data.filebrowser.actions.ValidateAction;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+
+/**
+ * The tree table model abstract implementation
+ * @author Calixte DENIZET
+ */
+public class SwingScilabTreeTable extends JTable {
+
+    private static final Insets INSETS = new Insets(0, 2, 0, 0);
+    private static final DateFormat DATEFORMAT = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
+
+    private static final Border BORDER = new AbstractBorder() {
+            public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
+                g.setColor(Color.LIGHT_GRAY);
+                g.drawLine(x, y, x, y + height);
+            }
+
+            public Insets getBorderInsets(Component c) {
+                return INSETS;
+            }
+
+            public Insets getBorderInsets(Component c, Insets insets) {
+                return INSETS;
+            }
+        };
+
+    private Method isLocationInExpandControl;
+
+    protected ScilabTreeTableCellRenderer tree;
+    protected ScilabFileSelectorComboBox combobox;
+    protected ScilabFileBrowserHistory history;
+
+    /**
+     * Default Constructor
+     * @param treeTableModel the tree table model
+     * @param combobox the combox used to set the path
+     */
+    public SwingScilabTreeTable(ScilabTreeTableModel treeTableModel, ScilabFileSelectorComboBox combobox) {
+        super();
+        this.combobox = combobox;
+        combobox.setTreeTable(this);
+        history = new ScilabFileBrowserHistory(this);
+        tree = new ScilabTreeTableCellRenderer(this, treeTableModel);
+        super.setModel(new ScilabTreeTableModelAdapter(treeTableModel, tree));
+
+        // Install the tree editor renderer and editor.
+        setDefaultRenderer(ScilabTreeTableModel.class, tree);
+        setDefaultRenderer(Date.class, new DefaultTableCellRenderer() {
+                {
+                    setHorizontalTextPosition(DefaultTableCellRenderer.LEFT);
+                }
+
+            public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean focus, int row, int col) {
+                JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, selected, focus, row, col);
+                label.setText(DATEFORMAT.format((Date) value));
+                if (col == 1) {
+                    label.setBorder(BORDER);
+                }
+                return label;
+            }
+        });
+        setDefaultRenderer(ScilabFileBrowserModel.FileSize.class, new DefaultTableCellRenderer() {
+                {
+                    setHorizontalTextPosition(DefaultTableCellRenderer.LEFT);
+                }
+
+            public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean focus, int row, int col) {
+                Component c = super.getTableCellRendererComponent(table, value, selected, focus, row, col);
+                if (col == 1) {
+                    JLabel jl = (JLabel) c;
+                    jl.setBorder(BORDER);
+                }
+                return c;
+            }
+        });
+        setDefaultRenderer(String.class, new DefaultTableCellRenderer() {
+                {
+                    setHorizontalTextPosition(DefaultTableCellRenderer.LEFT);
+                }
+
+            public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean focus, int row, int col) {
+                Component c = super.getTableCellRendererComponent(table, value, selected, focus, row, col);
+                if (col == 1) {
+                    JLabel jl = (JLabel) c;
+                    jl.setBorder(BORDER);
+                }
+                return c;
+            }
+        });
+
+
+        setShowGrid(false);
+        setFillsViewportHeight(true);
+        setIntercellSpacing(new Dimension(0, 0));
+        setRowSorter(new FileBrowserRowSorter(tree, this));
+        setAutoResizeMode(AUTO_RESIZE_NEXT_COLUMN);
+
+
+        try {
+            isLocationInExpandControl = BasicTreeUI.class.getDeclaredMethod("isLocationInExpandControl", new Class[]{TreePath.class, int.class, int.class});
+            isLocationInExpandControl.setAccessible(true);
+        } catch (NoSuchMethodException e) { }
+
+        addMouseListener(new MouseAdapter() {
+                public void mousePressed(MouseEvent e) {
+                    Point p = e.getPoint();
+                    int col = columnAtPoint(p);
+                    if (getColumnClass(col) == ScilabTreeTableModel.class && SwingUtilities.isLeftMouseButton(e)) {
+                        MouseEvent me = e;
+                        if (isLocationInExpandControl != null) {
+                            try {
+                                int row = rowAtPoint(p);
+                                TreePath path = tree.getPathForRow(row);
+                                boolean isOnExpander = ((Boolean) isLocationInExpandControl.invoke(tree.getUI(), path, e.getX(), e.getY())).booleanValue();
+                                Rectangle r = tree.getRowBounds(row);
+                                if (!isOnExpander && !r.contains(p)) {
+                                    me = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), r.x, r.y, e.getClickCount(), e.isPopupTrigger());
+                                }
+                            } catch (Exception ex) { }
+                        }
+                        tree.dispatchEvent(me);
+                    }
+                }
+            });
+
+        initActions();
+        setComponentPopupMenu(createPopup());
+    }
+
+    /**
+     * @return the Next button used in history
+     */
+    public PushButton getNextButton() {
+        return history.getNextButton();
+    }
+
+    /**
+     * @return the Previous button used in history
+     */
+    public PushButton getPreviousButton() {
+        return history.getPreviousButton();
+    }
+
+    /**
+     * @return the combobox used to set the path
+     */
+    public ScilabFileSelectorComboBox getComboBox() {
+        return combobox;
+    }
+
+    /**
+     * Get the selected rows as file path
+     * @return the paths
+     */
+    public String[] getSelectedPaths() {
+        int[] rows = getSelectedRows();
+        String[] paths = new String[rows.length];
+        for (int i = 0; i < rows.length; i++) {
+            TreePath path = tree.getPathForRow(rows[i]);
+            FileNode fn = (FileNode) path.getLastPathComponent();
+            paths[i] = fn.getFile().getAbsolutePath();
+        }
+
+        return paths;
+    }
+
+    /**
+     * Get the selected rows as file
+     * @return the paths
+     */
+    public File[] getSelectedFiles() {
+        int[] rows = getSelectedRows();
+        File[] files = new File[rows.length];
+        for (int i = 0; i < rows.length; i++) {
+            TreePath path = tree.getPathForRow(rows[i]);
+            FileNode fn = (FileNode) path.getLastPathComponent();
+            files[i] = fn.getFile();
+        }
+
+        return files;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getRowHeight(int row) {
+        return getRowHeight();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isOpaque() {
+        return false;
+    }
+
+    /**
+     * Set the base directory
+     * @param baseDir the base directory
+     */
+    public void setBaseDir(String baseDir) {
+        setBaseDir(baseDir, true);
+    }
+
+    /**
+     * Set the base directory
+     * @param baseDir the base directory
+     * @param addInHistory if true the dir is add in the history
+     */
+    public void setBaseDir(String baseDir, boolean addInHistory) {
+        ScilabFileBrowserModel model = (ScilabFileBrowserModel) tree.getModel();
+        combobox.setBaseDir(baseDir);
+        File f = new File(baseDir);
+        if (!baseDir.equals(model.getBaseDir()) && f.exists() && f.isDirectory() && f.canRead()) {
+            tree.setModel(null);
+            if (addInHistory) {
+                history.addPathInHistory(baseDir);
+            } else {
+                InterpreterManagement.requestScilabExec("chdir('" + baseDir + "')");
+            }
+            model.setBaseDir(baseDir, this);
+        }
+    }
+
+    /**
+     * Set the file filter to use in table
+     * @param pat the pattern to use
+     */
+    public void setFilter(Pattern pat) {
+        ScilabFileBrowserModel model = (ScilabFileBrowserModel) tree.getModel();
+        TreePath rootPath = new TreePath(model.getRoot());
+        Enumeration<TreePath> en = tree.getExpandedDescendants(rootPath);
+        tree.setModel(null);
+        model.setFilter(pat);
+        reload(model);
+        if (en != null) {
+            while (en.hasMoreElements()) {
+                tree.expandPath(en.nextElement());
+            }
+        }
+    }
+
+    /**
+     * Reload the table
+     */
+    public void reload(ScilabFileBrowserModel model) {
+        tree.setModel(model);
+        tree.setRowHeight(getRowHeight());
+        tree.setLargeModel(true);
+        TreePath path = new TreePath(model.getRoot());
+        tree.collapsePath(path);
+        ((JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, this)).getVerticalScrollBar().setValue(0);
+        tree.expandPath(path);
+        editingRow = 0;
+    }
+
+    /* Workaround for BasicTableUI anomaly. Make sure the UI never tries to
+     * paint the editor. The UI currently uses different techniques to
+     * paint the renderers and editors and overriding setBounds() below
+     * is not the right thing to do for an editor. Returning -1 for the
+     * editing row in this case, ensures the editor is never painted.
+     */
+    public int getEditingRow() {
+        if (getColumnClass(editingColumn) == ScilabTreeTableModel.class) {
+            return -1;
+        } else {
+            return editingRow;
+        }
+    }
+
+    /**
+     * Init the actions
+     */
+    private void initActions() {
+        final ActionMap actions = getActionMap();
+        actions.put("scinotes", new OpenFileInSciNotesAction(this));
+        actions.put("xcos", new ExecuteFileInXcosAction(this));
+        actions.put("console", new ExecuteFileInConsoleAction(this));
+        actions.put("load", new LoadFileInScilabAction(this));
+        actions.put("graph", new LoadFileAsGraphAction(this));
+        actions.put("cwd", new ChangeCWDAction(this));
+        if (EditFileWithDefaultAppAction.isSupported()) {
+            actions.put("edit", new EditFileWithDefaultAppAction(this));
+        }
+        if (OpenFileWithDefaultAppAction.isSupported()) {
+            actions.put("open", new OpenFileWithDefaultAppAction(this));
+        }
+        actions.put("validate", new ValidateAction(this));
+        actions.put("validateorexpand", new CallBack(null) {
+                public void callBack() {
+                    int[] rows = getSelectedRows();
+                    if (rows != null && rows.length != 0) {
+                        TreePath path = tree.getPathForRow(rows[0]);
+                        FileNode fn = (FileNode) path.getLastPathComponent();
+                        if (fn.isLeaf()) {
+                            ((CallBack) actions.get("validate")).callBack();
+                        } else {
+                            if (tree.isExpanded(path)) {
+                                tree.collapsePath(path);
+                            } else {
+                                tree.expandPath(path);
+                            }
+                            setRowSelectionInterval(rows[0], rows[0]);
+                        }
+                    }
+                }
+            });
+
+        combobox.setAction((CallBack) actions.get("cwd"));
+        InputMap map = getInputMap();
+        map.put(KeyStroke.getKeyStroke("ENTER"), "validateorexpand");
+    }
+
+    /**
+     * Create the popup menu
+     */
+    private JPopupMenu createPopup() {
+        ActionMap actions = getActionMap();
+        JPopupMenu popup = new JPopupMenu();
+        JMenuItem item = new JMenuItem(UiDataMessages.OPENINSCINOTES);
+        item.addActionListener(actions.get("scinotes"));
+        popup.add(item);
+
+        item = new JMenuItem(UiDataMessages.EXECINCONSOLE);
+        item.addActionListener(actions.get("console"));
+        popup.add(item);
+
+        item = new JMenuItem(UiDataMessages.OPENINXCOS);
+        item.addActionListener(actions.get("xcos"));
+        popup.add(item);
+
+        item = new JMenuItem(UiDataMessages.LOADINSCILAB);
+        item.addActionListener(actions.get("load"));
+        popup.add(item);
+
+        if (actions.get("edit") != null || actions.get("open") != null) {
+            popup.addSeparator();
+        }
+
+        if (actions.get("edit") != null) {
+            item = new JMenuItem(UiDataMessages.EDITWITHDEFAULT);
+            item.addActionListener(actions.get("edit"));
+            popup.add(item);
+        }
+
+        if (actions.get("open") != null) {
+            item = new JMenuItem(UiDataMessages.OPENWITHDEFAULT);
+            item.addActionListener(actions.get("open"));
+            popup.add(item);
+        }
+
+        popup.pack();
+
+        return popup;
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/ChangeCWDAction.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/ChangeCWDAction.java
new file mode 100644 (file)
index 0000000..e8b2bf2
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser.actions;
+
+import java.io.File;
+
+import javax.swing.JButton;
+
+import org.scilab.modules.action_binding.InterpreterManagement;
+import org.scilab.modules.gui.bridge.filechooser.SwingScilabFileChooser;
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+
+import org.scilab.modules.ui_data.FileBrowser;
+import org.scilab.modules.ui_data.filebrowser.FileUtils;
+import org.scilab.modules.ui_data.filebrowser.SwingScilabTreeTable;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+
+/**
+ * Change cwd action
+ * @author Calixte DENIZET
+ */
+public class ChangeCWDAction extends CallBack {
+
+    private SwingScilabTreeTable table;
+
+    /**
+     * Default constructor
+     * @param table the associated table
+     */
+    public ChangeCWDAction(SwingScilabTreeTable table) {
+        super(null);
+        this.table = table;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void callBack() {
+        changeDir(table.getComboBox().getBaseDir());
+    }
+
+    /**
+     * @return the button used to set the cwd in using a JFileChooser
+     */
+    public JButton createButton() {
+        PushButton button = ScilabPushButton.createPushButton();
+        button.setCallback(new CallBack(null) {
+                public void callBack() {
+                    SwingScilabFileChooser filechooser = new SwingScilabFileChooser();
+                    filechooser.setCurrentDirectory(new File(table.getComboBox().getBaseDir()));
+                    filechooser.setTitle(UiDataMessages.SELECTADIR);
+                    filechooser.setMultipleSelection(false);
+                    filechooser.setDirectorySelectionOnly();
+                    filechooser.displayAndWait();
+                    String[] paths = filechooser.getSelection();
+                    if (paths != null && paths.length != 0) {
+                        changeDir(paths[0]);
+                    }
+                }
+            });
+        ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(FileUtils.getClosedDirIcon());
+
+        return (SwingScilabPushButton) button.getAsSimplePushButton();
+    }
+
+    /**
+     * @return the button used to jump to the parent directory
+     */
+    public JButton createParentDirButton() {
+        PushButton button = ScilabPushButton.createPushButton();
+        button.setCallback(new CallBack(null) {
+                public void callBack() {
+                    File f = new File(table.getComboBox().getBaseDir());
+                    if (f.exists()) {
+                        File parent = f.getParentFile();
+                        if (parent.exists() && parent.canRead()) {
+                            changeDir(parent.getAbsolutePath());
+                        }
+                    }
+                }
+            });
+        ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(FileUtils.getUpDirIcon());
+
+        return (SwingScilabPushButton) button.getAsSimplePushButton();
+    }
+
+    /**
+     * Change the dir
+     * @param path the new path
+     */
+    private void changeDir(String path) {
+        File f = new File(path);
+        if (f.exists() && f.isDirectory() && f.canRead()) {
+            InterpreterManagement.requestScilabExec("chdir('" + path + "')");
+            FileBrowser.setBaseDir(path);
+        }
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/CloseAction.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/CloseAction.java
new file mode 100644 (file)
index 0000000..8d71029
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser.actions;
+
+import javax.swing.KeyStroke;
+
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
+import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
+import org.scilab.modules.gui.utils.ClosingOperationsManager;
+import org.scilab.modules.ui_data.filebrowser.ScilabFileBrowser;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+
+/**
+ * Close action
+ * @author Calixte DENIZET
+ */
+public class CloseAction extends CallBack {
+
+    private static final KeyStroke KEY = ScilabKeyStroke.getKeyStroke("OSSCKEY W");
+
+    /**
+     * Default constructor
+     */
+    public CloseAction() {
+        super(null);
+    }
+
+    /**
+     * @return a menuitem associated with this action
+     */
+    public static MenuItem createMenu() {
+        MenuItem item = ScilabMenuItem.createMenuItem();
+        SwingScilabMenuItem swingItem = (SwingScilabMenuItem) item.getAsSimpleMenuItem();
+        swingItem.setAction(new CloseAction());
+        swingItem.setText(UiDataMessages.CLOSE);
+        swingItem.setAccelerator(KEY);
+
+        return item;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void callBack() {
+        ClosingOperationsManager.startClosingOperation((SwingScilabTab) ScilabFileBrowser.getFileBrowser());
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/EditFileWithDefaultAppAction.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/EditFileWithDefaultAppAction.java
new file mode 100644 (file)
index 0000000..e07ac23
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser.actions;
+
+import java.awt.Desktop;
+import java.io.File;
+
+import javax.swing.SwingUtilities;
+
+import org.scilab.modules.gui.console.ScilabConsole;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.messagebox.ScilabModalDialog;
+import org.scilab.modules.gui.tab.Tab;
+import org.scilab.modules.ui_data.filebrowser.SwingScilabTreeTable;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+
+/**
+ * Action to edit a file with the default associated application
+ * @author Calixte DENIZET
+ */
+public class EditFileWithDefaultAppAction extends CallBack {
+
+    private SwingScilabTreeTable table;
+
+    /**
+     * Default constructor
+     * @param table the table associated with this action
+     */
+    public EditFileWithDefaultAppAction(SwingScilabTreeTable table) {
+        super(null);
+        this.table = table;
+    }
+
+    /**
+     * @return true if this action is available with the OS
+     */
+    public static boolean isSupported() {
+        return Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.EDIT);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void callBack() {
+        Desktop dt = Desktop.getDesktop();
+        File[] files = table.getSelectedFiles();
+        for (File file : files) {
+            try {
+                dt.edit(file);
+            } catch (Exception e) {
+                ScilabModalDialog.show((Tab) SwingUtilities.getAncestorOfClass(Tab.class, table), String.format(UiDataMessages.CANNOTREAD, file.getName()));
+            }
+        }
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/ExecuteCommandAction.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/ExecuteCommandAction.java
new file mode 100644 (file)
index 0000000..c1f611b
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser.actions;
+
+import java.io.File;
+
+import javax.swing.SwingUtilities;
+
+import org.scilab.modules.gui.console.ScilabConsole;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.messagebox.ScilabModalDialog;
+import org.scilab.modules.gui.tab.Tab;
+import org.scilab.modules.localization.Messages;
+import org.scilab.modules.ui_data.filebrowser.SwingScilabTreeTable;
+
+/**
+ * Action to execute a command
+ * @author Calixte DENIZET
+ */
+
+public class ExecuteCommandAction extends CallBack {
+
+    private SwingScilabTreeTable table;
+    private String cmd;
+
+    /**
+     * Default constructor
+     * @param table the table associated with this action
+     * @param the command with a %s which will be replaced by the file name
+     */
+    public ExecuteCommandAction(SwingScilabTreeTable table, String cmd) {
+        super(null);
+        this.table = table;
+        this.cmd = cmd;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void callBack() {
+        String[] paths = table.getSelectedPaths();
+        for (String path : paths) {
+            File f = new File(path);
+            if (f.exists() && f.canRead() && f.isFile()) {
+                try {
+                    String com = String.format(cmd, path);
+                    ScilabConsole.getConsole().getAsSimpleConsole().sendCommandsToScilab(com, true /* display */, true /* store in history */);
+                } catch (NoClassDefFoundError e) {
+                    ScilabModalDialog.show((Tab) SwingUtilities.getAncestorOfClass(Tab.class, table), Messages.gettext("Feature not available in this mode..."));
+                }
+            }
+        }
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/ExecuteFileInConsoleAction.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/ExecuteFileInConsoleAction.java
new file mode 100644 (file)
index 0000000..2b05fee
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser.actions;
+
+import org.scilab.modules.ui_data.filebrowser.SwingScilabTreeTable;
+
+/**
+ * Action to execute the file in the console
+ * @author Calixte DENIZET
+ */
+public class ExecuteFileInConsoleAction extends ExecuteCommandAction {
+
+    private static final String EXEC = "exec('%s',-1)";
+
+    /**
+     * {@inheritDoc}
+     */
+    public ExecuteFileInConsoleAction(SwingScilabTreeTable table) {
+        super(table, EXEC);
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/ExecuteFileInXcosAction.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/ExecuteFileInXcosAction.java
new file mode 100644 (file)
index 0000000..11732d1
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser.actions;
+
+import org.scilab.modules.ui_data.filebrowser.SwingScilabTreeTable;
+
+/**
+ * Action to execute the file in Xcos
+ * @author Calixte DENIZET
+ */
+public class ExecuteFileInXcosAction extends ExecuteCommandAction {
+
+    private static final String XCOS = "xcos('%s')";
+
+    /**
+     * {@inheritDoc}
+     */
+    public ExecuteFileInXcosAction(SwingScilabTreeTable table) {
+        super(table, XCOS);
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/GoToHomeAction.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/GoToHomeAction.java
new file mode 100644 (file)
index 0000000..8e9ec2f
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser.actions;
+
+import java.io.File;
+
+import org.scilab.modules.action_binding.InterpreterManagement;
+import org.scilab.modules.commons.ScilabConstants;
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+
+import org.scilab.modules.ui_data.FileBrowser;
+import org.scilab.modules.ui_data.filebrowser.FileUtils;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+
+/**
+ * Action to go to user-home
+ * @author Calixte DENIZET
+ */
+public class GoToHomeAction extends CallBack {
+
+    /**
+     * {@inheritDoc}
+     */
+    public GoToHomeAction() {
+        super(null);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void callBack() {
+        File f = new File(ScilabConstants.USERHOME);
+        if (f.exists() && f.isDirectory() && f.canRead()) {
+            InterpreterManagement.requestScilabExec("chdir('" + f.getAbsolutePath() + "')");
+            FileBrowser.setBaseDir(f.getAbsolutePath());
+        }
+    }
+
+    /**
+     * @return the corresponding button
+     */
+    public static PushButton createButton() {
+        PushButton button = ScilabPushButton.createPushButton();
+        button.setCallback(new GoToHomeAction());
+        button.setText(UiDataMessages.USERHOME);
+        ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(FileUtils.getClosedUserHomeIcon());
+
+        return button;
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/GoToSCIAction.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/GoToSCIAction.java
new file mode 100644 (file)
index 0000000..bcb9a1c
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser.actions;
+
+import java.io.File;
+
+import org.scilab.modules.action_binding.InterpreterManagement;
+import org.scilab.modules.commons.ScilabConstants;
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+
+import org.scilab.modules.ui_data.FileBrowser;
+import org.scilab.modules.ui_data.filebrowser.FileUtils;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+
+/**
+ * Action to go to SCI
+ * @author Calixte DENIZET
+ */
+public class GoToSCIAction extends CallBack {
+
+    /**
+     * {@inheritDoc}
+     */
+    public GoToSCIAction() {
+        super(null);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void callBack() {
+        File f = new File(System.getenv("SCI"));
+        if (f.exists() && f.isDirectory() && f.canRead()) {
+            InterpreterManagement.requestScilabExec("chdir('" + f.getAbsolutePath() + "')");
+            FileBrowser.setBaseDir(f.getAbsolutePath());
+        }
+    }
+
+    /**
+     * @return the corresponding button
+     */
+    public static PushButton createButton() {
+        PushButton button = ScilabPushButton.createPushButton();
+        button.setCallback(new GoToSCIAction());
+        button.setText(UiDataMessages.SCIFOLDER);
+        ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(FileUtils.getSCIIcon());
+
+        return button;
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/LoadFileAsGraphAction.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/LoadFileAsGraphAction.java
new file mode 100644 (file)
index 0000000..f7dd34e
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser.actions;
+
+import org.scilab.modules.ui_data.filebrowser.SwingScilabTreeTable;
+
+/**
+ * Action to load the file as a graph
+ * @author Calixte DENIZET
+ */
+public class LoadFileAsGraphAction extends ExecuteCommandAction {
+
+    private static final String LOADGRAPH = "load_graph('%s')";
+
+    /**
+     * {@inheritDoc}
+     */
+    public LoadFileAsGraphAction(SwingScilabTreeTable table) {
+        super(table, LOADGRAPH);
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/LoadFileInScilabAction.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/LoadFileInScilabAction.java
new file mode 100644 (file)
index 0000000..3ce20a8
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser.actions;
+
+import org.scilab.modules.ui_data.filebrowser.SwingScilabTreeTable;
+
+/**
+ * Action to load the file in Scilab
+ * @author Calixte DENIZET
+ */
+public class LoadFileInScilabAction extends ExecuteCommandAction {
+
+    private static final String LOAD = "load('%s')";
+
+    /**
+     * {@inheritDoc}
+     */
+    public LoadFileInScilabAction(SwingScilabTreeTable table) {
+        super(table, LOAD);
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/OpenFileInSciNotesAction.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/OpenFileInSciNotesAction.java
new file mode 100644 (file)
index 0000000..3a3d134
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser.actions;
+
+import java.io.File;
+import java.lang.reflect.Method;
+
+import javax.swing.JTree;
+import javax.swing.tree.TreePath;
+
+import org.scilab.modules.ui_data.FileBrowser;
+import org.scilab.modules.ui_data.filebrowser.ScilabFileBrowserModel;
+import org.scilab.modules.ui_data.filebrowser.SwingScilabTreeTable;
+import org.scilab.modules.gui.events.callback.CallBack;
+
+/**
+ * Action to open the file in SciNotes
+ * @author Calixte DENIZET
+ */
+public class OpenFileInSciNotesAction extends CallBack {
+
+    private SwingScilabTreeTable table;
+
+    /**
+     * Default constructor
+     * @param table the table associated with this action
+     */
+    public OpenFileInSciNotesAction(SwingScilabTreeTable table) {
+        super(null);
+        this.table = table;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void callBack() {
+        Class scinotesClass = null;
+        Method scinotes = null;
+        try {
+            scinotesClass = Class.forName("org.scilab.modules.scinotes.SciNotes");
+            scinotes = scinotesClass.getMethod("scinotes", new Class[] {String.class});
+        } catch (ClassNotFoundException e) {
+            System.err.println("Could not find SciNotes class");
+            e.printStackTrace();
+        } catch (SecurityException e) {
+            System.err.println("Security error: Could not access to SciNotes class");
+            e.printStackTrace();
+        } catch (NoSuchMethodException e) {
+            System.err.println("Could not access to scinotesWithText method from object SciNotes");
+            e.printStackTrace();
+        }
+        if (scinotesClass != null && scinotes != null) {
+            final Method scin = scinotes;
+            String[] paths = table.getSelectedPaths();
+            for (final String path : paths) {
+                File f = new File(path);
+                if (f.exists() && f.canRead() && f.isFile()) {
+                    Thread t = new Thread(new Runnable() {
+                            public void run() {
+                                try {
+                                    scin.invoke(null, new Object[]{path});
+                                } catch (Exception e) { e.printStackTrace(); }
+                            }
+                        });
+                    try {
+                        t.start();
+                    } catch (Exception e) { }
+                }
+            }
+        }
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/OpenFileWithDefaultAppAction.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/OpenFileWithDefaultAppAction.java
new file mode 100644 (file)
index 0000000..8796012
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser.actions;
+
+import java.awt.Desktop;
+import java.io.File;
+
+import javax.swing.SwingUtilities;
+
+import org.scilab.modules.gui.console.ScilabConsole;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.messagebox.ScilabModalDialog;
+import org.scilab.modules.gui.tab.Tab;
+import org.scilab.modules.ui_data.filebrowser.SwingScilabTreeTable;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+
+/**
+ * Action to open a file with the default associated application
+ * @author Calixte DENIZET
+ */
+public class OpenFileWithDefaultAppAction extends CallBack {
+
+    private SwingScilabTreeTable table;
+
+    /**
+     * Default constructor
+     * @param table the table associated with this action
+     */
+    public OpenFileWithDefaultAppAction(SwingScilabTreeTable table) {
+        super(null);
+        this.table = table;
+    }
+
+    /**
+     * @return true if this action is available with the OS
+     */
+    public static boolean isSupported() {
+        return Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void callBack() {
+        Desktop dt = Desktop.getDesktop();
+        File[] files = table.getSelectedFiles();
+        for (File file : files) {
+            try {
+                dt.open(file);
+            } catch (Exception e) {
+                ScilabModalDialog.show((Tab) SwingUtilities.getAncestorOfClass(Tab.class, table), String.format(UiDataMessages.CANNOTOPEN, file.getName()));
+            }
+        }
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/ValidateAction.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/actions/ValidateAction.java
new file mode 100644 (file)
index 0000000..eb4ba5e
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.filebrowser.actions;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.Action;
+import javax.swing.ActionMap;
+
+import org.scilab.modules.ui_data.filebrowser.FileUtils;
+import org.scilab.modules.ui_data.filebrowser.SwingScilabTreeTable;
+import org.scilab.modules.gui.events.callback.CallBack;
+
+/**
+ * Action to validate a file
+ * @author Calixte DENIZET
+ */
+public class ValidateAction extends CallBack {
+
+    private SwingScilabTreeTable table;
+    private Map<String, Action> ext = new HashMap<String, Action>();
+
+    /**
+     * Default constructor
+     * @param table the table associated with this action
+     */
+    public ValidateAction(SwingScilabTreeTable table) {
+        super(null);
+        this.table = table;
+        ActionMap actions = table.getActionMap();
+        ext.put("sce", actions.get("scinotes"));
+        ext.put("sci", actions.get("scinotes"));
+        ext.put("tst", actions.get("scinotes"));
+        ext.put("dem", actions.get("scinotes"));
+        ext.put("xcos", actions.get("xcos"));
+        ext.put("cos", actions.get("xcos"));
+        ext.put("cosf", actions.get("xcos"));
+        ext.put("bin", actions.get("load"));
+        ext.put("scg", actions.get("load"));
+        ext.put("sav", actions.get("load"));
+        ext.put("graph", actions.get("graph"));
+        ext.put("pdf", actions.get("open"));
+        ext.put("png", actions.get("open"));
+        ext.put("gif", actions.get("open"));
+        ext.put("jpg", actions.get("open"));
+        ext.put("jpeg", actions.get("open"));
+        ext.put("html", actions.get("open"));
+        ext.put("htm", actions.get("open"));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void callBack() {
+        File[] files = table.getSelectedFiles();
+        if (files[0].isDirectory() && files[0].canRead()) {
+            table.getComboBox().setBaseDirAndValidate(files[0].getAbsolutePath());
+            return;
+        }
+
+        String extension = FileUtils.getFileExtension(files[0]).toLowerCase();
+        CallBack c = (CallBack) ext.get(extension);
+        if (c != null) {
+            c.callBack();
+        } else {
+            ((CallBack) ext.get("sce")).callBack();
+        }
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/tabfactory/FileBrowserTab.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/tabfactory/FileBrowserTab.java
new file mode 100644 (file)
index 0000000..7dbf2a8
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) DIGITEO - 2011 - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.tabfactory;
+
+import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
+import org.scilab.modules.gui.tabfactory.ScilabTabFactory;
+import org.scilab.modules.gui.utils.ClosingOperationsManager;
+import org.scilab.modules.gui.utils.WindowsConfigurationManager;
+import org.scilab.modules.ui_data.filebrowser.ScilabFileBrowser;
+
+/**
+ * Class to create File Browser instances
+ * @author Calixte DENIZET
+ */
+public class FileBrowserTab {
+
+    /**
+     * @param uuid the uuid to restore
+     * @return a new SciNotes instance
+     */
+    public static SwingScilabTab getFileBrowserInstance() {
+       final SwingScilabTab filebrowser = ScilabFileBrowser.createFileBrowserTab();
+       ScilabTabFactory.getInstance().addToCache(filebrowser);
+        
+       ClosingOperationsManager.registerClosingOperation(filebrowser, new ClosingOperationsManager.ClosingOperation() {
+
+                public boolean canClose() {
+                    return true;
+                }
+
+                public void destroy() {
+                    ScilabFileBrowser.closeFileBrowser();
+                }
+
+                public String askForClosing() {
+                    return null;
+                }
+            });
+
+        ClosingOperationsManager.addDependencyWithRoot(filebrowser);
+
+        return filebrowser;
+    }
+}
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/tabfactory/FileBrowserTabFactory.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/tabfactory/FileBrowserTabFactory.java
new file mode 100644 (file)
index 0000000..b4cc53d
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) DIGITEO - 2011 - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.tabfactory;
+
+import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
+import org.scilab.modules.gui.tabfactory.AbstractScilabTabFactory;
+import org.scilab.modules.ui_data.filebrowser.SwingScilabFileBrowser;
+
+/**
+ * The main Tab factory.
+ * A component which needs to restore a Tab with a given uuid must register its factory.
+ *
+ * @author Calixte DENIZET
+ */
+public class FileBrowserTabFactory extends AbstractScilabTabFactory {
+
+    public static final String APPLICATION = "FileBrowser";
+    public static final String PACKAGE = "";
+    public static final String CLASS = "org.scilab.modules.ui_data.tabfactory.FileBrowserTabFactory";
+    
+    private static FileBrowserTabFactory instance;
+
+    /**
+     * Default constructor
+     */
+    public FileBrowserTabFactory() {
+       if (instance == null) {
+           instance = this;
+       }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public SwingScilabTab getTab(String uuid) {
+       return FileBrowserTab.getFileBrowserInstance();
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public String getPackage() {
+       return PACKAGE;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getClassName() {
+       return CLASS;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getApplication() {
+       return APPLICATION;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isAValidUUID(String uuid) {
+       return SwingScilabFileBrowser.FILEBROWSERUUID.equals(uuid);
+    }
+
+    /**
+     * @return an instance of this factory
+     */
+    public static FileBrowserTabFactory getInstance() {
+       new FileBrowserTabFactory();
+       
+       return instance;
+    }
+}
index 2d56a45..f47d467 100644 (file)
@@ -63,9 +63,35 @@ public final class UiDataMessages {
     public static final String COPY = Messages.gettext("Copy");
     public static final String PASTE = Messages.gettext("Paste");
     public static final String CUT = Messages.gettext("Cut");
+    public static final String CLEAR = Messages.gettext("Clear");
     public static final String UNDO = Messages.gettext("Undo");
     public static final String REDO = Messages.gettext("Redo");
 
+    public static final String FILE_BROWSER = Messages.gettext("File Browser");
+    public static final String NAME_COLUMN = Messages.gettext("Name");
+    public static final String SIZE_COLUMN = Messages.gettext("Size");
+    public static final String TYPE_COLUMN = Messages.gettext("Type");
+    public static final String LASTMODIF_COLUMN = Messages.gettext("Last modified");
+    public static final String DIRECTORY = Messages.gettext("Directory");
+    public static final String FILETYPE = Messages.gettext("%s File");
+    public static final String FILEFILTER = Messages.gettext("Enter a file filter");
+    public static final String CWD = Messages.gettext("Enter your working folder");
+    public static final String CASESENSITIVE = Messages.gettext("Case sensitive");
+    public static final String REGEXP = Messages.gettext("Regular expression");
+    public static final String SELECTADIR = Messages.gettext("Select a directory");
+    public static final String USERHOME = Messages.gettext("User home");
+    public static final String SCIFOLDER = Messages.gettext("Scilab");
+
+    public static final String CANNOTREAD = Messages.gettext("Cannot edit the file %s");
+    public static final String CANNOTOPEN = Messages.gettext("Cannot open the file %s");
+
+    public static final String OPENINSCINOTES = Messages.gettext("Open with SciNotes");
+    public static final String EXECINCONSOLE = Messages.gettext("Execute in Scilab");
+    public static final String OPENINXCOS = Messages.gettext("Open with Xcos");
+    public static final String LOADINSCILAB = Messages.gettext("Load in Scilab");
+    public static final String EDITWITHDEFAULT = Messages.gettext("Edit with default application");
+    public static final String OPENWITHDEFAULT = Messages.gettext("Open with default application");
+
     /** This class is a static singleton, thus it must not be instantiated */
     private UiDataMessages() { }
 
diff --git a/scilab/modules/ui_data/src/jni/FileBrowser.cpp b/scilab/modules/ui_data/src/jni/FileBrowser.cpp
new file mode 100644 (file)
index 0000000..58784bc
--- /dev/null
@@ -0,0 +1,196 @@
+#include "FileBrowser.hxx"
+/* Generated by GIWS (version 1.2.4) */
+/*
+
+Copyright 2007-2008 INRIA
+Copyright 2008-2011 DIGITEO
+
+Author : Sylvestre Ledru & others
+
+This is generated code.
+
+This software is a computer program whose purpose is to hide the complexity
+of accessing Java objects/methods from C++ code.
+
+This software is governed by the CeCILL-B license under French law and
+abiding by the rules of distribution of free software.  You can  use, 
+modify and/ or redistribute the software under the terms of the CeCILL-B
+license as circulated by CEA, CNRS and INRIA at the following URL
+"http://www.cecill.info". 
+
+As a counterpart to the access to the source code and  rights to copy,
+modify and redistribute granted by the license, users are provided only
+with a limited warranty  and the software's author,  the holder of the
+economic rights,  and the successive licensors  have only  limited
+liability. 
+
+In this respect, the user's attention is drawn to the risks associated
+with loading,  using,  modifying and/or developing or reproducing the
+software by the user in light of its specific status of free software,
+that may mean  that it is complicated to manipulate,  and  that  also
+therefore means  that it is reserved for developers  and  experienced
+professionals having in-depth computer knowledge. Users are therefore
+encouraged to load and test the software's suitability as regards their
+requirements in conditions enabling the security of their systems and/or 
+data to be ensured and,  more generally, to use and operate it in the 
+same conditions as regards security. 
+
+The fact that you are presently reading this means that you have had
+knowledge of the CeCILL-B license and that you accept its terms.
+*/
+
+namespace org_scilab_modules_ui_data {
+
+// Returns the current env
+
+JNIEnv * FileBrowser::getCurrentEnv() {
+JNIEnv * curEnv = NULL;
+jint res=this->jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+if (res != JNI_OK) {
+throw GiwsException::JniException(getCurrentEnv());
+}
+return curEnv;
+}
+// Destructor
+
+FileBrowser::~FileBrowser() {
+JNIEnv * curEnv = NULL;
+this->jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+
+curEnv->DeleteGlobalRef(this->instance);
+curEnv->DeleteGlobalRef(this->instanceClass);
+}
+// Constructors
+FileBrowser::FileBrowser(JavaVM * jvm_) {
+jmethodID constructObject = NULL ;
+jobject localInstance ;
+jclass localClass ;
+const std::string construct="<init>";
+const std::string param="()V";
+jvm=jvm_;
+
+JNIEnv * curEnv = getCurrentEnv();
+
+localClass = curEnv->FindClass( this->className().c_str() ) ;
+if (localClass == NULL) {
+  throw GiwsException::JniClassNotFoundException(curEnv, this->className());
+}
+
+this->instanceClass = static_cast<jclass>(curEnv->NewGlobalRef(localClass));
+
+/* localClass is not needed anymore */
+curEnv->DeleteLocalRef(localClass);
+
+if (this->instanceClass == NULL) {
+throw GiwsException::JniObjectCreationException(curEnv, this->className());
+}
+
+
+constructObject = curEnv->GetMethodID( this->instanceClass, construct.c_str() , param.c_str() ) ;
+if(constructObject == NULL){
+throw GiwsException::JniObjectCreationException(curEnv, this->className());
+}
+
+localInstance = curEnv->NewObject( this->instanceClass, constructObject ) ;
+if(localInstance == NULL){
+throw GiwsException::JniObjectCreationException(curEnv, this->className());
+}
+this->instance = curEnv->NewGlobalRef(localInstance) ;
+if(this->instance == NULL){
+throw GiwsException::JniObjectCreationException(curEnv, this->className());
+}
+/* localInstance not needed anymore */
+curEnv->DeleteLocalRef(localInstance);
+
+                /* Methods ID set to NULL */
+voidopenFileBrowserID=NULL; 
+voidsetBaseDirjstringID=NULL; 
+
+
+}
+
+FileBrowser::FileBrowser(JavaVM * jvm_, jobject JObj) {
+        jvm=jvm_;
+
+        JNIEnv * curEnv = getCurrentEnv();
+
+jclass localClass = curEnv->GetObjectClass(JObj);
+        this->instanceClass = static_cast<jclass>(curEnv->NewGlobalRef(localClass));
+        curEnv->DeleteLocalRef(localClass);
+
+        if (this->instanceClass == NULL) {
+throw GiwsException::JniObjectCreationException(curEnv, this->className());
+        }
+
+        this->instance = curEnv->NewGlobalRef(JObj) ;
+        if(this->instance == NULL){
+throw GiwsException::JniObjectCreationException(curEnv, this->className());
+        }
+        /* Methods ID set to NULL */
+        voidopenFileBrowserID=NULL; 
+voidsetBaseDirjstringID=NULL; 
+
+
+}
+
+// Generic methods
+
+void FileBrowser::synchronize() {
+if (getCurrentEnv()->MonitorEnter(instance) != JNI_OK) {
+throw GiwsException::JniMonitorException(getCurrentEnv(), "FileBrowser");
+}
+}
+
+void FileBrowser::endSynchronize() {
+if ( getCurrentEnv()->MonitorExit(instance) != JNI_OK) {
+throw GiwsException::JniMonitorException(getCurrentEnv(), "FileBrowser");
+}
+}
+// Method(s)
+
+void FileBrowser::openFileBrowser (JavaVM * jvm_){
+
+JNIEnv * curEnv = NULL;
+jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+jclass cls = curEnv->FindClass( className().c_str() );
+
+jmethodID voidopenFileBrowserID = curEnv->GetStaticMethodID(cls, "openFileBrowser", "()V" ) ;
+if (voidopenFileBrowserID == NULL) {
+throw GiwsException::JniMethodNotFoundException(curEnv, "openFileBrowser");
+}
+
+                         curEnv->CallStaticVoidMethod(cls, voidopenFileBrowserID );
+                        curEnv->DeleteLocalRef(cls);
+if (curEnv->ExceptionCheck()) {
+throw GiwsException::JniCallMethodException(curEnv);
+}
+}
+
+void FileBrowser::setBaseDir (JavaVM * jvm_, char * baseDir){
+
+JNIEnv * curEnv = NULL;
+jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+jclass cls = curEnv->FindClass( className().c_str() );
+
+jmethodID voidsetBaseDirjstringID = curEnv->GetStaticMethodID(cls, "setBaseDir", "(Ljava/lang/String;)V" ) ;
+if (voidsetBaseDirjstringID == NULL) {
+throw GiwsException::JniMethodNotFoundException(curEnv, "setBaseDir");
+}
+
+jstring baseDir_ = curEnv->NewStringUTF( baseDir );
+if (baseDir_ == NULL)
+{
+throw GiwsException::JniBadAllocException(curEnv);
+}
+
+
+                         curEnv->CallStaticVoidMethod(cls, voidsetBaseDirjstringID ,baseDir_);
+                        curEnv->DeleteLocalRef(baseDir_);
+curEnv->DeleteLocalRef(cls);
+if (curEnv->ExceptionCheck()) {
+throw GiwsException::JniCallMethodException(curEnv);
+}
+}
+
+}
diff --git a/scilab/modules/ui_data/src/jni/FileBrowser.giws.xml b/scilab/modules/ui_data/src/jni/FileBrowser.giws.xml
new file mode 100644 (file)
index 0000000..abb8532
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<package name="org.scilab.modules.ui_data">
+  <object name="FileBrowser">
+    <method name="openFileBrowser" returnType="void" modifier="static" />
+    <method name="setBaseDir" returnType="void" modifier="static" >
+      <parameter type="String" name="baseDir"/>
+    </method>
+  </object>
+</package>
\ No newline at end of file
diff --git a/scilab/modules/ui_data/src/jni/FileBrowser.hxx b/scilab/modules/ui_data/src/jni/FileBrowser.hxx
new file mode 100644 (file)
index 0000000..d99a443
--- /dev/null
@@ -0,0 +1,144 @@
+/* Generated by GIWS (version 1.2.4) */
+/*
+
+Copyright 2007-2008 INRIA
+Copyright 2008-2011 DIGITEO
+
+Author : Sylvestre Ledru & others
+
+This is generated code.
+
+This software is a computer program whose purpose is to hide the complexity
+of accessing Java objects/methods from C++ code.
+
+This software is governed by the CeCILL-B license under French law and
+abiding by the rules of distribution of free software.  You can  use, 
+modify and/ or redistribute the software under the terms of the CeCILL-B
+license as circulated by CEA, CNRS and INRIA at the following URL
+"http://www.cecill.info". 
+
+As a counterpart to the access to the source code and  rights to copy,
+modify and redistribute granted by the license, users are provided only
+with a limited warranty  and the software's author,  the holder of the
+economic rights,  and the successive licensors  have only  limited
+liability. 
+
+In this respect, the user's attention is drawn to the risks associated
+with loading,  using,  modifying and/or developing or reproducing the
+software by the user in light of its specific status of free software,
+that may mean  that it is complicated to manipulate,  and  that  also
+therefore means  that it is reserved for developers  and  experienced
+professionals having in-depth computer knowledge. Users are therefore
+encouraged to load and test the software's suitability as regards their
+requirements in conditions enabling the security of their systems and/or 
+data to be ensured and,  more generally, to use and operate it in the 
+same conditions as regards security. 
+
+The fact that you are presently reading this means that you have had
+knowledge of the CeCILL-B license and that you accept its terms.
+*/
+
+
+#ifndef __ORG_SCILAB_MODULES_UI_DATA_FILEBROWSER__
+#define __ORG_SCILAB_MODULES_UI_DATA_FILEBROWSER__
+#include <iostream>
+#include <string>
+#include <string.h>
+#include <stdlib.h>
+#include <jni.h>
+
+#include "GiwsException.hxx"
+
+#ifndef _MSC_VER /* Defined anyway with Visual */
+#if !defined(byte)
+typedef signed char byte;
+#else
+#pragma message("Byte has been redefined elsewhere. Some problems can happen")
+#endif
+#endif
+
+namespace org_scilab_modules_ui_data {
+class FileBrowser {
+
+private:
+JavaVM * jvm;
+
+protected:
+jmethodID voidopenFileBrowserID; // cache method id
+jmethodID voidsetBaseDirjstringID; // cache method id
+
+
+
+jobject instance;
+jclass instanceClass; // cache class
+
+
+/**
+* Get the environment matching to the current thread.
+*/
+virtual JNIEnv * getCurrentEnv();
+
+public:
+// Constructor
+/**
+* Create a wrapping of the object from a JNIEnv.
+* It will call the default constructor
+* @param JEnv_ the Java Env
+*/
+FileBrowser(JavaVM * jvm_);
+
+/**
+* Create a wrapping of an already existing object from a JNIEnv.
+* The object must have already been instantiated
+* @param JEnv_ the Java Env
+* @param JObj the object
+*/
+FileBrowser(JavaVM * jvm_, jobject JObj);
+
+
+/** 
+* This is a fake constructor to avoid the constructor
+* chaining when dealing with extended giws classes 
+*/
+#ifdef FAKEGIWSDATATYPE
+FileBrowser(fakeGiwsDataType::fakeGiwsDataType /* unused */) {}
+#endif
+
+// Destructor
+~FileBrowser();
+
+// Generic method
+// Synchronization methods
+/**
+* Enter monitor associated with the object.
+* Equivalent of creating a "synchronized(obj)" scope in Java.
+*/
+void synchronize();
+
+/**
+* Exit monitor associated with the object.
+* Equivalent of ending a "synchronized(obj)" scope.
+*/
+void endSynchronize();
+
+// Methods
+static void openFileBrowser(JavaVM * jvm_);
+
+static void setBaseDir(JavaVM * jvm_, char * baseDir);
+
+
+                        /**
+                        * Get class name to use for static methods
+                        * @return class name to use for static methods
+                        */
+                        
+                static const std::string className()
+                {
+                return "org/scilab/modules/ui_data/FileBrowser";
+                }
+                
+};
+
+
+}
+#endif
index 2b0906a..5915b87 100644 (file)
@@ -14,6 +14,7 @@
 #include "Scierror.h"
 #include "localization.h"
 #include "UpdateBrowseVar.h"
+#include "FileBrowserChDir.h"
 #include "BOOL.h"
 /*--------------------------------------------------------------------------*/
 int gw_ui_data(void)
@@ -27,3 +28,8 @@ void UpdateBrowseVar(BOOL b)
         return;
 }
 /*--------------------------------------------------------------------------*/
+void FileBrowserChDir(char * baseDir)
+{
+        return;
+}
+/*--------------------------------------------------------------------------*/