5151import org .eclipse .swt .widgets .Button ;
5252import org .eclipse .swt .widgets .Composite ;
5353import org .eclipse .swt .widgets .Text ;
54- import org .eclipse .swt .widgets .ToolBar ;
55- import org .eclipse .swt .widgets .ToolItem ;
5654import org .eclipse .swt .widgets .Tree ;
5755
5856import jakarta .annotation .PostConstruct ;
@@ -74,8 +72,12 @@ public class AdapterSpyPart {
7472
7573 private static final String NAMED_UPDATE_TREE_SOURCE_TO_DESTINATION = "updateTreeSourceToDestination" ;
7674 private static final String NAMED_UPDATE_TREE_DESTINATION_TO_SOURCE = "updateTreeDestinationToSource" ;
77- private static final String SWITCH_TO_SOURCE = "switch to Source Type first" ;
78- private static final String SWITCH_TO_DESTINATION = "switch to Destination Type first" ;
75+ private static final String SOURCE_TYPE = "Source Type" ;
76+ private static final String DESTINATION_TYPE = "Destination Type" ;
77+ private static final String DISPLAY_SOURCE_TYPE = "Display " + SOURCE_TYPE ;
78+ private static final String DISPLAY_DESTINATION_TYPE = "Display " + DESTINATION_TYPE ;
79+ private static final String TOOLTIP_SOURCE_TYPE = "Display the source type first, and list\n all destination types derived from that source as child elements." ;
80+ private static final String TOOLTIP_DESTINATION_TYPE = "Display the destination type first, and list\n all source types that can adapt to it as child elements." ;
7981
8082 @ Inject
8183 UISynchronize uisync ;
@@ -288,7 +290,8 @@ private void createToolBarZone(Composite parent, ImageRegistry imgr) {
288290 comp .setLayout (new GridLayout (4 , false ));
289291
290292 Text filterText = new Text (comp , SWT .SEARCH | SWT .ICON_SEARCH | SWT .ICON_CANCEL );
291- GridDataFactory .fillDefaults ().hint (250 , SWT .DEFAULT ).applyTo (filterText );
293+ GridDataFactory .swtDefaults ().align (SWT .CENTER , SWT .CENTER ).hint (250 , SWT .DEFAULT ).applyTo (filterText );
294+
292295 filterText .setMessage ("Search data" );
293296 filterText .setToolTipText ("Find any element in tree" );
294297
@@ -320,41 +323,58 @@ public void widgetSelected(SelectionEvent e) {
320323 }
321324 });
322325
326+ // --- Vertical radio buttons to choose display direction ---
327+ Composite radioGroup = new Composite (comp , SWT .NONE );
328+ radioGroup .setLayout (new GridLayout (1 , false ));
329+
330+ Button rbSource = new Button (radioGroup , SWT .RADIO );
331+ rbSource .setText (DISPLAY_SOURCE_TYPE );
332+ rbSource .setToolTipText (TOOLTIP_SOURCE_TYPE );
333+
334+ Button rbDestination = new Button (radioGroup , SWT .RADIO );
335+ rbDestination .setText (DISPLAY_DESTINATION_TYPE );
336+ rbDestination .setToolTipText (TOOLTIP_DESTINATION_TYPE );
337+
338+ rbSource .setSelection (sourceToDestination );
339+ rbDestination .setSelection (!sourceToDestination );
340+
341+ // Factorized refresh logic
342+ Runnable refreshView = () -> {
343+ FilterData fdata = getFilterData ();
344+ fdata .setSourceToDestination (sourceToDestination );
345+ context .set (AdapterFilter .UPDATE_CTX_FILTER , fdata );
346+
347+ if (sourceToDestination ) {
348+ sourceOrDestinationTvc .getColumn ().setText (SOURCE_TYPE );
349+ context .set (NAMED_UPDATE_TREE_SOURCE_TO_DESTINATION , adapterRepo .getAdapters ());
350+ } else {
351+ sourceOrDestinationTvc .getColumn ().setText (DESTINATION_TYPE );
352+ context .set (NAMED_UPDATE_TREE_DESTINATION_TO_SOURCE , adapterRepo .revertSourceToType ());
353+ }
354+ adapterTreeViewer .refresh (true );
355+ };
356+
357+ // Listeners
358+ rbSource .addSelectionListener (new SelectionAdapter () {
359+ @ Override
360+ public void widgetSelected (SelectionEvent e ) {
361+ if (rbSource .getSelection ()) {
362+ sourceToDestination = true ;
363+ refreshView .run ();
364+ }
365+ }
366+ });
323367
324- ToolBar toolBar = new ToolBar (comp , SWT .NONE );
325- ToolItem switchButton = new ToolItem (toolBar , SWT .CHECK );
326- switchButton .setImage (imgr .get (AdapterHelper .DESTINATION_TYPE_IMG_KEY ));
327- switchButton .setToolTipText (SWITCH_TO_DESTINATION );
328-
329- // sourceToType event
330- switchButton .addSelectionListener (new SelectionAdapter () {
331-
332- @ Override
333- public void widgetSelected (SelectionEvent event ) {
334- Object source = event .getSource ();
335- if (source instanceof ToolItem ) {
336- FilterData fdata = getFilterData ();
337- sourceToDestination = !sourceToDestination ;
338- String tooltiptext = sourceToDestination ? SWITCH_TO_DESTINATION :SWITCH_TO_SOURCE ;
339- String imageKey = sourceToDestination ? AdapterHelper .DESTINATION_TYPE_IMG_KEY
340- : AdapterHelper .SOURCE_TYPE_IMG_KEY ;
341- switchButton .setToolTipText (tooltiptext );
342- switchButton .setImage (imgr .get (imageKey ));
343-
344- if (sourceToDestination ) {
345- sourceOrDestinationTvc .getColumn ().setText ("Source Type" );
346- context .set (NAMED_UPDATE_TREE_SOURCE_TO_DESTINATION , adapterRepo .getAdapters ());
347- } else {
348- sourceOrDestinationTvc .getColumn ().setText ("Destination Type" );
349- context .set (NAMED_UPDATE_TREE_DESTINATION_TO_SOURCE , adapterRepo .revertSourceToType ());
350- }
351- fdata .setSourceToDestination (sourceToDestination );
352- context .set (AdapterFilter .UPDATE_CTX_FILTER , fdata );
353- adapterTreeViewer .refresh (true );
354- }
355-
356- }
368+ rbDestination .addSelectionListener (new SelectionAdapter () {
369+ @ Override
370+ public void widgetSelected (SelectionEvent e ) {
371+ if (rbDestination .getSelection ()) {
372+ sourceToDestination = false ;
373+ refreshView .run ();
374+ }
375+ }
357376 });
377+
358378 uisync .asyncExec (() -> comp .pack ());
359379
360380 }
0 commit comments