diff --git a/bundles/org.eclipse.ui.browser/META-INF/MANIFEST.MF b/bundles/org.eclipse.ui.browser/META-INF/MANIFEST.MF index bbd680a30c2..bb836775f35 100644 --- a/bundles/org.eclipse.ui.browser/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.ui.browser/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Plugin.name Bundle-SymbolicName: org.eclipse.ui.browser; singleton:=true -Bundle-Version: 3.8.600.qualifier +Bundle-Version: 3.8.700.qualifier Bundle-Activator: org.eclipse.ui.internal.browser.WebBrowserUIPlugin Bundle-Vendor: %Plugin.providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserDescriptorDialog.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserDescriptorDialog.java index f0936f903a8..1ed1db445ba 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserDescriptorDialog.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserDescriptorDialog.java @@ -67,10 +67,11 @@ public BrowserDescriptorDialog(Shell parentShell) { protected void configureShell(Shell shell) { super.configureShell(shell); - if (isEdit) + if (isEdit) { shell.setText(Messages.editExternalBrowser); - else + } else { shell.setText(Messages.createBrowser); + } } protected Text createText(Composite comp, String txt, final StringModifyListener listener, boolean multiLine) { @@ -91,8 +92,9 @@ protected Text createText(Composite comp, String txt, final StringModifyListener }); } // final Text text = SWTUtil.createMultilineText(comp, style); - if (txt != null) + if (txt != null) { text.setText(txt); + } GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false); data.widthHint = 450; @@ -104,8 +106,9 @@ protected Text createText(Composite comp, String txt, final StringModifyListener } text.setLayoutData(data); - if (listener != null) + if (listener != null) { text.addModifyListener(e -> listener.valueChanged(text.getText())); + } return text; } @@ -145,8 +148,9 @@ protected Control createDialogArea(Composite parent) { dialog.setFileName(fname); fname = dialog.open(); - if (fname != null) + if (fname != null) { browserLocationTextfield.setText(fname); + } })); SWTUtil.createLabel(composite, Messages.parameters).setFont(font); @@ -184,11 +188,13 @@ protected void okPressed() { } private void setOKButtonEnabled(boolean curIsEnabled) { - if (okButton == null) + if (okButton == null) { okButton = getButton(IDialogConstants.OK_ID); + } - if (okButton != null) + if (okButton != null) { okButton.setEnabled(curIsEnabled); + } } @Override @@ -202,12 +208,14 @@ protected void validateFields() { boolean valid = true; String name = browserNameTextfield.getText(); - if (name == null || name.trim().length() < 1) + if (name == null || name.trim().length() < 1) { valid = false; + } String location = browserLocationTextfield.getText(); - if (location == null || location.trim().length() < 1) + if (location == null || location.trim().length() < 1) { valid = false; + } setOKButtonEnabled(valid); } diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserDescriptorWorkingCopy.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserDescriptorWorkingCopy.java index 80b31795808..143de423ac4 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserDescriptorWorkingCopy.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserDescriptorWorkingCopy.java @@ -28,8 +28,9 @@ public BrowserDescriptorWorkingCopy(BrowserDescriptor browser) { @Override public void setName(String name) { - if (name == null) + if (name == null) { throw new IllegalArgumentException(); + } this.name = name; } diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserExt.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserExt.java index 89621c77ed0..ae1876f826b 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserExt.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserExt.java @@ -25,7 +25,7 @@ public class BrowserExt implements IBrowserExt { private static final String ATTR_FACTORY_CLASS = "factoryclass"; //$NON-NLS-1$ - private IConfigurationElement element; + private final IConfigurationElement element; private BrowserFactory delegate; @@ -50,8 +50,9 @@ public String getId() { @Override public String getName() { String label = element.getAttribute("name"); //$NON-NLS-1$ - if (label == null) + if (label == null) { return "n/a"; //$NON-NLS-1$ + } return label; } @@ -68,8 +69,9 @@ public String getExecutable() { @Override public String getOS() { String os = element.getAttribute("os"); //$NON-NLS-1$ - if (os == null) + if (os == null) { os = ""; //$NON-NLS-1$ + } return os; } @@ -92,8 +94,9 @@ public String[] getDefaultLocations() { protected BrowserFactory getDelegate() { if (delegate == null) { if (element.getAttribute(ATTR_FACTORY_CLASS) == null - || element.getAttribute(ATTR_FACTORY_CLASS).isEmpty()) + || element.getAttribute(ATTR_FACTORY_CLASS).isEmpty()) { return null; + } try { delegate = (BrowserFactory) element @@ -118,8 +121,9 @@ protected BrowserFactory getDelegate() { @Override public boolean isAvailable() { if (delegate == null && (element.getAttribute(ATTR_FACTORY_CLASS) == null - || element.getAttribute(ATTR_FACTORY_CLASS).isEmpty())) + || element.getAttribute(ATTR_FACTORY_CLASS).isEmpty())) { return true; + } try { return getDelegate().isAvailable(); diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserLauncher.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserLauncher.java index ed26fa5c8b7..c5b1054da32 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserLauncher.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserLauncher.java @@ -32,12 +32,13 @@ public BrowserLauncher() { public void open(IPath file) { IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport(); try { - if (WebBrowserPreference.getBrowserChoice()== WebBrowserPreference.INTERNAL) + if (WebBrowserPreference.getBrowserChoice()== WebBrowserPreference.INTERNAL) { support.createBrowser(IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.NAVIGATION_BAR, file.toPortableString(), null, null).openURL(file.toFile().toURI().toURL()); - else + } else { support.createBrowser(IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.NAVIGATION_BAR, DefaultBrowserSupport.SHARED_ID, null, null).openURL(file.toFile().toURI().toURL()); + } } catch (MalformedURLException e) { // ignore diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserManager.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserManager.java index fa8d5fc6d4b..e715560d477 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserManager.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserManager.java @@ -36,14 +36,15 @@ public class BrowserManager extends Observable { protected List browsers; protected IBrowserDescriptor currentBrowser; - private IPreferenceChangeListener pcl; + private final IPreferenceChangeListener pcl; protected boolean ignorePreferenceChanges = false; protected static BrowserManager instance; public static BrowserManager getInstance() { - if (instance == null) + if (instance == null) { instance = new BrowserManager(); + } return instance; } @@ -66,8 +67,9 @@ private BrowserManager() { } protected static void safeDispose() { - if (instance == null) + if (instance == null) { return; + } instance.dispose(); } @@ -82,8 +84,9 @@ public IBrowserDescriptorWorkingCopy createExternalWebBrowser() { } public List getWebBrowsers() { - if (browsers == null) + if (browsers == null) { loadBrowsers(); + } return new ArrayList<>(browsers); } @@ -101,8 +104,9 @@ public void loadBrowsers() { IMemento memento = XMLMemento.createReadRoot(reader); IMemento system = memento.getChild("system"); //$NON-NLS-1$ - if (system != null && WebBrowserUtil.canUseSystemBrowser()) + if (system != null && WebBrowserUtil.canUseSystemBrowser()) { browsers.add(new SystemBrowserDescriptor()); + } IMemento[] children = memento.getChildren("external"); //$NON-NLS-1$ int size = children.length; @@ -131,8 +135,9 @@ public void loadBrowsers() { saveBrowsers(); } - if (currentBrowser == null && browsers.size() > 0) + if (currentBrowser == null && browsers.size() > 0) { currentBrowser = browsers.get(0); + } setChanged(); notifyObservers(); } @@ -145,8 +150,7 @@ protected void saveBrowsers() { Iterator iterator = browsers.iterator(); while (iterator.hasNext()) { Object obj = iterator.next(); - if (obj instanceof BrowserDescriptor) { - BrowserDescriptor browser = (BrowserDescriptor) obj; + if (obj instanceof BrowserDescriptor browser) { IMemento child = memento.createChild("external"); //$NON-NLS-1$ browser.save(child); } else if (obj instanceof SystemBrowserDescriptor) { @@ -194,49 +198,59 @@ protected void addDefaultBrowsers() { // by default, if internal is there, that is current, else set the first // external one - if (!browsers.isEmpty() && currentBrowser == null) + if (!browsers.isEmpty() && currentBrowser == null) { currentBrowser = browsers.get(0); + } } protected void addBrowser(IBrowserDescriptor browser) { - if (browsers == null) + if (browsers == null) { loadBrowsers(); - if (!browsers.contains(browser)) + } + if (!browsers.contains(browser)) { browsers.add(browser); - if (browsers.size() == 1) + } + if (browsers.size() == 1) { setCurrentWebBrowser(browser); + } } protected void removeWebBrowser(IBrowserDescriptor browser) { - if (browsers == null) + if (browsers == null) { loadBrowsers(); + } browsers.remove(browser); if (currentBrowser == null || currentBrowser.equals(browser)) { currentBrowser = null; - if (browsers.size() > 0) + if (browsers.size() > 0) { currentBrowser = browsers.get(0); + } } } public IBrowserDescriptor getCurrentWebBrowser() { - if (browsers == null) + if (browsers == null) { loadBrowsers(); + } - if (currentBrowser == null && browsers.size() > 0) + if (currentBrowser == null && browsers.size() > 0) { return browsers.get(0); + } return currentBrowser; } public void setCurrentWebBrowser(IBrowserDescriptor wb) { - if (wb == null) + if (wb == null) { throw new IllegalArgumentException(); + } - if (browsers.contains(wb)) + if (browsers.contains(wb)) { currentBrowser = wb; - else + } else { throw new IllegalArgumentException(); + } saveBrowsers(); } diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserText.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserText.java index 210a73f346b..0ea3502330c 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserText.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserText.java @@ -34,7 +34,7 @@ public class BrowserText { private String url; - private FallbackScrolledComposite scomp; + private final FallbackScrolledComposite scomp; private Label title; @@ -46,7 +46,7 @@ public class BrowserText { protected Link link; - private BrowserViewer viewer; + private final BrowserViewer viewer; private Button button; @@ -54,7 +54,7 @@ public class BrowserText { private boolean expanded; - private Throwable ex; + private final Throwable ex; class ReflowScrolledComposite extends FallbackScrolledComposite { public ReflowScrolledComposite(Composite parent, int style) { @@ -140,10 +140,11 @@ protected void toggleException() { } private void updateButtonText() { - if (expanded) + if (expanded) { button.setText(Messages.BrowserText_button_collapse); - else + } else { button.setText(Messages.BrowserText_button_expand); + } } protected void updateWidth(Composite parent) { @@ -158,14 +159,16 @@ protected void updateWidth(Composite parent) { private void updateWidth(Control c, int width) { GridData gd = (GridData) c.getLayoutData(); - if (gd != null) + if (gd != null) { gd.widthHint = width - 10; + } } protected void doOpenExternal() { IBrowserViewerContainer container = viewer.getContainer(); - if (container != null) + if (container != null) { container.openInExternalBrowser(url); + } } public Control getControl() { diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserViewer.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserViewer.java index f101181c0cd..a466a14a24f 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserViewer.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserViewer.java @@ -189,11 +189,13 @@ public static interface IBackNextListener { public BrowserViewer(Composite parent, int style) { super(parent, SWT.NONE); - if ((style & LOCATION_BAR) != 0) + if ((style & LOCATION_BAR) != 0) { showURLbar = true; + } - if ((style & BUTTON_BAR) != 0) + if ((style & BUTTON_BAR) != 0) { showToolbar = true; + } GridLayout layout = new GridLayout(); layout.marginHeight = 0; @@ -211,11 +213,13 @@ public BrowserViewer(Composite parent, int style) { toolbarComp.setLayout(new ToolbarLayout()); toolbarComp.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL)); - if (showToolbar) + if (showToolbar) { createToolbar(toolbarComp); + } - if (showURLbar) + if (showURLbar) { createLocationBar(toolbarComp); + } if (showToolbar || showURLbar) { busy = new BusyIndicator(toolbarComp, SWT.NONE); @@ -238,15 +242,16 @@ public void mouseDown(MouseEvent e) { this.browser.addLocationListener(LocationListener.changingAdapter(event -> { URI uri = URI.create(event.location); if (!(uri.getScheme().equals("http") || uri.getScheme().equals("https") //$NON-NLS-1$ //$NON-NLS-2$ - || uri.getScheme().equals("file"))) //$NON-NLS-1$ + || uri.getScheme().equals("file"))) { //$NON-NLS-1$ try { - if (IUriSchemeProcessor.INSTANCE.canHandle(uri)) { - IUriSchemeProcessor.INSTANCE.handleUri(uri); - event.doit = false; - } + if (IUriSchemeProcessor.INSTANCE.canHandle(uri)) { + IUriSchemeProcessor.INSTANCE.handleUri(uri); + event.doit = false; + } } catch (CoreException e) { - WebBrowserUIPlugin.logError(e.getMessage(), e); + WebBrowserUIPlugin.logError(e.getMessage(), e); } + } })); } @@ -258,18 +263,20 @@ public void mouseDown(MouseEvent e) { text = new BrowserText(this, this, e); } - if (showURLbar) + if (showURLbar) { updateHistory(); - if (showToolbar) + } + if (showToolbar) { updateBackNextBusy(); + } if (browser!=null) { browser.setLayoutData(new GridData(GridData.FILL_BOTH)); PlatformUI.getWorkbench().getHelpSystem().setHelp(browser, ContextIds.WEB_BROWSER); - } - else + } else { text.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); + } addBrowserListeners(); addDisposeListener(this::dispose); @@ -324,20 +331,25 @@ protected void updateBackNextBusy() { busy.setBusy(loading); } - if (backNextListener != null) + if (backNextListener != null) { backNextListener.updateBackNextBusy(); + } } protected void updateLocation() { - if (locationListener != null) + if (locationListener != null) { locationListener.historyChanged(null); + } - if (locationListener != null) + if (locationListener != null) { locationListener.locationChanged(null); + } } private void addBrowserListeners() { - if (browser==null) return; + if (browser==null) { + return; + } // respond to ExternalBrowserInstance StatusTextEvents events by // updating the status line browser.addStatusTextListener(event -> { @@ -358,15 +370,19 @@ private void addBrowserListeners() { shell2.setLayout(new FillLayout()); shell2.setText(Messages.viewWebBrowserTitle); shell2.setImage(getShell().getImage()); - if (event.location != null) + if (event.location != null) { shell2.setLocation(event.location); - if (event.size != null) + } + if (event.size != null) { shell2.setSize(event.size); + } int style = 0; - if (showURLbar) + if (showURLbar) { style += LOCATION_BAR; - if (showToolbar) + } + if (showToolbar) { style += BUTTON_BAR; + } BrowserViewer browser2 = new BrowserViewer(shell2, style); browser2.newWindow = true; event.browser = browser2.browser; @@ -378,10 +394,12 @@ public void show(WindowEvent e) { Browser browser2 = (Browser) e.widget; if (browser2.getParent().getParent() instanceof Shell) { Shell shell = (Shell) browser2.getParent().getParent(); - if (e.location != null) + if (e.location != null) { shell.setLocation(e.location); - if (e.size != null) + } + if (e.size != null) { shell.setSize(shell.computeSize(e.size.x, e.size.y)); + } shell.open(); } } @@ -390,10 +408,11 @@ public void show(WindowEvent e) { browser.addCloseWindowListener(event -> { // if shell is not null, it must be a secondary popup window, // else its an editor window - if (newWindow) + if (newWindow) { getShell().dispose(); - else + } else { container.close(); + } }); browser.addProgressListener(new ProgressListener() { @@ -402,8 +421,9 @@ public void show(WindowEvent e) { @Override public void changed(ProgressEvent event) { //System.out.println("progress: " + event.current + ", " + event.total); //$NON-NLS-1$ //$NON-NLS-2$ - if (event.total == 0) + if (event.total == 0) { return; + } boolean done = (event.current == event.total); @@ -429,12 +449,13 @@ public void changed(ProgressEvent event) { } if (showToolbar) { - if (!busy.isBusy() && !done) + if (!busy.isBusy() && !done) { loading = true; - else if (busy.isBusy() && done) // once the progress hits + } else if (busy.isBusy() && done) { // once the progress hits // 100 percent, done, set // busy to false loading = false; + } //System.out.println("loading: " + loading); //$NON-NLS-1$ updateBackNextBusy(); @@ -460,8 +481,9 @@ public void completed(ProgressEvent event) { browser.addLocationListener(new LocationAdapter() { @Override public void changed(LocationEvent event) { - if (!event.top) + if (!event.top) { return; + } if (combo != null) { if (!"about:blank".equals(event.location)) { //$NON-NLS-1$ combo.setText(event.location); @@ -501,8 +523,9 @@ public void changed(LocationEvent event) { * @param listener java.beans.PropertyChangeListener */ public void addPropertyChangeListener(PropertyChangeListener listener) { - if (propertyListeners == null) + if (propertyListeners == null) { propertyListeners = new ArrayList<>(); + } propertyListeners.add(listener); } @@ -512,16 +535,18 @@ public void addPropertyChangeListener(PropertyChangeListener listener) { * @param listener java.beans.PropertyChangeListener */ public void removePropertyChangeListener(PropertyChangeListener listener) { - if (propertyListeners != null) + if (propertyListeners != null) { propertyListeners.remove(listener); + } } /** * Fire a property change event. */ protected void firePropertyChangeEvent(String propertyName, Object oldValue, Object newValue) { - if (propertyListeners == null) + if (propertyListeners == null) { return; + } PropertyChangeEvent event = new PropertyChangeEvent(this, propertyName, oldValue, newValue); //Trace.trace("Firing: " + event + " " + oldValue); @@ -530,12 +555,13 @@ protected void firePropertyChangeEvent(String propertyName, Object oldValue, Obj PropertyChangeListener[] pcl = new PropertyChangeListener[size]; propertyListeners.toArray(pcl); - for (int i = 0; i < size; i++) + for (int i = 0; i < size; i++) { try { pcl[i].propertyChange(event); } catch (Exception e) { // ignore } + } } catch (Exception e) { // ignore } @@ -557,8 +583,9 @@ protected void firePropertyChangeEvent(String propertyName, Object oldValue, Obj * @see #back */ public boolean forward() { - if (browser==null) + if (browser==null) { return false; + } return browser.forward(); } @@ -578,8 +605,9 @@ public boolean forward() { * @see #forward */ public boolean back() { - if (browser==null) + if (browser==null) { return false; + } return browser.back(); } @@ -599,8 +627,9 @@ public boolean back() { * @see #back */ public boolean isBackEnabled() { - if (browser==null) + if (browser==null) { return false; + } return browser.isBackEnabled(); } @@ -620,8 +649,9 @@ public boolean isBackEnabled() { * @see #forward */ public boolean isForwardEnabled() { - if (browser==null) + if (browser==null) { return false; + } return browser.isForwardEnabled(); } @@ -638,8 +668,9 @@ public boolean isForwardEnabled() { * */ public void stop() { - if (browser!=null) + if (browser!=null) { browser.stop(); + } } private boolean navigate(String url) { @@ -648,8 +679,9 @@ private boolean navigate(String url) { refresh(); return true; } - if (browser!=null) + if (browser!=null) { return browser.setUrl(url, null, new String[] {"Cache-Control: no-cache"}); //$NON-NLS-1$ + } return text.setUrl(url); } @@ -666,10 +698,11 @@ private boolean navigate(String url) { * */ public void refresh() { - if (browser!=null) + if (browser!=null) { browser.refresh(); - else + } else { text.refresh(); + } try { Thread.sleep(50); } catch (Exception e) { @@ -698,10 +731,11 @@ private void setURL(String url, boolean browse) { return; } - if ("eclipse".equalsIgnoreCase(url)) //$NON-NLS-1$ + if ("eclipse".equalsIgnoreCase(url)) { //$NON-NLS-1$ url = "http://www.eclipse.org"; //$NON-NLS-1$ - else if ("wtp".equalsIgnoreCase(url)) //$NON-NLS-1$ + } else if ("wtp".equalsIgnoreCase(url)) { //$NON-NLS-1$ url = "http://www.eclipse.org/webtools/"; //$NON-NLS-1$ + } if (browse) { navigate(url); @@ -712,8 +746,9 @@ else if ("wtp".equalsIgnoreCase(url)) //$NON-NLS-1$ } protected void addToHistory(String url) { - if (history == null) + if (history == null) { history = WebBrowserPreference.getInternalWebBrowserHistory(); + } int found = -1; int size = history.size(); for (int i = 0; i < size; i++) { @@ -725,8 +760,9 @@ protected void addToHistory(String url) { } if (found == -1) { - if (size >= MAX_HISTORY) + if (size >= MAX_HISTORY) { history.remove(size - 1); + } history.add(0, url); WebBrowserPreference.setInternalWebBrowserHistory(history); } else if (found != 0) { @@ -739,14 +775,16 @@ protected void addToHistory(String url) { private void dispose(DisposeEvent event) { showToolbar = false; - if (busy != null) + if (busy != null) { busy.dispose(); + } busy = null; browser = null; text = null; - if (clipboard!=null) + if (clipboard!=null) { clipboard.dispose(); + } clipboard=null; if (watcher != null) { @@ -849,8 +887,9 @@ private Image getImage(String folder, String name) { * @see #setURL(String) */ public String getURL() { - if (browser!=null) + if (browser!=null) { return browser.getUrl(); + } return text.getUrl(); } @@ -868,12 +907,14 @@ public boolean setFocus() { * Update the history list to the global/shared copy. */ protected void updateHistory() { - if (combo == null || combo.isDisposed()) + if (combo == null || combo.isDisposed()) { return; + } String temp = combo.getText(); - if (history == null) + if (history == null) { history = WebBrowserPreference.getInternalWebBrowserHistory(); + } String[] historyList = new String[history.size()]; history.toArray(historyList); @@ -904,8 +945,9 @@ public void setContainer(IBrowserViewerContainer container) { protected Object syncObject = new Object(); protected void addSynchronizationListener() { - if (fileListenerThread != null) + if (fileListenerThread != null) { return; + } fileListenerThread = new Thread("Browser file synchronization") { //$NON-NLS-1$ @Override @@ -937,8 +979,9 @@ public void changed(LocationEvent event) { file = temp; timestamp = file.lastModified(); } - } else + } else { file = null; + } } }; browser.addLocationListener(locationListener2); @@ -952,17 +995,20 @@ public void changed(LocationEvent event) { } protected static File getFile(String location) { - if (location == null) + if (location == null) { return null; - if (location.startsWith("file:/")) //$NON-NLS-1$ + } + if (location.startsWith("file:/")) { //$NON-NLS-1$ location = location.substring(6); + } return new File(location); } protected void removeSynchronizationListener() { - if (fileListenerThread == null) + if (fileListenerThread == null) { return; + } fileListenerThread = null; browser.removeLocationListener(locationListener2); diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BusyIndicator.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BusyIndicator.java index 8a3a9a5d646..3c38042ad7e 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BusyIndicator.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BusyIndicator.java @@ -67,8 +67,9 @@ public Point computeSize(int wHint, int hHint, boolean changed) { * Creates a thread to animate the image. */ protected synchronized void createBusyThread() { - if (busyThread != null) + if (busyThread != null) { return; + } stop = false; busyThread = new Thread() { @@ -80,11 +81,13 @@ public void run() { while (!stop) { Display.getDefault().syncExec(() -> { if (!stop) { - if (count < 13) + if (count < 13) { setImage(images[count]); + } count++; - if (count > 12) + if (count > 12) { count = 1; + } } }); try { @@ -93,8 +96,9 @@ public void run() { // ignore } } - if (busyThread == null) + if (busyThread == null) { Display.getDefault().syncExec(() -> setImage(images[0])); + } } catch (Exception e) { Trace.trace(Trace.WARNING, "Busy error", e); //$NON-NLS-1$ } @@ -134,12 +138,14 @@ public synchronized boolean isBusy() { */ protected void onPaint(PaintEvent event) { Rectangle rect = getClientArea(); - if (rect.width == 0 || rect.height == 0) + if (rect.width == 0 || rect.height == 0) { return; + } GC gc = event.gc; - if (image != null) + if (image != null) { gc.drawImage(image, 2, 2); + } } /** @@ -149,8 +155,9 @@ protected void onPaint(PaintEvent event) { */ public synchronized void setBusy(boolean busy) { if (busy) { - if (busyThread == null) + if (busyThread == null) { createBusyThread(); + } } else if (busyThread != null) { stop = true; busyThread = null; diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/DefaultBrowserSupport.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/DefaultBrowserSupport.java index c062889bbf2..c5669f6b3b6 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/DefaultBrowserSupport.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/DefaultBrowserSupport.java @@ -52,19 +52,18 @@ protected IWebBrowser getExistingWebBrowser(String browserId) { try { Object obj = browserIdMap.get(browserId); IWebBrowser browser = null; - if (obj instanceof IWebBrowser) + if (obj instanceof IWebBrowser) { browser = (IWebBrowser) obj; - else if (obj instanceof HashMap) { - @SuppressWarnings("rawtypes") - HashMap wmap = (HashMap) obj; + } else if (obj instanceof HashMap wmap) { IWorkbenchWindow window = PlatformUI.getWorkbench() .getActiveWorkbenchWindow(); if (window != null) { browser = (IWebBrowser) wmap.get(getWindowKey(window)); } } - if (browser != null) + if (browser != null) { return browser; + } } catch (Exception e) { // ignore } @@ -78,12 +77,12 @@ private Integer getWindowKey(IWorkbenchWindow window) { @Override public IWebBrowser createBrowser(int style, String browserId, String name, String tooltip) throws PartInitException { - if (browserId == null) + if (browserId == null) { browserId = getDefaultId(); + } IWebBrowser browser = getExistingWebBrowser(browserId); if (browser != null) { - if (browser instanceof InternalBrowserInstance) { - InternalBrowserInstance instance2 = (InternalBrowserInstance) browser; + if (browser instanceof InternalBrowserInstance instance2) { instance2.setName(name); instance2.setTooltip(tooltip); } @@ -101,18 +100,21 @@ public IWebBrowser createBrowser(int style, String browserId, String name, || !WebBrowserUtil.canUseInternalWebBrowser()) { IBrowserDescriptor ewb = BrowserManager.getInstance() .getCurrentWebBrowser(); - if (ewb == null) + if (ewb == null) { throw new PartInitException(Messages.errorNoBrowser); + } - if (ewb instanceof SystemBrowserDescriptor) + if (ewb instanceof SystemBrowserDescriptor) { webBrowser = new SystemBrowserInstance(browserId); - else { + } else { IBrowserExt ext = WebBrowserUIPlugin.findBrowsers(ewb.getLocation()); - if (ext != null) + if (ext != null) { webBrowser = ext.createBrowser(browserId, ewb.getLocation(), ewb.getParameters()); - if (webBrowser == null) + } + if (webBrowser == null) { webBrowser = new ExternalBrowserInstance(browserId, ewb); + } } } else if ((style & IWorkbenchBrowserSupport.AS_VIEW) != 0) { webBrowser = new InternalBrowserViewInstance(browserId, style, @@ -161,23 +163,24 @@ protected void removeBrowser(IWebBrowser browser) { // also remove the window map itself if it is empty. Integer key = ((InternalBrowserInstance) browser).getWindowKey(); Object entry = browserIdMap.get(baseId); - if (entry != null && entry instanceof HashMap) { - @SuppressWarnings("rawtypes") - HashMap wmap = (HashMap) entry; + if (entry != null && entry instanceof HashMap wmap) { wmap.remove(key); - if (wmap.isEmpty()) + if (wmap.isEmpty()) { browserIdMap.remove(baseId); + } } - } else + } else { browserIdMap.remove(baseId); + } } private String getDefaultId() { String id = null; for (int i = 0; i < Integer.MAX_VALUE; i++) { id = DEFAULT_ID_BASE + i; - if (browserIdMap.get(id) == null) + if (browserIdMap.get(id) == null) { break; + } } return id; } diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/FallbackScrolledComposite.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/FallbackScrolledComposite.java index 67c663ba24e..4f0bd75cc50 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/FallbackScrolledComposite.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/FallbackScrolledComposite.java @@ -53,8 +53,9 @@ public FallbackScrolledComposite(Composite parent, int style) { @Override public void setForeground(Color fg) { super.setForeground(fg); - if (getContent() != null) + if (getContent() != null) { getContent().setForeground(fg); + } } /** @@ -66,8 +67,9 @@ public void setForeground(Color fg) { @Override public void setBackground(Color bg) { super.setBackground(bg); - if (getContent() != null) + if (getContent() != null) { getContent().setBackground(bg); + } } /** @@ -77,8 +79,9 @@ public void setBackground(Color bg) { @Override public void setFont(Font font) { super.setFont(font); - if (getContent() != null) + if (getContent() != null) { getContent().setFont(font); + } } /** @@ -99,8 +102,9 @@ public void setContent(Control content) { */ @Override public boolean setFocus() { - if (getContent() != null) + if (getContent() != null) { return getContent().setFocus(); + } return super.setFocus(); } @@ -115,8 +119,9 @@ public boolean setFocus() { public void reflow(boolean flushCache) { Composite c = (Composite) getContent(); Rectangle clientArea = getClientArea(); - if (c == null) + if (c == null) { return; + } Point newSize = c .computeSize(clientArea.width, SWT.DEFAULT, flushCache); diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/ImageResourceManager.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/ImageResourceManager.java index eb87b7658de..b6395f47b86 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/ImageResourceManager.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/ImageResourceManager.java @@ -22,7 +22,7 @@ import org.osgi.framework.FrameworkUtil; class ImageResourceManager { - private LocalResourceManager manager; + private final LocalResourceManager manager; /** * The constructor diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/InternalBrowserEditorInstance.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/InternalBrowserEditorInstance.java index 6716f9d8733..c33c2d36d53 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/InternalBrowserEditorInstance.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/InternalBrowserEditorInstance.java @@ -38,11 +38,13 @@ public void openURL(URL url) throws PartInitException { IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage page = null; - if (workbenchWindow != null) + if (workbenchWindow != null) { page = workbenchWindow.getActivePage(); + } - if (page == null) + if (page == null) { throw new PartInitException(Messages.errorCouldNotLaunchInternalWebBrowser); + } if (editor != null) { editor.init(editor.getEditorSite(), input); diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/SWTUtil.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/SWTUtil.java index 05c5557289e..7de7ca74f89 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/SWTUtil.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/SWTUtil.java @@ -56,8 +56,9 @@ protected static int getButtonWidthHint(Button button) { public static Button createButton(Composite comp, String label) { Button b = new Button(comp, SWT.PUSH); b.setText(label); - if (fontMetrics == null) + if (fontMetrics == null) { initializeDialogUnits(comp); + } GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); data.widthHint = getButtonWidthHint(b); b.setLayoutData(data); diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/SystemBrowserInstance.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/SystemBrowserInstance.java index 8c4f17bfda6..7f4c15689d8 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/SystemBrowserInstance.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/SystemBrowserInstance.java @@ -34,10 +34,12 @@ public void openURL(URL url) throws PartInitException { Trace.trace(Trace.FINEST, "Launching system Web browser: " + urlText); //$NON-NLS-1$ Program program = Program.findProgram("html"); //$NON-NLS-1$ if (program != null) { - if (program.execute(urlText)) + if (program.execute(urlText)) { return; + } } - if (!Program.launch(urlText)) + if (!Program.launch(urlText)) { throw new PartInitException(NLS.bind(Messages.errorCouldNotLaunchExternalWebBrowser, urlText)); + } } } \ No newline at end of file diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/TextAction.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/TextAction.java index 67d2feb4749..b2eb267be29 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/TextAction.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/TextAction.java @@ -41,7 +41,7 @@ protected TextAction(BrowserViewer browser, byte type) { /** * Copies the selected text to the clipboard. The text will be put in the * clipboard in plain text format. - * + * * @exception org.eclipse.swt.SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • @@ -130,13 +130,15 @@ public void paste() { */ @Override public void run() { - if (browser == null || browser.combo == null) + if (browser == null || browser.combo == null) { return; - if (type == CUT) + } + if (type == CUT) { cut(); - else if (type == COPY) + } else if (type == COPY) { copy(); - else if (type == PASTE) + } else if (type == PASTE) { paste(); + } } } \ No newline at end of file diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/ToolbarLayout.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/ToolbarLayout.java index f6f7a511874..d0dc66fc395 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/ToolbarLayout.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/ToolbarLayout.java @@ -30,8 +30,9 @@ public class ToolbarLayout extends Layout { @Override protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { - if (hHint != SWT.DEFAULT) + if (hHint != SWT.DEFAULT) { return new Point(wHint, hHint); + } Control[] children = composite.getChildren(); int h = 0; @@ -67,13 +68,15 @@ protected void layout(Composite composite, boolean flushCache) { int tw = r.width - MARGIN * 2 - (size - 1) * SPACING - sizes[size-1].x - EXTRA_BUSY_SPACING; for (int i = 0; i < size - 1; i++) { - if (children[i] instanceof Combo) + if (children[i] instanceof Combo) { combo = i; - else + } else { tw -= sizes[i].x; + } } - if (combo >= 0) + if (combo >= 0) { sizes[combo].x = tw; + } // space out other children with their standard size, give combo all // remaining space (if it exists) diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/Trace.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/Trace.java index dc72e628f1b..ffb5ad78b45 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/Trace.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/Trace.java @@ -45,11 +45,13 @@ public static void trace(int level, String s) { * @param t java.lang.Throwable */ public static void trace(int level, String s, Throwable t) { - if (!WebBrowserUIPlugin.getInstance().isDebugging()) + if (!WebBrowserUIPlugin.getInstance().isDebugging()) { return; + } System.out.println(s); - if (t != null) + if (t != null) { t.printStackTrace(); + } } } \ No newline at end of file diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserEditor.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserEditor.java index ddb79d58c52..78e93c71d59 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserEditor.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserEditor.java @@ -146,8 +146,9 @@ public IAction getCutAction() { */ protected WebBrowserEditorInput getWebBrowserEditorInput() { IEditorInput input = getEditorInput(); - if (input instanceof WebBrowserEditorInput) + if (input instanceof WebBrowserEditorInput) { return (WebBrowserEditorInput) input; + } return null; } @@ -163,8 +164,7 @@ public IAction getPasteAction() { @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { Trace.trace(Trace.FINEST, "Opening browser: " + input); //$NON-NLS-1$ - if (input instanceof IPathEditorInput) { - IPathEditorInput pei = (IPathEditorInput) input; + if (input instanceof IPathEditorInput pei) { final IPath path= pei.getPath(); URL url = null; try { @@ -172,27 +172,30 @@ public void init(IEditorSite site, IEditorInput input) throws PartInitException setPartName(path.lastSegment()); url = path.toFile().toURI().toURL(); } - if (url != null) + if (url != null) { initialURL= url.toExternalForm(); + } } catch (Exception e) { Trace.trace(Trace.SEVERE, "Error getting URL to file"); //$NON-NLS-1$ } if (webBrowser != null) { - if (initialURL != null) + if (initialURL != null) { webBrowser.setURL(initialURL); + } site.getWorkbenchWindow().getActivePage().activate(this); } - if (url != null) + if (url != null) { setTitleToolTip(url.getFile()); + } imageDescriptor = ImageResourceManager.getImageDescriptor("$nl$/icons/obj16/" + "internal_browser.svg"); //$NON-NLS-1$ //$NON-NLS-2$ //addResourceListener(file); - } else if (input instanceof WebBrowserEditorInput) { - WebBrowserEditorInput wbei = (WebBrowserEditorInput) input; + } else if (input instanceof WebBrowserEditorInput wbei) { initialURL = null; - if (wbei.getURL() != null) + if (wbei.getURL() != null) { initialURL = wbei.getURL().toExternalForm(); + } if (webBrowser != null) { webBrowser.setURL(initialURL); site.getWorkbenchWindow().getActivePage().activate(this); @@ -239,8 +242,7 @@ public static void open(WebBrowserEditorInput input) { for (int i = 0; i < size; i++) { if (WEB_BROWSER_EDITOR_ID.equals(editors[i].getId())) { IEditorPart editor = editors[i].getEditor(true); - if (editor != null && editor instanceof WebBrowserEditor) { - WebBrowserEditor webEditor = (WebBrowserEditor) editor; + if (editor != null && editor instanceof WebBrowserEditor webEditor) { WebBrowserEditorInput input2 = webEditor.getWebBrowserEditorInput(); if (input2 == null || input.canReplaceInput(input2)) { editor.init(editor.getEditorSite(), input); @@ -261,8 +263,9 @@ public static void open(WebBrowserEditorInput input) { */ @Override public void setFocus() { - if (webBrowser != null) + if (webBrowser != null) { webBrowser.setFocus(); + } } /** @@ -299,8 +302,9 @@ protected void doOpenExternalEditor(String id, IEditorInput input) { String editorId = null; for (IEditorDescriptor editor : editors) { - if (editor.getId().equals(id)) + if (editor.getId().equals(id)) { continue; + } editorId = editor.getId(); break; } @@ -309,16 +313,18 @@ protected void doOpenExternalEditor(String id, IEditorInput input) { if (ddesc!=null && ddesc.getId().equals(id)) { int dot = name.lastIndexOf('.'); String ext = name; - if (dot!= -1) + if (dot!= -1) { ext = "*."+name.substring(dot+1); //$NON-NLS-1$ + } registry.setDefaultEditor(ext, null); } if (editorId==null) { // no editor // next check with the OS for an external editor - if (registry.isSystemExternalEditorAvailable(name)) + if (registry.isSystemExternalEditorAvailable(name)) { editorId = IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID; + } } if (editorId!=null) { diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserEditorActionBarContributor.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserEditorActionBarContributor.java index 94a590be5cb..b92502ff129 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserEditorActionBarContributor.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserEditorActionBarContributor.java @@ -29,8 +29,9 @@ public class WebBrowserEditorActionBarContributor extends EditorActionBarContrib class Updater implements BrowserViewer.IBackNextListener { @Override public void updateBackNextBusy() { - if (back == null) + if (back == null) { return; + } back.setEnabled(getWebBrowser().isBackEnabled()); forward.setEnabled(getWebBrowser().isForwardEnabled()); // busy.setBusy(getWebBrowser().loading); @@ -48,13 +49,15 @@ public WebBrowserEditorActionBarContributor() { public void setActiveEditor(IEditorPart targetEditor) { if (targetEditor instanceof WebBrowserEditor) { editor = (WebBrowserEditor) targetEditor; - } else + } else { editor = null; + } } protected BrowserViewer getWebBrowser() { - if (editor == null) + if (editor == null) { return null; + } return editor.webBrowser; } diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserEditorInput.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserEditorInput.java index 5401bcd325c..b75e7307912 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserEditorInput.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserEditorInput.java @@ -62,9 +62,9 @@ public class WebBrowserEditorInput implements IEditorInput, private static final String MEMENTO_TOOLTIP = "tooltip"; //$NON-NLS-1$ - private URL url; + private final URL url; - private int style; + private final int style; private String id = null; @@ -135,13 +135,14 @@ public boolean canReplaceInput(WebBrowserEditorInput input) { // if (input.isToolbarVisible() != isToolbarVisible()) // return false; // else - if (input.isStatusbarVisible() != isStatusbarVisible()) + if (input.isStatusbarVisible() != isStatusbarVisible()) { return false; - else if (id != null) { + } else if (id != null) { String bid = input.getBrowserId(); return id.equals(bid); - } else + } else { return false; + } } /** @@ -190,12 +191,12 @@ public IAdaptable createElement(IMemento memento) { */ @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (!(obj instanceof WebBrowserEditorInput)) + } + if (!(obj instanceof WebBrowserEditorInput other)) { return false; - WebBrowserEditorInput other = (WebBrowserEditorInput) obj; - + } if (url != null) { if (other.url == null || !url.toExternalForm().equals(other.url.toExternalForm())) { return false; @@ -211,8 +212,9 @@ public boolean equals(Object obj) { */ @Override public boolean exists() { - if ((style & IWorkbenchBrowserSupport.PERSISTENT) != 0) + if ((style & IWorkbenchBrowserSupport.PERSISTENT) != 0) { return false; + } return true; } @@ -250,27 +252,31 @@ protected boolean isNameLocked() { @Override public String getName() { - if (name != null) + if (name != null) { return name; + } return Messages.viewWebBrowserTitle; } @Override public IPersistableElement getPersistable() { - if ((style & IWorkbenchBrowserSupport.PERSISTENT) == 0) + if ((style & IWorkbenchBrowserSupport.PERSISTENT) == 0) { return null; + } return this; } @Override public String getToolTipText() { - if (tooltip != null) + if (tooltip != null) { return tooltip; + } - if (url != null) + if (url != null) { return url.toExternalForm(); + } return Messages.viewWebBrowserTitle; } diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserPreferencePage.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserPreferencePage.java index 300eca2661b..ee96e301d53 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserPreferencePage.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserPreferencePage.java @@ -115,8 +115,9 @@ public String getColumnText(Object element, int columnIndex) { } protected String notNull(String s) { - if (s == null) + if (s == null) { return ""; //$NON-NLS-1$ + } return s; } @@ -185,8 +186,9 @@ protected Control createContents(Composite parent) { data.horizontalSpan = 2; internal.setLayoutData(data); - if (!WebBrowserUtil.canUseInternalWebBrowser()) + if (!WebBrowserUtil.canUseInternalWebBrowser()) { internal.setEnabled(false); + } external = new Button(composite, SWT.RADIO); external.setText(Messages.prefExternalBrowser); @@ -229,8 +231,9 @@ protected Control createContents(Composite parent) { // browser. That is, don't permit unchecking if no other item // is checked which is supposed to be the case. Object[] obj = tableViewer.getCheckedElements(); - if (obj.length == 0) + if (obj.length == 0) { tableViewer.setChecked(e.getElement(), true); + } }); // set a default, checked browser based on the current browser. If there @@ -238,12 +241,13 @@ protected Control createContents(Composite parent) { // This will work currently until workbench shutdown, because current // browser is not yet persisted. checkedBrowser = BrowserManager.getInstance().getCurrentWebBrowser(); - if (checkedBrowser != null) + if (checkedBrowser != null) { tableViewer.setChecked(checkedBrowser, true); - else { + } else { Object obj = tableViewer.getElementAt(0); - if (obj != null) + if (obj != null) { tableViewer.setChecked(obj, true); + } } tableViewer @@ -321,11 +325,13 @@ public void keyPressed(KeyEvent e) { final Button add = SWTUtil.createButton(buttonComp, Messages.add); add.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { BrowserDescriptorDialog dialog = new BrowserDescriptorDialog(getShell()); - if (dialog.open() == Window.CANCEL) + if (dialog.open() == Window.CANCEL) { return; + } tableViewer.refresh(); - if (checkedBrowser != null) + if (checkedBrowser != null) { tableViewer.setChecked(checkedBrowser, true); + } })); edit = SWTUtil.createButton(buttonComp, Messages.edit); @@ -382,8 +388,9 @@ public void keyPressed(KeyEvent e) { dialog.setText(Messages.directoryDialogTitle); String path = dialog.open(); - if (path == null) + if (path == null) { return; + } final File rootDir = new File(path); ProgressMonitorDialog pm = new ProgressMonitorDialog(getShell()); @@ -405,8 +412,9 @@ public void keyPressed(KeyEvent e) { return; } - if (pm.getProgressMonitor().isCanceled()) + if (pm.getProgressMonitor().isCanceled()) { return; + } List browsersToCreate = foundBrowsers; @@ -422,8 +430,9 @@ public void keyPressed(KeyEvent e) { } tableViewer.refresh(); - if (checkedBrowser != null) + if (checkedBrowser != null) { tableViewer.setChecked(checkedBrowser, true); + } })); restore = SWTUtil.createButton(buttonComp, Messages.restore); @@ -465,8 +474,9 @@ public void init(IWorkbench workbench) { @Override public void setVisible(boolean visible) { super.setVisible(visible); - if (visible) + if (visible) { setTitle(Messages.preferenceWebBrowserTitle); + } } protected Object getSelection(ISelection sel2) { @@ -477,15 +487,17 @@ protected Object getSelection(ISelection sel2) { // Uncheck all the items except the current one that was just checked protected void checkNewDefaultBrowser(Object browser) { for (TableItem item : tableViewer.getTable().getItems()) { - if (!(item.getData().equals(browser))) + if (!(item.getData().equals(browser))) { item.setChecked(false); + } } } protected static void search(File directory, List existingPaths, List foundBrowsers, Set directoriesVisited, IProgressMonitor monitor) { - if (monitor.isCanceled()) + if (monitor.isCanceled()) { return; + } try { //bug 293159: protect against recursion due to cyclic symbolic link String canonicalPath = directory.getCanonicalPath(); @@ -506,21 +518,25 @@ protected static void search(File directory, List existingPaths, names = new String[0]; } for (String name : names) { - if (monitor.isCanceled()) + if (monitor.isCanceled()) { return; + } File file = new File(directory, name); - if (existingPaths.contains(file.getAbsolutePath().toLowerCase())) + if (existingPaths.contains(file.getAbsolutePath().toLowerCase())) { continue; + } IBrowserDescriptorWorkingCopy wc = WebBrowserUtil.createExternalBrowser(file); - if (wc != null) + if (wc != null) { foundBrowsers.add(wc); + } if (file.isDirectory()) { - if (monitor.isCanceled()) + if (monitor.isCanceled()) { return; + } subDirs.add(file); } } @@ -546,8 +562,9 @@ protected void performDefaults() { tableViewer.refresh(); checkedBrowser = BrowserManager.getInstance().getCurrentWebBrowser(); - if (checkedBrowser != null) + if (checkedBrowser != null) { tableViewer.setChecked(checkedBrowser, true); + } super.performDefaults(); } @@ -565,8 +582,9 @@ protected void addDefaults() { tableViewer.refresh(); checkedBrowser = BrowserManager.getInstance().getCurrentWebBrowser(); - if (checkedBrowser != null) + if (checkedBrowser != null) { tableViewer.setChecked(checkedBrowser, true); + } super.updateApplyButton(); } @@ -577,10 +595,11 @@ protected void addDefaults() { @Override public boolean performOk() { int choice; - if (internal.getSelection()) + if (internal.getSelection()) { choice = WebBrowserPreference.INTERNAL; - else + } else { choice = WebBrowserPreference.EXTERNAL; + } WebBrowserPreference.setBrowserChoice(choice); if (checkedBrowser != null) { BrowserManager.getInstance().setCurrentWebBrowser(checkedBrowser); diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserUIPlugin.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserUIPlugin.java index 557455bb9cb..5dc9f67ae15 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserUIPlugin.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserUIPlugin.java @@ -73,8 +73,9 @@ public void stop(BundleContext context) throws Exception { * @return a possibly-empty array of browser instances */ public static IBrowserExt[] getBrowsers() { - if (browsers == null) + if (browsers == null) { loadBrowsers(); + } IBrowserExt[] c = new IBrowserExt[browsers.size()]; browsers.toArray(c); return c; @@ -82,13 +83,15 @@ public static IBrowserExt[] getBrowsers() { public static IBrowserExt findBrowsers(String executable) { IBrowserExt[] browsers2 = getBrowsers(); - if (browsers2 == null || executable == null) + if (browsers2 == null || executable == null) { return null; + } int ind1 = executable.lastIndexOf('/'); int ind2 = executable.lastIndexOf('\\'); - if (ind2 > ind1) + if (ind2 > ind1) { ind1 = ind2; + } executable = executable.substring(ind1 + 1); String os = Platform.getOS(); @@ -97,8 +100,9 @@ public static IBrowserExt findBrowsers(String executable) { if (browsers2[i].getOS().toLowerCase().contains(os)) { if (browsers2[i].isAvailable()) { String executable2 = browsers2[i].getExecutable(); - if (executable.startsWith(executable2)) + if (executable.startsWith(executable2)) { return browsers2[i]; + } } } } @@ -109,8 +113,9 @@ public static IBrowserExt findBrowsers(String executable) { * Load the browsers extension point. */ private static synchronized void loadBrowsers() { - if (browsers != null) + if (browsers != null) { return; + } Trace.trace(Trace.CONFIG, "->- Loading .browsers extension point ->-"); //$NON-NLS-1$ IExtensionRegistry registry = Platform.getExtensionRegistry(); IConfigurationElement[] cf = registry.getConfigurationElementsFor(PLUGIN_ID, "browsers"); //$NON-NLS-1$ @@ -134,8 +139,9 @@ private static synchronized void loadBrowsers() { * already have been called */ public static synchronized void logError(String message, Throwable ex) { - if (message == null) + if (message == null) { message = ""; //$NON-NLS-1$ + } WebBrowserUIPlugin.getInstance().getLog().error(message, ex); } diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserUtil.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserUtil.java index 86d260f8df4..74062cfe4ec 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserUtil.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserUtil.java @@ -58,8 +58,9 @@ public WebBrowserUtil() { */ public static boolean isWindows() { String os = System.getProperty("os.name"); //$NON-NLS-1$ - if (os != null && os.toLowerCase().contains("win")) //$NON-NLS-1$ + if (os != null && os.toLowerCase().contains("win")) { //$NON-NLS-1$ return true; + } return false; } @@ -70,8 +71,9 @@ public static boolean isWindows() { */ public static boolean isLinux() { String os = System.getProperty("os.name"); //$NON-NLS-1$ - if (os != null && os.toLowerCase().contains("lin")) //$NON-NLS-1$ + if (os != null && os.toLowerCase().contains("lin")) { //$NON-NLS-1$ return true; + } return false; } @@ -83,8 +85,9 @@ public static boolean isLinux() { */ public static void openError(final String message) { Display d = Display.getCurrent(); - if (d == null) + if (d == null) { d = Display.getDefault(); + } d.asyncExec(() -> MessageDialog.openError(null, Messages.errorDialogTitle, message)); } @@ -96,8 +99,9 @@ public static void openError(final String message) { */ public static void openMessage(final String message) { Display d = Display.getCurrent(); - if (d == null) + if (d == null) { d = Display.getDefault(); + } d.asyncExec(() -> MessageDialog.openInformation(null, Messages.searchingTaskName, message)); } @@ -120,8 +124,9 @@ public static void openMessage(final String message) { */ public static boolean canUseInternalWebBrowser() { // if we have already figured this out, don't do it again. - if (isInternalBrowserOperational != null) + if (isInternalBrowserOperational != null) { return isInternalBrowserOperational.booleanValue(); + } // check for the class try { @@ -145,8 +150,9 @@ public static boolean canUseInternalWebBrowser() { isInternalBrowserOperational = Boolean.FALSE; return false; } finally { - if (shell != null) + if (shell != null) { shell.dispose(); + } } } @@ -160,8 +166,9 @@ public static List getExternalBrowserPaths() { .getWebBrowsers().iterator(); while (iterator.hasNext()) { IBrowserDescriptor wb = iterator.next(); - if (wb != null && wb.getLocation() != null) + if (wb != null && wb.getLocation() != null) { paths.add(wb.getLocation().toLowerCase()); + } } return paths; } @@ -251,14 +258,16 @@ private static String locateBrowser(List alreadyFoundPaths, } private static File[] getUsableDrives(File[] roots) { - if (!Platform.getOS().equals(Platform.OS_WIN32)) + if (!Platform.getOS().equals(Platform.OS_WIN32)) { return roots; + } ArrayList list = new ArrayList<>(); for (File root : roots) { String path = root.getAbsolutePath(); if (path != null - && (path.toLowerCase().startsWith("a:") || path.toLowerCase().startsWith("b:"))) //$NON-NLS-1$ //$NON-NLS-2$ + && (path.toLowerCase().startsWith("a:") || path.toLowerCase().startsWith("b:"))) { //$NON-NLS-1$ //$NON-NLS-2$ continue; + } list.add(root); } return list.toArray(new File[list.size()]); @@ -271,8 +280,9 @@ private static File[] getUsableDrives(File[] roots) { * @return an external browser working copy */ public static IBrowserDescriptorWorkingCopy createExternalBrowser(File file) { - if (file == null || !file.isFile()) + if (file == null || !file.isFile()) { return null; + } String executable = file.getName(); IBrowserExt[] browsers = WebBrowserUIPlugin.getBrowsers(); @@ -339,16 +349,18 @@ public static String createParameterString(String parameters, String urlText) { if (url == null) { url = ""; //$NON-NLS-1$ } - if (params == null) + if (params == null) { params = ""; //$NON-NLS-1$ + } int urlIndex = params.indexOf(IBrowserDescriptor.URL_PARAMETER); if (urlIndex >= 0) { params = params.substring(0, urlIndex) + url + params.substring(urlIndex + IBrowserDescriptor.URL_PARAMETER.length()); } else { - if (params.length() != 0 && !params.endsWith(" ")) //$NON-NLS-1$ + if (params.length() != 0 && !params.endsWith(" ")) { //$NON-NLS-1$ params += " "; //$NON-NLS-1$ + } params += url; } return params; @@ -361,8 +373,9 @@ public static String[] createParameterArray(String parameters, String urlText) { private static String[] tokenize(String string) { StringTokenizer tokenizer = new StringTokenizer(string); String[] tokens = new String[tokenizer.countTokens()]; - for (int i = 0; tokenizer.hasMoreTokens(); i++) + for (int i = 0; tokenizer.hasMoreTokens(); i++) { tokens[i] = tokenizer.nextToken(); + } return tokens; } } diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserView.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserView.java index d5655aba8d8..e935aaf3549 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserView.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserView.java @@ -56,15 +56,18 @@ public void createPartControl(Composite parent) { @Override public void dispose() { - if (viewer!=null) + if (viewer!=null) { viewer.setContainer(null); - if (listener != null) + } + if (listener != null) { removeSelectionListener(); + } } public void setURL(String url) { - if (viewer != null) + if (viewer != null) { viewer.setURL(url); + } } @Override @@ -100,8 +103,9 @@ public void openInExternalBrowser(String url) { } public void addSelectionListener() { - if (listener != null) + if (listener != null) { return; + } listener = (part, selection) -> onSelectionChange(selection); getSite().getWorkbenchWindow().getSelectionService() @@ -109,13 +113,14 @@ public void addSelectionListener() { } private void onSelectionChange(ISelection selection) { - if (!(selection instanceof IStructuredSelection)) + if (!(selection instanceof IStructuredSelection sel)) { return; - IStructuredSelection sel = (IStructuredSelection) selection; + } Object obj = sel.getFirstElement(); URL url = getURLFrom(obj); - if (url != null) + if (url != null) { setURL(url.toExternalForm()); + } } private URL getURLFrom(Object adapt) { @@ -123,19 +128,21 @@ private URL getURLFrom(Object adapt) { IPath path = Adapters.adapt(adapt, IPath.class); if (path != null) { File file = path.toFile(); - if (file.exists() && isWebFile(file.getName())) + if (file.exists() && isWebFile(file.getName())) { try { return file.toURI().toURL(); } catch (MalformedURLException e) { return null; } + } } return Adapters.adapt(adapt, URL.class); } public void removeSelectionListener() { - if (listener == null) + if (listener == null) { return; + } getSite().getWorkbenchWindow().getSelectionService() .removePostSelectionListener(listener); listener = null; diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserViewDropAdapter.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserViewDropAdapter.java index 253751399b6..a02b6f123fd 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserViewDropAdapter.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/WebBrowserViewDropAdapter.java @@ -24,7 +24,7 @@ public class WebBrowserViewDropAdapter extends DropTargetAdapter { /** * The view to which this drop support has been added. */ - private BrowserViewer view; + private final BrowserViewer view; /** * The current operation. @@ -48,14 +48,16 @@ protected WebBrowserViewDropAdapter(BrowserViewer view) { */ private void doDropValidation(DropTargetEvent event) { //update last valid operation - if (event.detail != DND.DROP_NONE) + if (event.detail != DND.DROP_NONE) { lastValidOperation = event.detail; + } //valid drop and set event detail accordingly - if (validateDrop(event.detail, event.currentDataType)) + if (validateDrop(event.detail, event.currentDataType)) { currentOperation = lastValidOperation; - else + } else { currentOperation = DND.DROP_NONE; + } event.detail = currentOperation; } @@ -92,8 +94,9 @@ public void dragOver(DropTargetEvent event) { @Override public void drop(DropTargetEvent event) { //perform the drop behaviour - if (!performDrop(event.data)) + if (!performDrop(event.data)) { event.detail = DND.DROP_NONE; + } currentOperation = event.detail; } @@ -104,14 +107,16 @@ public void drop(DropTargetEvent event) { */ @Override public void dropAccept(DropTargetEvent event) { - if (!validateDrop(event.detail, event.currentDataType)) + if (!validateDrop(event.detail, event.currentDataType)) { event.detail = DND.DROP_NONE; + } } @Override public void dragEnter(DropTargetEvent event) { - if (event.detail == DND.DROP_DEFAULT) + if (event.detail == DND.DROP_DEFAULT) { event.detail = DND.DROP_COPY; + } doDropValidation(event); } @@ -127,10 +132,10 @@ public void dragEnter(DropTargetEvent event) { * false otherwise */ protected boolean performDrop(Object data) { - if (data instanceof String[]) { - String[] s = (String[]) data; - if (s.length == 0) + if (data instanceof String[] s) { + if (s.length == 0) { return true; + } File f = new File(s[0]); try { view.setURL(f.toURI().toURL().toExternalForm()); @@ -155,12 +160,13 @@ protected boolean performDrop(Object data) { * otherwise */ protected boolean validateDrop(int operation, TransferData transferType) { - if (FileTransfer.getInstance().isSupportedType(transferType)) + if (FileTransfer.getInstance().isSupportedType(transferType)) { return true; /*if (ResourceTransfer.getInstance().isSupportedType(transferType)) return true; if (LocalSelectionTransfer.getInstance().isSupportedType(transferType)) return true;*/ + } return false; } diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/browsers/DefaultBrowser.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/browsers/DefaultBrowser.java index 656db6be136..1c57080075d 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/browsers/DefaultBrowser.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/browsers/DefaultBrowser.java @@ -113,8 +113,9 @@ protected String[] prepareCommand(String path, String url) { } } // add the url if not substituted already - if (!substituted) + if (!substituted) { tokenList.add(url); + } String[] command = new String[tokenList.size()]; tokenList.toArray(command); diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/browsers/MozillaBrowser.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/browsers/MozillaBrowser.java index ee8209f92e3..f94ec95793a 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/browsers/MozillaBrowser.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/browsers/MozillaBrowser.java @@ -74,8 +74,9 @@ public void openURL(URL url2) { else { url = ""; //$NON-NLS-1$ } - if (lastBrowserThread != null) + if (lastBrowserThread != null) { lastBrowserThread.exitRequested = true; + } lastBrowserThread = new BrowserThread(url); lastBrowserThread.setDaemon(true); @@ -85,7 +86,7 @@ public void openURL(URL url2) { private class BrowserThread extends Thread { public boolean exitRequested = false; - private String url; + private final String url; public BrowserThread(String urlName) { this.url = urlName; @@ -162,11 +163,13 @@ private boolean errorsInOutput(StreamConsumer outputs, public void run() { // if browser is opening, wait until it fully opens waitForBrowser(); - if (exitRequested) + if (exitRequested) { return; + } if (firstLaunch && Platform.OS_WIN32.equals(Platform.getOS())) { - if (openBrowser(executable, WebBrowserUtil.createParameterArray(parameters, url)) == 0) + if (openBrowser(executable, WebBrowserUtil.createParameterArray(parameters, url)) == 0) { return; + } browserFullyOpenedAt = System.currentTimeMillis() + DELAY; return; } @@ -174,24 +177,28 @@ public void run() { executable, WebBrowserUtil.createParameterArray(parameters + " -remote openURL(" + IBrowserDescriptor.URL_PARAMETER + ")", url)) //$NON-NLS-1$ //$NON-NLS-2$ - == 0) + == 0) { return; + } - if (exitRequested) + if (exitRequested) { return; + } browserFullyOpenedAt = System.currentTimeMillis() + DELAY; openBrowser(executable, WebBrowserUtil.createParameterArray(parameters, url)); } private void waitForBrowser() { - while (System.currentTimeMillis() < browserFullyOpenedAt) + while (System.currentTimeMillis() < browserFullyOpenedAt) { try { - if (exitRequested) + if (exitRequested) { return; + } Thread.sleep(100); } catch (InterruptedException ie) { // ignore } + } } } } \ No newline at end of file diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/macosx/SafariBrowser.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/macosx/SafariBrowser.java index 8b3bf95d312..657762644cd 100644 --- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/macosx/SafariBrowser.java +++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/macosx/SafariBrowser.java @@ -76,8 +76,9 @@ protected String[] prepareCommand(String path, String url) { } } // add the url if not substituted already - if (!substituted) + if (!substituted) { tokenList.add(url); + } String[] command = new String[tokenList.size()]; tokenList.toArray(command);