diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.ui.workbench.swt/META-INF/MANIFEST.MF index 5c551242e6d..8ecfefafc54 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.e4.ui.workbench.swt/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.e4.ui.workbench.swt;singleton:=true -Bundle-Version: 0.17.900.qualifier +Bundle-Version: 0.17.1000.qualifier Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/AbstractPartRenderer.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/AbstractPartRenderer.java index 80c77b92456..1751cfcdefc 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/AbstractPartRenderer.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/AbstractPartRenderer.java @@ -91,8 +91,9 @@ public void activate(MPart element) { IEclipseContext curContext = getContext(element); if (curContext != null) { EPartService ps = curContext.get(EPartService.class); - if (ps != null) + if (ps != null) { ps.activate(element, requiresFocus(element)); + } } } @@ -107,9 +108,9 @@ public void removeGui(MUIElement element, Object widget) { } public Object getUIContainer(MUIElement element) { - if (element.getParent() != null) + if (element.getParent() != null) { return element.getParent().getWidget(); - else { + } else { Object value = element.getTransientData().get(IPresentationEngine.RENDERING_PARENT_KEY); if (value != null) { return value; diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/CSSRenderingUtils.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/CSSRenderingUtils.java index 417dae9d3e2..e0e73d027b6 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/CSSRenderingUtils.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/CSSRenderingUtils.java @@ -132,13 +132,15 @@ private void initDragHandleResource() { IPath path = IPath.fromOSString("$ws$/images/dragHandle.svg"); URL url = FileLocator.find(bundle, path, null); ImageDescriptor desc = ImageDescriptor.createFromURL(url); - if (desc != null) + if (desc != null) { JFaceResources.getImageRegistry().put(DRAG_HANDLE, desc); + } path = IPath.fromOSString("$ws$/images/dragHandle-rotated.svg"); url = FileLocator.find(bundle, path, null); ImageDescriptor desc_rotated = ImageDescriptor.createFromURL(url); - if (desc_rotated != null) + if (desc_rotated != null) { JFaceResources.getImageRegistry().put(DRAG_HANDLE_ROTATED, desc_rotated); + } } private Image rotateImage(Display display, Image image, Integer[] frameInts) { @@ -153,8 +155,9 @@ private Image rotateImage(Display display, Image image, Integer[] frameInts) { frameInts[3] = tmp; } - if (rotatedImageMap.get(image) != null) + if (rotatedImageMap.get(image) != null) { return rotatedImageMap.get(image); + } // rotate 90 degrees,,, Rectangle bounds = image.getBounds(); @@ -206,14 +209,16 @@ public CSSValue getCSSValue(Control styleControl, String className, } // super hack - if (className != null) + if (className != null) { WidgetElement.setCSSClass(styleControl, className); + } CSSStyleDeclaration styleDeclarations = csseng.getViewCSS() .getComputedStyle(tempEment, ""); //$NON-NLS-1$ - if (styleDeclarations == null) + if (styleDeclarations == null) { return null; + } return styleDeclarations.getPropertyCSSValue(attributeName); } @@ -231,17 +236,20 @@ public Image createImage(Control styleControl, String classId, if (tempEment == null) { return null; } - if (classId != null) + if (classId != null) { WidgetElement.setCSSClass(styleControl, classId); + } CSSStyleDeclaration styleDeclarations = csseng.getViewCSS() .getComputedStyle(tempEment, ""); - if (styleDeclarations == null) + if (styleDeclarations == null) { return null; + } CSSValue imagePath = styleDeclarations.getPropertyCSSValue(attName); - if (imagePath == null) + if (imagePath == null) { return null; + } if (imagePath.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { // String imageString = ((CSSPrimitiveValue) imagePath) @@ -255,8 +263,9 @@ public Image createImage(Control styleControl, String classId, .getPropertyCSSValue("frame-cuts"); //$NON-NLS-1$ if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { CSSValueList valueList = (CSSValueList) value; - if (valueList.getLength() != 4) + if (valueList.getLength() != 4) { return null; + } for (int i = 0; i < valueList.getLength(); i++) { CSSValue val = valueList.item(i); @@ -283,11 +292,10 @@ private void addHandleImageDisposedListener( ImageBasedFrame imageBasedFrame, final Control toFrame, final String classId, final boolean vertical) { final Listener listener = event -> { - if (!(event.widget instanceof ImageBasedFrame)) { + if (!(event.widget instanceof ImageBasedFrame frame)) { return; } - ImageBasedFrame frame = (ImageBasedFrame) event.widget; if (!isImagesRefreshRequired(frame)) { return; } @@ -315,11 +323,10 @@ private void addHandleImageDisposedListener( private void addFrameImageDisposedListener(ImageBasedFrame imageBasedFrame, final Control toFrame, final String classId, final boolean vertical) { final Listener listener = event -> { - if (!(event.widget instanceof ImageBasedFrame)) { + if (!(event.widget instanceof ImageBasedFrame frame)) { return; } - ImageBasedFrame frame = (ImageBasedFrame) event.widget; if (!isImagesRefreshRequired(frame)) { return; } diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/DialogSettingsProvider.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/DialogSettingsProvider.java index 45a068d33b6..fda4276ca23 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/DialogSettingsProvider.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/DialogSettingsProvider.java @@ -71,7 +71,7 @@ public final class DialogSettingsProvider implements IDialogSettingsProvider { */ private static final String KEY_DEFAULT_DIALOG_SETTINGS_ROOTURL = "default_dialog_settings_rootUrl"; //$NON-NLS-1$ - private Bundle fBundle; + private final Bundle fBundle; private IDialogSettings fDialogSettings; diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java index a5a36716a6f..06f4205c810 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java @@ -17,7 +17,7 @@ * Terry Parker - Bug 416673 * Christian Georgi (SAP) - Bug 432480 * Simon Scholz - Bug 478896 - * Christoph Läubrich - Bug 563459 + * Christoph Läubrich - Bug 563459 ******************************************************************************/ package org.eclipse.e4.ui.internal.workbench.swt; @@ -158,8 +158,9 @@ public Object start(IApplicationContext applicationContext) throws Exception { // place it off so it's not visible shell.setLocation(0, 10000); } - if (!checkInstanceLocation(instanceLocation, shell, workbench.getContext())) + if (!checkInstanceLocation(instanceLocation, shell, workbench.getContext())) { return EXIT_OK; + } // Create and run the UI (if any) workbench.createAndRunUI(workbench.getApplication()); @@ -176,10 +177,12 @@ public Object start(IApplicationContext applicationContext) throws Exception { return EXIT_OK; } finally { - if (display != null) + if (display != null) { display.dispose(); - if (instanceLocation != null) + } + if (instanceLocation != null) { instanceLocation.release(); + } } } @@ -410,18 +413,21 @@ private URI determineApplicationModelURI(IApplicationContext appContext) { */ private Optional getArgValue(String argName, IApplicationContext appContext, boolean singledCmdArgValue) { // Is it in the arg list ? - if (argName == null || argName.length() == 0) + if (argName == null || argName.length() == 0) { return Optional.empty(); + } if (singledCmdArgValue) { for (String arg : args) { - if (("-" + argName).equals(arg)) + if (("-" + argName).equals(arg)) { return Optional.of("true"); + } } } else { for (int i = 0; i < args.length; i++) { - if (("-" + argName).equals(args[i]) && i + 1 < args.length) + if (("-" + argName).equals(args[i]) && i + 1 < args.length) { return Optional.of(args[i + 1]); + } } } @@ -737,8 +743,9 @@ private static File getVersionFile(URL workspaceUrl, boolean create) { static public void initializeServices(MApplication appModel) { IEclipseContext appContext = appModel.getContext(); // make sure we only add trackers once - if (appContext.containsKey(CONTEXT_INITIALIZED)) + if (appContext.containsKey(CONTEXT_INITIALIZED)) { return; + } appContext.set(CONTEXT_INITIALIZED, "true"); initializeApplicationServices(appContext); List windows = appModel.getChildren(); @@ -748,10 +755,12 @@ static public void initializeServices(MApplication appModel) { ((EObject) appModel).eAdapters().add(new AdapterImpl() { @Override public void notifyChanged(Notification notification) { - if (notification.getFeatureID(MApplication.class) != UiPackageImpl.ELEMENT_CONTAINER__CHILDREN) + if (notification.getFeatureID(MApplication.class) != UiPackageImpl.ELEMENT_CONTAINER__CHILDREN) { return; - if (notification.getEventType() != Notification.ADD) + } + if (notification.getEventType() != Notification.ADD) { return; + } MWindow childWindow = (MWindow) notification.getNewValue(); initializeWindowServices(childWindow); } @@ -792,8 +801,9 @@ static public void initializeWindowServices(MWindow childWindow) { ((EObject) childWindow).eAdapters().add(new AdapterImpl() { @Override public void notifyChanged(Notification notification) { - if (notification.getFeatureID(MWindow.class) != BasicPackageImpl.WINDOW__CONTEXT) + if (notification.getFeatureID(MWindow.class) != BasicPackageImpl.WINDOW__CONTEXT) { return; + } IEclipseContext windowContext = (IEclipseContext) notification.getNewValue(); initWindowContext(windowContext); } @@ -801,8 +811,9 @@ public void notifyChanged(Notification notification) { } static private void initWindowContext(IEclipseContext windowContext) { - if (windowContext == null) + if (windowContext == null) { return; + } SelectionAggregator selectionAggregator = ContextInjectionFactory.make(SelectionAggregator.class, windowContext); windowContext.set(SelectionAggregator.class, selectionAggregator); diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/MenuService.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/MenuService.java index 85da4fcc5ed..5413b2aa902 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/MenuService.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/MenuService.java @@ -32,10 +32,9 @@ public class MenuService implements EMenuService { @Override public boolean registerContextMenu(Object parent, String menuId) { - if (!(parent instanceof Control)) { + if (!(parent instanceof Control parentControl)) { return false; } - Control parentControl = (Control) parent; for (MMenu mmenu : myPart.getMenus()) { if (menuId.equals(mmenu.getElementId()) && mmenu instanceof MPopupMenu) { diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java index 2ed9cce1a36..be6ec14fc17 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java @@ -245,11 +245,10 @@ private void subscribeVisibilityHandler(@EventTopic(UIEvents.UIElement.TOPIC_VIS private void subscribeTrimHandler(@EventTopic(UIEvents.TrimmedWindow.TOPIC_TRIMBARS) Event event) { Object changedObj = event.getProperty(UIEvents.EventTags.ELEMENT); - if (!(changedObj instanceof MTrimmedWindow)) { + if (!(changedObj instanceof MTrimmedWindow window)) { return; } - MTrimmedWindow window = (MTrimmedWindow) changedObj; if (window.getWidget() == null) { return; } @@ -309,8 +308,7 @@ private void subscribeChildrenHandler(@EventTopic(UIEvents.ElementContainer.TOPI if (renderIt) { // NOTE: createGui will call 'childAdded' if successful Object w = createGui(added); - if (w instanceof Control && !(w instanceof Shell)) { - final Control ctrl = (Control) w; + if (w instanceof final Control ctrl && !(w instanceof Shell)) { fixZOrder(added); if (!ctrl.isDisposed()) { ctrl.requestLayout(); @@ -548,8 +546,9 @@ public void run() throws Exception { public Object safeCreateGui(MUIElement element, Object parentWidget, IEclipseContext parentContext) { - if (!element.isToBeRendered()) + if (!element.isToBeRendered()) { return null; + } // no creates while processing a remove if (removeRoot != null) { @@ -558,20 +557,19 @@ public Object safeCreateGui(MUIElement element, Object parentWidget, Object currentWidget = element.getWidget(); if (currentWidget != null) { - if (currentWidget instanceof Control) { - Control control = (Control) currentWidget; + if (currentWidget instanceof Control control) { // make sure the control is visible MUIElement elementParent = element.getParent(); if (!(element instanceof MPlaceholder) - || !(elementParent instanceof MPartStack)) + || !(elementParent instanceof MPartStack)) { control.setVisible(true); + } if (parentWidget instanceof Composite) { Composite currentParent = control.getParent(); if (currentParent != parentWidget) { // check if the original parent was a tab folder - if (currentParent instanceof CTabFolder) { - CTabFolder folder = (CTabFolder) currentParent; + if (currentParent instanceof CTabFolder folder) { // if we used to be the tab folder's top right // control, unset it if (folder.getTopRight() == control) { @@ -588,8 +586,9 @@ public Object safeCreateGui(MUIElement element, Object parentWidget, // Reparent the context (or the kid's context) if (element instanceof MContext) { IEclipseContext ctxt = ((MContext) element).getContext(); - if (ctxt != null) + if (ctxt != null) { ctxt.setParent(parentContext); + } } else { List childContexts = modelService.findElements( element, null, MContext.class, null); @@ -598,10 +597,12 @@ public Object safeCreateGui(MUIElement element, Object parentWidget, // children MUIElement kid = (MUIElement) c; MUIElement parent = kid.getParent(); - if (parent == null && kid.getCurSharedRef() != null) + if (parent == null && kid.getCurSharedRef() != null) { parent = kid.getCurSharedRef().getParent(); - if (!(element instanceof MPlaceholder) && parent != element) + } + if (!(element instanceof MPlaceholder) && parent != element) { continue; + } if (c.getContext() != null && c.getContext().getParent() != parentContext) { @@ -621,8 +622,7 @@ public Object safeCreateGui(MUIElement element, Object parentWidget, return element.getWidget(); } - if (element instanceof MContext) { - MContext ctxt = (MContext) element; + if (element instanceof MContext ctxt) { // Assert.isTrue(ctxt.getContext() == null, // "Before rendering Context should be null"); if (ctxt.getContext() == null) { @@ -684,8 +684,7 @@ public Object safeCreateGui(MUIElement element, Object parentWidget, } } } else // failed to create the widget, dispose its context if necessary - if (element instanceof MContext) { - MContext ctxt = (MContext) element; + if (element instanceof MContext ctxt) { IEclipseContext lclContext = ctxt.getContext(); if (lclContext != null) { lclContext.dispose(); @@ -734,8 +733,9 @@ private Object safeCreateGui(MUIElement element) { // Obtain the necessary parent widget Object parent = null; MUIElement parentME = element.getParent(); - if (parentME == null) + if (parentME == null) { parentME = (MUIElement) ((EObject) element).eContainer(); + } if (parentME != null) { AbstractPartRenderer renderer = getRendererFor(parentME); if (renderer != null) { @@ -774,7 +774,7 @@ public void focusGui(MUIElement element) { return; } - Object implementation = element instanceof MContribution ? ((MContribution) element) + Object implementation = element instanceof MContribution m ? m .getObject() : null; // If there is no class to call @Focus on then revert to the default @@ -860,8 +860,9 @@ public void run() throws Exception { } private void safeRemoveGui(MUIElement element) { - if (removeRoot == null) + if (removeRoot == null) { removeRoot = element; + } // We call 'hideChild' *before* checking if the actual element // has been rendered in order to pick up cases of 'lazy loading' @@ -897,27 +898,23 @@ private void safeRemoveGui(MUIElement element) { } } - if (element instanceof MPerspective) { - MPerspective perspective = (MPerspective) element; + if (element instanceof MPerspective perspective) { for (MWindow subWindow : perspective.getWindows()) { removeGui(subWindow); } - } else if (element instanceof MWindow) { - MWindow window = (MWindow) element; + } else if (element instanceof MWindow window) { for (MWindow subWindow : window.getWindows()) { removeGui(subWindow); } - if (window instanceof MTrimmedWindow) { - MTrimmedWindow trimmedWindow = (MTrimmedWindow) window; + if (window instanceof MTrimmedWindow trimmedWindow) { for (MUIElement trimBar : trimmedWindow.getTrimBars()) { removeGui(trimBar); } } } - if (element instanceof MContribution) { - MContribution contribution = (MContribution) element; + if (element instanceof MContribution contribution) { Object client = contribution.getObject(); IEclipseContext parentContext = renderer.getContext(element); if (parentContext != null && client != null) { @@ -934,8 +931,7 @@ private void safeRemoveGui(MUIElement element) { renderer.disposeWidget(element); // unset the client object - if (element instanceof MContribution) { - MContribution contribution = (MContribution) element; + if (element instanceof MContribution contribution) { Object client = contribution.getObject(); IEclipseContext parentContext = renderer.getContext(element); if (parentContext != null && client != null) { @@ -956,15 +952,15 @@ private void safeRemoveGui(MUIElement element) { } } - if (element instanceof MPlaceholder) { - MPlaceholder ph = (MPlaceholder) element; + if (element instanceof MPlaceholder ph) { if (ph.getRef() != null && ph.getRef().getCurSharedRef() == ph) { ph.getRef().setCurSharedRef(null); } } - if (removeRoot == element) + if (removeRoot == element) { removeRoot = null; + } } private void clearContext(MContext contextME) { diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/ResourceUtility.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/ResourceUtility.java index c364ca9655d..87167b4addc 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/ResourceUtility.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/ResourceUtility.java @@ -42,10 +42,12 @@ public ImageDescriptor imageDescriptorFromURI(URI iconPath) { @Override public Image adornImage(Image toAdorn, Image adornment) { - if (toAdorn == null) + if (toAdorn == null) { return null; - if (adornment == null) + } + if (adornment == null) { return toAdorn; + } Rectangle adornmentSize = adornment.getBounds(); final ImageGcDrawer imageGcDrawer = (gc, width, height) -> { diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/SelectionAdapterFactory.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/SelectionAdapterFactory.java index be0e8685619..1c3a1de80dd 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/SelectionAdapterFactory.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/SelectionAdapterFactory.java @@ -61,7 +61,7 @@ private IIterable iterable(final ISelection sel) { if (sel instanceof IStructuredSelection) { return ((IStructuredSelection) sel)::iterator; } - final List list = Arrays.asList(new Object[] { sel }); + final List list = Arrays.asList(sel); return list::iterator; } @@ -69,8 +69,7 @@ private ICountable countable(final ISelection sel) { if (sel.isEmpty()) { return ICOUNT_0; } - if (sel instanceof IStructuredSelection) { - final IStructuredSelection ss = (IStructuredSelection) sel; + if (sel instanceof final IStructuredSelection ss) { return ss::size; } return ICOUNT_1; diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/ShellActivationListener.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/ShellActivationListener.java index 3ad803fde23..bbb643175b0 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/ShellActivationListener.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/ShellActivationListener.java @@ -47,7 +47,7 @@ public class ShellActivationListener implements Listener { */ private static final String ECLIPSE_CONTEXT_SHELL_CONTEXT = "org.eclipse.e4.ui.shellContext"; //$NON-NLS-1$ - private MApplication application; + private final MApplication application; ShellActivationListener(MApplication application) { this.application = application; @@ -55,11 +55,10 @@ public class ShellActivationListener implements Listener { @Override public void handleEvent(Event event) { - if (!(event.widget instanceof Shell)) { + if (!(event.widget instanceof Shell shell)) { return; } - Shell shell = (Shell) event.widget; Object obj = shell.getData(AbstractPartRenderer.OWNING_ME); if (obj instanceof MWindow) { processWindow(event, shell, (MWindow) obj); diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/WorkbenchStatusReporter.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/WorkbenchStatusReporter.java index 286c98dd2b0..0ba1d2263cb 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/WorkbenchStatusReporter.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/WorkbenchStatusReporter.java @@ -93,14 +93,15 @@ private void openDialog(final IStatus status, boolean shouldBlock, // TBD this code should really be in IShellProvider which should be // available at the application context level. Shell myShell = null; - if (shellProvider != null) + if (shellProvider != null) { myShell = shellProvider.getShell(); - else { + } else { IEclipseContext activeLeaf = context.getActiveLeaf(); if (activeLeaf != null) { IShellProvider provider = activeLeaf.get(IShellProvider.class); - if (provider != null) + if (provider != null) { myShell = provider.getShell(); + } } } if (myShell == null) { diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/handlers/ShowViewHandler.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/handlers/ShowViewHandler.java index d61604fb432..5b14d2efef8 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/handlers/ShowViewHandler.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/handlers/ShowViewHandler.java @@ -43,8 +43,9 @@ public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, final ShowViewDialog dialog = new ShowViewDialog(shell, application, context); dialog.open(); - if (dialog.getReturnCode() != Window.OK) + if (dialog.getReturnCode() != Window.OK) { return; + } for (MPartDescriptor descriptor : dialog.getSelection()) { partService.showPart(descriptor.getElementId(), PartState.ACTIVATE); diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/DisplayUISynchronize.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/DisplayUISynchronize.java index 2ddab3c5abe..10e0a6992a0 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/DisplayUISynchronize.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/DisplayUISynchronize.java @@ -22,7 +22,7 @@ */ public final class DisplayUISynchronize extends UISynchronize { - private Display display; + private final Display display; public DisplayUISynchronize(Display display) { this.display = display; diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/SearchPattern.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/SearchPattern.java index 43c590c5468..993d76393ed 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/SearchPattern.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/SearchPattern.java @@ -96,7 +96,7 @@ public class SearchPattern { private static final char BLANK = ' '; - private int allowedRules; + private final int allowedRules; /** * Creates a new instance of SearchPattern with the following match rules @@ -227,12 +227,14 @@ private void initializePatternAndMatchRule(String pattern) { private boolean startsWithIgnoreCase(String text, String prefix) { int textLength = text.length(); int prefixLength = prefix.length(); - if (textLength < prefixLength) + if (textLength < prefixLength) { return false; + } for (int i = prefixLength - 1; i >= 0; i--) { if (Character.toLowerCase(prefix.charAt(i)) != Character - .toLowerCase(text.charAt(i))) + .toLowerCase(text.charAt(i))) { return false; + } } return true; } @@ -294,10 +296,12 @@ private boolean startsWithIgnoreCase(String text, String prefix) { * @return true if the pattern matches the given name, false otherwise */ private boolean camelCaseMatch(String pattern, String name) { - if (pattern == null) + if (pattern == null) { return true; // null pattern is equivalent to '*' - if (name == null) + } + if (name == null) { return false; // null name cannot match + } return camelCaseMatch(pattern, 0, pattern.length(), name, 0, name .length()); @@ -411,19 +415,25 @@ private boolean camelCaseMatch(String pattern, String name) { */ private boolean camelCaseMatch(String pattern, int patternStart, int patternEnd, String name, int nameStart, int nameEnd) { - if (name == null) + if (name == null) { return false; // null name cannot match - if (pattern == null) + } + if (pattern == null) { return true; // null pattern is equivalent to '*' - if (patternEnd < 0) + } + if (patternEnd < 0) { patternEnd = pattern.length(); - if (nameEnd < 0) + } + if (nameEnd < 0) { nameEnd = name.length(); + } - if (patternEnd <= patternStart) + if (patternEnd <= patternStart) { return nameEnd <= nameStart; - if (nameEnd <= nameStart) + } + if (nameEnd <= nameStart) { return false; + } // check first pattern char if (name.charAt(nameStart) != pattern.charAt(patternStart)) { // first char must strictly match (upper/lower) @@ -432,8 +442,9 @@ private boolean camelCaseMatch(String pattern, int patternStart, int patternLength = patternEnd; - if (pattern.charAt(patternEnd - 1) == END_SYMBOL || pattern.charAt(patternEnd - 1) == BLANK ) + if (pattern.charAt(patternEnd - 1) == END_SYMBOL || pattern.charAt(patternEnd - 1) == BLANK ) { patternLength = patternEnd - 1; + } char patternChar, nameChar; @@ -452,8 +463,9 @@ private boolean camelCaseMatch(String pattern, int patternStart, } if (iName == nameEnd) { - if (iPattern == patternLength) + if (iPattern == patternLength) { return true; + } // We have exhausted name (and not pattern), so it's not a match return false; } @@ -466,15 +478,17 @@ private boolean camelCaseMatch(String pattern, int patternStart, // If characters are not equals, then it's not a match if // patternChar is lowercase - if (!isPatternCharAllowed(patternChar)) + if (!isPatternCharAllowed(patternChar)) { return false; + } // patternChar is uppercase, so let's find the next uppercase in // name while (true) { if (iName == nameEnd) { - if ((iPattern == patternLength) && (patternChar == END_SYMBOL || patternChar == BLANK)) + if ((iPattern == patternLength) && (patternChar == END_SYMBOL || patternChar == BLANK)) { return true; + } return false; } @@ -490,7 +504,9 @@ private boolean camelCaseMatch(String pattern, int patternStart, if (Character.isDigit(nameChar)) { // nameChar is digit => break if the digit is current pattern character otherwise consume it - if (patternChar == nameChar) break; + if (patternChar == nameChar) { + break; + } iName++; } else if (!isNameCharAllowed(nameChar)) { // nameChar is lowercase diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ShowViewDialog.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ShowViewDialog.java index 1c0b13b496a..41a099ed5dd 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ShowViewDialog.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ShowViewDialog.java @@ -77,12 +77,12 @@ public class ShowViewDialog extends Dialog implements private Button okButton; - private MApplication application; + private final MApplication application; private MPartDescriptor[] viewDescs = new MPartDescriptor[0]; private Label descriptionHint; - private IEclipseContext context; + private final IEclipseContext context; /** * Constructs a new ShowViewDialog. @@ -295,11 +295,13 @@ protected void restoreWidgetValues() { String[] expandedCategoryIds = settings .getArray(STORE_EXPANDED_CATEGORIES_ID); - if (expandedCategoryIds == null) + if (expandedCategoryIds == null) { return; + } - if (expandedCategoryIds.length > 0) + if (expandedCategoryIds.length > 0) { filteredTree.getViewer().setExpandedElements((Object[]) expandedCategoryIds); + } String selectedPartId = settings.get(STORE_SELECTED_VIEW_ID); if (selectedPartId != null) { @@ -326,11 +328,12 @@ protected void saveWidgetValues() { .getExpandedElements(); String[] expandedCategoryIds = new String[expandedElements.length]; for (int i = 0; i < expandedElements.length; ++i) { - if (expandedElements[i] instanceof MPartDescriptor) + if (expandedElements[i] instanceof MPartDescriptor) { expandedCategoryIds[i] = ((MPartDescriptor) expandedElements[i]) .getElementId(); - else + } else { expandedCategoryIds[i] = expandedElements[i].toString(); + } } // Save them for next time. @@ -408,8 +411,9 @@ void handleTreeViewerKeyPressed(KeyEvent event) { String description = ((MPartDescriptor) o).getTooltip(); description = LocalizationHelper.getLocalized(description, (MPartDescriptor) o, context); - if (description != null && description.length() == 0) + if (description != null && description.length() == 0) { description = WorkbenchSWTMessages.ShowView_noDesc; + } popUp(description); } } diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ViewComparator.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ViewComparator.java index d0a6de4e07a..11cd71dd113 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ViewComparator.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ViewComparator.java @@ -38,26 +38,32 @@ public ViewComparator() { @Override public int compare(Viewer viewer, Object e1, Object e2) { // place "General" category first - if (WorkbenchSWTMessages.ICategory_general.equals(e1)) + if (WorkbenchSWTMessages.ICategory_general.equals(e1)) { return -1; - if (WorkbenchSWTMessages.ICategory_general.equals(e2)) + } + if (WorkbenchSWTMessages.ICategory_general.equals(e2)) { return 1; + } String str1; - if (e1 instanceof MPartDescriptor) + if (e1 instanceof MPartDescriptor) { str1 = ((MPartDescriptor) e1).getLocalizedLabel(); - else + } else { str1 = e1.toString(); + } String str2; - if (e2 instanceof MPartDescriptor) + if (e2 instanceof MPartDescriptor) { str2 = ((MPartDescriptor) e2).getLocalizedLabel(); - else + } else { str2 = e2.toString(); - if (str1 == null) + } + if (str1 == null) { str1 = EMPTY_STRING; - if (str2 == null) + } + if (str2 == null) { str2 = EMPTY_STRING; + } return getComparator().compare(str1, str2); } } diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ViewContentProvider.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ViewContentProvider.java index 0362e1e95ce..37266aebc9b 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ViewContentProvider.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ViewContentProvider.java @@ -35,7 +35,7 @@ public class ViewContentProvider implements ITreeContentProvider { * Child cache. Map from Object->Object[]. Our hasChildren() method is * expensive so it's better to cache the results of getChildren(). */ - private Map childMap = new HashMap<>(); + private final Map childMap = new HashMap<>(); private MApplication application; @@ -95,17 +95,18 @@ private Object[] createChildren(Object element) { String category = null; boolean isView = false; for (String tag : tags) { - if (tag.equals("View")) + if (tag.equals("View")) { isView = true; - else if (tag.startsWith(CATEGORY_TAG)) { + } else if (tag.startsWith(CATEGORY_TAG)) { category = tag.substring(CATEGORY_TAG_LENGTH); } } if (isView) { - if (category != null) + if (category != null) { categoryTags.add(category); - else + } else { noCategoryDescriptors.add(descriptor); + } } } @@ -119,11 +120,13 @@ else if (tag.startsWith(CATEGORY_TAG)) { for (MPartDescriptor descriptor : descriptors) { List tags = descriptor.getTags(); for (String tag : tags) { - if (!tag.startsWith(CATEGORY_TAG)) + if (!tag.startsWith(CATEGORY_TAG)) { continue; + } String categoryTag = tag.substring(CATEGORY_TAG_LENGTH); - if (element.equals(categoryTag)) + if (element.equals(categoryTag)) { categoryDescriptors.add(descriptor); + } } } return categoryDescriptors.toArray(); diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ViewLabelProvider.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ViewLabelProvider.java index 5f4a63f08ea..2e58b4ade06 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ViewLabelProvider.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ViewLabelProvider.java @@ -50,13 +50,14 @@ public class ViewLabelProvider extends ColumnLabelProvider { IPath path = IPath.fromOSString("$nl$/icons/full/obj16/fldr_obj.svg"); URL url = FileLocator.find(bundle, path, null); ImageDescriptor enabledDesc = ImageDescriptor.createFromURL(url); - if (enabledDesc != null) + if (enabledDesc != null) { JFaceResources.getImageRegistry().put(FOLDER_ICON, enabledDesc); + } } - private Map imageMap = new HashMap<>(); + private final Map imageMap = new HashMap<>(); - private IEclipseContext context; + private final IEclipseContext context; public ViewLabelProvider(IEclipseContext context) { this.context = context; diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ViewPatternFilter.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ViewPatternFilter.java index 9b973a411f9..c079ef62c5c 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ViewPatternFilter.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/copy/ViewPatternFilter.java @@ -26,7 +26,7 @@ */ public class ViewPatternFilter extends PatternFilter { - private IEclipseContext context; + private final IEclipseContext context; /** * Create a new instance of a ViewPatternFilter diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/util/BindingProcessingAddon.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/util/BindingProcessingAddon.java index aed68c82419..ab0077d18c5 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/util/BindingProcessingAddon.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/util/BindingProcessingAddon.java @@ -116,9 +116,8 @@ private final Scheme getScheme(String schemeId) { } private void activateContexts(Object me) { - if (me instanceof MBindings) { + if (me instanceof MBindings container) { MContext contextModel = (MContext) me; - MBindings container = (MBindings) me; List bindingContexts = container .getBindingContexts(); IEclipseContext context = contextModel.getContext(); @@ -287,8 +286,7 @@ private void subscribeBindingTableContainerTopicBindingTables( if (UIEvents.isADD(event)) { for (Object newObj : UIEvents.asIterable(event, UIEvents.EventTags.NEW_VALUE)) { - if (newObj instanceof MBindingTable) { - MBindingTable bt = (MBindingTable) newObj; + if (newObj instanceof MBindingTable bt) { final Context bindingContext = contextManager.getContext(bt.getBindingContext().getElementId()); final BindingTable table = new BindingTable(bindingContext, application); bindingTables.addTable(table); @@ -316,8 +314,7 @@ private void subscribeTopicBinding(@UIEventTopic(UIEvents.BindingTable.TOPIC_BIN // adding a binding if (UIEvents.isADD(event)) { for (Object newObj : UIEvents.asIterable(event, UIEvents.EventTags.NEW_VALUE)) { - if (newObj instanceof MKeyBinding) { - MKeyBinding binding = (MKeyBinding) newObj; + if (newObj instanceof MKeyBinding binding) { updateBinding(binding, true, elementObj); } } @@ -325,8 +322,7 @@ private void subscribeTopicBinding(@UIEventTopic(UIEvents.BindingTable.TOPIC_BIN // removing a binding else if (UIEvents.isREMOVE(event)) { for (Object oldObj : UIEvents.asIterable(event, UIEvents.EventTags.OLD_VALUE)) { - if (oldObj instanceof MKeyBinding) { - MKeyBinding binding = (MKeyBinding) oldObj; + if (oldObj instanceof MKeyBinding binding) { updateBinding(binding, false, elementObj); } } @@ -337,11 +333,10 @@ else if (UIEvents.isREMOVE(event)) { @Optional private void subscribeTopicCommand(@UIEventTopic(UIEvents.KeyBinding.TOPIC_COMMAND) Event event) { Object elementObj = event.getProperty(UIEvents.EventTags.ELEMENT); - if (!(elementObj instanceof MKeyBinding)) { + if (!(elementObj instanceof MKeyBinding binding)) { return; } - MKeyBinding binding = (MKeyBinding) elementObj; Object oldObj = event.getProperty(UIEvents.EventTags.OLD_VALUE); MKeyBinding oldBinding = (MKeyBinding) EcoreUtil.copy((EObject) binding); @@ -354,11 +349,10 @@ private void subscribeTopicCommand(@UIEventTopic(UIEvents.KeyBinding.TOPIC_COMMA @Optional private void subscribeTopicKeySequence(@UIEventTopic(UIEvents.KeySequence.TOPIC_KEYSEQUENCE) Event event) { Object elementObj = event.getProperty(UIEvents.EventTags.ELEMENT); - if (!(elementObj instanceof MKeyBinding)) { + if (!(elementObj instanceof MKeyBinding binding)) { return; } - MKeyBinding binding = (MKeyBinding) elementObj; Object oldObj = event.getProperty(UIEvents.EventTags.OLD_VALUE); MKeyBinding oldBinding = (MKeyBinding) EcoreUtil.copy((EObject) binding); @@ -371,12 +365,10 @@ private void subscribeTopicKeySequence(@UIEventTopic(UIEvents.KeySequence.TOPIC_ @Optional private void subscribeTopicParameters(@UIEventTopic(UIEvents.KeyBinding.TOPIC_PARAMETERS) Event event) { Object elementObj = event.getProperty(UIEvents.EventTags.ELEMENT); - if (!(elementObj instanceof MKeyBinding)) { + if (!(elementObj instanceof MKeyBinding binding)) { return; } - MKeyBinding binding = (MKeyBinding) elementObj; - if (UIEvents.isADD(event)) { Object newObj = event.getProperty(UIEvents.EventTags.NEW_VALUE); MKeyBinding oldBinding = (MKeyBinding) EcoreUtil.copy((EObject) binding); @@ -407,12 +399,10 @@ private void subscribeTopicParameters(@UIEventTopic(UIEvents.KeyBinding.TOPIC_PA @Optional private void subscribeAppElemTopicTags(@UIEventTopic(UIEvents.ApplicationElement.TOPIC_TAGS) Event event) { Object elementObj = event.getProperty(UIEvents.EventTags.ELEMENT); - if (!(elementObj instanceof MKeyBinding)) { + if (!(elementObj instanceof MKeyBinding binding)) { return; } - MKeyBinding binding = (MKeyBinding) elementObj; - List tags = binding.getTags(); // if we added a deleted tag to the MKeyBinding, then // remove it from the runtime binding tables