@@ -53,7 +53,11 @@ public interface DragAndDropService extends
5353 *
5454 * @see DragAndDropHandler
5555 */
56- boolean supports (DragAndDropData data , Display <?> display );
56+ default boolean supports (final DragAndDropData data ,
57+ final Display <?> display )
58+ {
59+ return getHandler (data , display ) != null ;
60+ }
5761
5862 /**
5963 * Checks whether the given object can be dropped onto the specified display.
@@ -62,7 +66,9 @@ public interface DragAndDropService extends
6266 *
6367 * @see DragAndDropHandler
6468 */
65- boolean supports (Object object , Display <?> display );
69+ default boolean supports (final Object object , final Display <?> display ) {
70+ return getHandler (object , display ) != null ;
71+ }
6672
6773 /**
6874 * Performs a drag-and-drop operation in the given display with the specified
@@ -73,7 +79,11 @@ public interface DragAndDropService extends
7379 * @throws IllegalArgumentException if the display and/or data object are
7480 * unsupported, or are incompatible with one another.
7581 */
76- boolean drop (DragAndDropData data , Display <?> display );
82+ default boolean drop (final DragAndDropData data , final Display <?> display ) {
83+ final DragAndDropHandler <?> handler = getHandler (data , display );
84+ if (handler == null ) return false ;
85+ return handler .dropData (data , display );
86+ }
7787
7888 /**
7989 * Performs a drag-and-drop operation in the given display with the specified
@@ -84,7 +94,11 @@ public interface DragAndDropService extends
8494 * @throws IllegalArgumentException if the display and/or data object are
8595 * unsupported, or are incompatible with one another.
8696 */
87- boolean drop (Object data , Display <?> display );
97+ default boolean drop (final Object data , final Display <?> display ) {
98+ final DragAndDropHandler <?> handler = getHandler (data , display );
99+ if (handler == null ) return false ;
100+ return handler .dropObject (data , display );
101+ }
88102
89103 /**
90104 * Gets the drag-and-drop handler which will be used to handle the given
@@ -93,7 +107,14 @@ public interface DragAndDropService extends
93107 * @return The first compatible drag-and-drop handler, or null if none
94108 * available.
95109 */
96- DragAndDropHandler <?> getHandler (DragAndDropData data , Display <?> display );
110+ default DragAndDropHandler <?> getHandler (final DragAndDropData data ,
111+ final Display <?> display )
112+ {
113+ for (final DragAndDropHandler <?> handler : getInstances ()) {
114+ if (handler .supportsData (data , display )) return handler ;
115+ }
116+ return null ;
117+ }
97118
98119 /**
99120 * Gets the drag-and-drop handler which will be used to handle the given
@@ -102,7 +123,14 @@ public interface DragAndDropService extends
102123 * @return The first compatible drag-and-drop handler, or null if none
103124 * available.
104125 */
105- DragAndDropHandler <?> getHandler (Object object , Display <?> display );
126+ default DragAndDropHandler <?> getHandler (final Object object ,
127+ final Display <?> display )
128+ {
129+ for (final DragAndDropHandler <?> handler : getInstances ()) {
130+ if (handler .supportsObject (object , display )) return handler ;
131+ }
132+ return null ;
133+ }
106134
107135 // NB: Javadoc overrides.
108136
@@ -115,4 +143,18 @@ public interface DragAndDropService extends
115143 @ Override
116144 List <DragAndDropHandler <Object >> getInstances ();
117145
146+ // -- PTService methods --
147+
148+ @ Override
149+ @ SuppressWarnings ({"rawtypes" , "unchecked" })
150+ default Class <DragAndDropHandler <Object >> getPluginType () {
151+ return (Class ) DragAndDropHandler .class ;
152+ }
153+
154+ // -- Typed methods --
155+
156+ @ Override
157+ default Class <Object > getType () {
158+ return Object .class ;
159+ }
118160}
0 commit comments