Skip to content

Commit 8cc6d1b

Browse files
eclipse-platform-botakurtakov
authored andcommitted
Perform clean code of bundles/org.eclipse.ui.forms
1 parent 8ce075d commit 8cc6d1b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1447
-830
lines changed

bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/DetailsPart.java

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@
4141
*/
4242
public final class DetailsPart implements IFormPart, IPartSelectionListener {
4343
private IManagedForm managedForm;
44-
private ScrolledPageBook pageBook;
44+
private final ScrolledPageBook pageBook;
4545
private IFormPart masterPart;
4646
private IStructuredSelection currentSelection;
47-
private Hashtable<Object, PageBag> pages;
47+
private final Hashtable<Object, PageBag> pages;
4848
private IDetailsPageProvider pageProvider;
4949
private int pageLimit=Integer.MAX_VALUE;
5050

5151
private static class PageBag {
5252
private static int counter;
53-
private int ticket;
53+
private final int ticket;
5454
private IDetailsPage page;
55-
private boolean fixed;
55+
private final boolean fixed;
5656

5757
public PageBag(IDetailsPage page, boolean fixed) {
5858
this.page= page;
@@ -127,8 +127,9 @@ public void setPageProvider(IDetailsPageProvider provider) {
127127
@Override
128128
public void commit(boolean onSave) {
129129
IDetailsPage page = getCurrentPage();
130-
if (page != null)
130+
if (page != null) {
131131
page.commit(onSave);
132+
}
132133
}
133134
/**
134135
* Returns the current page visible in the part.
@@ -138,8 +139,9 @@ public IDetailsPage getCurrentPage() {
138139
Control control = pageBook.getCurrentPage();
139140
if (control != null && !control.isDisposed()) {
140141
Object data = control.getData();
141-
if (data instanceof IDetailsPage)
142+
if (data instanceof IDetailsPage) {
142143
return (IDetailsPage) data;
144+
}
143145
}
144146
return null;
145147
}
@@ -163,8 +165,9 @@ public void initialize(IManagedForm form) {
163165
@Override
164166
public boolean isDirty() {
165167
IDetailsPage page = getCurrentPage();
166-
if (page != null)
168+
if (page != null) {
167169
return page.isDirty();
170+
}
168171
return false;
169172
}
170173
/**
@@ -174,8 +177,9 @@ public boolean isDirty() {
174177
@Override
175178
public boolean isStale() {
176179
IDetailsPage page = getCurrentPage();
177-
if (page != null)
180+
if (page != null) {
178181
return page.isStale();
182+
}
179183
return false;
180184
}
181185

@@ -185,17 +189,19 @@ public boolean isStale() {
185189
@Override
186190
public void refresh() {
187191
IDetailsPage page = getCurrentPage();
188-
if (page != null)
192+
if (page != null) {
189193
page.refresh();
194+
}
190195
}
191196
/**
192197
* Sets the focus to the currently visible page.
193198
*/
194199
@Override
195200
public void setFocus() {
196201
IDetailsPage page = getCurrentPage();
197-
if (page != null)
202+
if (page != null) {
198203
page.setFocus();
204+
}
199205
}
200206

201207
@Override
@@ -208,19 +214,20 @@ public void selectionChanged(IFormPart part, ISelection selection) {
208214
this.masterPart = part;
209215
if (currentSelection != null) {
210216
}
211-
if (selection instanceof IStructuredSelection)
217+
if (selection instanceof IStructuredSelection) {
212218
currentSelection = (IStructuredSelection) selection;
213-
else
219+
} else {
214220
currentSelection = null;
221+
}
215222
update();
216223
}
217224
private void update() {
218225
Object key = null;
219226
if (currentSelection != null) {
220227
for (Object obj : currentSelection) {
221-
if (key == null)
228+
if (key == null) {
222229
key = getKey(obj);
223-
else if (!getKey(obj).equals(key)) {
230+
} else if (!getKey(obj).equals(key)) {
224231
key = null;
225232
break;
226233
}
@@ -231,8 +238,9 @@ else if (!getKey(obj).equals(key)) {
231238
private Object getKey(Object object) {
232239
if (pageProvider!=null) {
233240
Object key = pageProvider.getPageKey(object);
234-
if (key!=null)
241+
if (key!=null) {
235242
return key;
243+
}
236244
}
237245
return object.getClass();
238246
}
@@ -260,11 +268,13 @@ private void showPage(final Object key) {
260268
parent.setData(fpage);
261269
}
262270
//commit the current page
263-
if (oldPage!=null && oldPage.isDirty())
271+
if (oldPage!=null && oldPage.isDirty()) {
264272
oldPage.commit(false);
273+
}
265274
//refresh the new page
266-
if (fpage.isStale())
275+
if (fpage.isStale()) {
267276
fpage.refresh();
277+
}
268278
fpage.selectionChanged(masterPart, currentSelection);
269279
pageBook.showPage(key);
270280
});
@@ -273,12 +283,15 @@ private void showPage(final Object key) {
273283
}
274284
// If we are switching from an old page to nothing,
275285
// don't loose data
276-
if (oldPage!=null && oldPage.isDirty())
286+
if (oldPage!=null && oldPage.isDirty()) {
277287
oldPage.commit(false);
288+
}
278289
pageBook.showEmptyPage();
279290
}
280291
private void checkLimit() {
281-
if (pages.size() <= getPageLimit()) return;
292+
if (pages.size() <= getPageLimit()) {
293+
return;
294+
}
282295
// overflow
283296
int currentTicket = PageBag.getCurrentTicket();
284297
int cutoffTicket = currentTicket - getPageLimit();

bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/FormColors.java

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ protected void initializeColorTable() {
175175
* keys to ensure they are available.
176176
*/
177177
public void initializeSectionToolBarColors() {
178-
if (colorRegistry.containsKey(IFormColors.TB_BG))
178+
if (colorRegistry.containsKey(IFormColors.TB_BG)) {
179179
return;
180+
}
180181
createTitleBarGradientColors();
181182
createTitleBarOutlineColors();
182183
createTwistieColors();
@@ -194,8 +195,9 @@ public void initializeSectionToolBarColors() {
194195
* @since 3.3
195196
*/
196197
protected void initializeFormHeaderColors() {
197-
if (colorRegistry.containsKey(IFormColors.H_BOTTOM_KEYLINE2))
198+
if (colorRegistry.containsKey(IFormColors.H_BOTTOM_KEYLINE2)) {
198199
return;
200+
}
199201
createFormHeaderColors();
200202
}
201203

@@ -226,8 +228,9 @@ public RGB getSystemColor(int code) {
226228
public Color createColor(String key, RGB rgb) {
227229
Color c = getResourceManager().createColor(rgb);
228230
Color prevC = colorRegistry.get(key);
229-
if (prevC != null && !prevC.isDisposed())
231+
if (prevC != null && !prevC.isDisposed()) {
230232
getResourceManager().destroyColor(prevC.getRGB());
233+
}
231234
colorRegistry.put(key, c);
232235
return c;
233236
}
@@ -282,15 +285,16 @@ public Color createColor(String key, int r, int g, int b) {
282285
* background color will be used.
283286
*/
284287
protected void updateBorderColor() {
285-
if (isWhiteBackground())
288+
if (isWhiteBackground()) {
286289
border = getColor(IFormColors.BORDER);
287-
else {
290+
} else {
288291
border = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
289292
Color bg = getImpliedBackground();
290293
if (border.getRed() == bg.getRed()
291294
&& border.getGreen() == bg.getGreen()
292-
&& border.getBlue() == bg.getBlue())
295+
&& border.getBlue() == bg.getBlue()) {
293296
border = display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
297+
}
294298
}
295299
}
296300

@@ -368,19 +372,21 @@ public boolean isWhiteBackground() {
368372
* @return color object if found, or <samp>null </samp> if not.
369373
*/
370374
public Color getColor(String key) {
371-
if (key.startsWith(IFormColors.TB_PREFIX))
375+
if (key.startsWith(IFormColors.TB_PREFIX)) {
372376
initializeSectionToolBarColors();
373-
else if (key.startsWith(IFormColors.H_PREFIX))
377+
} else if (key.startsWith(IFormColors.H_PREFIX)) {
374378
initializeFormHeaderColors();
379+
}
375380
return colorRegistry.get(key);
376381
}
377382

378383
/**
379384
* Disposes all the colors in the registry.
380385
*/
381386
public void dispose() {
382-
if (resources != null)
387+
if (resources != null) {
383388
resources.dispose();
389+
}
384390
resources = null;
385391
colorRegistry = null;
386392
}
@@ -436,12 +442,15 @@ public static RGB blend(RGB c1, RGB c2, int ratio) {
436442
* @since 3.1
437443
*/
438444
public static boolean testAnyPrimaryColor(RGB rgb, int from, int to) {
439-
if (testPrimaryColor(rgb.red, from, to))
445+
if (testPrimaryColor(rgb.red, from, to)) {
440446
return true;
441-
if (testPrimaryColor(rgb.green, from, to))
447+
}
448+
if (testPrimaryColor(rgb.green, from, to)) {
442449
return true;
443-
if (testPrimaryColor(rgb.blue, from, to))
450+
}
451+
if (testPrimaryColor(rgb.blue, from, to)) {
444452
return true;
453+
}
445454
return false;
446455
}
447456

@@ -461,12 +470,15 @@ public static boolean testAnyPrimaryColor(RGB rgb, int from, int to) {
461470
*/
462471
public static boolean testTwoPrimaryColors(RGB rgb, int from, int to) {
463472
int total = 0;
464-
if (testPrimaryColor(rgb.red, from, to))
473+
if (testPrimaryColor(rgb.red, from, to)) {
465474
total++;
466-
if (testPrimaryColor(rgb.green, from, to))
475+
}
476+
if (testPrimaryColor(rgb.green, from, to)) {
467477
total++;
468-
if (testPrimaryColor(rgb.blue, from, to))
478+
}
479+
if (testPrimaryColor(rgb.blue, from, to)) {
469480
total++;
481+
}
470482
return total >= 2;
471483
}
472484

@@ -487,8 +499,9 @@ private static int blend(int v1, int v2, int ratio) {
487499
}
488500

489501
private Color getImpliedBackground() {
490-
if (getBackground() != null)
502+
if (getBackground() != null) {
491503
return getBackground();
504+
}
492505
return getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
493506
}
494507

@@ -641,8 +654,9 @@ private void createFormHeaderDNDColors() {
641654
}
642655

643656
private LocalResourceManager getResourceManager() {
644-
if (resources == null)
657+
if (resources == null) {
645658
resources = new LocalResourceManager(JFaceResources.getResources());
659+
}
646660
return resources;
647661
}
648662
}

bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/HyperlinkGroup.java

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
*/
3535

3636
public final class HyperlinkGroup extends HyperlinkSettings {
37-
private ArrayList<Hyperlink> links = new ArrayList<>();
37+
private final ArrayList<Hyperlink> links = new ArrayList<>();
3838
private Hyperlink lastActivated;
3939
private Hyperlink lastEntered;
40-
private GroupListener listener;
40+
private final GroupListener listener;
4141
private boolean isActiveBackgroundSet;
4242
private boolean isActiveForegroundSet;
4343
private boolean isBackgroundSet;
@@ -69,22 +69,28 @@ private void onMouseEnter(Event e) {
6969
Hyperlink link = (Hyperlink) e.widget;
7070
previousBackground = link.getBackground();
7171
previousForeground = link.getForeground();
72-
if (isActiveBackgroundSet)
72+
if (isActiveBackgroundSet) {
7373
link.setBackground(getActiveBackground());
74-
if (isActiveForegroundSet)
74+
}
75+
if (isActiveForegroundSet) {
7576
link.setForeground(getActiveForeground());
76-
if (getHyperlinkUnderlineMode() == UNDERLINE_HOVER)
77+
}
78+
if (getHyperlinkUnderlineMode() == UNDERLINE_HOVER) {
7779
link.setUnderlined(true);
80+
}
7881
link.setCursor(getHyperlinkCursor());
7982
}
8083
private void onMouseExit(Event e) {
8184
Hyperlink link = (Hyperlink) e.widget;
82-
if (isActiveBackgroundSet)
85+
if (isActiveBackgroundSet) {
8386
link.setBackground(previousBackground);
84-
if (isActiveForegroundSet)
87+
}
88+
if (isActiveForegroundSet) {
8589
link.setForeground(previousForeground);
86-
if (getHyperlinkUnderlineMode() == UNDERLINE_HOVER)
90+
}
91+
if (getHyperlinkUnderlineMode() == UNDERLINE_HOVER) {
8792
link.setUnderlined(false);
93+
}
8894
}
8995
@Override
9096
public void linkActivated(HyperlinkEvent e) {
@@ -105,8 +111,9 @@ public void linkExited(HyperlinkEvent e) {
105111
}
106112
private void linkExited(Hyperlink link) {
107113
link.setCursor(null);
108-
if (lastEntered == link)
114+
if (lastEntered == link) {
109115
lastEntered = null;
116+
}
110117
}
111118
}
112119

@@ -139,12 +146,15 @@ public Hyperlink getLastActivated() {
139146
*/
140147

141148
public void add(Hyperlink link) {
142-
if (isBackgroundSet)
149+
if (isBackgroundSet) {
143150
link.setBackground(getBackground());
144-
if (isForegroundSet)
151+
}
152+
if (isForegroundSet) {
145153
link.setForeground(getForeground());
146-
if (getHyperlinkUnderlineMode() == UNDERLINE_ALWAYS)
154+
}
155+
if (getHyperlinkUnderlineMode() == UNDERLINE_ALWAYS) {
147156
link.setUnderlined(true);
157+
}
148158
hook(link);
149159
}
150160

@@ -237,16 +247,19 @@ private void unhook(Hyperlink link) {
237247
link.removeHyperlinkListener(listener);
238248
link.removeListener(SWT.MouseEnter, listener);
239249
link.removeListener(SWT.MouseExit, listener);
240-
if (lastActivated == link)
250+
if (lastActivated == link) {
241251
lastActivated = null;
242-
if (lastEntered == link)
252+
}
253+
if (lastEntered == link) {
243254
lastEntered = null;
255+
}
244256
links.remove(link);
245257
}
246258

247259
private void onMouseDown(Event e) {
248-
if (e.button == 1)
260+
if (e.button == 1) {
249261
return;
262+
}
250263
lastActivated = (Hyperlink) e.widget;
251264
}
252265
}

0 commit comments

Comments
 (0)