Improve FS UI
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 9 Apr 2018 07:06:52 +0000 (09:06 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 9 Apr 2018 07:06:52 +0000 (09:06 +0200)
org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/fs/AdvancedFsBrowser.java
org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/fs/NioFileLabelProvider.java
org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/fs/SimpleFsBrowser.java

index 40d42e3962dae93a0ba2e65de5e1402f9b8439df..136eb5055b3f7e0f59ca97b4630694b5350e01b9 100644 (file)
@@ -31,7 +31,6 @@ import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.Text;
 
-
 /** Simple UI provider that populates a composite parent given a NIO path */
 public class AdvancedFsBrowser {
        private final static Log log = LogFactory.getLog(AdvancedFsBrowser.class);
@@ -288,8 +287,8 @@ public class AdvancedFsBrowser {
        }
 
        /**
-        * Recreates the content of the box that displays information about the
-        * current selected node.
+        * Recreates the content of the box that displays information about the current
+        * selected node.
         */
        private void populateCurrEditedDisplay(Composite parent, Path context) {
                parent.setLayout(new GridLayout());
@@ -355,8 +354,8 @@ public class AdvancedFsBrowser {
                }
 
                /**
-                * Enable highlighting the correct element in the table when externally
-                * browsing (typically via the command-line-like Text field)
+                * Enable highlighting the correct element in the table when externally browsing
+                * (typically via the command-line-like Text field)
                 */
                void setSelected(Path selected) {
                        // to prevent change selection event to be thrown
@@ -399,13 +398,19 @@ public class AdvancedFsBrowser {
                                        IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
                                        if (selection.isEmpty())
                                                return;
-                                       else {
-                                               Path newSelected = (Path) selection.getFirstElement();
-                                               if (newSelected.equals(currSelected))
-                                                       return;
-                                               currSelected = newSelected;
-                                               setEdited(newSelected);
-                                       }
+                                       Object obj = selection.getFirstElement();
+                                       Path newSelected;
+                                       if (obj instanceof Path)
+                                               newSelected = (Path) obj;
+                                       else if (obj instanceof ParentDir)
+                                               newSelected = ((ParentDir) obj).getPath();
+                                       else
+                                               return;
+                                       if (newSelected.equals(currSelected))
+                                               return;
+                                       currSelected = newSelected;
+                                       setEdited(newSelected);
+
                                }
                        });
 
index 68fc70b77dae92714aedbd87ef0c14ff51991b55..e2ea90596a33b0ade3abfcd0aa8acf2a449eab71 100644 (file)
@@ -18,8 +18,19 @@ public class NioFileLabelProvider extends ColumnLabelProvider {
 
        @Override
        public String getText(Object element) {
-               Path path = (Path) element;
                try {
+                       if (element instanceof ParentDir) {
+                               switch (propName) {
+                               case FsUiConstants.PROPERTY_SIZE:
+                                       return "-";
+                               case FsUiConstants.PROPERTY_LAST_MODIFIED:
+                                       return Files.getLastModifiedTime(((ParentDir) element).getPath()).toString();
+                               case FsUiConstants.PROPERTY_TYPE:
+                                       return "Folder";
+                               }
+                       }
+
+                       Path path = (Path) element;
                        switch (propName) {
                        case FsUiConstants.PROPERTY_SIZE:
                                if (Files.isDirectory(path))
@@ -42,7 +53,7 @@ public class NioFileLabelProvider extends ColumnLabelProvider {
                                throw new IllegalArgumentException("Unsupported property " + propName);
                        }
                } catch (IOException ioe) {
-                       throw new FsUiException("Cannot get property " + propName + " on " + path.toString());
+                       throw new FsUiException("Cannot get property " + propName + " on " + element);
                }
        }
 }
index 7bbcd8525e4cee09e82349a07b03656031b8e5f3..ff93d82514b442ce00bdb7a2a84119936696d105 100644 (file)
@@ -167,29 +167,39 @@ public class SimpleFsBrowser extends Composite {
                        }
                });
 
-               directoryDisplayViewer.addDoubleClickListener(new IDoubleClickListener() {
-                       @Override
-                       public void doubleClick(DoubleClickEvent event) {
-                               IStructuredSelection selection = (IStructuredSelection) directoryDisplayViewer.getSelection();
-                               Path selected = null;
-                               if (!selection.isEmpty())
-                                       selected = ((Path) selection.getFirstElement());
-                               if (selected != null) {
-                                       if (!Files.isDirectory(selected))
-                                               return;
-                                       currSelected = selected;
-                                       directoryDisplayViewer.setInput(currSelected, "*");
-                               }
-                       }
-               });
+//             directoryDisplayViewer.addDoubleClickListener(new IDoubleClickListener() {
+//                     @Override
+//                     public void doubleClick(DoubleClickEvent event) {
+//                             IStructuredSelection selection = (IStructuredSelection) directoryDisplayViewer.getSelection();
+//                             Path selected = null;
+//                             if (!selection.isEmpty()) {
+//                                     Object obj = selection.getFirstElement();
+//                                     if (obj instanceof Path)
+//                                             selected = (Path) obj;
+//                                     else if (obj instanceof ParentDir)
+//                                             selected = ((ParentDir) obj).getPath();
+//                             }
+//                             if (selected != null) {
+//                                     if (!Files.isDirectory(selected))
+//                                             return;
+//                                     currSelected = selected;
+//                                     directoryDisplayViewer.setInput(currSelected, "*");
+//                             }
+//                     }
+//             });
 
                directoryDisplayViewer.addDoubleClickListener(new IDoubleClickListener() {
                        @Override
                        public void doubleClick(DoubleClickEvent event) {
                                IStructuredSelection selection = (IStructuredSelection) directoryDisplayViewer.getSelection();
                                Path selected = null;
-                               if (!selection.isEmpty())
-                                       selected = ((Path) selection.getFirstElement());
+                               if (!selection.isEmpty()) {
+                                       Object obj = selection.getFirstElement();
+                                       if (obj instanceof Path)
+                                               selected = (Path) obj;
+                                       else if (obj instanceof ParentDir)
+                                               selected = ((ParentDir) obj).getPath();
+                               }
                                if (selected != null) {
                                        if (!Files.isDirectory(selected))
                                                return;