Download Basic Tool Support for Requirements Engineering

Transcript
66
Implementation
element is doubleclicked ElementExplorerImpl, containing the listener, calls
elementDoubleClicked upon its presenter. The method uses
getExtensionRegistry() to look at all the plug-ins extending dk.dtu.imm.red.core.element.
A for-loop runs through the extending plug-ins and calls openElement(). If an
extending plug-in contains a method to open the element type that is doubleclicked an editor is opened. This ensures that Core has no dependencies to
contributing plug-ins.
4.4
Moving Elements in the Tree-View
This section describes how moving elements in the tree-view placed in the Element Explorer view is implemented.
From the users perspective a selection of elements to be moved are made, the
elements are dragged to the wished location and dropped. Drag and drop is a
part of the SWT framework and below is a description of how it is implemented.
Drag – In the class ElementDragListener the method dragStart saves the
elements selected from the tree-view in a list. dragSetData is called and uses
createDraggableResource to create a pseudo folder that the elements from the
list is placed in. The folder is added to an EMF resource, similar to when saving.
The resource is serialized to xml and saved in a string. The convertion to xml
is done because it is enforced by the SWT framework to use a known format to
transfer the data from drag to drop. The framework uses the underlying operating system mechanism which allows data transfer across applications in order
to have the best possible system integration. The TextTransfer class provides
a text transfer type which has a platform specific mechanism for converting
plain text represented as a Java string to a platform specific representation of
the data. With the convertion to xml the selected elements are ready to be
dropped.
Drop – The class ElementDropListener, performDrop recieves the data from
the OS as a string containing the xml. The framework provides the methods
getCurrentLocation() and getCurrentTarget() to get the targetted element
for the drop and if the location of the drop is before, after or on the target. At
this point the list of selected elements to be moved is just a copy of the real
elements. A list of the real element is created by using the unique id of the
elements to find the real elements. While the list is made a check is performed
to see if any of the real elements is a group and if the target is a child to
the element. If this is true that element is not included in the list, since it is
considered to be an illegal act to drag a parent element into a descendant.