CleanUp
Change-Id: Ibd11cccfd6e7a26866ad74e33b5ff3108bb9b4b4
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/actions/SearchContributionItem.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/actions/SearchContributionItem.java
index aed1a14..9a7115c 100644
--- a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/actions/SearchContributionItem.java
+++ b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/actions/SearchContributionItem.java
@@ -14,6 +14,9 @@
package org.eclipse.statet.ecommons.ui.actions;
+import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert;
+import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullLateInit;
+
import org.eclipse.jface.action.ContributionItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
@@ -28,16 +31,20 @@
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.statet.jcommons.lang.NonNull;
+import org.eclipse.statet.jcommons.lang.NonNullByDefault;
+import org.eclipse.statet.jcommons.lang.Nullable;
+
import org.eclipse.statet.ecommons.ui.components.SearchText;
import org.eclipse.statet.ecommons.ui.util.LayoutUtils;
import org.eclipse.statet.ecommons.ui.util.UIAccess;
-import org.eclipse.statet.ecommons.ui.workbench.WorkbenchUIUtils;
+@NonNullByDefault
public class SearchContributionItem extends ContributionItem {
- public static final int VIEW_TOOLBAR = 0x10000000;
+ public static final int VIEW_TOOLBAR= 0x10000000;
private class SWTListener implements Listener {
@@ -54,60 +61,61 @@
}
- private final int fOptions;
+ private final int options;
- private SearchText fControl;
- private ToolItem fTextItem;
+ private SearchText control= nonNullLateInit();
+ private ToolItem textItem= nonNullLateInit();
- private String fToolTipText;
+ private @Nullable String toolTipText;
- private Composite fSizeControl;
- private Control fResultControl;
+ private @Nullable Composite sizeControl;
+ private @Nullable Control resultControl;
- private final boolean fUpdateWhenTyping;
+ private final boolean updateWhenTyping;
- private final Runnable fSizeCheckRunnable = new Runnable() {
+ private final Runnable sizeCheckRunnable= new Runnable() {
@Override
public void run() {
- fSizeCheckScheduled = false;
+ SearchContributionItem.this.sizeCheckScheduled= false;
resize();
}
};
- private boolean fSizeCheckScheduled;
+ private boolean sizeCheckScheduled;
+ public SearchContributionItem(final String id, final int options,
+ final boolean updateWhenTyping) {
+ super(id);
+ this.options= options;
+ this.updateWhenTyping= updateWhenTyping;
+ }
+
public SearchContributionItem(final String id, final int options) {
this(id, options, false);
}
- public SearchContributionItem(final String id, final int options, final boolean updateWhenTyping) {
- super(id);
- fOptions = options;
- fUpdateWhenTyping = updateWhenTyping;
- }
-
public SearchText getSearchText() {
- return fControl;
+ return this.control;
}
/**
* Table or tree to select
*/
- public void setResultControl(final Control control) {
- fResultControl = control;
+ public void setResultControl(final @Nullable Control control) {
+ this.resultControl= control;
}
- public void setToolTip(final String text) {
- fToolTipText = text;
+ public void setToolTip(final @Nullable String text) {
+ this.toolTipText= text;
}
/**
* For views the control of the view
*/
public void setSizeControl(final Composite control) {
- fSizeControl = control;
- fSizeControl.addListener(SWT.Resize, new Listener() {
+ this.sizeControl= control;
+ control.addListener(SWT.Resize, new Listener() {
@Override
public void handleEvent(final Event event) {
resize();
@@ -116,90 +124,84 @@
}
public void resize() {
- if (fTextItem != null && !fTextItem.isDisposed()
- && fSizeControl != null) {
- final int viewWidth = fSizeControl.getClientArea().width;
+ final var sizeControl= this.sizeControl;
+ if (this.textItem != null && !this.textItem.isDisposed()
+ && sizeControl != null ) {
+ final int viewWidth= sizeControl.getClientArea().width;
if (viewWidth <= 0) {
return;
}
- final ToolBar toolBar = fTextItem.getParent();
- final Composite toolBarParent = toolBar.getParent();
- final int toolBarWidth = toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
- final int currentWidth = fTextItem.getWidth();
- final int minWidth = LayoutUtils.hintWidth(fControl.getTextControl(), 8);
+ final ToolBar toolBar= this.textItem.getParent();
+ final Composite toolBarParent= nonNullAssert(toolBar.getParent());
+ final int toolBarWidth= toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
+ final int currentWidth= this.textItem.getWidth();
+ final int minWidth= LayoutUtils.hintWidth(this.control.getTextControl(), 8);
- int corr = toolBarWidth - currentWidth;
- if ((fOptions & VIEW_TOOLBAR) != 0) {
- if (WorkbenchUIUtils.IS_E4) {
- // E-4.2 View Toolbar (=> space for view menu)
- final Layout layout = toolBarParent.getLayout();
- if (layout instanceof RowLayout && ((RowLayout) layout).type == SWT.HORIZONTAL) {
- final Control[] children = toolBarParent.getChildren();
- for (int i = 0; i < children.length; i++) {
- if (children[i] != toolBar) {
- corr += children[i].getSize().x;
- }
+ int corr= toolBarWidth - currentWidth;
+ if ((this.options & VIEW_TOOLBAR) != 0) {
+ // E-4.2 View Toolbar (=> space for view menu)
+ final Layout layout= toolBarParent.getLayout();
+ if (layout instanceof RowLayout && ((RowLayout)layout).type == SWT.HORIZONTAL) {
+ final Control[] children= toolBarParent.getChildren();
+ for (int i= 0; i < children.length; i++) {
+ if (children[i] != toolBar) {
+ corr += children[i].getSize().x;
}
- corr += (children.length - 1) * ((RowLayout) layout).spacing;
}
- }
- else {
- corr += 18;
+ corr += (children.length - 1) * ((RowLayout)layout).spacing;
}
}
corr += 16; // 2 required
- final int width = Math.min(310, Math.max(minWidth, viewWidth - corr));
+ final int width= Math.min(310, Math.max(minWidth, viewWidth - corr));
if (width == currentWidth) {
return;
}
// scheduleSizeCheck();
- fTextItem.setWidth(width);
- toolBar.layout(new Control[] { fControl });
- toolBarParent.layout(true, true);
- if (WorkbenchUIUtils.IS_E4) {
- toolBarParent.pack(true);
- }
+ this.textItem.setWidth(width);
+ toolBarParent.layout(new @NonNull Control[] { this.control });
+ toolBarParent.pack(true);
}
}
private void scheduleSizeCheck() {
- if (!fSizeCheckScheduled && fTextItem != null && !fTextItem.isDisposed()) {
- fSizeCheckScheduled = true;
- fTextItem.getDisplay().asyncExec(fSizeCheckRunnable);
+ if (!this.sizeCheckScheduled
+ && this.textItem != null && !this.textItem.isDisposed() ) {
+ this.sizeCheckScheduled= true;
+ this.textItem.getDisplay().asyncExec(this.sizeCheckRunnable);
}
}
@Override
public void fill(final ToolBar parent, final int index) {
- fControl = new SearchText(parent);
- fControl.addListener(createSearchTextListener());
- final Listener swtListener = new SWTListener();
- fControl.addListener(SWT.Resize, swtListener);
- fControl.setToolTipText(fToolTipText);
+ this.control= new SearchText(parent);
+ this.control.addListener(createSearchTextListener());
+ final Listener swtListener= new SWTListener();
+ this.control.addListener(SWT.Resize, swtListener);
+ this.control.setToolTipText(this.toolTipText);
- fTextItem = new ToolItem(parent, SWT.SEPARATOR, index);
- fTextItem.setControl(fControl);
- fTextItem.setToolTipText(fToolTipText);
- fTextItem.setWidth(310); // high value prevents that the toolbar is moved to tabs
+ this.textItem= new ToolItem(parent, SWT.SEPARATOR, index);
+ this.textItem.setControl(this.control);
+ this.textItem.setToolTipText(this.toolTipText);
+ this.textItem.setWidth(310); // high value prevents that the toolbar is moved to tabs
}
public Control create(final Composite parent) {
- fControl = new SearchText(parent);
- fControl.addListener(createSearchTextListener());
- final Listener swtListener = new SWTListener();
- fControl.addListener(SWT.Resize, swtListener);
- fControl.setToolTipText(fToolTipText);
- return fControl;
+ this.control= new SearchText(parent);
+ this.control.addListener(createSearchTextListener());
+ final Listener swtListener= new SWTListener();
+ this.control.addListener(SWT.Resize, swtListener);
+ this.control.setToolTipText(this.toolTipText);
+ return this.control;
}
protected SearchText.Listener createSearchTextListener() {
return new SearchText.Listener() {
@Override
public void textChanged(final boolean user) {
- if (fUpdateWhenTyping || !user) {
+ if (SearchContributionItem.this.updateWhenTyping || !user) {
SearchContributionItem.this.search();
}
}
@@ -218,21 +220,22 @@
}
protected void selectFirst() {
- if (fResultControl instanceof Table) {
- final Table table = (Table) fResultControl;
+ final var resultControl= this.resultControl;
+ if (resultControl instanceof Table) {
+ final Table table= (Table)resultControl;
table.setFocus();
if (table.getSelectionCount() == 0) {
- final int idx = table.getTopIndex();
+ final int idx= table.getTopIndex();
if (idx >= 0) {
table.setSelection(idx);
}
}
}
- else if (fResultControl instanceof Tree) {
- final Tree table = (Tree) fResultControl;
+ else if (resultControl instanceof Tree) {
+ final Tree table= (Tree)resultControl;
table.setFocus();
if (table.getSelectionCount() == 0) {
- final TreeItem item = table.getTopItem();
+ final TreeItem item= table.getTopItem();
if (item != null) {
table.setSelection(item);
}
@@ -241,14 +244,14 @@
}
public String getText() {
- return fControl.getText();
+ return this.control.getText();
}
public void show() {
- if (!UIAccess.isOkToUse(fControl)) {
+ if (!UIAccess.isOkToUse(this.control)) {
return;
}
- fControl.setFocus();
+ this.control.setFocus();
}
}
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/mpbv/BrowserSession.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/mpbv/BrowserSession.java
index 7ea5c2a..ea15d93 100644
--- a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/mpbv/BrowserSession.java
+++ b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/mpbv/BrowserSession.java
@@ -127,7 +127,7 @@
return this.title;
}
- void setImageDescriptor(final ImageDescriptor imageDescriptor) {
+ void setImageDescriptor(final @Nullable ImageDescriptor imageDescriptor) {
this.imageDescriptor= imageDescriptor;
}
@@ -138,19 +138,22 @@
int putStatic(final String html) {
- if (this.staticContent == null) {
- this.staticContent= new IntArrayMap<>();
+ var staticContent= this.staticContent;
+ if (staticContent == null) {
+ staticContent= new IntArrayMap<>();
+ this.staticContent= staticContent;
}
- final int id= this.staticContent.size();
- this.staticContent.put(id, html);
+ final int id= staticContent.size();
+ staticContent.put(id, html);
return id;
}
@Nullable String getStatic(final int id) {
- if (this.staticContent == null) {
+ final var staticContent= this.staticContent;
+ if (staticContent == null) {
return null;
}
- return this.staticContent.get(id);
+ return staticContent.get(id);
}
}
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/mpbv/PageBookBrowserPage.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/mpbv/PageBookBrowserPage.java
index d2fc8e4..86315eb 100644
--- a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/mpbv/PageBookBrowserPage.java
+++ b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/mpbv/PageBookBrowserPage.java
@@ -14,6 +14,7 @@
package org.eclipse.statet.ecommons.ui.mpbv;
+import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert;
import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullElse;
import java.net.URI;
@@ -58,6 +59,7 @@
import org.eclipse.ui.menus.CommandContributionItemParameter;
import org.eclipse.ui.services.IServiceLocator;
+import org.eclipse.statet.jcommons.lang.NonNull;
import org.eclipse.statet.jcommons.lang.NonNullByDefault;
import org.eclipse.statet.jcommons.lang.Nullable;
@@ -76,8 +78,9 @@
@NonNullByDefault
-public class PageBookBrowserPage extends ManagedPage<ManagedPageBookView> implements ProgressListener,
- LocationListener, TitleListener, StatusTextListener, OpenWindowListener, CloseWindowListener {
+public class PageBookBrowserPage extends ManagedPage<ManagedPageBookView<BrowserSession>>
+ implements ProgressListener, LocationListener, TitleListener, StatusTextListener,
+ OpenWindowListener, CloseWindowListener {
protected static void setIcon(final BrowserSession session, final ImageDescriptor imageDescriptor) {
@@ -104,13 +107,8 @@
public SearchBar(final Composite parent) {
- create(parent);
- }
-
-
- private void create(final Composite parent) {
this.toolBarManager= new ToolBarManager(SWT.FLAT);
- this.toolBar= this.toolBarManager.createControl(parent);
+ this.toolBar= nonNullAssert(this.toolBarManager.createControl(parent));
this.toolBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
this.toolBar.addDisposeListener(this);
@@ -205,18 +203,20 @@
}
+ @SuppressWarnings("null")
public void show() {
- final GridData gd= (GridData) this.toolBar.getLayoutData();
+ final GridData gd= (GridData)this.toolBar.getLayoutData();
gd.exclude= false;
this.toolBar.getParent().layout(true, true);
this.searchTextItem.getSearchText().setFocus();
}
+ @SuppressWarnings("null")
public void hide() {
setFocusToBrowser();
- final GridData gd= (GridData) this.toolBar.getLayoutData();
+ final GridData gd= (GridData)this.toolBar.getLayoutData();
gd.exclude= true;
- this.toolBar.getParent().layout(new Control[] { this.toolBar });
+ this.toolBar.getParent().layout(new @NonNull Control[] { this.toolBar });
}
public String getText() {
@@ -245,11 +245,10 @@
private @Nullable StatusLineMessageManager statusManager;
- private BrowserAddressBar addressBar;
+ private @Nullable BrowserAddressBar addressBar;
- public PageBookBrowserPage(final ManagedPageBookView view,
- final BrowserSession session) {
+ public PageBookBrowserPage(final ManagedPageBookView view, final BrowserSession session) {
super(view);
this.session= session;
}
@@ -288,23 +287,25 @@
}
private Control createBrowser(final Composite parent) {
- this.browser= new Browser(parent, SWT.NONE);
+ final var browser= new Browser(parent, SWT.NONE);
+ this.browser= browser;
- this.browser.addProgressListener(this);
- this.browser.addLocationListener(this);
- this.browser.addTitleListener(this);
- this.browser.addStatusTextListener(this);
- this.browser.addOpenWindowListener(this);
- this.browser.addCloseWindowListener(this);
+ browser.addProgressListener(this);
+ browser.addLocationListener(this);
+ browser.addTitleListener(this);
+ browser.addStatusTextListener(this);
+ browser.addOpenWindowListener(this);
+ browser.addCloseWindowListener(this);
- return this.browser;
+ return browser;
}
protected @Nullable Control createAddressBar(final Composite parent) {
- this.addressBar= new BrowserAddressBar(parent, this,
+ final var addressBar= new BrowserAddressBar(parent, this,
BrowserUtils.getDefaultAddressInputHistory() );
+ this.addressBar= addressBar;
- return this.addressBar;
+ return addressBar;
}
void setStatusManager(final @Nullable StatusLineMessageManager statusManager) {
@@ -326,10 +327,12 @@
if (!UIAccess.isOkToUse(PageBookBrowserPage.this.browser)) {
return null;
}
- if (PageBookBrowserPage.this.searchBar == null) {
- PageBookBrowserPage.this.searchBar= new SearchBar(PageBookBrowserPage.this.composite);
+ var searchBar= PageBookBrowserPage.this.searchBar;
+ if (searchBar == null) {
+ searchBar= new SearchBar(PageBookBrowserPage.this.composite);
+ PageBookBrowserPage.this.searchBar= searchBar;
}
- PageBookBrowserPage.this.searchBar.show();
+ searchBar.show();
return null;
}
};
@@ -359,14 +362,15 @@
}
private void search(final boolean forward) {
- if (this.searchBar == null || !UIAccess.isOkToUse(this.browser)) {
+ final var searchBar= this.searchBar;
+ if (searchBar == null || !UIAccess.isOkToUse(this.browser)) {
return;
}
- final String text= this.searchBar.getText();
+ final String text= searchBar.getText();
if (text == null || text.isEmpty()) {
return;
}
- final boolean caseSensitive= this.searchBar.isCaseSensitiveEnabled();
+ final boolean caseSensitive= searchBar.isCaseSensitiveEnabled();
final String message;
if (BrowserUtils.searchText(this.browser, text, forward, caseSensitive, false)) {
@@ -380,8 +384,9 @@
message= "Search text not found";
}
- if (this.statusManager != null) {
- this.statusManager.setMessage(new StatusInfo(IStatus.INFO, message));
+ final var statusManager= this.statusManager;
+ if (statusManager != null) {
+ statusManager.setMessage(new StatusInfo(IStatus.INFO, message));
}
}
@@ -401,9 +406,10 @@
}
protected boolean setDefaultFocus() {
- if (this.addressBar != null && this.addressBar.isVisible()
- && (this.session.getUrl().equals(ABOUT_BLANK_URI_STRING) || this.addressBar.isEdited()) ) {
- return this.addressBar.setFocus();
+ final var addressBar= this.addressBar;
+ if (addressBar != null && addressBar.isVisible()
+ && (this.session.getUrl().equals(ABOUT_BLANK_URI_STRING) || addressBar.isEdited()) ) {
+ return addressBar.setFocus();
}
return setFocusToBrowser();
}
@@ -418,7 +424,8 @@
public void setUrl(@Nullable String url) {
- if (this.browser == null) {
+ final var browser= this.browser;
+ if (browser == null) {
return;
}
if (url == null || url.isEmpty()) {
@@ -428,11 +435,12 @@
final int id= this.session.putStatic(url.substring(8));
url= STATIC_CONTENT_URL_PREFIX + id;
}
- this.browser.setUrl(url, null, getHeaders());
+ browser.setUrl(url, null, getHeaders());
}
public void setUrl(@Nullable URI url) {
- if (this.browser == null) {
+ final var browser= this.browser;
+ if (browser == null) {
return;
}
if (url == null) {
@@ -519,8 +527,9 @@
}
protected void onPageChanged() {
- if (this.addressBar != null) {
- this.addressBar.onPageChanged();
+ final var addressBar= this.addressBar;
+ if (addressBar != null) {
+ addressBar.onPageChanged();
}
}
@@ -546,16 +555,17 @@
public void changed(final StatusTextEvent event) {
this.browserStatus= (event.text != null && !event.text.isEmpty()) ?
new StatusInfo(IStatus.OK, event.text) : null;
- if (this.statusManager != null) {
- this.statusManager.setSelectionMessage(this.browserStatus);
+
+ final var statusManager= this.statusManager;
+ if (statusManager != null) {
+ statusManager.setSelectionMessage(this.browserStatus);
}
}
@Override
public void open(final WindowEvent event) {
- final PageBookBrowserPage page= (PageBookBrowserPage) getView().newPage(
- new BrowserSession(), true );
+ final var page= (PageBookBrowserPage)getView().newPage(new BrowserSession(), true);
if (page != null) {
event.browser= page.browser;
}
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/workbench/WorkbenchUIUtils.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/workbench/WorkbenchUIUtils.java
index b0288da..1502999 100644
--- a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/workbench/WorkbenchUIUtils.java
+++ b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/workbench/WorkbenchUIUtils.java
@@ -24,7 +24,6 @@
import org.eclipse.core.commands.contexts.Context;
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.bindings.TriggerSequence;
import org.eclipse.jface.bindings.keys.KeySequence;
@@ -60,9 +59,6 @@
public class WorkbenchUIUtils {
- public static final boolean IS_E4= (Platform.getBundle("org.eclipse.e4.ui.workbench") != null); //$NON-NLS-1$
-
-
public static @Nullable ISelection getCurrentSelection(final @Nullable Object context) {
if (context instanceof IEvaluationContext) {
final IEvaluationContext evaluationContext= (IEvaluationContext) context;