Skip to content

Commit b92acfc

Browse files
Perform clean code of bundles/org.eclipse.e4.ui.workbench.addons.swt
1 parent b431a28 commit b92acfc

File tree

17 files changed

+60
-102
lines changed

17 files changed

+60
-102
lines changed

bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/cleanupaddon/CleanupAddon.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ private void subscribeVisibilityChanged(
224224
if (parent.getRenderer() != null) {
225225
Object myParent = ((AbstractPartRenderer) parent.getRenderer())
226226
.getUIContainer(changedObj);
227-
if (myParent instanceof Composite) {
228-
Composite parentComp = (Composite) myParent;
227+
if (myParent instanceof Composite parentComp) {
229228
ctrl.setParent(parentComp);
230229

231230
Control prevControl = null;

bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DetachedDropAgent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
public class DetachedDropAgent extends DropAgent {
3131
DnDManager manager;
32-
private EModelService modelService;
32+
private final EModelService modelService;
3333
private Rectangle curRect;
3434

3535
public DetachedDropAgent(DnDManager manager) {

bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DnDAddon.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ void subscribeTopicWidget(@UIEventTopic(UIEvents.UIElement.TOPIC_WIDGET) Event e
5050
}
5151

5252
Object widget = event.getProperty(EventTags.NEW_VALUE);
53-
if (widget instanceof Shell && !((Shell) widget).isDisposed()) {
54-
Shell shell = (Shell) widget;
53+
if (widget instanceof Shell shell && !shell.isDisposed()) {
5554
DnDManager theManager = (DnDManager) shell.getData("DnDManager"); //$NON-NLS-1$
5655
if (theManager == null) {
5756
theManager = new DnDManager((MWindow) changedElement);

bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DnDInfo.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ private void setItemInfo() {
127127
Control ctrl = (Control) curElement.getWidget();
128128

129129
// KLUDGE!! Should delegate to curElement's renderer
130-
if (ctrl instanceof CTabFolder) {
131-
CTabFolder ctf = (CTabFolder) ctrl;
130+
if (ctrl instanceof CTabFolder ctf) {
132131
Point localPos = display.map(null, ctf, cursorPos);
133132
curItem = ctf.getItem(localPos);
134133
if (curItem != null) {
@@ -137,8 +136,7 @@ private void setItemInfo() {
137136
itemRect = display.map(ctf, ctf.getShell(), ((CTabItem) curItem).getBounds());
138137
}
139138
}
140-
} else if (ctrl instanceof ToolBar) {
141-
ToolBar tb = (ToolBar) ctrl;
139+
} else if (ctrl instanceof ToolBar tb) {
142140
Point localPos = display.map(null, tb, cursorPos);
143141
ToolItem curItem = tb.getItem(localPos);
144142
if (curItem != null) {

bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DnDManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ class DnDManager {
5151
public static final int HOSTED = 1;
5252
public static final int GHOSTED = 2;
5353
public static final int SIMPLE = 3;
54-
private int feedbackStyle = SIMPLE;
54+
private final int feedbackStyle = SIMPLE;
5555

5656
Collection<DragAgent> dragAgents = new ArrayList<>();
5757
Collection<DropAgent> dropAgents = new ArrayList<>();
5858

5959
DnDInfo info;
6060
DragAgent dragAgent;
6161

62-
private MWindow dragWindow;
62+
private final MWindow dragWindow;
6363

6464
private Shell dragHost;
6565
private Control dragCtrl;
@@ -68,7 +68,7 @@ class DnDManager {
6868
boolean dragging;
6969

7070
private Shell overlayFrame;
71-
private List<Rectangle> frames = new ArrayList<>();
71+
private final List<Rectangle> frames = new ArrayList<>();
7272

7373
DragDetectListener dragDetector = e -> {
7474
if (dragging || e.widget.isDisposed()) {
@@ -93,8 +93,8 @@ public void addFrame(Rectangle newRect) {
9393
updateOverlay();
9494
}
9595

96-
private List<Image> images = new ArrayList<>();
97-
private List<Rectangle> imageRects = new ArrayList<>();
96+
private final List<Image> images = new ArrayList<>();
97+
private final List<Rectangle> imageRects = new ArrayList<>();
9898

9999
protected boolean isModified;
100100

bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DropAgent.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ public void reactivatePart(MUIElement dragElement) {
4242
MPart partToActivate = null;
4343
if (dragElement instanceof MPart) {
4444
partToActivate = (MPart) dragElement;
45-
} else if (dragElement instanceof MPlaceholder) {
46-
MPlaceholder ph = (MPlaceholder) dragElement;
45+
} else if (dragElement instanceof MPlaceholder ph) {
4746
if (ph.getRef() instanceof MPart) {
4847
partToActivate = (MPart) ph.getRef();
4948
}
50-
} else if (dragElement instanceof MPartStack) {
51-
MPartStack stack = (MPartStack) dragElement;
49+
} else if (dragElement instanceof MPartStack stack) {
5250
if (stack.getSelectedElement() instanceof MPart) {
5351
partToActivate = (MPart) stack.getSelectedElement();
5452
} else if (stack.getSelectedElement() instanceof MPlaceholder) {

bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/IBFDragAgent.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ public MUIElement getElementToDrag(DnDInfo info) {
6565
public void dragStart(DnDInfo info) {
6666
super.dragStart(info);
6767

68-
if (dragElement instanceof MToolControl) {
69-
MToolControl tc = (MToolControl) dragElement;
68+
if (dragElement instanceof MToolControl tc) {
7069
if (tc.getObject() instanceof TrimStack) {
7170
TrimStack ts = (TrimStack) tc.getObject();
7271
ts.showStack(false);

bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/PartDragAgent.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ public PartDragAgent(DnDManager manager) {
3232

3333
@Override
3434
public MUIElement getElementToDrag(DnDInfo info) {
35-
if (!(info.curElement instanceof MPartStack)) {
35+
if (!(info.curElement instanceof MPartStack stack)) {
3636
return null;
3737
}
3838

39-
MPartStack stack = (MPartStack) info.curElement;
40-
4139
// Drag a part that is in a stack
4240
if (info.itemElement instanceof MStackElement) {
4341
// Prevent dragging 'No Move' parts

bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/SplitDropAgent2.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,19 +308,17 @@ public boolean drop(MUIElement dragElement, DnDInfo info) {
308308
}
309309

310310
// Adjust the relToElement based on the location of the dragElement
311-
if (relToElement instanceof MArea) {
311+
if (relToElement instanceof MArea area) {
312312
// make it difficult to drag outside parts into the shared area
313313
boolean fromSharedArea = dragElementLocation == EModelService.IN_SHARED_AREA;
314314
// if from shared area and no modifier, is ok
315315
// if not from shared area and modifier is on, then ok
316316
boolean shouldBePlacedInSharedArea = fromSharedArea == !isModified();
317317
if (shouldBePlacedInSharedArea) {
318-
MArea area = (MArea) relToElement;
319318
relToElement = area.getChildren().get(0);
320319
}
321-
} else if (relToElement instanceof MPerspective) {
320+
} else if (relToElement instanceof MPerspective persp) {
322321
if (dragElementLocation == EModelService.IN_ACTIVE_PERSPECTIVE) {
323-
MPerspective persp = (MPerspective) relToElement;
324322
relToElement = persp.getChildren().get(0);
325323
}
326324
}

bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/SplitFeedbackOverlay.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ public class SplitFeedbackOverlay {
3030

3131
private Shell feedbackShell;
3232
private int curSide = 0;
33-
private float ratio;
33+
private final float ratio;
3434

35-
private List<Rectangle> rects = new ArrayList<>();
36-
private Rectangle outerRect;
35+
private final List<Rectangle> rects = new ArrayList<>();
36+
private final Rectangle outerRect;
3737

3838
Boolean isModified = null;
39-
private IStylingEngine stylingEngine;
39+
private final IStylingEngine stylingEngine;
4040

4141
public SplitFeedbackOverlay(Shell dragShell, Rectangle rect, int side, float pct,
4242
boolean enclosed, boolean modified) {
@@ -119,9 +119,7 @@ private void defineRegion() {
119119
// shadows will end up being drawn on top of the shadows for the parent
120120
// shell rather than in the middle of the workbench window.
121121
Composite parent = feedbackShell.getParent();
122-
if (parent instanceof Shell) {
123-
Shell parentShell = (Shell) parent;
124-
122+
if (parent instanceof Shell parentShell) {
125123
Rectangle bounds = parentShell.getBounds();
126124
rgn.add(bounds.width - 1, bounds.height - 1, 1, 1);
127125
}

0 commit comments

Comments
 (0)