wiki:BASE_DND_R0

Version 8 (modified by peko, 16 years ago) (diff)

--

Error: Macro BackLinksMenu(None) failed
compressed data is corrupt

Error: Macro TicketQuery(summary=BASE_DND_R0, format=table, col=summary|owner|status|type|component|priority|effort|importance, rows=description|analysis_owners|analysis_reviewers|analysis_score|design_owners|design_reviewers|design_score|implementation_owners|implementation_reviewers|implementation_score|test_owners|test_reviewers|test_score|) failed
current transaction is aborted, commands ignored until end of transaction block

Analysis

Overview

  • This task is about the Drag'N'Drop base implementation. Sophie 2.0 should be able to provide a relatively complex DnD behavior.

Task requirements

  • Think of the following scenarios of a DND functionalities:
    • DnD for resources:
      • media resources - audio, video, images etc. (may include things like flash in a later revision).
      • text resources - txt, rtf.
      • html resources.
      • content - text content should be processes when dragged to a text frame for example.
    • DnD into UI components:
      • text frames - should be able to process text dragging and dropping.
      • image frames - should be able to accept DnD of image content.
      • media frames - should be able to accept DnD of media files.
      • palletes:
        • Resource palette:
          • Should process dropping of files.
          • User should be able to drag files outside Sophie 2.0.
        • Same applies to Page templates palette, Plug-in palette, Books palette, Pages palette, Book templates palette etc.
        • Things should be dragged into palettes and out of, or just transfer things from one palette to another

(from Page palette to Page templates palette should create a template for the page that is dragged and dropped in the templates palette.) .

  • work areas - should process dragging of frame templates, resources (resulting in creating an appropriate frame).
  • books desktop - should process creating a book from a template by dropping that template, should be able to export a book template by dragging it to the book templates.
  • All of the things mentioned should be made possible. The person should decide on whether some library should be used or another one should be written.
    • provide a way to actually test the drag and drop functionalities.
    • implement at least 3 DnD scenarios from the table that follows.
  • A description in a wiki page should be created, explaining how to use the library and how things work.
  • Examine the following table => http://spreadsheets.google.com/ccc?key=p-0Oq38E1aysuTs69KE68Nw&hl=en
    • decide what could added.
    • decide if there is something to remove.
  • Unit test for the base implementation.

Task result

  • source code

Implementation idea

  • review DnD library in java.
  • research for some other library.
  • design the final library that we are going to use - it may be something existing or something that is newly created and uses something existing.

How to demo

  • Execute the Unit tests.
  • Execute the three scenarios that have been implemented.

Design

General things

  • Drag and Drop should be able to transfer things from Source to Target.
    • Both Source and Target should be able to export and import different types of data, called DataFlavor.
    • As of Java 1.4, dragging and dropping things is done through the so called TransferHandler.
      • it is responsible for initiating a drag, accepting a drop and changing the UI correspondingly (changing the mouse cursor depending on the action performed - COPY, MOVE, LINK.)
      • the TransferHandler need a JComponent in order to detect drag and drop gestures. It is usually enough for a simple Java application, since it transfers text, images, files etc. almost on the fly.
      • the drag and drop mechanism in Java is quite complicated since it can be done in two ways which is sometimes misleading.
  • We need to define three things in order to be able to perform Drad and Drop. The things below are enough to create a library that can provide drag and drop.
    • SophieTransferHandler
    • Transferable
    • DataFlavor

SophieTransferHandler

  • a class representing a TransferHandler similar to the one described above. It can wrap the one in Java and use part of the methods.
    • It will be responsible for:
      • initiating a drag.
      • accepting a drop.
      • changing the cursor.
      • dropping something.
  • Wrapping the TransferHandler in Java will help us with the cursor and the drag and drop gestures.
  • We need to following methods to perform a drag and drop operation:
    • protected abstract boolean canDropIn(Transferable transferable); - should tell whether a drop is acceptable provided a Transferable with a DataFlavor.
    • protected abstract boolean dropIn(Transferable transferable, DropLocation dropLocation, int dropAction); - should perform the actual drop. The Data is contained in the Transferable.
    • protected abstract Transferable createTransferable(); - creates the actual Transferable.
    • protected abstract void transferDone(Transferable data, int action); - invoked after the transfer has been performed.
    • The SophieTransferHandler should be provided a JComponent and set such so that Drad and Drop gestures are recognized from it.
  • Transferring of data will be done by creating Transferables.
  • SophieTransferHandler should be extended and defined for most UI components that support drag and drop (Palettes, BookDesktop etc.) - for example in an inner class and an AutoProperty that depends on the JComponent of a Palette one can create a handler and latter change the Palette's model if a drop operation is performed.

source:/trunk/sophie2-platform/doc/uml-design-diagrams/SophieTransferHandler.png@1805

Transferables

  • provides information about the drag operation.
    • type of data transferred - through DataFlavor constants.
    • may provide more than one type of data, depending on the number of DataFlavors supported.
  • contains the data transferred - obtained through the DataFlavor.
  • We should define several Transferables:
    • FileTransferable - responsible for Transferring of files. Transferring of files between the OS and Sophie will not create such but it will be useful for transferring inside Sophie.
    • ResourceTransferable - it should have some implementing classes for pages, frames etc.
    • we may later need to define more.

DataFlavor

  • Used to unify the types of data a drag and drop operation should deal with.
  • There are some DataFlavors defined in the Java library.
  • For some things we need to define DataFlavors.
    • FrameResources.
    • BookResources.
    • and other depending on what other drag and drop operations will be implemented.

Note: Some DataFlavors are not created properly in different platforms despite the idea of being so. For example dragging and dropping of files works fine on windows (the system uses the DataFlavor.javaFileListFlavor flavor) while it does not in gnome (creating different flavor usually with text/uri-list mime type). So be careful when using the Transferables and DataFlavors.

Implementation

(Implementation results should be described and linked here (from the wiki or the repository))

Testing

Comments

(Write comments for this or later revisions here.)