Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6242241

Add a TransferFlavor that supports D&D of Microsoft Outlook attachments

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 7
    • 5.0, 7
    • client-libs
    • b84
    • x86
    • windows, windows_xp
    • Verified

    Description

      A DESCRIPTION OF THE REQUEST :
      I am trying to provide support for users to drag & drop files into my application. It works fine when dragging from Windows Explorer but if I try to drag an attachment from a Microsoft Outlook message, the only TransferFlavors available are Strings, Readers, InputStreams, etc. and the contents of those items are either blank (in the case of dragging a single attachment) or some semi-colons (in te case of dragging multiple attachments).

      JUSTIFICATION :
      Currently, the only way for the user to drag an attachment from an Outlook message into a Java application is to first save it as a file, then drag the file from Windows Explorer.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Obviously, this is not a simple piece of behavior to implement. First, the message could be in either RTF or HTML format. (I was testing using the HTML format.) Then, in RTF format, it is possible for the user to select both text from the message and attachments at the same time.

      Perhaps on any drag that includes attachments, you could have one flavor that's the same as dragging from Windows Explorer (the x-java-file-list flavor), plus a more complicated flavor for dealing with drags that include both text & attachments. I don't really need that second option, though; just having the first would be awesome.
      ACTUAL -
      Dragging attachments from Outlook only provides plain text flavors.

      ---------- BEGIN SOURCE ----------
          private final class FileHandler extends TransferHandler {
              public boolean canImport(JComponent component,
                                       DataFlavor[] transferFlavors) {
                  for (int index = 0; index < transferFlavors.length; index++) {
                      String subType = transferFlavors[index].getSubType();
                      if (subType.equals("x-java-file-list")) return true;
                      Class rc = transferFlavors[index].getRepresentationClass();
                      if (rc.equals(InputStream.class)) return true;
                  } //Ends for
                  return false;
              } //Ends method canImport

              public boolean importData(JComponent component,
                                        Transferable data) {
                  DataFlavor[] flavors = data.getTransferDataFlavors();
                  System.out.println("Got " + flavors.length + " flavors.");
                  for (int index = 0; index < flavors.length; index++) {
                      String subType = flavors[index].getSubType();
                      if (subType.equals("x-java-file-list")) {
                          try {
                              List fileList = (List)data.getTransferData(flavors[index]);
                              importFiles(fileList);
                              return true;
                          } catch (Exception e) {
                              e.printStackTrace();
                              return false;
                          } //Ends try..catch
                      } else {
                          Class rc = flavors[index].getRepresentationClass();
                          if (rc.equals(InputStream.class)) {
                              try {
                                  InputStream is = (InputStream)data.getTransferData(flavors[index]);
                                  long numBytes = 0;
                                  while (is.read() > 0) numBytes++;
      //This line will show that there were only 2 bytes read.
                                  System.out.println("Num bytes: " + numBytes);
                                  return true;
                              } catch (Exception e) {
                                  e.printStackTrace();
                                  return false;
                              } //Ends try..catch
                          } //Ends if
                      } //Ends if..else
                  } //Ends for
                  return false;
              } //Ends method importData
          } //Ends class FileHandler

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Drag attachments from Outlook into Windows Explorer;
      Drag from Windows Explorer into Java application
      ###@###.### 2005-03-17 17:02:41 GMT

      Attachments

        Issue Links

          Activity

            People

              uta Alexey Utkin (Inactive)
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: