Author: mes
Date: 2012-01-18 15:37:05 -0800 (Wed, 18 Jan 2012)
New Revision: 28043

Modified:
   
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
   
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JDialogTunableMutator.java
   
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JPanelTunableMutator.java
Log:
fixes #359 We now have special case handling for single file tunables so that 
we only see the file chooser and not the tunable dialog

Modified: 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
===================================================================
--- 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
   2012-01-18 23:33:35 UTC (rev 28042)
+++ 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
   2012-01-18 23:37:05 UTC (rev 28043)
@@ -7,6 +7,8 @@
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
+import java.awt.Component;
+import java.awt.Window;
 import java.io.File;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
@@ -57,6 +59,11 @@
        private boolean input;
        private List<FileChooserFilter> filters;
 
+       private Window possibleParent;
+
+       private String defaultString;
+
+
        /**
         * Constructs the <code>GUIHandler</code> for the <code>File</code> type
         *
@@ -91,8 +98,8 @@
                input = isInput();
 
                final String fileCategory = getFileCategory();
-               filters = 
fileTypesManager.getSupportedFileTypes(DataCategory.valueOf(fileCategory.toUpperCase()),
-                                                                input);
+               filters = 
fileTypesManager.getSupportedFileTypes(DataCategory.valueOf(fileCategory.toUpperCase()),
 input);
+               defaultString = "Please select a " + fileCategory.toLowerCase() 
+ " file...";
 
                setGui();
                setLayout();
@@ -133,7 +140,7 @@
 
                //set title and textfield text for the file type
                final String fileCategory = getFileCategory();
-               fileTextField.setText("Please select a " + 
fileCategory.toLowerCase() + " file...");
+               fileTextField.setText(defaultString);
                titleLabel.setText((input ? "Load " : "Save ") + 
initialCaps(fileCategory) + " File");
        }
 
@@ -184,6 +191,20 @@
                                                  .addContainerGap()));
        }
 
+       /**
+        * This method allows us to bypass the normal tunable support when the 
only
+        * tunable in a Task is a File.  This allows us to pop up a file dialog
+        * without first presenting the tunable dialog.
+        */
+       boolean setFileTunableDirectly(Window possibleParent) {
+               this.possibleParent = possibleParent;
+               setGui();
+               myFileActionListener action = new myFileActionListener();
+               action.actionPerformed(null);
+               handle();
+               return !fileTextField.getText().equals(defaultString);
+       }
+
        // Click on the "open" or "save" button action listener
        private final class myFileActionListener implements ActionListener{
                public void actionPerformed(ActionEvent ae) {
@@ -203,10 +224,14 @@
                                        }
                                }
                        }
-                               
-                       final File file =
-                               
fileUtil.getFile(SwingUtilities.getWindowAncestor(panel),
-                                                titleLabel.getText(), 
load_or_save, filters);
+
+                       // Use the panel's parent if we have it, otherwise use 
the possible
+                       // parent specified in setFileTunableDirectly. 
+                       Component parentComponent = 
SwingUtilities.getWindowAncestor(panel);
+                       if ( parentComponent == null )
+                               parentComponent = possibleParent;
+       
+                       final File file = fileUtil.getFile(parentComponent, 
titleLabel.getText(), load_or_save, filters);
                        if (file != null) {
                                fileTextField.setFont(FILE_NAME_FONT);
                                fileTextField.setText(file.getAbsolutePath());

Modified: 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JDialogTunableMutator.java
===================================================================
--- 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JDialogTunableMutator.java
 2012-01-18 23:33:35 UTC (rev 28042)
+++ 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JDialogTunableMutator.java
 2012-01-18 23:37:05 UTC (rev 28043)
@@ -57,11 +57,19 @@
        
        /** {@inheritDoc} */
        public boolean validateAndWriteBack(Object objectWithTunables) {
-               final JPanel panel = buildConfiguration(objectWithTunables);
+               final JPanel panel = buildConfiguration(objectWithTunables, 
parent);
+
+               // no tunables found, everything OK for task to proceed
                if (panel == null)
                        return true;
 
-               return displayGUI(panel, objectWithTunables);
+               // found the special case of the file handle cancel panel,
+               // which means we should quit now
+               else if ( panel == FILE_HANDLER_CANCEL_PANEL )
+                       return false;
+
+               else
+                       return displayGUI(panel, objectWithTunables);
        }
 
        /** 

Modified: 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JPanelTunableMutator.java
===================================================================
--- 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JPanelTunableMutator.java
  2012-01-18 23:33:35 UTC (rev 28042)
+++ 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JPanelTunableMutator.java
  2012-01-18 23:37:05 UTC (rev 28043)
@@ -2,6 +2,7 @@
 
 
 import java.awt.Color;
+import java.awt.Window;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -59,6 +60,9 @@
        /** Provides an initialised logger. */
        private final Logger logger = 
LoggerFactory.getLogger(JPanelTunableMutator.class);
 
+       /** Do not ever modify this panel! Used for special case handling of 
files. */
+       protected final JPanel FILE_HANDLER_CANCEL_PANEL = new JPanel();
+
        /**
         * Constructor.
         */
@@ -93,7 +97,16 @@
 
        /** {@inheritDoc} */
        public JPanel buildConfiguration(final Object objectWithTunables) {
+               return buildConfiguration(objectWithTunables,null);
+       }
 
+       /** 
+        * A special case of buildConfiguration that allows a parent window to 
be specified.
+        * This special case is when a task only has a single tunable of type 
File, in
+        * which case we don't want to show the normal tunable dialog, just the 
file dialog.
+        */
+       JPanel buildConfiguration(final Object objectWithTunables, Window 
possibleParent) {
+
                int factoryCount = 0; // # of descendents of TaskFactory...
                int otherCount = 0;   // ...everything else.  (Presumeably 
descendents of Task.)
                if (objectWithTunables instanceof TaskFactory)
@@ -135,6 +148,18 @@
                        return null; 
                }
 
+               // This is special case handling for when the only tunable 
specified
+               // in a task is a file, in which case we don't want a full 
tunable dialog
+               // and all of the extra clicks, instead we just want a file 
dialog.
+               if ( handlers.size() == 1 && handlers.get(0) instanceof 
FileHandler ) {
+                       FileHandler fh = (FileHandler) handlers.get(0);
+                       boolean fileFound = 
fh.setFileTunableDirectly(possibleParent);
+                       if ( fileFound )
+                               return null; 
+                       else
+                               return FILE_HANDLER_CANCEL_PANEL;
+               } 
+
                if (!panelMap.containsKey(handlers)) {
                        final String MAIN = " ";
                        Map<String, JPanel> panels = new HashMap<String, 
JPanel>();

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to