@@ -146,17 +146,19 @@ void handleChildrenEvent(@UIEventTopic(UIEvents.ElementContainer.TOPIC_CHILDREN)
146
146
for (Object o : UIEvents .asIterable (event , UIEvents .EventTags .NEW_VALUE )) {
147
147
MPerspective added = (MPerspective ) o ;
148
148
// Adding invisible elements is a NO-OP
149
- if (!added .isToBeRendered ())
149
+ if (!added .isToBeRendered ()) {
150
150
continue ;
151
+ }
151
152
152
153
addPerspectiveItem (added );
153
154
}
154
155
} else if (UIEvents .isREMOVE (event )) {
155
156
for (Object o : UIEvents .asIterable (event , UIEvents .EventTags .OLD_VALUE )) {
156
157
MPerspective removed = (MPerspective ) o ;
157
158
// Removing invisible elements is a NO-OP
158
- if (!removed .isToBeRendered ())
159
+ if (!removed .isToBeRendered ()) {
159
160
continue ;
161
+ }
160
162
161
163
removePerspectiveItem (removed );
162
164
}
@@ -174,8 +176,9 @@ void handleToBeRenderedEvent(@UIEventTopic(UIEvents.UIElement.TOPIC_TOBERENDERED
174
176
175
177
MPerspective persp = (MPerspective ) event .getProperty (UIEvents .EventTags .ELEMENT );
176
178
177
- if (!persp .getParent ().isToBeRendered ())
179
+ if (!persp .getParent ().isToBeRendered ()) {
178
180
return ;
181
+ }
179
182
180
183
if (persp .isToBeRendered ()) {
181
184
addPerspectiveItem (persp );
@@ -224,8 +227,9 @@ void handleSelectionEvent(@UIEventTopic(UIEvents.ElementContainer.TOPIC_SELECTED
224
227
225
228
MPerspectiveStack perspStack = (MPerspectiveStack ) changedObj ;
226
229
227
- if (!perspStack .isToBeRendered ())
230
+ if (!perspStack .isToBeRendered ()) {
228
231
return ;
232
+ }
229
233
230
234
MPerspective selElement = perspStack .getSelectedElement ();
231
235
for (ToolItem ti : perspSwitcherToolbar .getItems ()) {
@@ -256,8 +260,9 @@ void createWidget(Composite parent, MToolControl toolControl) {
256
260
int orientation = SWT .HORIZONTAL ;
257
261
if (meParent instanceof MTrimBar ) {
258
262
MTrimBar bar = (MTrimBar ) meParent ;
259
- if (bar .getSide () == SideValue .RIGHT || bar .getSide () == SideValue .LEFT )
263
+ if (bar .getSide () == SideValue .RIGHT || bar .getSide () == SideValue .LEFT ) {
260
264
orientation = SWT .VERTICAL ;
265
+ }
261
266
}
262
267
comp = new Composite (parent , SWT .NONE );
263
268
RowLayout layout = new RowLayout (SWT .HORIZONTAL );
@@ -276,14 +281,15 @@ void createWidget(Composite parent, MToolControl toolControl) {
276
281
Point p = new Point (e .x , e .y );
277
282
p = perspSwitcherToolbar .getDisplay ().map (null , perspSwitcherToolbar , p );
278
283
ToolItem item = tb .getItem (p );
279
- if (item == null )
284
+ if (item == null ) {
280
285
E4Util .message (" ToolBar menu" ); //$NON-NLS-1$
281
- else {
286
+ } else {
282
287
MPerspective persp = (MPerspective ) item .getData ();
283
- if (persp == null )
288
+ if (persp == null ) {
284
289
E4Util .message (" Add button Menu" ); //$NON-NLS-1$
285
- else
290
+ } else {
286
291
openMenuFor (item , persp );
292
+ }
287
293
}
288
294
});
289
295
@@ -355,8 +361,9 @@ private boolean ignoreEvent(Object changedObj) {
355
361
356
362
private void track (MouseEvent e ) {
357
363
// Create and track the feedback overlay
358
- if (dragShell == null )
364
+ if (dragShell == null ) {
359
365
createFeedback ();
366
+ }
360
367
361
368
// Move the drag shell
362
369
Rectangle b = dragItem .getBounds ();
@@ -390,8 +397,9 @@ private void hookupDnD(ToolBar bar) {
390
397
bar .addMouseListener (new MouseListener () {
391
398
@ Override
392
399
public void mouseUp (MouseEvent e ) {
393
- if (dragItem == null )
400
+ if (dragItem == null ) {
394
401
return ;
402
+ }
395
403
396
404
ToolBar bar = (ToolBar ) e .widget ;
397
405
ToolItem curItem = bar .getItem (new Point (e .x , e .y ));
@@ -406,21 +414,24 @@ public void mouseUp(MouseEvent e) {
406
414
int dragPerspIndex = dragPersp .getParent ().getChildren ().indexOf (dragPersp );
407
415
MPerspective dropPersp = (MPerspective ) curItem .getData ();
408
416
int dropPerspIndex = dropPersp .getParent ().getChildren ().indexOf (dropPersp );
409
- if (!atStart )
417
+ if (!atStart ) {
410
418
dropPerspIndex ++; // We're 'after' the item we're over
419
+ }
411
420
412
- if (dropPerspIndex > dragPerspIndex )
421
+ if (dropPerspIndex > dragPerspIndex ) {
413
422
dropPerspIndex --; // Need to account for the removal of
414
423
// the drag item itself
424
+ }
415
425
416
426
// If it's not a no-op move the perspective
417
427
if (dropPerspIndex != dragPerspIndex ) {
418
428
MElementContainer <MUIElement > parent = dragPersp .getParent ();
419
429
boolean selected = dragPersp == parent .getSelectedElement ();
420
430
parent .getChildren ().remove (dragPersp );
421
431
parent .getChildren ().add (dropPerspIndex , dragPersp );
422
- if (selected )
432
+ if (selected ) {
423
433
parent .setSelectedElement (dragPersp );
434
+ }
424
435
}
425
436
}
426
437
@@ -429,8 +440,9 @@ public void mouseUp(MouseEvent e) {
429
440
downPos = null ;
430
441
dragging = false ;
431
442
perspSwitcherToolbar .setCursor (null );
432
- if (dragShell != null && !dragShell .isDisposed ())
443
+ if (dragShell != null && !dragShell .isDisposed ()) {
433
444
dragShell .dispose ();
445
+ }
434
446
dragShell = null ;
435
447
}
436
448
@@ -442,8 +454,9 @@ public void mouseDown(MouseEvent e) {
442
454
443
455
// We're only interested if the button went down over a
444
456
// perspective item
445
- if (downItem != null && downItem .getData () instanceof MPerspective )
457
+ if (downItem != null && downItem .getData () instanceof MPerspective ) {
446
458
dragItem = downItem ;
459
+ }
447
460
}
448
461
449
462
@ Override
@@ -475,8 +488,9 @@ private Image getOpenPerspectiveImage() {
475
488
476
489
MPerspectiveStack getPerspectiveStack () {
477
490
List <MPerspectiveStack > psList = modelService .findElements (window , null , MPerspectiveStack .class );
478
- if (psList .size () > 0 )
491
+ if (psList .size () > 0 ) {
479
492
return psList .get (0 );
493
+ }
480
494
return null ;
481
495
}
482
496
@@ -500,8 +514,9 @@ private ToolItem addPerspectiveItem(MPerspective persp) {
500
514
501
515
psItem .addListener (SWT .Dispose , event -> {
502
516
Image currentImage = psItem .getImage ();
503
- if (currentImage != null )
517
+ if (currentImage != null ) {
504
518
currentImage .dispose ();
519
+ }
505
520
});
506
521
foundImage = true ;
507
522
psItem .setToolTipText (persp .getLocalizedLabel ());
@@ -582,8 +597,9 @@ private void addCloseItem(final Menu menu) {
582
597
menuItem .setText (WorkbenchMessages .WorkbenchWindow_close );
583
598
menuItem .addSelectionListener (widgetSelectedAdapter (e -> {
584
599
MPerspective persp = (MPerspective ) menu .getData ();
585
- if (persp != null )
600
+ if (persp != null ) {
586
601
closePerspective (persp );
602
+ }
587
603
}));
588
604
}
589
605
@@ -601,8 +617,9 @@ private void addSaveAsItem(final Menu menu) {
601
617
workbenchWindow .getWorkbench ().getHelpSystem ().setHelp (saveAsMenuItem ,
602
618
IWorkbenchHelpContextIds .SAVE_PERSPECTIVE_ACTION );
603
619
saveAsMenuItem .addSelectionListener (widgetSelectedAdapter (event -> {
604
- if (perspSwitcherToolbar .isDisposed ())
620
+ if (perspSwitcherToolbar .isDisposed ()) {
605
621
return ;
622
+ }
606
623
IHandlerService handlerService = workbenchWindow .getService (IHandlerService .class );
607
624
IStatus status = Status .OK_STATUS ;
608
625
try {
@@ -611,8 +628,9 @@ private void addSaveAsItem(final Menu menu) {
611
628
status = new Status (IStatus .ERROR , PlatformUI .PLUGIN_ID , e .getMessage (), e );
612
629
} catch (NotHandledException e ) {
613
630
}
614
- if (!status .isOK ())
631
+ if (!status .isOK ()) {
615
632
StatusManager .getManager ().handle (status , StatusManager .SHOW | StatusManager .LOG );
633
+ }
616
634
}));
617
635
}
618
636
@@ -623,8 +641,9 @@ private void addResetItem(final Menu menu) {
623
641
workbenchWindow .getWorkbench ().getHelpSystem ().setHelp (resetMenuItem ,
624
642
IWorkbenchHelpContextIds .RESET_PERSPECTIVE_ACTION );
625
643
resetMenuItem .addSelectionListener (widgetSelectedAdapter (event -> {
626
- if (perspSwitcherToolbar .isDisposed ())
644
+ if (perspSwitcherToolbar .isDisposed ()) {
627
645
return ;
646
+ }
628
647
IHandlerService handlerService = workbenchWindow .getService (IHandlerService .class );
629
648
IStatus status = Status .OK_STATUS ;
630
649
try {
@@ -633,8 +652,9 @@ private void addResetItem(final Menu menu) {
633
652
status = new Status (IStatus .ERROR , PlatformUI .PLUGIN_ID , e .getMessage (), e );
634
653
} catch (NotHandledException e ) {
635
654
}
636
- if (!status .isOK ())
655
+ if (!status .isOK ()) {
637
656
StatusManager .getManager ().handle (status , StatusManager .SHOW | StatusManager .LOG );
657
+ }
638
658
}));
639
659
}
640
660
@@ -681,10 +701,11 @@ private void setPropertyChangeListener() {
681
701
if (IWorkbenchPreferenceConstants .SHOW_TEXT_ON_PERSPECTIVE_BAR .equals (propertyChangeEvent .getProperty ())) {
682
702
Object newValue = propertyChangeEvent .getNewValue ();
683
703
boolean showText = true ; // default
684
- if (newValue instanceof Boolean )
704
+ if (newValue instanceof Boolean ) {
685
705
showText = ((Boolean ) newValue ).booleanValue ();
686
- else if ("false" .equals (newValue )) //$NON-NLS-1$
706
+ } else if ("false" .equals (newValue )) { //$NON-NLS-1$
687
707
showText = false ;
708
+ }
688
709
changeShowText (showText );
689
710
}
690
711
};
@@ -695,10 +716,11 @@ private void changeShowText(boolean showText) {
695
716
ToolItem [] items = perspSwitcherToolbar .getItems ();
696
717
for (ToolItem item : items ) {
697
718
MPerspective persp = (MPerspective ) item .getData ();
698
- if (persp != null )
719
+ if (persp != null ) {
699
720
if (showText ) {
700
- if (persp .getLabel () != null )
721
+ if (persp .getLabel () != null ) {
701
722
item .setText (persp .getLocalizedLabel ());
723
+ }
702
724
item .setToolTipText (persp .getLocalizedTooltip ());
703
725
} else {
704
726
Image image = item .getImage ();
@@ -707,6 +729,7 @@ private void changeShowText(boolean showText) {
707
729
item .setToolTipText (persp .getLocalizedLabel ());
708
730
}
709
731
}
732
+ }
710
733
}
711
734
712
735
// update the size
@@ -734,12 +757,14 @@ private void removePerspectiveItem(MPerspective toRemove) {
734
757
* @return the tool item
735
758
*/
736
759
protected ToolItem getItemFor (MPerspective persp ) {
737
- if (perspSwitcherToolbar == null )
760
+ if (perspSwitcherToolbar == null ) {
738
761
return null ;
762
+ }
739
763
740
764
for (ToolItem ti : perspSwitcherToolbar .getItems ()) {
741
- if (ti .getData () == persp )
765
+ if (ti .getData () == persp ) {
742
766
return ti ;
767
+ }
743
768
}
744
769
745
770
return null ;
@@ -779,14 +804,16 @@ private void updateToolItem(ToolItem ti, String attName, Object newValue) {
779
804
ImageDescriptor descriptor = ImageDescriptor .createFromURL (url );
780
805
if (descriptor == null ) {
781
806
ti .setImage (null );
782
- } else
807
+ } else {
783
808
ti .setImage (descriptor .createImage ());
809
+ }
784
810
} catch (IOException e ) {
785
811
ti .setImage (null );
786
812
logger .warn (e );
787
813
} finally {
788
- if (currentImage != null )
814
+ if (currentImage != null ) {
789
815
currentImage .dispose ();
816
+ }
790
817
}
791
818
}
792
819
}
0 commit comments