diff options
author | Alexander Kurtakov | 2017-02-27 14:29:34 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2017-02-27 14:29:34 +0000 |
commit | 194eae6d5ad097ac7bb614004c8bb5b3f342e0c5 (patch) | |
tree | 4fe7fde3a06ee9b0775028d41cd1b67a6bfc8ea2 | |
parent | 4f2338266f5dd9dcac0adbd8a2fdc491b29cc409 (diff) | |
download | org.eclipse.dltk.core-194eae6d5ad097ac7bb614004c8bb5b3f342e0c5.tar.gz org.eclipse.dltk.core-194eae6d5ad097ac7bb614004c8bb5b3f342e0c5.tar.xz org.eclipse.dltk.core-194eae6d5ad097ac7bb614004c8bb5b3f342e0c5.zip |
Convert various listeners to lambdas.
Change-Id: I1312d6a12136b7e782429609ccd47888e1bc0293
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
16 files changed, 1102 insertions, 1157 deletions
diff --git a/core/plugins/org.eclipse.dltk.core/environment/org/eclipse/dltk/core/environment/EnvironmentManager.java b/core/plugins/org.eclipse.dltk.core/environment/org/eclipse/dltk/core/environment/EnvironmentManager.java index 51f96e549..7fd6b082e 100644 --- a/core/plugins/org.eclipse.dltk.core/environment/org/eclipse/dltk/core/environment/EnvironmentManager.java +++ b/core/plugins/org.eclipse.dltk.core/environment/org/eclipse/dltk/core/environment/EnvironmentManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2016 IBM Corporation and others. + * Copyright (c) 2005, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -109,22 +109,18 @@ public final class EnvironmentManager { private static final Map<IProject, IEnvironment> environmentCache = new HashMap<IProject, IEnvironment>(); - private static IResourceChangeListener resourceListener = new IResourceChangeListener() { + private static IResourceChangeListener resourceListener = event -> { + int eventType = event.getType(); + IResource resource = event.getResource(); - @Override - public void resourceChanged(IResourceChangeEvent event) { - int eventType = event.getType(); - IResource resource = event.getResource(); - - switch (eventType) { - case IResourceChangeEvent.PRE_DELETE: - if (resource.getType() == IResource.PROJECT) { - synchronized (environmentCache) { - environmentCache.remove(resource); - } + switch (eventType) { + case IResourceChangeEvent.PRE_DELETE: + if (resource.getType() == IResource.PROJECT) { + synchronized (environmentCache) { + environmentCache.remove(resource); } - return; } + return; } }; diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/DLTKContentTypeManager.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/DLTKContentTypeManager.java index 0fb9bd3e5..7f37a18ea 100644 --- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/DLTKContentTypeManager.java +++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/DLTKContentTypeManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2016 IBM Corporation and others. + * Copyright (c) 2005, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -36,7 +36,6 @@ import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.content.IContentDescription; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.content.IContentTypeManager; -import org.eclipse.core.runtime.content.IContentTypeManager.ContentTypeChangeEvent; import org.eclipse.core.runtime.content.IContentTypeManager.IContentTypeChangeListener; import org.eclipse.dltk.core.environment.EnvironmentPathUtils; import org.eclipse.dltk.core.environment.IFileHandle; @@ -395,12 +394,9 @@ public class DLTKContentTypeManager { final IContentTypeManager manager = Platform.getContentTypeManager(); synchronized (contentTypesCache) { if (changeListener == null) { - changeListener = new IContentTypeChangeListener() { - @Override - public void contentTypeChanged(ContentTypeChangeEvent event) { - synchronized (contentTypesCache) { - contentTypesCache.clear(); - } + changeListener = event -> { + synchronized (contentTypesCache) { + contentTypesCache.clear(); } }; manager.addContentTypeChangeListener(changeListener); diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ModelManager.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ModelManager.java index d7e98593a..15215f3f9 100644 --- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ModelManager.java +++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ModelManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2016 IBM Corporation and others. + * Copyright (c) 2005, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -57,7 +57,6 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.preferences.DefaultScope; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; -import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.dltk.compiler.problem.IProblem; @@ -1279,22 +1278,14 @@ public class ModelManager implements ISaveParticipant { // Initialize eclipse preferences initializePreferences(); // Listen to preference changes - this.propertyListener = new IEclipsePreferences.IPreferenceChangeListener() { - @Override - public void preferenceChange(PreferenceChangeEvent event) { - ModelManager.this.optionsCache = null; - } - }; + this.propertyListener = event -> ModelManager.this.optionsCache = null; installPreferenceChangeListener(DLTKCore.PLUGIN_ID, this.propertyListener); // listen for encoding changes (see // https://bugs.eclipse.org/bugs/show_bug.cgi?id=255501 ) - this.resourcesPropertyListener = new IEclipsePreferences.IPreferenceChangeListener() { - @Override - public void preferenceChange(PreferenceChangeEvent event) { - if (ResourcesPlugin.PREF_ENCODING.equals(event.getKey())) { - ModelManager.this.optionsCache = null; - } + this.resourcesPropertyListener = event -> { + if (ResourcesPlugin.PREF_ENCODING.equals(event.getKey())) { + ModelManager.this.optionsCache = null; } }; installPreferenceChangeListener(ResourcesPlugin.getPlugin() @@ -1327,24 +1318,19 @@ public class ModelManager implements ISaveParticipant { // add save participant and process delta atomically // see // https://bugs.eclipse.org/bugs/show_bug.cgi?id=59937 - workspace.run(new IWorkspaceRunnable() { - @Override - public void run(IProgressMonitor progress) - throws CoreException { - ISavedState savedState = workspace - .addSaveParticipant( - DLTKCore.getPlugin(), - ModelManager.this); - if (savedState != null) { - // the event type coming from the saved - // state is always POST_AUTO_BUILD - // force it to be POST_CHANGE so that the - // delta processor can handle it - ModelManager.this.deltaState - .getDeltaProcessor().overridenEventType = IResourceChangeEvent.POST_CHANGE; - savedState - .processResourceChangeEvents(ModelManager.this.deltaState); - } + workspace.run(progress -> { + ISavedState savedState = workspace + .addSaveParticipant(DLTKCore.getPlugin(), + ModelManager.this); + if (savedState != null) { + // the event type coming from the saved + // state is always POST_AUTO_BUILD + // force it to be POST_CHANGE so that the + // delta processor can handle it + ModelManager.this.deltaState + .getDeltaProcessor().overridenEventType = IResourceChangeEvent.POST_CHANGE; + savedState.processResourceChangeEvents( + ModelManager.this.deltaState); } }, monitor); } catch (CoreException e) { @@ -1921,34 +1907,32 @@ public class ModelManager implements ISaveParticipant { // if possible run inside an IWokspaceRunnable with AVOID_UPATE to // avoid unwanted builds // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=118507) - IWorkspaceRunnable runnable = new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException { - Set keys = allContainerPaths.keySet(); - int length = keys.size(); - IScriptProject[] scriptProjects = new IScriptProject[length]; // clone - // as - // the - // following - // will - // have - // a - // side - // effect - keys.toArray(scriptProjects); - for (int i = 0; i < length; i++) { - IScriptProject scriptProject = scriptProjects[i]; - HashSet pathSet = (HashSet) allContainerPaths - .get(scriptProject); - if (pathSet == null) - continue; - int length2 = pathSet.size(); - IPath[] paths = new IPath[length2]; - pathSet.toArray(paths); // clone as the following will - // have a side effect - for (int j = 0; j < length2; j++) { - IPath path = paths[j]; - initializeContainer(scriptProject, path); - } + IWorkspaceRunnable runnable = monitor -> { + Set keys = allContainerPaths.keySet(); + int length = keys.size(); + IScriptProject[] scriptProjects = new IScriptProject[length]; // clone + // as + // the + // following + // will + // have + // a + // side + // effect + keys.toArray(scriptProjects); + for (int i = 0; i < length; i++) { + IScriptProject scriptProject = scriptProjects[i]; + HashSet pathSet = (HashSet) allContainerPaths + .get(scriptProject); + if (pathSet == null) + continue; + int length2 = pathSet.size(); + IPath[] paths = new IPath[length2]; + pathSet.toArray(paths); // clone as the following will + // have a side effect + for (int j = 0; j < length2; j++) { + IPath path = paths[j]; + initializeContainer(scriptProject, path); } } }; @@ -2203,16 +2187,14 @@ public class ModelManager implements ISaveParticipant { " project: " + project.getElementName() + '\n' + //$NON-NLS-1$ " container path: " + containerPath + '\n' + //$NON-NLS-1$ " classpath entries: {\n" + //$NON-NLS-1$ - Util.toString(classpathEntries, new Util.Displayable() { - public String displayString(Object o) { - StringBuffer buffer = new StringBuffer(" "); //$NON-NLS-1$ - if (o == null) { - buffer.append("<null>"); //$NON-NLS-1$ - return buffer.toString(); - } - buffer.append(o); + Util.toString(classpathEntries, o -> { + StringBuffer buffer = new StringBuffer(" "); //$NON-NLS-1$ + if (o == null) { + buffer.append("<null>"); //$NON-NLS-1$ return buffer.toString(); } + buffer.append(o); + return buffer.toString(); }) + "\n }" //$NON-NLS-1$ ); } @@ -2275,55 +2257,47 @@ public class ModelManager implements ISaveParticipant { + containerPath + '\n' + " projects: {" //$NON-NLS-1$ - + Util.toString(projects, new Util.Displayable() { - public String displayString(Object o) { - return ((IScriptProject) o) - .getElementName(); - } - }) + + Util.toString(projects, + o -> ((IScriptProject) o).getElementName()) + "}\n values on previous session: {\n" + //$NON-NLS-1$ Util.toString(respectiveContainers, - new Util.Displayable() { - public String displayString(Object o) { - StringBuffer buffer = new StringBuffer( - " "); //$NON-NLS-1$ - if (o == null) { - buffer.append("<null>"); //$NON-NLS-1$ - return buffer.toString(); - } - buffer.append(container - .getDescription()); - buffer.append(" {\n"); //$NON-NLS-1$ - for (int j = 0; j < oldEntries.length; j++) { - buffer.append(" "); //$NON-NLS-1$ - buffer.append(oldEntries[j]); - buffer.append('\n'); - } - buffer.append(" }"); //$NON-NLS-1$ + o -> { + StringBuffer buffer = new StringBuffer( + " "); //$NON-NLS-1$ + if (o == null) { + buffer.append("<null>"); //$NON-NLS-1$ return buffer.toString(); } + buffer.append( + container.getDescription()); + buffer.append(" {\n"); //$NON-NLS-1$ + for (int j = 0; j < oldEntries.length; j++) { + buffer.append(" "); //$NON-NLS-1$ + buffer.append(oldEntries[j]); + buffer.append('\n'); + } + buffer.append(" }"); //$NON-NLS-1$ + return buffer.toString(); }) + "}\n new values: {\n" + //$NON-NLS-1$ Util.toString(respectiveContainers, - new Util.Displayable() { - public String displayString(Object o) { - StringBuffer buffer = new StringBuffer( - " "); //$NON-NLS-1$ - if (o == null) { - buffer.append("<null>"); //$NON-NLS-1$ - return buffer.toString(); - } - buffer.append(container - .getDescription()); - buffer.append(" {\n"); //$NON-NLS-1$ - for (int j = 0; j < newEntries.length; j++) { - buffer.append(" "); //$NON-NLS-1$ - buffer.append(newEntries[j]); - buffer.append('\n'); - } - buffer.append(" }"); //$NON-NLS-1$ + o -> { + StringBuffer buffer = new StringBuffer( + " "); //$NON-NLS-1$ + if (o == null) { + buffer.append("<null>"); //$NON-NLS-1$ return buffer.toString(); } + buffer.append( + container.getDescription()); + buffer.append(" {\n"); //$NON-NLS-1$ + for (int j = 0; j < newEntries.length; j++) { + buffer.append(" "); //$NON-NLS-1$ + buffer.append(newEntries[j]); + buffer.append('\n'); + } + buffer.append(" }"); //$NON-NLS-1$ + return buffer.toString(); }) + "\n }"); //$NON-NLS-1$ } return false; diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ScriptProject.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ScriptProject.java index 3e8dade06..a67a2c334 100644 --- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ScriptProject.java +++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ScriptProject.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2016 IBM Corporation and others. + * Copyright (c) 2005, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1946,14 +1946,8 @@ public class ScriptProject extends Openable implements IScriptProject, ((IEclipsePreferences) eclipsePreferences.parent()) .addNodeChangeListener(nodeListener); // Listen to preference changes - IEclipsePreferences.IPreferenceChangeListener preferenceListener = new IEclipsePreferences.IPreferenceChangeListener() { - @Override - public void preferenceChange( - IEclipsePreferences.PreferenceChangeEvent event) { - ModelManager.getModelManager().resetProjectOptions( - ScriptProject.this); - } - }; + IEclipsePreferences.IPreferenceChangeListener preferenceListener = event -> ModelManager + .getModelManager().resetProjectOptions(ScriptProject.this); eclipsePreferences.addPreferenceChangeListener(preferenceListener); return eclipsePreferences; } diff --git a/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/ui/FailureTrace.java b/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/ui/FailureTrace.java index bde9d1e56..c3276b4dc 100755 --- a/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/ui/FailureTrace.java +++ b/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/ui/FailureTrace.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,7 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Sebastian Davids: sdavids@gmx.de bug 37333, 26653 + * Sebastian Davids: sdavids@gmx.de bug 37333, 26653 * Johan Walles: walles@mailblocks.com bug 68737 *******************************************************************************/ package org.eclipse.dltk.internal.testing.ui; @@ -20,11 +20,9 @@ import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.ToolBarManager; -import org.eclipse.jface.util.IOpenEventListener; import org.eclipse.jface.util.OpenStrategy; import org.eclipse.swt.SWT; import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Shell; @@ -36,124 +34,127 @@ import org.eclipse.swt.widgets.ToolBar; * A pane that shows a stack trace of a failed test. */ public class FailureTrace implements IMenuListener { - private static final int MAX_LABEL_LENGTH = 256; - + private static final int MAX_LABEL_LENGTH = 256; + private Table fTable; private TestRunnerViewPart fTestRunner; private String fInputTrace; private final Clipboard fClipboard; - private TestElement fFailure; - private CompareResultsAction fCompareAction; - private EnableStackFilterAction fStackTraceFilterAction; + private TestElement fFailure; + private CompareResultsAction fCompareAction; + private EnableStackFilterAction fStackTraceFilterAction; private final FailureTableDisplay fFailureTableDisplay; - public FailureTrace(Composite parent, Clipboard clipboard, TestRunnerViewPart testRunner, ToolBar toolBar) { + public FailureTrace(Composite parent, Clipboard clipboard, + TestRunnerViewPart testRunner, ToolBar toolBar) { Assert.isNotNull(clipboard); - - fTestRunner= testRunner; - fClipboard= clipboard; + + fTestRunner = testRunner; + fClipboard = clipboard; // fill the failure trace viewer toolbar - ToolBarManager failureToolBarmanager= new ToolBarManager(toolBar); + ToolBarManager failureToolBarmanager = new ToolBarManager(toolBar); fStackTraceFilterAction = new EnableStackFilterAction(this); - failureToolBarmanager.add(fStackTraceFilterAction); + failureToolBarmanager.add(fStackTraceFilterAction); fCompareAction = new CompareResultsAction(this); fCompareAction.setEnabled(false); - failureToolBarmanager.add(fCompareAction); + failureToolBarmanager.add(fCompareAction); failureToolBarmanager.update(true); - - fTable= new Table(parent, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL); - + + fTable = new Table(parent, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL); + OpenStrategy handler = new OpenStrategy(fTable); - handler.addOpenListener(new IOpenEventListener() { - @Override - public void handleOpen(SelectionEvent e) { - if (fTable.getSelectionIndex() == 0 && fFailure.isComparisonFailure()) { - fCompareAction.run(); - } - if (fTable.getSelection().length != 0) { - IAction a = createOpenEditorAction(getSelectedText()); - if (a != null) - a.run(); - } + handler.addOpenListener(e -> { + if (fTable.getSelectionIndex() == 0 + && fFailure.isComparisonFailure()) { + fCompareAction.run(); + } + if (fTable.getSelection().length != 0) { + IAction a = createOpenEditorAction(getSelectedText()); + if (a != null) + a.run(); } }); - + initMenu(); - + fFailureTableDisplay = new FailureTableDisplay(fTable); } - + private void initMenu() { - MenuManager menuMgr= new MenuManager(); + MenuManager menuMgr = new MenuManager(); menuMgr.setRemoveAllWhenShown(true); menuMgr.addMenuListener(this); - Menu menu= menuMgr.createContextMenu(fTable); - fTable.setMenu(menu); + Menu menu = menuMgr.createContextMenu(fTable); + fTable.setMenu(menu); } - + @Override public void menuAboutToShow(IMenuManager manager) { if (fTable.getSelectionCount() > 0) { - IAction a= createOpenEditorAction(getSelectedText()); + IAction a = createOpenEditorAction(getSelectedText()); if (a != null) - manager.add(a); - manager.add(new DLTKTestingCopyAction(FailureTrace.this, fClipboard)); + manager.add(a); + manager.add( + new DLTKTestingCopyAction(FailureTrace.this, fClipboard)); } // fix for bug 68058 - if (fFailure != null && fFailure.isComparisonFailure()) + if (fFailure != null && fFailure.isComparisonFailure()) manager.add(fCompareAction); } public String getTrace() { return fInputTrace; } - + private String getSelectedText() { return fTable.getSelection()[0].getText(); - } + } private IAction createOpenEditorAction(String traceLine) { final ITestRunnerUI runnerUI = fTestRunner.getTestRunnerUI(); return runnerUI.createOpenEditorAction(traceLine); } - + ITestRunnerUI getTestRunnerUI() { return fTestRunner.getTestRunnerUI(); } - + /** * Returns the composite used to present the trace + * * @return The composite */ - Composite getComposite(){ + Composite getComposite() { return fTable; } - + /** * Refresh the table from the trace. */ public void refresh() { updateTable(fInputTrace); } - + /** * Shows a TestFailure - * @param test the failed test + * + * @param test + * the failed test */ - public void showFailure(TestElement test) { - fFailure= test; - String trace= ""; //$NON-NLS-1$ - updateEnablement(test); - if (test != null) - trace= test.getTrace(); + public void showFailure(TestElement test) { + fFailure = test; + String trace = ""; //$NON-NLS-1$ + updateEnablement(test); + if (test != null) + trace = test.getTrace(); if (fInputTrace == trace) return; - fInputTrace= trace; + fInputTrace = trace; updateTable(trace); } public void updateEnablement(TestElement test) { - boolean enableCompare= test != null && test.isComparisonFailure(); + boolean enableCompare = test != null && test.isComparisonFailure(); fCompareAction.setEnabled(enableCompare); if (enableCompare) { fCompareAction.updateOpenDialog(test); @@ -161,25 +162,27 @@ public class FailureTrace implements IMenuListener { } private void updateTable(String trace) { - if(trace == null || trace.trim().equals("")) { //$NON-NLS-1$ + if (trace == null || trace.trim().equals("")) { //$NON-NLS-1$ clear(); return; } - trace= trace.trim(); + trace = trace.trim(); fTable.setRedraw(false); fTable.removeAll(); - new TextualTrace(trace, fTestRunner.getTestRunnerUI()).display( - fFailureTableDisplay, MAX_LABEL_LENGTH); + new TextualTrace(trace, fTestRunner.getTestRunnerUI()) + .display(fFailureTableDisplay, MAX_LABEL_LENGTH); fTable.setRedraw(true); } /** * Shows other information than a stack trace. - * @param text the informational message to be shown + * + * @param text + * the informational message to be shown */ public void setInformation(String text) { clear(); - TableItem tableItem= fFailureTableDisplay.newTableItem(); + TableItem tableItem = fFailureTableDisplay.newTableItem(); tableItem.setText(text); } @@ -203,16 +206,16 @@ public class FailureTrace implements IMenuListener { */ public void clear() { fTable.removeAll(); - fInputTrace= null; + fInputTrace = null; } - public TestElement getFailedTest() { - return fFailure; - } + public TestElement getFailedTest() { + return fFailure; + } - public Shell getShell() { - return fTable.getShell(); - } + public Shell getShell() { + return fTable.getShell(); + } public FailureTableDisplay getFailureTableDisplay() { return fFailureTableDisplay; diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/BrowserInformationControl.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/BrowserInformationControl.java index 88d8aae7f..8643b69be 100644 --- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/BrowserInformationControl.java +++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/BrowserInformationControl.java @@ -22,7 +22,6 @@ import org.eclipse.jface.action.ToolBarManager; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.AbstractInformationControl; import org.eclipse.jface.text.IDelayedInputChangeProvider; -import org.eclipse.jface.text.IInformationControl; import org.eclipse.jface.text.IInformationControlCreator; import org.eclipse.jface.text.IInformationControlExtension2; import org.eclipse.jface.text.IInputChangedListener; @@ -31,10 +30,8 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.SWTError; import org.eclipse.swt.browser.Browser; import org.eclipse.swt.browser.LocationListener; -import org.eclipse.swt.browser.OpenWindowListener; import org.eclipse.swt.browser.ProgressAdapter; import org.eclipse.swt.browser.ProgressEvent; -import org.eclipse.swt.browser.WindowEvent; import org.eclipse.swt.custom.StyleRange; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; @@ -110,9 +107,9 @@ public class BrowserInformationControl extends AbstractInformationControl return fgIsAvailable; } - /** * Minimal size constraints. + * * @since 3.2 */ private static final int MIN_WIDTH = 80; @@ -139,7 +136,9 @@ public class BrowserInformationControl extends AbstractInformationControl /** Tells whether the browser has content */ private boolean fBrowserHasContent; - /** Text layout used to approximate size of content when rendered in browser */ + /** + * Text layout used to approximate size of content when rendered in browser + */ private TextLayout fTextLayout; /** Bold text style */ @@ -168,7 +167,7 @@ public class BrowserInformationControl extends AbstractInformationControl * * @since 3.4 */ - private ListenerList/* <IInputChangedListener> */fInputChangeListeners = new ListenerList( + private ListenerList/* <IInputChangedListener> */ fInputChangeListeners = new ListenerList( ListenerList.IDENTITY); /** @@ -179,7 +178,6 @@ public class BrowserInformationControl extends AbstractInformationControl */ private final String fSymbolicFontName; - /** * Creates a browser information control with the given shell as parent. * @@ -237,23 +235,13 @@ public class BrowserInformationControl extends AbstractInformationControl @Override public IInformationControlCreator getInformationPresenterControlCreator() { - return new IInformationControlCreator() { - /* - * @see org.eclipse.jface.text.IInformationControlCreator# - * createInformationControl(org.eclipse.swt.widgets.Shell) - */ - @Override - public IInformationControl createInformationControl(Shell parent) { - return new BrowserInformationControl(parent, fSymbolicFontName, - true); - } - }; + return parent -> new BrowserInformationControl(parent, + fSymbolicFontName, true); } /* - * @see - * org.eclipse.jface.text.AbstractInformationControl#createContent(org.eclipse - * .swt.widgets.Composite) + * @see org.eclipse.jface.text.AbstractInformationControl#createContent(org. + * eclipse .swt.widgets.Composite) */ @Override protected void createContent(Composite parent) { @@ -261,10 +249,10 @@ public class BrowserInformationControl extends AbstractInformationControl fBrowser.setJavascriptEnabled(false); Display display = getShell().getDisplay(); - fBrowser.setForeground(display - .getSystemColor(SWT.COLOR_INFO_FOREGROUND)); - fBrowser.setBackground(display - .getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + fBrowser.setForeground( + display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); + fBrowser.setBackground( + display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); fBrowser.addProgressListener(new ProgressAdapter() { @Override @@ -273,12 +261,7 @@ public class BrowserInformationControl extends AbstractInformationControl } }); - fBrowser.addOpenWindowListener(new OpenWindowListener() { - @Override - public void open(WindowEvent event) { - event.required = true; // Cancel opening of new windows - } - }); + fBrowser.addOpenWindowListener(event -> event.required = true); // Replace browser's built-in context menu with none fBrowser.setMenu(new Menu(getShell(), SWT.NONE)); @@ -345,17 +328,18 @@ public class BrowserInformationControl extends AbstractInformationControl // and the re-wrapping would cause visual noise String[] styles = null; if (RTL && resizable) - styles = new String[] { - "direction:rtl;", "overflow:scroll;", "word-wrap:break-word;" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + styles = new String[] { "direction:rtl;", "overflow:scroll;", //$NON-NLS-1$ //$NON-NLS-2$ + "word-wrap:break-word;" }; //$NON-NLS-1$ else if (RTL && !resizable) - styles = new String[] { - "direction:rtl;", "overflow:hidden;", "word-wrap:break-word;" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + styles = new String[] { "direction:rtl;", "overflow:hidden;", //$NON-NLS-1$ //$NON-NLS-2$ + "word-wrap:break-word;" }; //$NON-NLS-1$ else if (!resizable) // XXX: In IE, "word-wrap: break-word;" causes bogus wrapping even // in non-broken words :-(see e.g. Javadoc of String). // Re-check whether we really still need this now that the Javadoc // Hover header already sets this style. - styles = new String[] { "overflow:hidden;"/*, "word-wrap: break-word;"*/}; //$NON-NLS-1$ + styles = new String[] { + "overflow:hidden;"/* , "word-wrap: break-word;" */ }; //$NON-NLS-1$ else styles = new String[] { "overflow:scroll;" }; //$NON-NLS-1$ @@ -444,7 +428,8 @@ public class BrowserInformationControl extends AbstractInformationControl fTextLayout = new TextLayout(fBrowser.getDisplay()); // Initialize fonts - String symbolicFontName = fSymbolicFontName == null ? JFaceResources.DIALOG_FONT + String symbolicFontName = fSymbolicFontName == null + ? JFaceResources.DIALOG_FONT : fSymbolicFontName; Font font = JFaceResources.getFont(symbolicFontName); fTextLayout.setFont(font); @@ -481,8 +466,8 @@ public class BrowserInformationControl extends AbstractInformationControl // Furthermore, the indentation of <dl><dd> elements is too small (e.g // with a long @see line) TextPresentation presentation = new TextPresentation(); - HTML2TextReader reader = new HTML2TextReader(new StringReader( - fInput.getHtml()), presentation); + HTML2TextReader reader = new HTML2TextReader( + new StringReader(fInput.getHtml()), presentation); String text; try { text = reader.getString(); @@ -497,8 +482,8 @@ public class BrowserInformationControl extends AbstractInformationControl while (iter.hasNext()) { StyleRange sr = (StyleRange) iter.next(); if (sr.fontStyle == SWT.BOLD) - fTextLayout.setStyle(fBoldStyle, sr.start, sr.start + sr.length - - 1); + fTextLayout.setStyle(fBoldStyle, sr.start, + sr.start + sr.length - 1); } Rectangle bounds = fTextLayout.getBounds(); // does not return minimum @@ -523,7 +508,6 @@ public class BrowserInformationControl extends AbstractInformationControl minWidth += 15; height += 15; - // Apply max size constraints if (sizeConstraints != null) { if (sizeConstraints.x != SWT.DEFAULT) @@ -590,7 +574,8 @@ public class BrowserInformationControl extends AbstractInformationControl * the listener to add * @since 3.4 */ - public void addInputChangeListener(IInputChangedListener inputChangeListener) { + public void addInputChangeListener( + IInputChangedListener inputChangeListener) { Assert.isNotNull(inputChangeListener); fInputChangeListeners.add(inputChangeListener); } @@ -644,7 +629,8 @@ public class BrowserInformationControl extends AbstractInformationControl */ @Override public String toString() { - String style = (getShell().getStyle() & SWT.RESIZE) == 0 ? "fixed" : "resizeable"; //$NON-NLS-1$ //$NON-NLS-2$ + String style = (getShell().getStyle() & SWT.RESIZE) == 0 ? "fixed" //$NON-NLS-1$ + : "resizeable"; //$NON-NLS-1$ return super.toString() + " - style: " + style; //$NON-NLS-1$ } @@ -656,9 +642,8 @@ public class BrowserInformationControl extends AbstractInformationControl } /* - * @see - * org.eclipse.jface.text.IInformationControlExtension5#computeSizeConstraints - * (int, int) + * @see org.eclipse.jface.text.IInformationControlExtension5# + * computeSizeConstraints (int, int) */ @Override public Point computeSizeConstraints(int widthInChars, int heightInChars) { diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/actions/refactoring/RefactorActionGroup.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/actions/refactoring/RefactorActionGroup.java index f5912a08d..162739808 100644 --- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/actions/refactoring/RefactorActionGroup.java +++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/actions/refactoring/RefactorActionGroup.java @@ -35,7 +35,6 @@ import org.eclipse.dltk.utils.LazyExtensionManager; import org.eclipse.dltk.utils.LazyExtensionManager.Descriptor; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; @@ -119,7 +118,8 @@ public class RefactorActionGroup extends ActionGroup { * * */ - private static final String GROUP_REORG2 = "reorgGroup2"; //$NON-NLS-1$ //TODO(3.3): make public + private static final String GROUP_REORG2 = "reorgGroup2"; //$NON-NLS-1$ //TODO(3.3): + // make public /** * Pop-up menu: id of the type group 2 of the refactor sub menu (value @@ -127,7 +127,8 @@ public class RefactorActionGroup extends ActionGroup { * * */ - private static final String GROUP_TYPE2 = "typeGroup2"; //$NON-NLS-1$ //TODO(3.3): make public + private static final String GROUP_TYPE2 = "typeGroup2"; //$NON-NLS-1$ //TODO(3.3): + // make public private IWorkbenchSite fSite; private ScriptEditor fEditor; @@ -190,8 +191,8 @@ public class RefactorActionGroup extends ActionGroup { public RefactorActionGroup(IViewPart part, IDLTKLanguageToolkit toolkit) { this(part.getSite(), toolkit); - IUndoContext workspaceContext = ResourcesPlugin - .getWorkspace().getAdapter(IUndoContext.class); + IUndoContext workspaceContext = ResourcesPlugin.getWorkspace() + .getAdapter(IUndoContext.class); fUndoRedoActionGroup = new UndoRedoActionGroup(part.getViewSite(), workspaceContext, true); installQuickAccessAction(); @@ -229,8 +230,8 @@ public class RefactorActionGroup extends ActionGroup { */ public RefactorActionGroup(ScriptEditor editor, String groupName) { - final PerformanceStats stats = PerformanceStats.getStats( - PERF_REFACTOR_ACTION_GROUP, this); + final PerformanceStats stats = PerformanceStats + .getStats(PERF_REFACTOR_ACTION_GROUP, this); stats.startRun(); fSite = editor.getEditorSite(); @@ -274,104 +275,119 @@ public class RefactorActionGroup extends ActionGroup { // fModifyParametersAction= new ModifyParametersAction(editor); // initAction(fModifyParametersAction, selection, // IScriptEditorActionDefinitionIds.MODIFY_METHOD_PARAMETERS); - // editor.setAction("ModifyParameters", fModifyParametersAction); //$NON-NLS-1$ + // editor.setAction("ModifyParameters", fModifyParametersAction); + // //$NON-NLS-1$ // // fConvertAnonymousToNestedAction= new // ConvertAnonymousToNestedAction(editor); // initUpdatingAction(fConvertAnonymousToNestedAction, provider, // selection, // IScriptEditorActionDefinitionIds.CONVERT_ANONYMOUS_TO_NESTED); - // editor.setAction("ConvertAnonymousToNested", fConvertAnonymousToNestedAction); //$NON-NLS-1$ + // editor.setAction("ConvertAnonymousToNested", + // fConvertAnonymousToNestedAction); //$NON-NLS-1$ // // fConvertNestedToTopAction= new ConvertNestedToTopAction(editor); // initAction(fConvertNestedToTopAction, selection, // IScriptEditorActionDefinitionIds.MOVE_INNER_TO_TOP); - // editor.setAction("MoveInnerToTop", fConvertNestedToTopAction); //$NON-NLS-1$ + // editor.setAction("MoveInnerToTop", fConvertNestedToTopAction); + // //$NON-NLS-1$ // // fPullUpAction= new PullUpAction(editor); // initAction(fPullUpAction, selection, // IScriptEditorActionDefinitionIds.PULL_UP); - // editor.setAction("PullUp", fPullUpAction); //$NON-NLS-1$ + // editor.setAction("PullUp", fPullUpAction); //$NON-NLS-1$ // // fPushDownAction= new PushDownAction(editor); // initAction(fPushDownAction, selection, // IScriptEditorActionDefinitionIds.PUSH_DOWN); - // editor.setAction("PushDown", fPushDownAction); //$NON-NLS-1$ + // editor.setAction("PushDown", fPushDownAction); //$NON-NLS-1$ // // fExtractSupertypeAction= new ExtractSuperTypeAction(editor); // initAction(fExtractSupertypeAction, selection, // ExtractSuperTypeAction.EXTRACT_SUPERTYPE); - // editor.setAction("ExtractSupertype", fExtractSupertypeAction); //$NON-NLS-1$ + // editor.setAction("ExtractSupertype", fExtractSupertypeAction); + // //$NON-NLS-1$ // // fExtractInterfaceAction= new ExtractInterfaceAction(editor); // initAction(fExtractInterfaceAction, selection, // IScriptEditorActionDefinitionIds.EXTRACT_INTERFACE); - // editor.setAction("ExtractInterface", fExtractInterfaceAction); //$NON-NLS-1$ + // editor.setAction("ExtractInterface", fExtractInterfaceAction); + // //$NON-NLS-1$ // // fChangeTypeAction= new ChangeTypeAction(editor); // initUpdatingAction(fChangeTypeAction, provider, selection, // IScriptEditorActionDefinitionIds.CHANGE_TYPE); - // editor.setAction("ChangeType", fChangeTypeAction); //$NON-NLS-1$ + // editor.setAction("ChangeType", fChangeTypeAction); //$NON-NLS-1$ // // fUseSupertypeAction= new UseSupertypeAction(editor); // initAction(fUseSupertypeAction, selection, // IScriptEditorActionDefinitionIds.USE_SUPERTYPE); - // editor.setAction("UseSupertype", fUseSupertypeAction); //$NON-NLS-1$ + // editor.setAction("UseSupertype", fUseSupertypeAction); //$NON-NLS-1$ // // fInferTypeArgumentsAction= new InferTypeArgumentsAction(editor); // initAction(fInferTypeArgumentsAction, selection, // IScriptEditorActionDefinitionIds.INFER_TYPE_ARGUMENTS_ACTION); - // editor.setAction("InferTypeArguments", fInferTypeArgumentsAction); //$NON-NLS-1$ + // editor.setAction("InferTypeArguments", fInferTypeArgumentsAction); + // //$NON-NLS-1$ // // fInlineAction= new InlineAction(editor); // initAction(fInlineAction, selection, // IScriptEditorActionDefinitionIds.INLINE); - // editor.setAction("Inline", fInlineAction); //$NON-NLS-1$ + // editor.setAction("Inline", fInlineAction); //$NON-NLS-1$ // // fExtractMethodAction= new ExtractMethodAction(editor); // initUpdatingAction(fExtractMethodAction, provider, selection, // IScriptEditorActionDefinitionIds.EXTRACT_METHOD); - // editor.setAction("ExtractMethod", fExtractMethodAction); //$NON-NLS-1$ + // editor.setAction("ExtractMethod", fExtractMethodAction); + // //$NON-NLS-1$ // // fExtractTempAction= new ExtractTempAction(editor); // initUpdatingAction(fExtractTempAction, provider, selection, // IScriptEditorActionDefinitionIds.EXTRACT_LOCAL_VARIABLE); - // editor.setAction("ExtractLocalVariable", fExtractTempAction); //$NON-NLS-1$ + // editor.setAction("ExtractLocalVariable", fExtractTempAction); + // //$NON-NLS-1$ // // fExtractConstantAction= new ExtractConstantAction(editor); // initUpdatingAction(fExtractConstantAction, provider, selection, // IScriptEditorActionDefinitionIds.EXTRACT_CONSTANT); - // editor.setAction("ExtractConstant", fExtractConstantAction); //$NON-NLS-1$ + // editor.setAction("ExtractConstant", fExtractConstantAction); + // //$NON-NLS-1$ // // // fReplaceInvocationsAction= new ReplaceInvocationsAction(editor); // // initUpdatingAction(fReplaceInvocationsAction, provider, selection, // IScriptEditorActionDefinitionIds.REPLACE_INVOCATIONS); - //// editor.setAction("ReplaceInvocations", fReplaceInvocationsAction); //$NON-NLS-1$ + //// editor.setAction("ReplaceInvocations", fReplaceInvocationsAction); + // //$NON-NLS-1$ // // fIntroduceIndirectionAction= new IntroduceIndirectionAction(editor); // initUpdatingAction(fIntroduceIndirectionAction, provider, selection, // IScriptEditorActionDefinitionIds.INTRODUCE_INDIRECTION); - // editor.setAction("IntroduceIndirection", fIntroduceIndirectionAction); //$NON-NLS-1$ + // editor.setAction("IntroduceIndirection", + // fIntroduceIndirectionAction); //$NON-NLS-1$ // // fIntroduceParameterAction= new IntroduceParameterAction(editor); // initUpdatingAction(fIntroduceParameterAction, provider, selection, // IScriptEditorActionDefinitionIds.INTRODUCE_PARAMETER); - // editor.setAction("IntroduceParameter", fIntroduceParameterAction); //$NON-NLS-1$ + // editor.setAction("IntroduceParameter", fIntroduceParameterAction); + // //$NON-NLS-1$ // // fIntroduceFactoryAction= new IntroduceFactoryAction(editor); // initUpdatingAction(fIntroduceFactoryAction, provider, selection, // IScriptEditorActionDefinitionIds.INTRODUCE_FACTORY); - // editor.setAction("IntroduceFactory", fIntroduceFactoryAction); //$NON-NLS-1$ + // editor.setAction("IntroduceFactory", fIntroduceFactoryAction); + // //$NON-NLS-1$ // // fConvertLocalToFieldAction= new ConvertLocalToFieldAction(editor); // initUpdatingAction(fConvertLocalToFieldAction, provider, selection, // IScriptEditorActionDefinitionIds.PROMOTE_LOCAL_VARIABLE); - // editor.setAction("PromoteTemp", fConvertLocalToFieldAction); //$NON-NLS-1$ + // editor.setAction("PromoteTemp", fConvertLocalToFieldAction); + // //$NON-NLS-1$ // // fSelfEncapsulateField= new SelfEncapsulateFieldAction(editor); // initAction(fSelfEncapsulateField, selection, // IScriptEditorActionDefinitionIds.SELF_ENCAPSULATE_FIELD); - // editor.setAction("SelfEncapsulateField", fSelfEncapsulateField); //$NON-NLS-1$ + // editor.setAction("SelfEncapsulateField", fSelfEncapsulateField); + // //$NON-NLS-1$ // // fQuickAccessAction= new RefactorQuickAccessAction(editor); // fKeyBindingService= editor.getEditorSite().getKeyBindingService(); @@ -385,8 +401,8 @@ public class RefactorActionGroup extends ActionGroup { private RefactorActionGroup(IWorkbenchSite site, final IDLTKLanguageToolkit toolkit) { - final PerformanceStats stats = PerformanceStats.getStats( - PERF_REFACTOR_ACTION_GROUP, this); + final PerformanceStats stats = PerformanceStats + .getStats(PERF_REFACTOR_ACTION_GROUP, this); stats.startRun(); fSite = site; @@ -401,26 +417,23 @@ public class RefactorActionGroup extends ActionGroup { initUpdatingAction(fRenameAction, provider, selection, IScriptEditorActionDefinitionIds.RENAME_ELEMENT); if (toolkit != null) { - /*final Descriptor<IEditorActionDelegate>[] delegates = new LazyExtensionManager<IEditorActionDelegate>( - DLTKUIPlugin.PLUGIN_ID + ".refactoring") { - protected boolean isValidElement(IConfigurationElement element) { - return "action".equals(element.getName()) - && toolkit.getNatureId().equals( - element.getAttribute("nature")); - } - }.getDescriptors(); - for (Descriptor<IEditorActionDelegate> descriptor : delegates) { - final IEditorActionDelegate delegate = descriptor.get(); - if (delegate != null) { - final ContributedRefactoringAction action = new ContributedRefactoringAction( - site, delegate); - String id = descriptor.getAttribute("id"); - action.setId(id); - action.setText(descriptor.getAttribute("label")); - initUpdatingAction(action, provider, selection, id); - fContributedActions.add(action); - } - }*/ + /* + * final Descriptor<IEditorActionDelegate>[] delegates = new + * LazyExtensionManager<IEditorActionDelegate>( + * DLTKUIPlugin.PLUGIN_ID + ".refactoring") { protected boolean + * isValidElement(IConfigurationElement element) { return + * "action".equals(element.getName()) && + * toolkit.getNatureId().equals( element.getAttribute("nature")); } + * }.getDescriptors(); for (Descriptor<IEditorActionDelegate> + * descriptor : delegates) { final IEditorActionDelegate delegate = + * descriptor.get(); if (delegate != null) { final + * ContributedRefactoringAction action = new + * ContributedRefactoringAction( site, delegate); String id = + * descriptor.getAttribute("id"); action.setId(id); + * action.setText(descriptor.getAttribute("label")); + * initUpdatingAction(action, provider, selection, id); + * fContributedActions.add(action); } } + */ } // // fModifyParametersAction= new ModifyParametersAction(fSite); @@ -495,8 +508,7 @@ public class RefactorActionGroup extends ActionGroup { } private void installQuickAccessAction() { - fHandlerService = fSite - .getService(IHandlerService.class); + fHandlerService = fSite.getService(IHandlerService.class); if (fHandlerService != null) { final QuickMenuCreator creator = new QuickMenuCreator() { @Override @@ -512,8 +524,8 @@ public class RefactorActionGroup extends ActionGroup { return null; } }; - fQuickAccessHandlerActivation = fHandlerService.activateHandler( - QUICK_MENU_ID, handler); + fQuickAccessHandlerActivation = fHandlerService + .activateHandler(QUICK_MENU_ID, handler); } } @@ -547,8 +559,8 @@ public class RefactorActionGroup extends ActionGroup { super.fillActionBars(actionBars); // actionBars.setGlobalActionHandler(DLTKActionConstants.SELF_ENCAPSULATE_FIELD, // fSelfEncapsulateField); - actionBars - .setGlobalActionHandler(DLTKActionConstants.MOVE, fMoveAction); + actionBars.setGlobalActionHandler(DLTKActionConstants.MOVE, + fMoveAction); actionBars.setGlobalActionHandler(DLTKActionConstants.RENAME, fRenameAction); for (ContributedRefactoringAction action : fContributedActions) @@ -669,12 +681,8 @@ public class RefactorActionGroup extends ActionGroup { if (fEditor != null) { IModelElement element = SelectionConverter.getInput(fEditor); if (element != null && ActionUtil.isOnBuildPath(element)) { - refactorSubmenu.addMenuListener(new IMenuListener() { - @Override - public void menuAboutToShow(IMenuManager manager) { - refactorMenuShown(manager); - } - }); + refactorSubmenu + .addMenuListener(manager -> refactorMenuShown(manager)); refactorSubmenu.add(fNoActionAvailable); menu.appendToGroup(fGroupName, refactorSubmenu); } diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/callhierarchy/CallHierarchyViewPart.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/callhierarchy/CallHierarchyViewPart.java index c1324c994..72d2f04c3 100644 --- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/callhierarchy/CallHierarchyViewPart.java +++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/callhierarchy/CallHierarchyViewPart.java @@ -1,14 +1,10 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - - * (report 36180: Callers/Callees view) - * Michael Fraenkel (fraenkel@us.ibm.com) - patch - * (report 60714: Call Hierarchy: display search scope in view title) *******************************************************************************/ package org.eclipse.dltk.internal.ui.callhierarchy; @@ -40,7 +36,6 @@ import org.eclipse.dltk.ui.actions.OpenEditorActionGroup; import org.eclipse.dltk.ui.actions.OpenViewActionGroup; import org.eclipse.dltk.ui.viewsupport.SelectionProviderMediator; import org.eclipse.dltk.ui.viewsupport.StatusBarUpdater; -import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.action.IToolBarManager; @@ -50,11 +45,9 @@ import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.util.LocalSelectionTransfer; import org.eclipse.jface.util.TransferDragSourceListener; import org.eclipse.jface.util.TransferDropTargetListener; -import org.eclipse.jface.viewers.IOpenListener; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.OpenEvent; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredViewer; @@ -96,13 +89,13 @@ import org.eclipse.ui.texteditor.ITextEditor; * This is the main view for the callers plugin. It builds a tree of * callers/callees and allows the user to double click an entry to go to the * selected method. - * + * */ -public class CallHierarchyViewPart extends ViewPart implements - ICallHierarchyViewPart, ISelectionChangedListener { +public class CallHierarchyViewPart extends ViewPart + implements ICallHierarchyViewPart, ISelectionChangedListener { - private class CallHierarchySelectionProvider extends - SelectionProviderMediator { + private class CallHierarchySelectionProvider + extends SelectionProviderMediator { public CallHierarchySelectionProvider(StructuredViewer[] viewers) { super(viewers, null); @@ -203,13 +196,13 @@ public class CallHierarchyViewPart extends ViewPart implements updateHistoryEntries(); } - return (IMethod[]) fMethodHistory.toArray(new IMethod[fMethodHistory - .size()]); + return (IMethod[]) fMethodHistory + .toArray(new IMethod[fMethodHistory.size()]); } /** * Method setMethod. - * + * * @param method */ public void setMethod(IMethod method) { @@ -256,7 +249,7 @@ public class CallHierarchyViewPart extends ViewPart implements /** * called from ToggleOrientationAction. - * + * * @param orientation * VIEW_ORIENTATION_HORIZONTAL or VIEW_ORIENTATION_VERTICAL */ @@ -274,9 +267,8 @@ public class CallHierarchyViewPart extends ViewPart implements } boolean horizontal = orientation == CallHierarchyViewPart.VIEW_ORIENTATION_HORIZONTAL; - fHierarchyLocationSplitter - .setOrientation(horizontal ? SWT.HORIZONTAL - : SWT.VERTICAL); + fHierarchyLocationSplitter.setOrientation( + horizontal ? SWT.HORIZONTAL : SWT.VERTICAL); } fHierarchyLocationSplitter.layout(); @@ -300,15 +292,15 @@ public class CallHierarchyViewPart extends ViewPart implements /** * called from ToggleCallModeAction. - * + * * @param mode * CALL_MODE_CALLERS or CALL_MODE_CALLEES */ void setCallMode(int mode) { if (fCurrentCallMode != mode) { for (int i = 0; i < fToggleCallModeActions.length; i++) { - fToggleCallModeActions[i] - .setChecked(mode == fToggleCallModeActions[i].getMode()); + fToggleCallModeActions[i].setChecked( + mode == fToggleCallModeActions[i].getMode()); } fCurrentCallMode = mode; @@ -336,22 +328,22 @@ public class CallHierarchyViewPart extends ViewPart implements // dnd on empty hierarchy DropTarget dropTarget = new DropTarget(fPagebook, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_DEFAULT); - dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer - .getTransfer() }); + dropTarget.setTransfer( + new Transfer[] { LocalSelectionTransfer.getTransfer() }); dropTarget.addDropListener(new CallHierarchyTransferDropAdapter(this, fCallHierarchyViewer)); } private void addDropAdapters(StructuredViewer viewer) { - Transfer[] transfers = new Transfer[] { LocalSelectionTransfer - .getTransfer() }; + Transfer[] transfers = new Transfer[] { + LocalSelectionTransfer.getTransfer() }; int ops = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_DEFAULT; - TransferDropTargetListener[] dropListeners = new TransferDropTargetListener[] { new CallHierarchyTransferDropAdapter( - this, viewer) }; - viewer.addDropSupport(ops, transfers, new DelegatingDropAdapter( - dropListeners)); + TransferDropTargetListener[] dropListeners = new TransferDropTargetListener[] { + new CallHierarchyTransferDropAdapter(this, viewer) }; + viewer.addDropSupport(ops, transfers, + new DelegatingDropAdapter(dropListeners)); } private void addDragAdapters(StructuredViewer viewer) { @@ -379,8 +371,8 @@ public class CallHierarchyViewPart extends ViewPart implements createLocationViewer(fHierarchyLocationSplitter); // Page 2: Nothing selected - fNoHierarchyShownLabel = new Label(fPagebook, SWT.TOP + SWT.LEFT - + SWT.WRAP); + fNoHierarchyShownLabel = new Label(fPagebook, + SWT.TOP + SWT.LEFT + SWT.WRAP); fNoHierarchyShownLabel .setText(CallHierarchyMessages.CallHierarchyViewPart_empty); // @@ -395,7 +387,8 @@ public class CallHierarchyViewPart extends ViewPart implements } fSelectionProviderMediator = new CallHierarchySelectionProvider( - new StructuredViewer[] { fCallHierarchyViewer, fLocationViewer }); + new StructuredViewer[] { fCallHierarchyViewer, + fLocationViewer }); IStatusLineManager slManager = getViewSite().getActionBars() .getStatusLineManager(); @@ -403,12 +396,9 @@ public class CallHierarchyViewPart extends ViewPart implements .addSelectionChangedListener(new StatusBarUpdater(slManager)); getSite().setSelectionProvider(fSelectionProviderMediator); - fCallHierarchyViewer.initContextMenu(new IMenuListener() { - @Override - public void menuAboutToShow(IMenuManager menu) { - fillCallHierarchyViewerContextMenu(menu); - } - }, getSite(), fSelectionProviderMediator); + fCallHierarchyViewer.initContextMenu( + menu -> fillCallHierarchyViewerContextMenu(menu), getSite(), + fSelectionProviderMediator); fClipboard = new Clipboard(parent.getDisplay()); @@ -424,8 +414,8 @@ public class CallHierarchyViewPart extends ViewPart implements } restoreSplitterRatio(); addPartListener(); - IContextService ctxService = getSite().getService( - IContextService.class); + IContextService ctxService = getSite() + .getService(IContextService.class); if (ctxService != null) { fContextActivation = ctxService .activateContext(DLTKUIPlugin.CONTEXT_VIEWS); @@ -433,15 +423,14 @@ public class CallHierarchyViewPart extends ViewPart implements } private void restoreSplitterRatio() { - String ratio = fDialogSettings - .get(CallHierarchyViewPart.DIALOGSTORE_RATIO - + fCurrentOrientation); + String ratio = fDialogSettings.get( + CallHierarchyViewPart.DIALOGSTORE_RATIO + fCurrentOrientation); if (ratio == null) { return; } int intRatio = Integer.parseInt(ratio); - fHierarchyLocationSplitter.setWeights(new int[] { intRatio, - 1000 - intRatio }); + fHierarchyLocationSplitter + .setWeights(new int[] { intRatio, 1000 - intRatio }); } private void saveSplitterRatio() { @@ -467,16 +456,16 @@ public class CallHierarchyViewPart extends ViewPart implements @Override public void partClosed(IWorkbenchPartReference partRef) { - if (CallHierarchyViewPart.ID_CALL_HIERARCHY.equals(partRef - .getId())) { + if (CallHierarchyViewPart.ID_CALL_HIERARCHY + .equals(partRef.getId())) { saveViewSettings(); } } @Override public void partDeactivated(IWorkbenchPartReference partRef) { - if (CallHierarchyViewPart.ID_CALL_HIERARCHY.equals(partRef - .getId())) { + if (CallHierarchyViewPart.ID_CALL_HIERARCHY + .equals(partRef.getId())) { saveViewSettings(); } } @@ -532,9 +521,11 @@ public class CallHierarchyViewPart extends ViewPart implements Point size = fParent.getSize(); if (size.x != 0 && size.y != 0) { if (size.x > size.y) { - setOrientation(CallHierarchyViewPart.VIEW_ORIENTATION_HORIZONTAL); + setOrientation( + CallHierarchyViewPart.VIEW_ORIENTATION_HORIZONTAL); } else { - setOrientation(CallHierarchyViewPart.VIEW_ORIENTATION_VERTICAL); + setOrientation( + CallHierarchyViewPart.VIEW_ORIENTATION_VERTICAL); } } } @@ -614,7 +605,7 @@ public class CallHierarchyViewPart extends ViewPart implements } /** - * + * */ @Override public void dispose() { @@ -655,13 +646,14 @@ public class CallHierarchyViewPart extends ViewPart implements * (non-Javadoc) Method declared on IViewPart. */ @Override - public void init(IViewSite site, IMemento memento) throws PartInitException { + public void init(IViewSite site, IMemento memento) + throws PartInitException { super.init(site, memento); fMemento = memento; } /** - * + * */ public void refresh() { setCalleeRoot(null); @@ -737,15 +729,15 @@ public class CallHierarchyViewPart extends ViewPart implements if (editorPart instanceof ITextEditor) { ITextEditor editor = (ITextEditor) editorPart; editor.selectAndReveal(callLocation.getStart(), - (callLocation.getEnd() - callLocation - .getStart())); + (callLocation.getEnd() + - callLocation.getStart())); } } } else { IEditorPart editorPart = CallHierarchyUI.isOpenInEditor(elem); getSite().getPage().bringToTop(editorPart); - EditorUtility.revealInEditor(editorPart, ((MethodWrapper) elem) - .getMember()); + EditorUtility.revealInEditor(editorPart, + ((MethodWrapper) elem).getMember()); } } else if (elem instanceof IModelElement) { IEditorPart editorPart = EditorUtility.isOpenInEditor(elem); @@ -858,12 +850,9 @@ public class CallHierarchyViewPart extends ViewPart implements fLocationViewer.getControl().addKeyListener(createKeyListener()); - fLocationViewer.initContextMenu(new IMenuListener() { - @Override - public void menuAboutToShow(IMenuManager menu) { - fillLocationViewerContextMenu(menu); - } - }, CallHierarchyViewPart.ID_CALL_HIERARCHY, getSite()); + fLocationViewer.initContextMenu( + menu -> fillLocationViewerContextMenu(menu), + CallHierarchyViewPart.ID_CALL_HIERARCHY, getSite()); } private void createHierarchyLocationSplitter(Composite parent) { @@ -886,8 +875,8 @@ public class CallHierarchyViewPart extends ViewPart implements DLTKUIPlugin.createStandardGroups(menu); menu.appendToGroup(IContextMenuConstants.GROUP_SHOW, fRefreshAction); - menu.appendToGroup(IContextMenuConstants.GROUP_SHOW, new Separator( - CallHierarchyViewPart.GROUP_FOCUS)); + menu.appendToGroup(IContextMenuConstants.GROUP_SHOW, + new Separator(CallHierarchyViewPart.GROUP_FOCUS)); if (fFocusOnSelectionAction.canActionBeAdded()) { menu.appendToGroup(CallHierarchyViewPart.GROUP_FOCUS, @@ -927,23 +916,19 @@ public class CallHierarchyViewPart extends ViewPart implements } /** - * + * */ private void makeActions() { fRefreshAction = new RefreshAction(this); fOpenLocationAction = new OpenLocationAction(this, getSite()); - fLocationViewer.addOpenListener(new IOpenListener() { - @Override - public void open(OpenEvent event) { - fOpenLocationAction.run(); - } - }); + fLocationViewer.addOpenListener(event -> fOpenLocationAction.run()); fFocusOnSelectionAction = new FocusOnSelectionAction(this); fCopyAction = new CopyCallHierarchyAction(this, fClipboard, fCallHierarchyViewer); - fSearchScopeActions = new SearchScopeActionGroup(this, fDialogSettings) { + fSearchScopeActions = new SearchScopeActionGroup(this, + fDialogSettings) { @Override protected IDLTKLanguageToolkit getLangaugeToolkit() { return getMethodLanguageToolkit(); @@ -969,13 +954,13 @@ public class CallHierarchyViewPart extends ViewPart implements CallHierarchyViewPart.CALL_MODE_CALLERS), new ToggleCallModeAction(this, CallHierarchyViewPart.CALL_MODE_CALLEES) }; - fActionGroups = new CompositeActionGroup(new ActionGroup[] { - new OpenEditorActionGroup(this), new OpenViewActionGroup(this), - new CCPActionGroup(this), - // new GenerateActionGroup(this), - new RefactorActionGroup(this), - // new DLTKSearchActionGroup(this), - fSearchScopeActions, fFiltersActionGroup }); + fActionGroups = new CompositeActionGroup( + new ActionGroup[] { new OpenEditorActionGroup(this), + new OpenViewActionGroup(this), new CCPActionGroup(this), + // new GenerateActionGroup(this), + new RefactorActionGroup(this), + // new DLTKSearchActionGroup(this), + fSearchScopeActions, fFiltersActionGroup }); } protected IDLTKLanguageToolkit getMethodLanguageToolkit() { @@ -989,16 +974,16 @@ public class CallHierarchyViewPart extends ViewPart implements if (fShowCallDetails) { fHierarchyLocationSplitter.setMaximizedControl(null); } else { - fHierarchyLocationSplitter.setMaximizedControl(fCallHierarchyViewer - .getControl()); + fHierarchyLocationSplitter + .setMaximizedControl(fCallHierarchyViewer.getControl()); } } private void updateLocationsView(MethodWrapper methodWrapper) { if (methodWrapper != null && methodWrapper.getMethodCall().hasCallLocations()) { - fLocationViewer.setInput(methodWrapper.getMethodCall() - .getCallLocations()); + fLocationViewer + .setInput(methodWrapper.getMethodCall().getCallLocations()); } else { fLocationViewer.clearViewer(); } @@ -1034,10 +1019,9 @@ public class CallHierarchyViewPart extends ViewPart implements // the old contents: fCallHierarchyViewer.setInput(null); if (fCurrentCallMode == CallHierarchyViewPart.CALL_MODE_CALLERS) { - setContentDescription(Messages - .format( - CallHierarchyMessages.CallHierarchyViewPart_callsToMethod, - args)); + setContentDescription(Messages.format( + CallHierarchyMessages.CallHierarchyViewPart_callsToMethod, + args)); fCallHierarchyViewer.setSorter(new ViewerSorter()); // bug // 111423: // sort @@ -1046,17 +1030,17 @@ public class CallHierarchyViewPart extends ViewPart implements // alphabetically fCallHierarchyViewer.setMethodWrapper(getCallerRoot()); } else { - setContentDescription(Messages - .format( - CallHierarchyMessages.CallHierarchyViewPart_callsFromMethod, - args)); + setContentDescription(Messages.format( + CallHierarchyMessages.CallHierarchyViewPart_callsFromMethod, + args)); fCallHierarchyViewer.setSorter(null); fCallHierarchyViewer.setMethodWrapper(getCalleeRoot()); } } } - static CallHierarchyViewPart findAndShowCallersView(IWorkbenchPartSite site) { + static CallHierarchyViewPart findAndShowCallersView( + IWorkbenchPartSite site) { IWorkbenchPage workbenchPage = site.getPage(); CallHierarchyViewPart callersView = null; @@ -1079,7 +1063,7 @@ public class CallHierarchyViewPart extends ViewPart implements /** * Sets the enablement state of the cancel button. - * + * * @param enabled */ void setCancelEnabled(boolean enabled) { diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/dialogs/TypeSelectionComponent.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/dialogs/TypeSelectionComponent.java index fbc6fdffa..1b5f3013b 100644 --- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/dialogs/TypeSelectionComponent.java +++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/dialogs/TypeSelectionComponent.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * *******************************************************************************/ - package org.eclipse.dltk.internal.ui.dialogs; +package org.eclipse.dltk.internal.ui.dialogs; import java.io.IOException; import java.io.StringReader; @@ -33,8 +33,6 @@ import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.dialogs.DialogSettings; import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.SWT; import org.eclipse.swt.accessibility.AccessibleAdapter; import org.eclipse.swt.accessibility.AccessibleEvent; @@ -45,8 +43,6 @@ import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.events.TraverseEvent; -import org.eclipse.swt.events.TraverseListener; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; @@ -65,7 +61,8 @@ import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.WorkbenchException; import org.eclipse.ui.XMLMemento; -public class TypeSelectionComponent extends Composite implements ITypeSelectionComponent { +public class TypeSelectionComponent extends Composite + implements ITypeSelectionComponent { private IDialogSettings fSettings; private boolean fMultipleSelection; @@ -84,27 +81,29 @@ public class TypeSelectionComponent extends Composite implements ITypeSelectionC private ViewForm fForm; private CLabel fLabel; - public static final int NONE= 0; - public static final int CARET_BEGINNING= 1; - public static final int FULL_SELECTION= 2; + public static final int NONE = 0; + public static final int CARET_BEGINNING = 1; + public static final int FULL_SELECTION = 2; - private static final String DIALOG_SETTINGS= "org.eclipse.jdt.internal.ui.dialogs.TypeSelectionComponent"; //$NON-NLS-1$ - private static final String SHOW_STATUS_LINE= "show_status_line"; //$NON-NLS-1$ - private static final String WORKINGS_SET_SETTINGS= "workingset_settings"; //$NON-NLS-1$ + private static final String DIALOG_SETTINGS = "org.eclipse.jdt.internal.ui.dialogs.TypeSelectionComponent"; //$NON-NLS-1$ + private static final String SHOW_STATUS_LINE = "show_status_line"; //$NON-NLS-1$ + private static final String WORKINGS_SET_SETTINGS = "workingset_settings"; //$NON-NLS-1$ private IDLTKUILanguageToolkit fToolkit; private class ToggleStatusLineAction extends Action { public ToggleStatusLineAction() { - super(DLTKUIMessages.TypeSelectionComponent_show_status_line_label, IAction.AS_CHECK_BOX); + super(DLTKUIMessages.TypeSelectionComponent_show_status_line_label, + IAction.AS_CHECK_BOX); } + @Override public void run() { if (fForm == null) return; - GridData gd= (GridData)fForm.getLayoutData(); - boolean checked= isChecked(); - gd.exclude= !checked; + GridData gd = (GridData) fForm.getLayoutData(); + boolean checked = isChecked(); + gd.exclude = !checked; fForm.setVisible(checked); fSettings.put(SHOW_STATUS_LINE, checked); TypeSelectionComponent.this.layout(); @@ -112,33 +111,35 @@ public class TypeSelectionComponent extends Composite implements ITypeSelectionC } /** - * Special interface to access a title lable in - * a generic fashion. + * Special interface to access a title lable in a generic fashion. */ public interface ITitleLabel { /** * Sets the title to the given text * - * @param text the title text + * @param text + * the title text */ public void setText(String text); } - public TypeSelectionComponent(Composite parent, int style, String message, boolean multi, - IDLTKSearchScope scope, int elementKind, String initialFilter, ITitleLabel titleLabel, - TypeSelectionExtension extension, IDLTKUILanguageToolkit toolkit ) { + public TypeSelectionComponent(Composite parent, int style, String message, + boolean multi, IDLTKSearchScope scope, int elementKind, + String initialFilter, ITitleLabel titleLabel, + TypeSelectionExtension extension, IDLTKUILanguageToolkit toolkit) { super(parent, style); this.fToolkit = toolkit; setFont(parent.getFont()); - fMultipleSelection= multi; - fScope= scope; - fInitialFilterText= initialFilter; - fTitleLabel= titleLabel; - fTypeSelectionExtension= extension; - IDialogSettings settings= DLTKUIPlugin.getDefault().getDialogSettings(); - fSettings= settings.getSection(DIALOG_SETTINGS); + fMultipleSelection = multi; + fScope = scope; + fInitialFilterText = initialFilter; + fTitleLabel = titleLabel; + fTypeSelectionExtension = extension; + IDialogSettings settings = DLTKUIPlugin.getDefault() + .getDialogSettings(); + fSettings = settings.getSection(DIALOG_SETTINGS); if (fSettings == null) { - fSettings= new DialogSettings(DIALOG_SETTINGS); + fSettings = new DialogSettings(DIALOG_SETTINGS); settings.addSection(fSettings); } if (fSettings.get(SHOW_STATUS_LINE) == null) { @@ -161,24 +162,25 @@ public class TypeSelectionComponent extends Composite implements ITypeSelectionC } private void createContent(final String message, int elementKind) { - GridLayout layout= new GridLayout(); - layout.numColumns= 2; - layout.marginWidth= 0; layout.marginHeight= 0; + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.marginWidth = 0; + layout.marginHeight = 0; setLayout(layout); - Font font= getFont(); + Font font = getFont(); - Control header= createHeader(this, font, message); - GridData gd= new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan= 2; + Control header = createHeader(this, font, message); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 2; header.setLayoutData(gd); - fFilter= new Text(this, SWT.BORDER | SWT.FLAT); + fFilter = new Text(this, SWT.BORDER | SWT.FLAT); fFilter.setFont(font); if (fInitialFilterText != null) { fFilter.setText(fInitialFilterText); } - gd= new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan= 2; + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 2; fFilter.setLayoutData(gd); fFilter.addModifyListener(e -> patternChanged((Text) e.widget)); fFilter.addKeyListener(new KeyListener() { @@ -196,80 +198,87 @@ public class TypeSelectionComponent extends Composite implements ITypeSelectionC fFilter.getAccessible().addAccessibleListener(new AccessibleAdapter() { @Override public void getName(AccessibleEvent e) { - e.result= Strings.removeMnemonicIndicator(message); + e.result = Strings.removeMnemonicIndicator(message); } }); TextFieldNavigationHandler.install(fFilter); - Label label= new Label(this, SWT.NONE); + Label label = new Label(this, SWT.NONE); label.setFont(font); label.setText(DLTKUIMessages.TypeSelectionComponent_label); - label.addTraverseListener(new TraverseListener() { - @Override - public void keyTraversed(TraverseEvent e) { - if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) { - e.detail= SWT.TRAVERSE_NONE; - fViewer.setFocus(); - } + label.addTraverseListener(e -> { + if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) { + e.detail = SWT.TRAVERSE_NONE; + fViewer.setFocus(); } }); - label= new Label(this, SWT.RIGHT); + label = new Label(this, SWT.RIGHT); label.setFont(font); - gd= new GridData(GridData.FILL_HORIZONTAL); + gd = new GridData(GridData.FILL_HORIZONTAL); label.setLayoutData(gd); - fViewer = new TypeInfoViewer(this, fMultipleSelection ? SWT.MULTI - : SWT.NONE, label, fScope, elementKind, fInitialFilterText, - fTypeSelectionExtension != null ? fTypeSelectionExtension - .getFilterExtension() : null, - fTypeSelectionExtension != null ? fTypeSelectionExtension - .getImageProvider() : null, - fTypeSelectionExtension != null ? fTypeSelectionExtension - .getSearchPatternProcessor() : null, this.fToolkit); - gd= new GridData(GridData.FILL_BOTH); - final Table table= fViewer.getTable(); - PixelConverter converter= new PixelConverter(table); - gd.widthHint= converter.convertWidthInCharsToPixels(70); - gd.heightHint= SWTUtil.getTableHeightHint(table, 10); - gd.horizontalSpan= 2; + fViewer = new TypeInfoViewer(this, + fMultipleSelection ? SWT.MULTI : SWT.NONE, label, fScope, + elementKind, fInitialFilterText, + fTypeSelectionExtension != null + ? fTypeSelectionExtension.getFilterExtension() + : null, + fTypeSelectionExtension != null + ? fTypeSelectionExtension.getImageProvider() + : null, + fTypeSelectionExtension != null + ? fTypeSelectionExtension.getSearchPatternProcessor() + : null, + this.fToolkit); + gd = new GridData(GridData.FILL_BOTH); + final Table table = fViewer.getTable(); + PixelConverter converter = new PixelConverter(table); + gd.widthHint = converter.convertWidthInCharsToPixels(70); + gd.heightHint = SWTUtil.getTableHeightHint(table, 10); + gd.horizontalSpan = 2; table.setLayoutData(gd); table.getAccessible().addAccessibleListener(new AccessibleAdapter() { @Override public void getName(AccessibleEvent e) { if (table.getSelectionCount() == 0) { - e.result= Strings.removeMnemonicIndicator(DLTKUIMessages.TypeSelectionComponent_label); + e.result = Strings.removeMnemonicIndicator( + DLTKUIMessages.TypeSelectionComponent_label); } } }); if (fTypeSelectionExtension != null) { - Control addition= fTypeSelectionExtension.createContentArea(this); + Control addition = fTypeSelectionExtension.createContentArea(this); if (addition != null) { addition.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); } } if (!fMultipleSelection) { - fForm= new ViewForm(this, SWT.BORDER | SWT.FLAT); + fForm = new ViewForm(this, SWT.BORDER | SWT.FLAT); fForm.setFont(font); - gd= new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan= 2; - boolean showStatusLine= fSettings.getBoolean(SHOW_STATUS_LINE); - gd.exclude= !showStatusLine; + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 2; + boolean showStatusLine = fSettings.getBoolean(SHOW_STATUS_LINE); + gd.exclude = !showStatusLine; fForm.setVisible(showStatusLine); fForm.setLayoutData(gd); - fLabel= new CLabel(fForm, SWT.FLAT); + fLabel = new CLabel(fForm, SWT.FLAT); fLabel.setFont(fForm.getFont()); fForm.setContent(fLabel); table.addSelectionListener(new SelectionAdapter() { - private TypeNameMatchLabelProvider fLabelProvider= new TypeNameMatchLabelProvider( - TypeNameMatchLabelProvider.SHOW_TYPE_CONTAINER_ONLY + TypeNameMatchLabelProvider.SHOW_ROOT_POSTFIX, fToolkit); + private TypeNameMatchLabelProvider fLabelProvider = new TypeNameMatchLabelProvider( + TypeNameMatchLabelProvider.SHOW_TYPE_CONTAINER_ONLY + + TypeNameMatchLabelProvider.SHOW_ROOT_POSTFIX, + fToolkit); + @Override public void widgetSelected(SelectionEvent event) { - TypeNameMatch[] selection= fViewer.getSelection(); + TypeNameMatch[] selection = fViewer.getSelection(); if (selection.length != 1) { fLabel.setText(""); //$NON-NLS-1$ fLabel.setImage(null); } else { - TypeNameMatch type= selection[0]; - fLabel.setText(fViewer.getLabelProvider().getQualificationText(type)); + TypeNameMatch type = selection[0]; + fLabel.setText(fViewer.getLabelProvider() + .getQualificationText(type)); fLabel.setImage(fLabelProvider.getImage(type)); } } @@ -287,13 +296,13 @@ public class TypeSelectionComponent extends Composite implements ITypeSelectionC public void populate(int selectionMode) { if (fInitialFilterText != null) { - switch(selectionMode) { - case CARET_BEGINNING: - fFilter.setSelection(0, 0); - break; - case FULL_SELECTION: - fFilter.setSelection(0, fInitialFilterText.length()); - break; + switch (selectionMode) { + case CARET_BEGINNING: + fFilter.setSelection(0, 0); + break; + case FULL_SELECTION: + fFilter.setSelection(0, fInitialFilterText.length()); + break; } } fFilter.setFocus(); @@ -305,25 +314,23 @@ public class TypeSelectionComponent extends Composite implements ITypeSelectionC } private Control createHeader(Composite parent, Font font, String message) { - Composite header= new Composite(parent, SWT.NONE); - GridLayout layout= new GridLayout(); - layout.numColumns= 2; - layout.marginWidth= 0; layout.marginHeight= 0; + Composite header = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.marginWidth = 0; + layout.marginHeight = 0; header.setLayout(layout); header.setFont(font); - Label label= new Label(header, SWT.NONE); + Label label = new Label(header, SWT.NONE); label.setText(message); label.setFont(font); - label.addTraverseListener(new TraverseListener() { - @Override - public void keyTraversed(TraverseEvent e) { - if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) { - e.detail= SWT.TRAVERSE_NONE; - fFilter.setFocus(); - } + label.addTraverseListener(e -> { + if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) { + e.detail = SWT.TRAVERSE_NONE; + fFilter.setFocus(); } }); - GridData gd= new GridData(GridData.FILL_HORIZONTAL); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); label.setLayoutData(gd); createViewMenu(header); @@ -331,15 +338,15 @@ public class TypeSelectionComponent extends Composite implements ITypeSelectionC } private void createViewMenu(Composite parent) { - fToolBar= new ToolBar(parent, SWT.FLAT); - fToolItem= new ToolItem(fToolBar, SWT.PUSH, 0); + fToolBar = new ToolBar(parent, SWT.FLAT); + fToolItem = new ToolItem(fToolBar, SWT.PUSH, 0); - GridData data= new GridData(); - data.horizontalAlignment= GridData.END; + GridData data = new GridData(); + data.horizontalAlignment = GridData.END; fToolBar.setLayoutData(data); - fToolItem.setImage(DLTKUIPlugin.getImageDescriptorRegistry().get( - DLTKPluginImages.DESC_ELCL_VIEW_MENU)); + fToolItem.setImage(DLTKUIPlugin.getImageDescriptorRegistry() + .get(DLTKPluginImages.DESC_ELCL_VIEW_MENU)); fToolItem.setDisabledImage(DLTKUIPlugin.getImageDescriptorRegistry() .get(DLTKPluginImages.DESC_DLCL_VIEW_MENU)); fToolItem.setToolTipText(DLTKUIMessages.TypeSelectionComponent_menu); @@ -350,11 +357,13 @@ public class TypeSelectionComponent extends Composite implements ITypeSelectionC } }); - fMenuManager= new MenuManager(); + fMenuManager = new MenuManager(); fillViewMenu(fMenuManager); - // ICommandService commandService= (ICommandService)PlatformUI.getWorkbench().getAdapter(ICommandService.class); - // IHandlerService handlerService= (IHandlerService)PlatformUI.getWorkbench().getAdapter(IHandlerService.class); + // ICommandService commandService= + // (ICommandService)PlatformUI.getWorkbench().getAdapter(ICommandService.class); + // IHandlerService handlerService= + // (IHandlerService)PlatformUI.getWorkbench().getAdapter(IHandlerService.class); } private void showViewMenu() { @@ -368,42 +377,46 @@ public class TypeSelectionComponent extends Composite implements ITypeSelectionC private void fillViewMenu(IMenuManager viewMenu) { if (!fMultipleSelection) { - ToggleStatusLineAction showStatusLineAction= new ToggleStatusLineAction(); - showStatusLineAction.setChecked(fSettings.getBoolean(SHOW_STATUS_LINE)); + ToggleStatusLineAction showStatusLineAction = new ToggleStatusLineAction(); + showStatusLineAction + .setChecked(fSettings.getBoolean(SHOW_STATUS_LINE)); viewMenu.add(showStatusLineAction); } if (fScope == null) { - fFilterActionGroup= new WorkingSetFilterActionGroup(getShell(), - DLTKUIPlugin.getActivePage(), - new IPropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent event) { - IWorkingSet ws= (IWorkingSet)event.getNewValue(); - if (ws == null || (ws.isAggregateWorkingSet() && ws.isEmpty())) { - fScope= SearchEngine.createWorkspaceScope(fToolkit.getCoreToolkit()); + fFilterActionGroup = new WorkingSetFilterActionGroup(getShell(), + DLTKUIPlugin.getActivePage(), event -> { + IWorkingSet ws = (IWorkingSet) event.getNewValue(); + if (ws == null || (ws.isAggregateWorkingSet() + && ws.isEmpty())) { + fScope = SearchEngine.createWorkspaceScope( + fToolkit.getCoreToolkit()); fTitleLabel.setText(null); } else { - fScope= DLTKSearchScopeFactory.getInstance().createSearchScope(ws, true, fToolkit.getCoreToolkit()); + fScope = DLTKSearchScopeFactory.getInstance() + .createSearchScope(ws, true, + fToolkit.getCoreToolkit()); fTitleLabel.setText(ws.getLabel()); } fViewer.setSearchScope(fScope, true); - } - }); - String setting= fSettings.get(WORKINGS_SET_SETTINGS); + }); + String setting = fSettings.get(WORKINGS_SET_SETTINGS); if (setting != null) { try { - IMemento memento= XMLMemento.createReadRoot(new StringReader(setting)); + IMemento memento = XMLMemento + .createReadRoot(new StringReader(setting)); fFilterActionGroup.restoreState(memento); } catch (WorkbenchException e) { } } - IWorkingSet ws= fFilterActionGroup.getWorkingSet(); + IWorkingSet ws = fFilterActionGroup.getWorkingSet(); if (ws == null || (ws.isAggregateWorkingSet() && ws.isEmpty())) { - fScope= SearchEngine.createWorkspaceScope(fToolkit.getCoreToolkit()); + fScope = SearchEngine + .createWorkspaceScope(fToolkit.getCoreToolkit()); fTitleLabel.setText(null); } else { - fScope= DLTKSearchScopeFactory.getInstance().createSearchScope(ws, true, fToolkit.getCoreToolkit()); + fScope = DLTKSearchScopeFactory.getInstance() + .createSearchScope(ws, true, fToolkit.getCoreToolkit()); fTitleLabel.setText(ws.getLabel()); } fFilterActionGroup.fillViewMenu(viewMenu); @@ -412,13 +425,14 @@ public class TypeSelectionComponent extends Composite implements ITypeSelectionC private void disposeComponent() { if (fFilterActionGroup != null) { - XMLMemento memento= XMLMemento.createWriteRoot("workingSet"); //$NON-NLS-1$ + XMLMemento memento = XMLMemento.createWriteRoot("workingSet"); //$NON-NLS-1$ fFilterActionGroup.saveState(memento); fFilterActionGroup.dispose(); - StringWriter writer= new StringWriter(); + StringWriter writer = new StringWriter(); try { memento.save(writer); - fSettings.put(WORKINGS_SET_SETTINGS, writer.getBuffer().toString()); + fSettings.put(WORKINGS_SET_SETTINGS, + writer.getBuffer().toString()); } catch (IOException e) { // don't do anything. Simply don't store the settings } diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/editor/SourceModuleDocumentProvider.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/editor/SourceModuleDocumentProvider.java index 9cc27af5a..f47de2983 100644 --- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/editor/SourceModuleDocumentProvider.java +++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/editor/SourceModuleDocumentProvider.java @@ -95,7 +95,6 @@ import org.eclipse.jface.text.source.IAnnotationModelListenerExtension; import org.eclipse.jface.text.source.IAnnotationPresentation; import org.eclipse.jface.text.source.ImageUtilities; import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.GC; @@ -155,8 +154,9 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider /** * Annotation representing an <code>IProblem</code>. */ - static public class ProblemAnnotation extends Annotation implements - IScriptAnnotation, IAnnotationPresentation, IQuickFixableAnnotation { + static public class ProblemAnnotation extends Annotation + implements IScriptAnnotation, IAnnotationPresentation, + IQuickFixableAnnotation { public static final String SPELLING_ANNOTATION_TYPE = SpellingAnnotation.TYPE; @@ -327,10 +327,8 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider for (int i = 0; i < arguments.length; i++) { String ar = arguments[i]; if (ar.startsWith(IProblem.DESCRIPTION_ARGUMENT_PREFIX)) { - return fProblem.getMessage() - + '\n' - + ar.substring(IProblem.DESCRIPTION_ARGUMENT_PREFIX - .length()); + return fProblem.getMessage() + '\n' + ar.substring( + IProblem.DESCRIPTION_ARGUMENT_PREFIX.length()); } } } @@ -351,8 +349,7 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider public boolean isProblem() { String type = getType(); return ScriptMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(type) - || ScriptMarkerAnnotation.ERROR_ANNOTATION_TYPE - .equals(type) + || ScriptMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(type) || SPELLING_ANNOTATION_TYPE.equals(type); } @@ -434,9 +431,8 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider } /* - * @see - * org.eclipse.jface.text.quickassist.IQuickFixableAnnotation#isQuickFixable - * () + * @see org.eclipse.jface.text.quickassist.IQuickFixableAnnotation# + * isQuickFixable () * * @since 3.2 */ @@ -541,9 +537,9 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider * problems. Also acts as problem requester for its compilation unit. * Initially inactive. Must explicitly be activated. */ - public static class SourceModuleAnnotationModel extends - ResourceMarkerAnnotationModel implements IProblemRequestor, - IProblemRequestorExtension { + public static class SourceModuleAnnotationModel + extends ResourceMarkerAnnotationModel + implements IProblemRequestor, IProblemRequestorExtension { private static class ProblemRequestorState { boolean fInsideReportingSequence = false; @@ -922,8 +918,8 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider * problems. Also acts as problem requester for its compilation unit. * Initially inactive. Must explicitly be activated. */ - protected static class ExternalSourceModuleAnnotationModel extends - SourceModuleAnnotationModel { + protected static class ExternalSourceModuleAnnotationModel + extends SourceModuleAnnotationModel { private final IPath location; public ExternalSourceModuleAnnotationModel(IPath location) { @@ -1047,12 +1043,9 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider setParentDocumentProvider(provider); fGlobalAnnotationModelListener = new GlobalAnnotationModelListener(); - fPropertyListener = new IPropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent event) { - if (HANDLE_TEMPORARY_PROBLEMS.equals(event.getProperty())) - enableHandlingTemporaryProblems(); - } + fPropertyListener = event -> { + if (HANDLE_TEMPORARY_PROBLEMS.equals(event.getProperty())) + enableHandlingTemporaryProblems(); }; DLTKUIPlugin.getDefault().getPreferenceStore() .addPropertyChangeListener(fPropertyListener); @@ -1069,7 +1062,8 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider public ISourceModule fCopy; public IProblemRequestor getProblemRequestor() { - return fModel instanceof IProblemRequestor ? (IProblemRequestor) fModel + return fModel instanceof IProblemRequestor + ? (IProblemRequestor) fModel : null; } } @@ -1269,8 +1263,8 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider if (requestor instanceof IProblemRequestorExtension) { IProblemRequestorExtension extension = (IProblemRequestorExtension) requestor; extension.setIsActive(false); - extension - .setIsHandlingTemporaryProblems(isHandlingTemporaryProblems()); + extension.setIsHandlingTemporaryProblems( + isHandlingTemporaryProblems()); } if (ScriptModelUtil.isPrimary(original)) @@ -1348,11 +1342,9 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider // -> saveAs was executed with a target that is already open // in another editor // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=85519 - System.out - .println("SourceModuleDocumentProvider: need to replace with messages api"); //$NON-NLS-1$ - Status status = new Status( - IStatus.WARNING, - EditorsUI.PLUGIN_ID, + System.out.println( + "SourceModuleDocumentProvider: need to replace with messages api"); //$NON-NLS-1$ + Status status = new Status(IStatus.WARNING, EditorsUI.PLUGIN_ID, IStatus.ERROR, Messages.SourceModuleDocumentProvider_saveAsTargetOpenInEditor, null); @@ -1364,8 +1356,8 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider protected void execute(IProgressMonitor monitor) throws CoreException { - commitWorkingCopy(monitor, element, - (SourceModuleInfo) info, overwrite); + commitWorkingCopy(monitor, element, (SourceModuleInfo) info, + overwrite); } /* @@ -1436,7 +1428,8 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider try { if (listeners.length > 0) needsChangedRegions = SaveParticipantRegistry - .isChangedRegionsRequired(info.fCopy, listeners); + .isChangedRegionsRequired(info.fCopy, + listeners); } catch (CoreException ex) { changedRegionException = ex; } @@ -1623,7 +1616,8 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider } private ISourceModule createFakeSourceModule( - NonExistingFileEditorInput editorInput, IProblemRequestor requestor) { + NonExistingFileEditorInput editorInput, + IProblemRequestor requestor) { try { final IPath path = editorInput.getPath(editorInput); URI uri = URIUtil.toURI(path); @@ -1634,9 +1628,8 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider WorkingCopyOwner woc = new WorkingCopyOwner() { /* - * @see - * org.eclipse.jdt.core.WorkingCopyOwner#createBuffer(org.eclipse - * .jdt.core.ICompilationUnit) + * @see org.eclipse.jdt.core.WorkingCopyOwner#createBuffer(org. + * eclipse .jdt.core.ICompilationUnit) * * @since 3.2 */ @@ -1652,8 +1645,8 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider cpEntries = jp.getResolvedBuildpath(true); if (cpEntries == null || cpEntries.length == 0) - cpEntries = new IBuildpathEntry[] { ScriptRuntime - .getDefaultInterpreterContainerEntry() }; + cpEntries = new IBuildpathEntry[] { + ScriptRuntime.getDefaultInterpreterContainerEntry() }; final ISourceModule cu = woc.newWorkingCopy(fileStore.getName(), cpEntries, requestor, getProgressMonitor()); @@ -1679,9 +1672,8 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider WorkingCopyOwner woc = new WorkingCopyOwner() { /* - * @see - * org.eclipse.jdt.core.WorkingCopyOwner#createBuffer(org.eclipse - * .jdt.core.ICompilationUnit) + * @see org.eclipse.jdt.core.WorkingCopyOwner#createBuffer(org. + * eclipse .jdt.core.ICompilationUnit) * * @since 3.2 */ @@ -1697,8 +1689,8 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider cpEntries = jp.getResolvedBuildpath(true); if (cpEntries == null || cpEntries.length == 0) - cpEntries = new IBuildpathEntry[] { ScriptRuntime - .getDefaultInterpreterContainerEntry() }; + cpEntries = new IBuildpathEntry[] { + ScriptRuntime.getDefaultInterpreterContainerEntry() }; final ISourceModule cu = woc.newWorkingCopy(fileStoreName, cpEntries, requestor, getProgressMonitor()); @@ -1741,16 +1733,16 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider cpEntries = jp.getResolvedBuildpath(true); if (cpEntries == null || cpEntries.length == 0) - cpEntries = new IBuildpathEntry[] { ScriptRuntime - .getDefaultInterpreterContainerEntry() }; + cpEntries = new IBuildpathEntry[] { + ScriptRuntime.getDefaultInterpreterContainerEntry() }; final ISourceModule cu = woc.newWorkingCopy(storage.getName(), cpEntries, requestor, getProgressMonitor()); if (setContents) { int READER_CHUNK_SIZE = 2048; int BUFFER_SIZE = 8 * READER_CHUNK_SIZE; - Reader in = new BufferedReader(new InputStreamReader( - storage.getContents())); + Reader in = new BufferedReader( + new InputStreamReader(storage.getContents())); StringBuffer buffer = new StringBuffer(BUFFER_SIZE); char[] readBuffer = new char[READER_CHUNK_SIZE]; int n; @@ -1790,8 +1782,8 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider return null; String[] pathSegments = path.segments(); - IScriptModel model = DLTKCore.create(DLTKUIPlugin.getWorkspace() - .getRoot()); + IScriptModel model = DLTKCore + .create(DLTKUIPlugin.getWorkspace().getRoot()); IScriptProject[] projects; try { projects = model.getScriptProjects(); @@ -1874,15 +1866,13 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider if (stamp != unit.getResource() .getModificationStamp()) { - String msg = NLS - .bind(DLTKEditorMessages.CompilationUnitDocumentProvider_error_saveParticipantSavedFile, - participantName); - errorStatus - .add(new Status( - IStatus.ERROR, - DLTKUIPlugin.PLUGIN_ID, - IDLTKStatusConstants.EDITOR_POST_SAVE_NOTIFICATION, - msg, null)); + String msg = NLS.bind( + DLTKEditorMessages.CompilationUnitDocumentProvider_error_saveParticipantSavedFile, + participantName); + errorStatus.add(new Status(IStatus.ERROR, + DLTKUIPlugin.PLUGIN_ID, + IDLTKStatusConstants.EDITOR_POST_SAVE_NOTIFICATION, + msg, null)); } if (buffer.hasUnsavedChanges()) @@ -1898,36 +1888,32 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider @Override public void handleException(Throwable ex) { - String msg = NLS - .bind("The save participant ''{0}'' caused an exception: {1}", listener.getId(), ex.toString()); //$NON-NLS-1$ - DLTKUIPlugin - .log(new Status( - IStatus.ERROR, - DLTKUIPlugin.PLUGIN_ID, - IDLTKStatusConstants.EDITOR_POST_SAVE_NOTIFICATION, - msg, ex)); - - msg = NLS - .bind(DLTKEditorMessages.CompilationUnitDocumentProvider_error_saveParticipantFailed, - participantName, ex.toString()); - errorStatus - .add(new Status( - IStatus.ERROR, - DLTKUIPlugin.PLUGIN_ID, - IDLTKStatusConstants.EDITOR_POST_SAVE_NOTIFICATION, - msg, null)); + String msg = NLS.bind( + "The save participant ''{0}'' caused an exception: {1}", //$NON-NLS-1$ + listener.getId(), ex.toString()); + DLTKUIPlugin.log(new Status(IStatus.ERROR, + DLTKUIPlugin.PLUGIN_ID, + IDLTKStatusConstants.EDITOR_POST_SAVE_NOTIFICATION, + msg, ex)); + + msg = NLS.bind( + DLTKEditorMessages.CompilationUnitDocumentProvider_error_saveParticipantFailed, + participantName, ex.toString()); + errorStatus.add(new Status(IStatus.ERROR, + DLTKUIPlugin.PLUGIN_ID, + IDLTKStatusConstants.EDITOR_POST_SAVE_NOTIFICATION, + msg, null)); // Revert the changes if (buffer.hasUnsavedChanges()) { try { - info.fTextFileBuffer - .revert(getSubProgressMonitor(monitor, - 1)); + info.fTextFileBuffer.revert( + getSubProgressMonitor(monitor, 1)); } catch (CoreException e) { - msg = NLS - .bind("Error on revert after failure of save participant ''{0}''.", participantName); //$NON-NLS-1$ - IStatus status = new Status( - IStatus.ERROR, + msg = NLS.bind( + "Error on revert after failure of save participant ''{0}''.", //$NON-NLS-1$ + participantName); + IStatus status = new Status(IStatus.ERROR, DLTKUIPlugin.PLUGIN_ID, IDLTKStatusConstants.EDITOR_POST_SAVE_NOTIFICATION, msg, ex); @@ -1945,7 +1931,9 @@ public class SourceModuleDocumentProvider extends TextFileDocumentProvider // try { // buffer.save(getSubProgressMonitor(monitor, 1), true); // } catch (JavaModelException e) { - // message= Messages.format("Error reverting changes after failure of save participant ''{0}''.", participantName); //$NON-NLS-1$ + // message= Messages.format("Error reverting changes + // after failure of save participant ''{0}''.", + // participantName); //$NON-NLS-1$ // IStatus status= new Status(IStatus.ERROR, // JavaUI.ID_PLUGIN, IStatus.OK, message, ex); // JavaPlugin.getDefault().getLog().log(status); diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/filters/CustomFiltersDialog.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/filters/CustomFiltersDialog.java index a2d275f1b..c50162e63 100644 --- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/filters/CustomFiltersDialog.java +++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/filters/CustomFiltersDialog.java @@ -21,15 +21,11 @@ import org.eclipse.core.runtime.Assert; import org.eclipse.dltk.internal.ui.util.SWTUtil; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; -import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -45,11 +41,9 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.dialogs.SelectionDialog; - - public class CustomFiltersDialog extends SelectionDialog { - private static final String SEPARATOR= ","; //$NON-NLS-1$ + private static final String SEPARATOR = ","; //$NON-NLS-1$ private String fViewId; private boolean fEnablePatterns; @@ -64,21 +58,22 @@ public class CustomFiltersDialog extends SelectionDialog { private Stack fFilterDescriptorChangeHistory; - /** * Creates a dialog to customize script element filters. * - * @param shell the parent shell - * @param viewId the id of the view - * @param enablePatterns <code>true</code> if pattern filters are enabled - * @param patterns the filter patterns - * @param enabledFilterIds the Ids of the enabled filters + * @param shell + * the parent shell + * @param viewId + * the id of the view + * @param enablePatterns + * <code>true</code> if pattern filters are enabled + * @param patterns + * the filter patterns + * @param enabledFilterIds + * the Ids of the enabled filters */ - public CustomFiltersDialog( - Shell shell, - String viewId, - boolean enablePatterns, - String[] patterns, + public CustomFiltersDialog(Shell shell, String viewId, + boolean enablePatterns, String[] patterns, String[] enabledFilterIds) { super(shell); @@ -86,13 +81,13 @@ public class CustomFiltersDialog extends SelectionDialog { Assert.isNotNull(patterns); Assert.isNotNull(enabledFilterIds); - fViewId= viewId; - fPatterns= patterns; - fEnablePatterns= enablePatterns; - fEnabledFilterIds= enabledFilterIds; + fViewId = viewId; + fPatterns = patterns; + fEnablePatterns = enablePatterns; + fEnabledFilterIds = enabledFilterIds; - fBuiltInFilters= FilterDescriptor.getFilterDescriptors(fViewId); - fFilterDescriptorChangeHistory= new Stack(); + fBuiltInFilters = FilterDescriptor.getFilterDescriptors(fViewId); + fFilterDescriptorChangeHistory = new Stack(); setShellStyle(getShellStyle() | SWT.RESIZE); } @@ -101,8 +96,9 @@ public class CustomFiltersDialog extends SelectionDialog { setTitle(FilterMessages.CustomFiltersDialog_title); setMessage(FilterMessages.CustomFiltersDialog_filterList_label); super.configureShell(shell); - //TODO: help system - //PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IDLTKHelpContextIds.CUSTOM_FILTERS_DIALOG); + // TODO: help system + // PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, + // IDLTKHelpContextIds.CUSTOM_FILTERS_DIALOG); } /** @@ -114,32 +110,38 @@ public class CustomFiltersDialog extends SelectionDialog { protected Control createDialogArea(Composite parent) { initializeDialogUnits(parent); // create a composite with standard margins and spacing - Composite composite= new Composite(parent, SWT.NONE); - GridLayout layout= new GridLayout(); - layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); - layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); - layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginHeight = convertVerticalDLUsToPixels( + IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth = convertHorizontalDLUsToPixels( + IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing = convertVerticalDLUsToPixels( + IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing = convertHorizontalDLUsToPixels( + IDialogConstants.HORIZONTAL_SPACING); composite.setLayout(layout); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); composite.setFont(parent.getFont()); - Composite group= composite; + Composite group = composite; // Checkbox - fEnableUserDefinedPatterns= new Button(group, SWT.CHECK); + fEnableUserDefinedPatterns = new Button(group, SWT.CHECK); fEnableUserDefinedPatterns.setFocus(); - fEnableUserDefinedPatterns.setText(FilterMessages.CustomFiltersDialog_enableUserDefinedPattern); - - // Pattern field - fUserDefinedPatterns= new Text(group, SWT.SINGLE | SWT.BORDER); - GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); - data.widthHint= convertWidthInCharsToPixels(59); + fEnableUserDefinedPatterns.setText( + FilterMessages.CustomFiltersDialog_enableUserDefinedPattern); + + // Pattern field + fUserDefinedPatterns = new Text(group, SWT.SINGLE | SWT.BORDER); + GridData data = new GridData( + GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); + data.widthHint = convertWidthInCharsToPixels(59); fUserDefinedPatterns.setLayoutData(data); - String patterns= convertToString(fPatterns, SEPARATOR); + String patterns = convertToString(fPatterns, SEPARATOR); fUserDefinedPatterns.setText(patterns); // Info text - final Label info= new Label(group, SWT.LEFT); + final Label info = new Label(group, SWT.LEFT); info.setText(FilterMessages.CustomFiltersDialog_patternInfo); // Enabling / disabling of pattern group @@ -149,7 +151,7 @@ public class CustomFiltersDialog extends SelectionDialog { fEnableUserDefinedPatterns.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - boolean state= fEnableUserDefinedPatterns.getSelection(); + boolean state = fEnableUserDefinedPatterns.getSelection(); fUserDefinedPatterns.setEnabled(state); info.setEnabled(fEnableUserDefinedPatterns.getSelection()); if (state) @@ -169,12 +171,12 @@ public class CustomFiltersDialog extends SelectionDialog { // Filler new Label(parent, SWT.NONE); - Label info= new Label(parent, SWT.LEFT); + Label info = new Label(parent, SWT.LEFT); info.setText(FilterMessages.CustomFiltersDialog_filterList_label); - fCheckBoxList= CheckboxTableViewer.newCheckList(parent, SWT.BORDER); - GridData data= new GridData(GridData.FILL_BOTH); - data.heightHint= fCheckBoxList.getTable().getItemHeight() * 10; + fCheckBoxList = CheckboxTableViewer.newCheckList(parent, SWT.BORDER); + GridData data = new GridData(GridData.FILL_BOTH); + data.heightHint = fCheckBoxList.getTable().getItemHeight() * 10; fCheckBoxList.getTable().setLayoutData(data); fCheckBoxList.setLabelProvider(createLabelPrivder()); @@ -183,80 +185,78 @@ public class CustomFiltersDialog extends SelectionDialog { fCheckBoxList.setInput(fBuiltInFilters); setInitialSelections(getEnabledFilterDescriptors()); - List initialSelection= getInitialElementSelections(); + List initialSelection = getInitialElementSelections(); if (initialSelection != null && !initialSelection.isEmpty()) checkInitialSelections(); // Description - info= new Label(parent, SWT.LEFT); + info = new Label(parent, SWT.LEFT); info.setText(FilterMessages.CustomFiltersDialog_description_label); - final Text description= new Text(parent, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL); + final Text description = new Text(parent, SWT.LEFT | SWT.WRAP + | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL); data = new GridData(GridData.FILL_HORIZONTAL); - data.heightHint= convertHeightInCharsToPixels(3); + data.heightHint = convertHeightInCharsToPixels(3); description.setLayoutData(data); - fCheckBoxList.addSelectionChangedListener(new ISelectionChangedListener() { - @Override - public void selectionChanged(SelectionChangedEvent event) { - ISelection selection= event.getSelection(); - if (selection instanceof IStructuredSelection) { - Object selectedElement= ((IStructuredSelection)selection).getFirstElement(); - if (selectedElement instanceof FilterDescriptor) - description.setText(((FilterDescriptor)selectedElement).getDescription()); - } + fCheckBoxList.addSelectionChangedListener(event -> { + ISelection selection = event.getSelection(); + if (selection instanceof IStructuredSelection) { + Object selectedElement = ((IStructuredSelection) selection) + .getFirstElement(); + if (selectedElement instanceof FilterDescriptor) + description.setText(((FilterDescriptor) selectedElement) + .getDescription()); + } + }); + fCheckBoxList.addCheckStateListener(event -> { + Object element = event.getElement(); + if (element instanceof FilterDescriptor) { + // renew if already touched + if (fFilterDescriptorChangeHistory.contains(element)) + fFilterDescriptorChangeHistory.remove(element); + fFilterDescriptorChangeHistory.push(element); } }); - fCheckBoxList.addCheckStateListener(new ICheckStateListener() { - /* - * @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent) - */ - @Override - public void checkStateChanged(CheckStateChangedEvent event) { - Object element= event.getElement(); - if (element instanceof FilterDescriptor) { - // renew if already touched - if (fFilterDescriptorChangeHistory.contains(element)) - fFilterDescriptorChangeHistory.remove(element); - fFilterDescriptorChangeHistory.push(element); - } - }}); addSelectionButtons(parent); } private void addSelectionButtons(Composite composite) { - Composite buttonComposite= new Composite(composite, SWT.RIGHT); - GridLayout layout= new GridLayout(); - layout.numColumns= 2; + Composite buttonComposite = new Composite(composite, SWT.RIGHT); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; buttonComposite.setLayout(layout); - GridData data= new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL); - data.grabExcessHorizontalSpace= true; + GridData data = new GridData( + GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL); + data.grabExcessHorizontalSpace = true; composite.setData(data); // Select All button - String label= FilterMessages.CustomFiltersDialog_SelectAllButton_label; - Button selectButton= createButton(buttonComposite, IDialogConstants.SELECT_ALL_ID, label, false); + String label = FilterMessages.CustomFiltersDialog_SelectAllButton_label; + Button selectButton = createButton(buttonComposite, + IDialogConstants.SELECT_ALL_ID, label, false); SWTUtil.setButtonDimensionHint(selectButton); - SelectionListener listener= new SelectionAdapter() { + SelectionListener listener = new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { fCheckBoxList.setAllChecked(true); fFilterDescriptorChangeHistory.clear(); - for (int i= 0; i < fBuiltInFilters.length; i++) + for (int i = 0; i < fBuiltInFilters.length; i++) fFilterDescriptorChangeHistory.push(fBuiltInFilters[i]); } }; selectButton.addSelectionListener(listener); // De-select All button - label= FilterMessages.CustomFiltersDialog_DeselectAllButton_label; - Button deselectButton= createButton(buttonComposite, IDialogConstants.DESELECT_ALL_ID, label, false); + label = FilterMessages.CustomFiltersDialog_DeselectAllButton_label; + Button deselectButton = createButton(buttonComposite, + IDialogConstants.DESELECT_ALL_ID, label, false); SWTUtil.setButtonDimensionHint(deselectButton); - listener= new SelectionAdapter() { + listener = new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { fCheckBoxList.setAllChecked(false); fFilterDescriptorChangeHistory.clear(); - for (int i= 0; i < fBuiltInFilters.length; i++) + for (int i = 0; i < fBuiltInFilters.length; i++) fFilterDescriptorChangeHistory.push(fBuiltInFilters[i]); } }; @@ -264,16 +264,16 @@ public class CustomFiltersDialog extends SelectionDialog { } private void checkInitialSelections() { - Iterator itemsToCheck= getInitialElementSelections().iterator(); + Iterator itemsToCheck = getInitialElementSelections().iterator(); while (itemsToCheck.hasNext()) - fCheckBoxList.setChecked(itemsToCheck.next(),true); + fCheckBoxList.setChecked(itemsToCheck.next(), true); } @Override protected void okPressed() { if (fBuiltInFilters != null) { - ArrayList result= new ArrayList(); - for (int i= 0; i < fBuiltInFilters.length; ++i) { + ArrayList result = new ArrayList(); + for (int i = 0; i < fBuiltInFilters.length; ++i) { if (fCheckBoxList.getChecked(fBuiltInFilters[i])) result.add(fBuiltInFilters[i]); } @@ -283,21 +283,20 @@ public class CustomFiltersDialog extends SelectionDialog { } private ILabelProvider createLabelPrivder() { - return - new LabelProvider() { + return new LabelProvider() { @Override - public Image getImage(Object element) { - return null; - } + public Image getImage(Object element) { + return null; + } @Override - public String getText(Object element) { - if (element instanceof FilterDescriptor) - return ((FilterDescriptor)element).getName(); - else - return null; - } - }; + public String getText(Object element) { + if (element instanceof FilterDescriptor) + return ((FilterDescriptor) element).getName(); + else + return null; + } + }; } // ---------- result handling ---------- @@ -306,15 +305,15 @@ public class CustomFiltersDialog extends SelectionDialog { protected void setResult(List newResult) { super.setResult(newResult); if (fUserDefinedPatterns.getText().length() > 0) { - fEnablePatterns= fEnableUserDefinedPatterns.getSelection(); - fPatterns= convertFromString(fUserDefinedPatterns.getText(), SEPARATOR); + fEnablePatterns = fEnableUserDefinedPatterns.getSelection(); + fPatterns = convertFromString(fUserDefinedPatterns.getText(), + SEPARATOR); } else { - fEnablePatterns= false; - fPatterns= new String[0]; + fEnablePatterns = false; + fPatterns = new String[0]; } } - /** * @return the patterns which have been entered by the user */ @@ -326,10 +325,10 @@ public class CustomFiltersDialog extends SelectionDialog { * @return the Ids of the enabled built-in filters */ public String[] getEnabledFilterIds() { - Object[] result= getResult(); + Object[] result = getResult(); Set<String> enabledIds = new HashSet<String>(result.length); - for (int i= 0; i < result.length; i++) - enabledIds.add(((FilterDescriptor)result[i]).getId()); + for (int i = 0; i < result.length; i++) + enabledIds.add(((FilterDescriptor) result[i]).getId()); return enabledIds.toArray(new String[enabledIds.size()]); } @@ -349,41 +348,42 @@ public class CustomFiltersDialog extends SelectionDialog { } private FilterDescriptor[] getEnabledFilterDescriptors() { - FilterDescriptor[] filterDescs= fBuiltInFilters; + FilterDescriptor[] filterDescs = fBuiltInFilters; List<FilterDescriptor> result = new ArrayList<FilterDescriptor>( filterDescs.length); List<String> enabledFilterIds = Arrays.asList(fEnabledFilterIds); - for (int i= 0; i < filterDescs.length; i++) { - String id= filterDescs[i].getId(); + for (int i = 0; i < filterDescs.length; i++) { + String id = filterDescs[i].getId(); if (enabledFilterIds.contains(id)) result.add(filterDescs[i]); } return result.toArray(new FilterDescriptor[result.size()]); } - - public static String[] convertFromString(String patterns, String separator) { - StringTokenizer tokenizer= new StringTokenizer(patterns, separator, true); - int tokenCount= tokenizer.countTokens(); + public static String[] convertFromString(String patterns, + String separator) { + StringTokenizer tokenizer = new StringTokenizer(patterns, separator, + true); + int tokenCount = tokenizer.countTokens(); List<String> result = new ArrayList<String>(tokenCount); - boolean escape= false; - boolean append= false; + boolean escape = false; + boolean append = false; while (tokenizer.hasMoreTokens()) { - String token= tokenizer.nextToken().trim(); + String token = tokenizer.nextToken().trim(); if (separator.equals(token)) { if (!escape) - escape= true; + escape = true; else { addPattern(result, separator); - append= true; + append = true; } - } else { + } else { if (!append) - result.add(token); + result.add(token); else addPattern(result, token); - append= false; - escape= false; + append = false; + escape = false; } } return result.toArray(new String[result.size()]); @@ -393,19 +393,19 @@ public class CustomFiltersDialog extends SelectionDialog { if (list.isEmpty()) list.add(pattern); else { - int index= list.size() - 1; + int index = list.size() - 1; list.set(index, (list.get(index)) + pattern); } } public static String convertToString(String[] patterns, String separator) { - int length= patterns.length; - StringBuffer strBuf= new StringBuffer(); + int length = patterns.length; + StringBuffer strBuf = new StringBuffer(); if (length > 0) strBuf.append(escapeSeparator(patterns[0], separator)); else return ""; //$NON-NLS-1$ - int i= 1; + int i = 1; while (i < length) { strBuf.append(separator); strBuf.append(" "); //$NON-NLS-1$ @@ -415,10 +415,10 @@ public class CustomFiltersDialog extends SelectionDialog { } private static String escapeSeparator(String pattern, String separator) { - int length= pattern.length(); - StringBuffer buf= new StringBuffer(length); - for (int i= 0; i < length; i++) { - char ch= pattern.charAt(i); + int length = pattern.length(); + StringBuffer buf = new StringBuffer(length); + for (int i = 0; i < length; i++) { + char ch = pattern.charAt(i); if (separator.equals(String.valueOf(ch))) buf.append(ch); buf.append(ch); diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/workingsets/WorkingSetConfigurationDialog.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/workingsets/WorkingSetConfigurationDialog.java index 3bda54d5b..454045f8e 100644 --- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/workingsets/WorkingSetConfigurationDialog.java +++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/workingsets/WorkingSetConfigurationDialog.java @@ -23,15 +23,11 @@ import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; -import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; @@ -58,15 +54,16 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { private static class WorkingSetLabelProvider extends LabelProvider { private Map fIcons; + public WorkingSetLabelProvider() { - fIcons= new Hashtable(); + fIcons = new Hashtable(); } @Override public void dispose() { - Iterator iterator= fIcons.values().iterator(); + Iterator iterator = fIcons.values().iterator(); while (iterator.hasNext()) { - Image icon= (Image)iterator.next(); + Image icon = (Image) iterator.next(); icon.dispose(); } super.dispose(); @@ -75,13 +72,13 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { @Override public Image getImage(Object object) { Assert.isTrue(object instanceof IWorkingSet); - IWorkingSet workingSet= (IWorkingSet)object; - ImageDescriptor imageDescriptor= workingSet.getImageDescriptor(); + IWorkingSet workingSet = (IWorkingSet) object; + ImageDescriptor imageDescriptor = workingSet.getImageDescriptor(); if (imageDescriptor == null) return null; - Image icon= (Image)fIcons.get(imageDescriptor); + Image icon = (Image) fIcons.get(imageDescriptor); if (icon == null) { - icon= imageDescriptor.createImage(); + icon = imageDescriptor.createImage(); fIcons.put(imageDescriptor, icon); } return icon; @@ -90,35 +87,38 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { @Override public String getText(Object object) { Assert.isTrue(object instanceof IWorkingSet); - IWorkingSet workingSet= (IWorkingSet)object; + IWorkingSet workingSet = (IWorkingSet) object; return workingSet.getName(); } } private class Filter extends ViewerFilter { @Override - public boolean select(Viewer viewer, Object parentElement, Object element) { - IWorkingSet ws= (IWorkingSet)element; - String id= ws.getId(); + public boolean select(Viewer viewer, Object parentElement, + Object element) { + IWorkingSet ws = (IWorkingSet) element; + String id = ws.getId(); return WorkingSetIDs.OTHERS.equals(id) || WorkingSetIDs.SCRIPT.equals(id) || WorkingSetIDs.RESOURCE.equals(id) || isCompatible(ws) || isActive(ws); } + private boolean isCompatible(IWorkingSet set) { if (!set.isSelfUpdating() || set.isAggregateWorkingSet()) return false; - IAdaptable[] elements= set.getElements(); + IAdaptable[] elements = set.getElements(); if (elements.length == 0) return false; - for (int i= 0; i < elements.length; i++) { - IAdaptable element= elements[i]; + for (int i = 0; i < elements.length; i++) { + IAdaptable element = elements[i]; IProject p = element.getAdapter(IProject.class); if (p == null || p.exists()) return true; } return false; } + private boolean isActive(IWorkingSet workingSet) { return fActiveWorkingSets.contains(workingSet); } @@ -142,16 +142,17 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { private Map fEditedWorkingSets; private List fRemovedMRUWorkingSets; - private int nextButtonId= IDialogConstants.CLIENT_ID + 1; + private int nextButtonId = IDialogConstants.CLIENT_ID + 1; - public WorkingSetConfigurationDialog(Shell parentShell, IWorkingSet[] allWorkingSets, IWorkingSet[] activeWorkingSets) { + public WorkingSetConfigurationDialog(Shell parentShell, + IWorkingSet[] allWorkingSets, IWorkingSet[] activeWorkingSets) { super(parentShell); setTitle(WorkingSetMessages.WorkingSetConfigurationDialog_title); setMessage(WorkingSetMessages.WorkingSetConfigurationDialog_message); - fAllWorkingSets= new ArrayList(allWorkingSets.length); - fActiveWorkingSets= Arrays.asList(activeWorkingSets); - Filter filter= new Filter(); - for (int i= 0; i < allWorkingSets.length; i++) { + fAllWorkingSets = new ArrayList(allWorkingSets.length); + fActiveWorkingSets = Arrays.asList(activeWorkingSets); + Filter filter = new Filter(); + for (int i = 0; i < allWorkingSets.length; i++) { if (filter.select(null, null, allWorkingSets[i])) fAllWorkingSets.add(allWorkingSets[i]); } @@ -170,10 +171,11 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { /** * Sets the initial selection * - * @param workingSets the initial selection + * @param workingSets + * the initial selection */ public void setSelection(IWorkingSet[] workingSets) { - fResult= workingSets; + fResult = workingSets; setInitialSelections(workingSets); } @@ -182,7 +184,7 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { */ @Override protected Control createContents(Composite parent) { - Control control= super.createContents(parent); + Control control = super.createContents(parent); setInitialSelection(); updateButtonAvailability(); return control; @@ -193,17 +195,17 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { */ @Override protected Control createDialogArea(Composite parent) { - Composite composite= (Composite)super.createDialogArea(parent); + Composite composite = (Composite) super.createDialogArea(parent); composite.setFont(parent.getFont()); createMessageArea(composite); - Composite inner= new Composite(composite, SWT.NONE); + Composite inner = new Composite(composite, SWT.NONE); inner.setFont(composite.getFont()); inner.setLayoutData(new GridData(GridData.FILL_BOTH)); - GridLayout layout= new GridLayout(); - layout.numColumns= 2; - layout.marginHeight= 0; - layout.marginWidth= 0; + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.marginHeight = 0; + layout.marginWidth = 0; inner.setLayout(layout); createTableViewer(inner); createOrderButtons(inner); @@ -214,16 +216,12 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { } private void createTableViewer(Composite parent) { - fTableViewer= CheckboxTableViewer.newCheckList(parent, SWT.BORDER | SWT.MULTI); - fTableViewer.addCheckStateListener(new ICheckStateListener() { - @Override - public void checkStateChanged(CheckStateChangedEvent event) { - updateButtonAvailability(); - } - }); - GridData data= new GridData(GridData.FILL_BOTH); - data.heightHint= convertHeightInCharsToPixels(20); - data.widthHint= convertWidthInCharsToPixels(50); + fTableViewer = CheckboxTableViewer.newCheckList(parent, + SWT.BORDER | SWT.MULTI); + fTableViewer.addCheckStateListener(event -> updateButtonAvailability()); + GridData data = new GridData(GridData.FILL_BOTH); + data.heightHint = convertHeightInCharsToPixels(20); + data.widthHint = convertWidthInCharsToPixels(50); fTableViewer.getTable().setLayoutData(data); fTableViewer.getTable().setFont(parent.getFont()); @@ -232,7 +230,7 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { fTableViewer.setContentProvider(new IStructuredContentProvider() { @Override public Object[] getElements(Object element) { - return ((List)element).toArray(); + return ((List) element).toArray(); } @Override @@ -240,28 +238,27 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { } @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - }); - fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { - @Override - public void selectionChanged(SelectionChangedEvent event) { - handleSelectionChanged(); + public void inputChanged(Viewer viewer, Object oldInput, + Object newInput) { } }); + fTableViewer + .addSelectionChangedListener(event -> handleSelectionChanged()); } private void createModifyButtons(Composite composite) { - Composite buttonComposite= new Composite(composite, SWT.RIGHT); - GridLayout layout= new GridLayout(); - layout.numColumns= 2; + Composite buttonComposite = new Composite(composite, SWT.RIGHT); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; buttonComposite.setLayout(layout); - GridData data= new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL); - data.grabExcessHorizontalSpace= true; + GridData data = new GridData( + GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL); + data.grabExcessHorizontalSpace = true; composite.setData(data); - fNewButton= createButton(buttonComposite, nextButtonId++, - WorkingSetMessages.WorkingSetConfigurationDialog_new_label, false); + fNewButton = createButton(buttonComposite, nextButtonId++, + WorkingSetMessages.WorkingSetConfigurationDialog_new_label, + false); fNewButton.setFont(composite.getFont()); fNewButton.addSelectionListener(new SelectionAdapter() { @Override @@ -270,8 +267,9 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { } }); - fEditButton= createButton(buttonComposite, nextButtonId++, - WorkingSetMessages.WorkingSetConfigurationDialog_edit_label, false); + fEditButton = createButton(buttonComposite, nextButtonId++, + WorkingSetMessages.WorkingSetConfigurationDialog_edit_label, + false); fEditButton.setFont(composite.getFont()); fEditButton.addSelectionListener(new SelectionAdapter() { @Override @@ -280,8 +278,9 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { } }); - fRemoveButton= createButton(buttonComposite, nextButtonId++, - WorkingSetMessages.WorkingSetConfigurationDialog_remove_label, false); + fRemoveButton = createButton(buttonComposite, nextButtonId++, + WorkingSetMessages.WorkingSetConfigurationDialog_remove_label, + false); fRemoveButton.setFont(composite.getFont()); fRemoveButton.addSelectionListener(new SelectionAdapter() { @Override @@ -292,38 +291,43 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { } private void createOrderButtons(Composite parent) { - Composite buttons= new Composite(parent, SWT.NONE); + Composite buttons = new Composite(parent, SWT.NONE); buttons.setFont(parent.getFont()); buttons.setLayoutData(new GridData(GridData.FILL_VERTICAL)); - GridLayout layout= new GridLayout(); - layout.marginHeight= 0; - layout.marginWidth= 0; + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; buttons.setLayout(layout); - fUpButton= new Button(buttons, SWT.PUSH); - fUpButton.setText(WorkingSetMessages.WorkingSetConfigurationDialog_up_label); + fUpButton = new Button(buttons, SWT.PUSH); + fUpButton.setText( + WorkingSetMessages.WorkingSetConfigurationDialog_up_label); fUpButton.setFont(parent.getFont()); setButtonLayoutData(fUpButton); fUpButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - moveUp(((IStructuredSelection)fTableViewer.getSelection()).toList()); + moveUp(((IStructuredSelection) fTableViewer.getSelection()) + .toList()); } }); - fDownButton= new Button(buttons, SWT.PUSH); - fDownButton.setText(WorkingSetMessages.WorkingSetConfigurationDialog_down_label); + fDownButton = new Button(buttons, SWT.PUSH); + fDownButton.setText( + WorkingSetMessages.WorkingSetConfigurationDialog_down_label); fDownButton.setFont(parent.getFont()); setButtonLayoutData(fDownButton); fDownButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - moveDown(((IStructuredSelection)fTableViewer.getSelection()).toList()); + moveDown(((IStructuredSelection) fTableViewer.getSelection()) + .toList()); } }); - fSelectAll= new Button(buttons, SWT.PUSH); - fSelectAll.setText(WorkingSetMessages.WorkingSetConfigurationDialog_selectAll_label); + fSelectAll = new Button(buttons, SWT.PUSH); + fSelectAll.setText( + WorkingSetMessages.WorkingSetConfigurationDialog_selectAll_label); fSelectAll.setFont(parent.getFont()); setButtonLayoutData(fSelectAll); fSelectAll.addSelectionListener(new SelectionAdapter() { @@ -333,8 +337,9 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { } }); - fDeselectAll= new Button(buttons, SWT.PUSH); - fDeselectAll.setText(WorkingSetMessages.WorkingSetConfigurationDialog_deselectAll_label); + fDeselectAll = new Button(buttons, SWT.PUSH); + fDeselectAll.setText( + WorkingSetMessages.WorkingSetConfigurationDialog_deselectAll_label); fDeselectAll.setFont(parent.getFont()); setButtonLayoutData(fDeselectAll); fDeselectAll.addSelectionListener(new SelectionAdapter() { @@ -350,14 +355,15 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { */ @Override protected void okPressed() { - List newResult= getResultWorkingSets(); - fResult= (IWorkingSet[])newResult.toArray(new IWorkingSet[newResult.size()]); + List newResult = getResultWorkingSets(); + fResult = (IWorkingSet[]) newResult + .toArray(new IWorkingSet[newResult.size()]); setResult(newResult); super.okPressed(); } private List getResultWorkingSets() { - Object[] checked= fTableViewer.getCheckedElements(); + Object[] checked = fTableViewer.getCheckedElements(); return new ArrayList(Arrays.asList(checked)); } @@ -373,25 +379,29 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { } private void setInitialSelection() { - List selections= getInitialElementSelections(); + List selections = getInitialElementSelections(); if (!selections.isEmpty()) { fTableViewer.setCheckedElements(selections.toArray()); } } private void createWorkingSet() { - IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager(); - IWorkingSetNewWizard wizard= manager.createWorkingSetNewWizard(new String[] {WorkingSetIDs.SCRIPT}); - // the wizard can't be null since we have at least the Script working set. - WizardDialog dialog= new WizardDialog(getShell(), wizard); + IWorkingSetManager manager = PlatformUI.getWorkbench() + .getWorkingSetManager(); + IWorkingSetNewWizard wizard = manager.createWorkingSetNewWizard( + new String[] { WorkingSetIDs.SCRIPT }); + // the wizard can't be null since we have at least the Script working + // set. + WizardDialog dialog = new WizardDialog(getShell(), wizard); dialog.create(); if (dialog.open() == Window.OK) { - IWorkingSet workingSet= wizard.getSelection(); - Filter filter= new Filter(); + IWorkingSet workingSet = wizard.getSelection(); + Filter filter = new Filter(); if (filter.select(null, null, workingSet)) { fAllWorkingSets.add(workingSet); fTableViewer.add(workingSet); - fTableViewer.setSelection(new StructuredSelection(workingSet), true); + fTableViewer.setSelection(new StructuredSelection(workingSet), + true); fTableViewer.setChecked(workingSet, true); manager.addWorkingSet(workingSet); fAddedWorkingSets.add(workingSet); @@ -400,25 +410,30 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { } private void editSelectedWorkingSet() { - IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager(); - IWorkingSet editWorkingSet= (IWorkingSet)((IStructuredSelection)fTableViewer.getSelection()).getFirstElement(); - IWorkingSetEditWizard wizard= manager.createWorkingSetEditWizard(editWorkingSet); - WizardDialog dialog= new WizardDialog(getShell(), wizard); - IWorkingSet originalWorkingSet= (IWorkingSet)fEditedWorkingSets.get(editWorkingSet); - boolean firstEdit= originalWorkingSet == null; + IWorkingSetManager manager = PlatformUI.getWorkbench() + .getWorkingSetManager(); + IWorkingSet editWorkingSet = (IWorkingSet) ((IStructuredSelection) fTableViewer + .getSelection()).getFirstElement(); + IWorkingSetEditWizard wizard = manager + .createWorkingSetEditWizard(editWorkingSet); + WizardDialog dialog = new WizardDialog(getShell(), wizard); + IWorkingSet originalWorkingSet = (IWorkingSet) fEditedWorkingSets + .get(editWorkingSet); + boolean firstEdit = originalWorkingSet == null; // save the original working set values for restoration when selection // dialog is cancelled. if (firstEdit) { - originalWorkingSet= - PlatformUI.getWorkbench().getWorkingSetManager(). - createWorkingSet(editWorkingSet.getName(), editWorkingSet.getElements()); + originalWorkingSet = PlatformUI.getWorkbench() + .getWorkingSetManager() + .createWorkingSet(editWorkingSet.getName(), + editWorkingSet.getElements()); } else { fEditedWorkingSets.remove(editWorkingSet); } dialog.create(); if (dialog.open() == Window.OK) { - editWorkingSet= wizard.getSelection(); + editWorkingSet = wizard.getSelection(); fTableViewer.update(editWorkingSet, null); // make sure ok button is enabled when the selected working set // is edited. Fixes bug 33386. @@ -441,10 +456,10 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { */ @Override public int open() { - fAddedWorkingSets= new ArrayList(); - fRemovedWorkingSets= new ArrayList(); - fEditedWorkingSets= new HashMap(); - fRemovedMRUWorkingSets= new ArrayList(); + fAddedWorkingSets = new ArrayList(); + fRemovedWorkingSets = new ArrayList(); + fEditedWorkingSets = new HashMap(); + fRemovedMRUWorkingSets = new ArrayList(); return super.open(); } @@ -452,17 +467,19 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { * Removes the selected working sets from the workbench. */ private void removeSelectedWorkingSets() { - ISelection selection= fTableViewer.getSelection(); + ISelection selection = fTableViewer.getSelection(); if (selection instanceof IStructuredSelection) { - IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager(); - Iterator iter= ((IStructuredSelection)selection).iterator(); + IWorkingSetManager manager = PlatformUI.getWorkbench() + .getWorkingSetManager(); + Iterator iter = ((IStructuredSelection) selection).iterator(); while (iter.hasNext()) { - IWorkingSet workingSet= (IWorkingSet)iter.next(); + IWorkingSet workingSet = (IWorkingSet) iter.next(); if (fAddedWorkingSets.contains(workingSet)) { fAddedWorkingSets.remove(workingSet); } else { - IWorkingSet[] recentWorkingSets= manager.getRecentWorkingSets(); - for (int i= 0; i < recentWorkingSets.length; i++) { + IWorkingSet[] recentWorkingSets = manager + .getRecentWorkingSets(); + for (int i = 0; i < recentWorkingSets.length; i++) { if (workingSet.equals(recentWorkingSets[i])) { fRemovedMRUWorkingSets.add(workingSet); break; @@ -473,7 +490,7 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { fAllWorkingSets.remove(workingSet); manager.removeWorkingSet(workingSet); } - fTableViewer.remove(((IStructuredSelection)selection).toArray()); + fTableViewer.remove(((IStructuredSelection) selection).toArray()); } } @@ -481,11 +498,12 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { * Removes newly created working sets from the working set manager. */ private void restoreAddedWorkingSets() { - IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager(); - Iterator iterator= fAddedWorkingSets.iterator(); + IWorkingSetManager manager = PlatformUI.getWorkbench() + .getWorkingSetManager(); + Iterator iterator = fAddedWorkingSets.iterator(); while (iterator.hasNext()) { - manager.removeWorkingSet(((IWorkingSet)iterator.next())); + manager.removeWorkingSet(((IWorkingSet) iterator.next())); } } @@ -493,16 +511,19 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { * Rolls back changes to working sets. */ private void restoreChangedWorkingSets() { - Iterator iterator= fEditedWorkingSets.keySet().iterator(); + Iterator iterator = fEditedWorkingSets.keySet().iterator(); while (iterator.hasNext()) { - IWorkingSet editedWorkingSet= (IWorkingSet)iterator.next(); - IWorkingSet originalWorkingSet= (IWorkingSet)fEditedWorkingSets.get(editedWorkingSet); + IWorkingSet editedWorkingSet = (IWorkingSet) iterator.next(); + IWorkingSet originalWorkingSet = (IWorkingSet) fEditedWorkingSets + .get(editedWorkingSet); - if (editedWorkingSet.getName().equals(originalWorkingSet.getName()) == false) { + if (editedWorkingSet.getName() + .equals(originalWorkingSet.getName()) == false) { editedWorkingSet.setName(originalWorkingSet.getName()); } - if (editedWorkingSet.getElements().equals(originalWorkingSet.getElements()) == false) { + if (editedWorkingSet.getElements() + .equals(originalWorkingSet.getElements()) == false) { editedWorkingSet.setElements(originalWorkingSet.getElements()); } } @@ -512,15 +533,16 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { * Adds back removed working sets to the working set manager. */ private void restoreRemovedWorkingSets() { - IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager(); - Iterator iterator= fRemovedWorkingSets.iterator(); + IWorkingSetManager manager = PlatformUI.getWorkbench() + .getWorkingSetManager(); + Iterator iterator = fRemovedWorkingSets.iterator(); while (iterator.hasNext()) { - manager.addWorkingSet(((IWorkingSet)iterator.next())); + manager.addWorkingSet(((IWorkingSet) iterator.next())); } - iterator= fRemovedMRUWorkingSets.iterator(); + iterator = fRemovedMRUWorkingSets.iterator(); while (iterator.hasNext()) { - manager.addRecentWorkingSet(((IWorkingSet)iterator.next())); + manager.addRecentWorkingSet(((IWorkingSet) iterator.next())); } } @@ -528,12 +550,15 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { * Updates the modify buttons' enabled state based on the current seleciton. */ private void updateButtonAvailability() { - IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection(); - boolean hasSelection= !selection.isEmpty(); - boolean hasSingleSelection= selection.size() == 1; - - fRemoveButton.setEnabled(hasSelection && areAllGlobalWorkingSets(selection)); - fEditButton.setEnabled(hasSingleSelection && ((IWorkingSet)selection.getFirstElement()).isEditable()); + IStructuredSelection selection = (IStructuredSelection) fTableViewer + .getSelection(); + boolean hasSelection = !selection.isEmpty(); + boolean hasSingleSelection = selection.size() == 1; + + fRemoveButton + .setEnabled(hasSelection && areAllGlobalWorkingSets(selection)); + fEditButton.setEnabled(hasSingleSelection + && ((IWorkingSet) selection.getFirstElement()).isEditable()); if (fUpButton != null) { fUpButton.setEnabled(canMoveUp()); } @@ -543,8 +568,9 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { } private boolean areAllGlobalWorkingSets(IStructuredSelection selection) { - Set globals= new HashSet(Arrays.asList(PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets())); - for (Iterator iter= selection.iterator(); iter.hasNext();) { + Set globals = new HashSet(Arrays.asList(PlatformUI.getWorkbench() + .getWorkingSetManager().getWorkingSets())); + for (Iterator iter = selection.iterator(); iter.hasNext();) { if (!globals.contains(iter.next())) return false; } @@ -566,24 +592,24 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { } private void setElements(List elements) { - fAllWorkingSets= elements; + fAllWorkingSets = elements; fTableViewer.setInput(fAllWorkingSets); updateButtonAvailability(); } private List moveUp(List elements, List move) { - int nElements= elements.size(); - List res= new ArrayList(nElements); - Object floating= null; - for (int i= 0; i < nElements; i++) { - Object curr= elements.get(i); + int nElements = elements.size(); + List res = new ArrayList(nElements); + Object floating = null; + for (int i = 0; i < nElements; i++) { + Object curr = elements.get(i); if (move.contains(curr)) { res.add(curr); } else { if (floating != null) { res.add(floating); } - floating= curr; + floating = curr; } } if (floating != null) { @@ -593,16 +619,16 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { } private List reverse(List p) { - List reverse= new ArrayList(p.size()); - for (int i= p.size() - 1; i >= 0; i--) { + List reverse = new ArrayList(p.size()); + for (int i = p.size() - 1; i >= 0; i--) { reverse.add(p.get(i)); } return reverse; } private boolean canMoveUp() { - int[] indc= fTableViewer.getTable().getSelectionIndices(); - for (int i= 0; i < indc.length; i++) { + int[] indc = fTableViewer.getTable().getSelectionIndices(); + for (int i = 0; i < indc.length; i++) { if (indc[i] != i) { return true; } @@ -611,9 +637,9 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { } private boolean canMoveDown() { - int[] indc= fTableViewer.getTable().getSelectionIndices(); - int k= fAllWorkingSets.size() - 1; - for (int i= indc.length - 1; i >= 0; i--, k--) { + int[] indc = fTableViewer.getTable().getSelectionIndices(); + int k = fAllWorkingSets.size() - 1; + for (int i = indc.length - 1; i >= 0; i--, k--) { if (indc[i] != k) { return true; } @@ -621,7 +647,7 @@ public class WorkingSetConfigurationDialog extends SelectionDialog { return false; } - //---- select / deselect -------------------------------------------------- + // ---- select / deselect -------------------------------------------------- private void selectAll() { fTableViewer.setAllChecked(true); diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/ProblemsLabelDecorator.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/ProblemsLabelDecorator.java index c9522bed3..a94a6eca3 100644 --- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/ProblemsLabelDecorator.java +++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/ProblemsLabelDecorator.java @@ -54,8 +54,8 @@ import org.eclipse.ui.texteditor.MarkerAnnotation; * the <code>org.eclipse.ui.decorators</code> extension. Only use this class in * your own views and label providers. */ -public class ProblemsLabelDecorator implements ILabelDecorator, - ILightweightLabelDecorator { +public class ProblemsLabelDecorator + implements ILabelDecorator, ILightweightLabelDecorator { /** * This is a special <code>LabelProviderChangedEvent</code> carrying @@ -65,8 +65,8 @@ public class ProblemsLabelDecorator implements ILabelDecorator, * ProblemsLabelDecorator</code>s. * </p> */ - public static class ProblemsLabelChangedEvent extends - LabelProviderChangedEvent { + public static class ProblemsLabelChangedEvent + extends LabelProviderChangedEvent { private static final long serialVersionUID = 1L; @@ -153,9 +153,8 @@ public class ProblemsLabelDecorator implements ILabelDecorator, if (adornmentFlags != 0) { ImageDescriptor baseImage = new ImageImageDescriptor(image); Rectangle bounds = image.getBounds(); - return getRegistry().get( - new ScriptElementImageDescriptor(baseImage, adornmentFlags, - new Point(bounds.width, bounds.height))); + return getRegistry().get(new ScriptElementImageDescriptor(baseImage, + adornmentFlags, new Point(bounds.width, bounds.height))); } return image; } @@ -198,7 +197,8 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ISourceModule cu = (ISourceModule) element .getAncestor(IModelElement.SOURCE_MODULE); if (cu != null) { - ISourceReference ref = (type == IModelElement.SOURCE_MODULE) ? null + ISourceReference ref = (type == IModelElement.SOURCE_MODULE) + ? null : (ISourceReference) element; // The assumption is that only source elements in // compilation unit can have markers @@ -246,7 +246,8 @@ public class ProblemsLabelDecorator implements ILabelDecorator, IMarker[] markers = res.findMarkers(IMarker.PROBLEM, true, depth); if (markers != null) { - for (int i = 0; i < markers.length && (info != ERRORTICK_ERROR); i++) { + for (int i = 0; i < markers.length + && (info != ERRORTICK_ERROR); i++) { IMarker curr = markers[i]; if (sourceElement == null || isMarkerInRange(curr, sourceElement)) { @@ -349,7 +350,8 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ISourceRange range = fCachedRange; if (range != null) { int rangeOffset = range.getOffset(); - return (rangeOffset <= pos && rangeOffset + range.getLength() > pos); + return (rangeOffset <= pos + && rangeOffset + range.getLength() > pos); } return false; } @@ -378,13 +380,9 @@ public class ProblemsLabelDecorator implements ILabelDecorator, } fListeners.add(listener); if (fProblemChangedListener == null) { - fProblemChangedListener = new IProblemChangedListener() { - @Override - public void problemsChanged(IResource[] changedResources, - boolean isMarkerChange) { - fireProblemsChanged(changedResources, isMarkerChange); - } - }; + fProblemChangedListener = (changedResources, + isMarkerChange) -> fireProblemsChanged(changedResources, + isMarkerChange); DLTKUIPlugin.getDefault().getProblemMarkerManager() .addListener(fProblemChangedListener); } diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/browsing/ProjectsView.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/browsing/ProjectsView.java index a2db63f88..dcc893da5 100644 --- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/browsing/ProjectsView.java +++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/browsing/ProjectsView.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -25,9 +25,7 @@ import org.eclipse.dltk.ui.DLTKUIPlugin; import org.eclipse.dltk.ui.PreferenceConstants; import org.eclipse.dltk.ui.viewsupport.FilterUpdater; import org.eclipse.dltk.ui.viewsupport.ProblemTreeViewer; -import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IContentProvider; -import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; @@ -41,11 +39,6 @@ public class ProjectsView extends ScriptBrowsingPart { private FilterUpdater fFilterUpdater; - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.ui.browsing.JavaBrowsingPart#createViewer(org.eclipse.swt.widgets.Composite) - */ @Override protected StructuredViewer createViewer(Composite parent) { ProblemTreeViewer result = new ProblemTreeViewer(parent, SWT.MULTI); @@ -56,16 +49,11 @@ public class ProjectsView extends ScriptBrowsingPart { return result; } - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.ui.browsing.JavaBrowsingPart#dispose() - */ @Override public void dispose() { if (fFilterUpdater != null) - ResourcesPlugin.getWorkspace().removeResourceChangeListener( - fFilterUpdater); + ResourcesPlugin.getWorkspace() + .removeResourceChangeListener(fFilterUpdater); super.dispose(); } @@ -82,11 +70,6 @@ public class ProjectsView extends ScriptBrowsingPart { return super.getAdapter(key); } - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.ui.browsing.JavaBrowsingPart#createContentProvider() - */ @Override protected IContentProvider createContentProvider() { return new ProjectAndSourceFolderContentProvider(this, getToolkit()); @@ -94,7 +77,7 @@ public class ProjectsView extends ScriptBrowsingPart { /** * Returns the context ID for the Help system. - * + * * @return the string used as ID for the Help context */ @Override @@ -114,31 +97,27 @@ public class ProjectsView extends ScriptBrowsingPart { @Override protected void hookViewerListeners() { super.hookViewerListeners(); - getViewer().addDoubleClickListener(new IDoubleClickListener() { - @Override - public void doubleClick(DoubleClickEvent event) { - TreeViewer viewer = (TreeViewer) getViewer(); - Object element = ((IStructuredSelection) event.getSelection()) - .getFirstElement(); - if (viewer.isExpandable(element)) - viewer.setExpandedState(element, !viewer - .getExpandedState(element)); - } + getViewer().addDoubleClickListener(event -> { + TreeViewer viewer = (TreeViewer) getViewer(); + Object element = ((IStructuredSelection) event.getSelection()) + .getFirstElement(); + if (viewer.isExpandable(element)) + viewer.setExpandedState(element, + !viewer.getExpandedState(element)); }); } @Override protected void setInitialInput() { - IModelElement root = DLTKCore.create(DLTKUIPlugin.getWorkspace() - .getRoot()); + IModelElement root = DLTKCore + .create(DLTKUIPlugin.getWorkspace().getRoot()); getViewer().setInput(root); updateTitle(); } /** - * Answers if the given <code>element</code> is a valid input for this - * part. - * + * Answers if the given <code>element</code> is a valid input for this part. + * * @param element * the object to test * @return <true> if the given element is a valid input @@ -151,29 +130,30 @@ public class ProjectsView extends ScriptBrowsingPart { /** * Answers if the given <code>element</code> is a valid element for this * part. - * + * * @param element * the object to test * @return <true> if the given element is a valid element */ @Override protected boolean isValidElement(Object element) { - if (!(element instanceof IScriptProject || element instanceof IProjectFragment)) { + if (!(element instanceof IScriptProject + || element instanceof IProjectFragment)) { return false; } IDLTKLanguageToolkit languageToolkit; languageToolkit = DLTKLanguageManager .getLanguageToolkit((IModelElement) element); if (languageToolkit != null) { - return languageToolkit.getNatureId().equals( - getToolkit().getNatureId()); + return languageToolkit.getNatureId() + .equals(getToolkit().getNatureId()); } return false; } /** * Finds the element which has to be selected in this part. - * + * * @param je * the Java element which has the focus * @return the element to select @@ -189,8 +169,8 @@ public class ProjectsView extends ScriptBrowsingPart { case IModelElement.SCRIPT_PROJECT: return je; case IModelElement.PROJECT_FRAGMENT: - if (je.getElementName().equals( - IProjectFragment.DEFAULT_PACKAGE_ROOT)) + if (je.getElementName() + .equals(IProjectFragment.DEFAULT_PACKAGE_ROOT)) return je.getParent(); else return je; @@ -199,9 +179,6 @@ public class ProjectsView extends ScriptBrowsingPart { } } - /* - * @see JavaBrowsingPart#setInput(Object) - */ @Override protected void setInput(Object input) { // Don't allow to clear input for this view @@ -219,7 +196,7 @@ public class ProjectsView extends ScriptBrowsingPart { /** * Handles selection of LogicalPackage in Packages view. - * + * * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, * org.eclipse.jface.viewers.ISelection) * @since 2.1 diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/browsing/ScriptBrowsingPart.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/browsing/ScriptBrowsingPart.java index 9b6bcdab3..679fb14bd 100644 --- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/browsing/ScriptBrowsingPart.java +++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/browsing/ScriptBrowsingPart.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -72,13 +72,9 @@ import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.IContentProvider; import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.IOpenListener; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.OpenEvent; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.search.internal.ui.Messages; @@ -116,8 +112,8 @@ import org.eclipse.ui.part.ShowInContext; import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.texteditor.ITextEditor; -public abstract class ScriptBrowsingPart extends ViewPart implements - IMenuListener, ISelectionListener, IViewPartInputProvider, +public abstract class ScriptBrowsingPart extends ViewPart + implements IMenuListener, ISelectionListener, IViewPartInputProvider, IExecutableExtension { private static final String TAG_SELECTED_ELEMENTS = "selectedElements"; //$NON-NLS-1$ @@ -210,7 +206,8 @@ public abstract class ScriptBrowsingPart extends ViewPart implements * Implements method from IViewPart. */ @Override - public void init(IViewSite site, IMemento memento) throws PartInitException { + public void init(IViewSite site, IMemento memento) + throws PartInitException { super.init(site, memento); fMemento = memento; } @@ -248,10 +245,9 @@ public abstract class ScriptBrowsingPart extends ViewPart implements .createChild(TAG_SELECTED_ELEMENT); Object o = elements[i]; if (o instanceof IModelElement) - elementMem - .putString(TAG_SELECTED_ELEMENT_PATH, - ((IModelElement) elements[i]) - .getHandleIdentifier()); + elementMem.putString(TAG_SELECTED_ELEMENT_PATH, + ((IModelElement) elements[i]) + .getHandleIdentifier()); else if (o instanceof LogicalPackage) { IScriptFolder[] packages = ((LogicalPackage) o) .getScriptFolders(); @@ -330,10 +326,9 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /* * (non-Javadoc) - * - * @see - * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets - * .Composite) + * + * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt. + * widgets .Composite) */ @Override public void createPartControl(Composite parent) { @@ -392,8 +387,8 @@ public abstract class ScriptBrowsingPart extends ViewPart implements getViewSite().getPage().addPartListener(fPartListener); fillActionBars(getViewSite().getActionBars()); - IContextService ctxService = getSite().getService( - IContextService.class); + IContextService ctxService = getSite() + .getService(IContextService.class); if (ctxService != null) { fContextActivation = ctxService .activateContext(DLTKUIPlugin.CONTEXT_VIEWS); @@ -415,17 +410,12 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /** * Returns the <code>IShowInSource</code> for this view. - * + * * @return returns the <code>IShowInSource</code> */ protected IShowInSource getShowInSource() { - return new IShowInSource() { - @Override - public ShowInContext getShowInContext() { - return new ShowInContext(null, getSite().getSelectionProvider() - .getSelection()); - } - }; + return () -> new ShowInContext(null, + getSite().getSelectionProvider().getSelection()); } /** @@ -433,7 +423,8 @@ public abstract class ScriptBrowsingPart extends ViewPart implements */ protected ILabelProvider createDelegatingLabelProvider( ScriptUILabelProvider provider) { - DecoratingModelLabelProvider labelprovider = createDecoratingLabelProvider(provider); + DecoratingModelLabelProvider labelprovider = createDecoratingLabelProvider( + provider); if (labelprovider != null) return labelprovider; return new StyledDecoratingModelLabelProvider(provider); @@ -441,7 +432,8 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /** * @deprecated override - * org.eclipse.dltk.ui.browsing.ScriptBrowsingPart.createDelegatingLabelProvider (ScriptUILabelProvider) instead + * org.eclipse.dltk.ui.browsing.ScriptBrowsingPart.createDelegatingLabelProvider + * (ScriptUILabelProvider) instead */ @Deprecated protected DecoratingModelLabelProvider createDecoratingLabelProvider( @@ -499,8 +491,8 @@ public abstract class ScriptBrowsingPart extends ViewPart implements fillToolBar(toolBar); if (fHasWorkingSetFilter) - fWorkingSetFilterActionGroup.fillActionBars(getViewSite() - .getActionBars()); + fWorkingSetFilterActionGroup + .fillActionBars(getViewSite().getActionBars()); actionBars.updateActionBars(); @@ -576,7 +568,7 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /* * (non-Javadoc) - * + * * @see * org.eclipse.jface.action.IMenuListener#menuAboutToShow(org.eclipse.jface * .action.IMenuManager) @@ -626,16 +618,12 @@ public abstract class ScriptBrowsingPart extends ViewPart implements if (fHasWorkingSetFilter) { String viewId = getConfigurationElement().getAttribute("id"); //$NON-NLS-1$ Assert.isNotNull(viewId); - IPropertyChangeListener workingSetListener = new IPropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent event) { - doWorkingSetChanged(event); - } - }; + IPropertyChangeListener workingSetListener = event -> doWorkingSetChanged( + event); fWorkingSetFilterActionGroup = new WorkingSetFilterActionGroup( getSite(), workingSetListener); - fViewer.addFilter(fWorkingSetFilterActionGroup - .getWorkingSetFilter()); + fViewer.addFilter( + fWorkingSetFilterActionGroup.getWorkingSetFilter()); } // Custom filter group @@ -663,7 +651,7 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /** * Returns the shell to use for opening dialogs. Used in this class, and in * the actions. - * + * * @return returns the shell */ Shell getShell() { @@ -676,7 +664,7 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /** * Returns the selection provider. - * + * * @return the selection provider */ ISelectionProvider getSelectionProvider() { @@ -685,7 +673,7 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /** * Answers if the given <code>element</code> is a valid input for this part. - * + * * @param element * the object to test * @return <code>true</code> if the given element is a valid input @@ -695,7 +683,7 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /** * Answers if the given <code>element</code> is a valid element for this * part. - * + * * @param element * the object to test * @return <code>true</code> if the given element is a valid element @@ -751,9 +739,8 @@ public abstract class ScriptBrowsingPart extends ViewPart implements protected boolean isAncestorOf(Object ancestor, Object element) { if (element instanceof IModelElement && ancestor instanceof IModelElement) - return !element.equals(ancestor) - && internalIsAncestorOf((IModelElement) ancestor, - (IModelElement) element); + return !element.equals(ancestor) && internalIsAncestorOf( + (IModelElement) ancestor, (IModelElement) element); if (element instanceof IModelElement && ancestor instanceof List) { List l = (List) ancestor; for (Iterator iterator = l.iterator(); iterator.hasNext();) { @@ -783,8 +770,8 @@ public abstract class ScriptBrowsingPart extends ViewPart implements protected boolean needsToProcessSelectionChanged(IWorkbenchPart part, ISelection selection) { - if (!fProcessSelectionEvents || part == this - || isSearchResultView(part) || part instanceof AbstractInfoView) { + if (!fProcessSelectionEvents || part == this || isSearchResultView(part) + || part instanceof AbstractInfoView) { if (part == this) fPreviousSelectionProvider = part; return false; @@ -818,9 +805,8 @@ public abstract class ScriptBrowsingPart extends ViewPart implements Object currentInput = getViewer().getInput(); if (selectedElement != null && selectedElement.equals(currentInput)) { Object elementToSelect = findElementToSelect(selectedElement); - if (elementToSelect != null - && getTypeComparator().compare(selectedElement, - elementToSelect) < 0) + if (elementToSelect != null && getTypeComparator() + .compare(selectedElement, elementToSelect) < 0) setSelection(new StructuredSelection(elementToSelect), true); else if (elementToSelect == null && (this instanceof MembersView)) { setSelection(StructuredSelection.EMPTY, true); @@ -891,7 +877,7 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /** * Returns the tool tip text for the given element. - * + * * @param element * the element * @return the tooltip for the element @@ -920,14 +906,13 @@ public abstract class ScriptBrowsingPart extends ViewPart implements new String[] { ws.getLabel() }); if (result.length() == 0) return wsstr; - return Messages.format( - ScriptBrowsingMessages.JavaBrowsingPart_toolTip2, new String[] { - result, ws.getLabel() }); + return Messages.format(ScriptBrowsingMessages.JavaBrowsingPart_toolTip2, + new String[] { result, ws.getLabel() }); } /* * (non-Javadoc) - * + * * @see org.eclipse.ui.part.WorkbenchPart#getTitleToolTip() */ @Override @@ -949,8 +934,8 @@ public abstract class ScriptBrowsingPart extends ViewPart implements return new AppearanceAwareLabelProvider( AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS, AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS - | ScriptElementImageProvider.SMALL_ICONS, DLTKUIPlugin - .getDefault().getPreferenceStore()); + | ScriptElementImageProvider.SMALL_ICONS, + DLTKUIPlugin.getDefault().getPreferenceStore()); } protected ILabelProvider createTitleProvider() { @@ -969,7 +954,7 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /** * Creates the viewer of this part. - * + * * @param parent * the parent for the viewer * @return the created viewer @@ -995,7 +980,7 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /** * Creates the content provider of this part. - * + * * @return the content provider */ protected IContentProvider createContentProvider() { @@ -1062,14 +1047,14 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /** * Returns the context ID for the Help system - * + * * @return the string used as ID for the Help context */ abstract protected String getHelpContextId(); /** * Returns the preference key for the link to editor setting. - * + * * @return the string used as key into the preference store */ abstract protected String getLinkToEditorKey(); @@ -1079,37 +1064,28 @@ public abstract class ScriptBrowsingPart extends ViewPart implements * should call super. */ protected void hookViewerListeners() { - fViewer - .addPostSelectionChangedListener(new ISelectionChangedListener() { - @Override - public void selectionChanged(SelectionChangedEvent event) { - if (!fProcessSelectionEvents) - return; - - fPreviousSelectedElement = getSingleElementFromSelection(event - .getSelection()); - - IWorkbenchPage page = getSite().getPage(); - if (page == null) - return; - - if (page.equals(DLTKUIPlugin.getActivePage()) - && ScriptBrowsingPart.this.equals(page - .getActivePart())) { - linkToEditor((IStructuredSelection) event - .getSelection()); - } - } - }); + fViewer.addPostSelectionChangedListener(event -> { + if (!fProcessSelectionEvents) + return; - fViewer.addOpenListener(new IOpenListener() { - @Override - public void open(OpenEvent event) { - IAction open = fOpenEditorGroup.getOpenAction(); - if (open.isEnabled()) { - open.run(); - restoreSelection(); - } + fPreviousSelectedElement = getSingleElementFromSelection( + event.getSelection()); + + IWorkbenchPage page = getSite().getPage(); + if (page == null) + return; + + if (page.equals(DLTKUIPlugin.getActivePage()) + && ScriptBrowsingPart.this.equals(page.getActivePart())) { + linkToEditor((IStructuredSelection) event.getSelection()); + } + }); + + fViewer.addOpenListener(event -> { + IAction open = fOpenEditorGroup.getOpenAction(); + if (open.isEnabled()) { + open.run(); + restoreSelection(); } }); } @@ -1154,7 +1130,7 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /** * Compute if a new input must be set. - * + * * @param elementToSelect * the element to select * @param oldInput @@ -1167,16 +1143,18 @@ public abstract class ScriptBrowsingPart extends ViewPart implements private boolean mustSetNewInput(IModelElement elementToSelect, IModelElement oldInput, IModelElement newInput) { return (newInput == null || !newInput.equals(oldInput)) - && (elementToSelect == null || oldInput == null || (!((elementToSelect instanceof IPackageDeclaration) - && (elementToSelect.getParent().equals(oldInput - .getParent())) && (!isAncestorOf( - getViewPartInput(), elementToSelect))))); + && (elementToSelect == null || oldInput == null + || (!((elementToSelect instanceof IPackageDeclaration) + && (elementToSelect.getParent() + .equals(oldInput.getParent())) + && (!isAncestorOf(getViewPartInput(), + elementToSelect))))); } /** * Finds the closest Java element which can be used as input for this part * and has the given Java element as child - * + * * @param je * the Java element for which to search the closest input * @return the closest Java element used as input for this part @@ -1200,7 +1178,7 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /** * Finds the element which has to be selected in this part. - * + * * @param je * the Java element which has the focus * @return returns the element to select @@ -1233,9 +1211,8 @@ public abstract class ScriptBrowsingPart extends ViewPart implements } Object currentInput = getViewer().getInput(); List elements = new ArrayList(); - if (currentInput == null - || !currentInput - .equals(findInputForJavaElement((IModelElement) firstElement))) + if (currentInput == null || !currentInput + .equals(findInputForJavaElement((IModelElement) firstElement))) if (iter.hasNext() && selection instanceof StructuredSelection) { // multi-selection and view is empty return ((StructuredSelection) selection).toList(); @@ -1257,7 +1234,7 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /** * Gets the typeComparator. - * + * * @return Returns a JavaElementTypeComparator */ protected Comparator getTypeComparator() { @@ -1266,7 +1243,7 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /** * Links to editor (if option enabled) - * + * * @param selection * the selection */ @@ -1317,14 +1294,12 @@ public abstract class ScriptBrowsingPart extends ViewPart implements } if (ei instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) ei).getFile(); - IModelElement je = file - .getAdapter(IModelElement.class); + IModelElement je = file.getAdapter(IModelElement.class); if (je == null) { IContainer container = ((IFileEditorInput) ei).getFile() .getParent(); if (container != null) - je = container - .getAdapter(IModelElement.class); + je = container.getAdapter(IModelElement.class); } if (je == null) { setSelection(null, false); @@ -1332,16 +1307,16 @@ public abstract class ScriptBrowsingPart extends ViewPart implements } adjustInputAndSetSelection(je); } /* - * else if (ei instanceof IClassFileEditorInput) { IClassFile cf = - * ((IClassFileEditorInput) ei).getClassFile(); - * adjustInputAndSetSelection(cf); } - */ + * else if (ei instanceof IClassFileEditorInput) { IClassFile cf + * = ((IClassFileEditorInput) ei).getClassFile(); + * adjustInputAndSetSelection(cf); } + */ } } /** * Returns the element contained in the EditorInput - * + * * @param input * the editor input * @return the input element @@ -1415,7 +1390,7 @@ public abstract class ScriptBrowsingPart extends ViewPart implements /* * (non-Javadoc) - * + * * @seeorg.eclipse.jdt.internal.ui.viewsupport.IViewPartInputProvider# * getViewPartInput() */ @@ -1474,8 +1449,8 @@ public abstract class ScriptBrowsingPart extends ViewPart implements public void setLinkingEnabled(boolean enabled) { fLinkingEnabled = enabled; - DLTKUIPlugin.getDefault().getPreferenceStore().setValue( - getLinkToEditorKey(), enabled); + DLTKUIPlugin.getDefault().getPreferenceStore() + .setValue(getLinkToEditorKey(), enabled); if (enabled) { IEditorPart editor = getSite().getPage().getActiveEditor(); if (editor != null) { diff --git a/core/plugins/org.eclipse.dltk.ui/ui refactoring/org/eclipse/dltk/internal/ui/refactoring/reorg/ReorgMoveWizard.java b/core/plugins/org.eclipse.dltk.ui/ui refactoring/org/eclipse/dltk/internal/ui/refactoring/reorg/ReorgMoveWizard.java index b59c8a688..74d3a4d7f 100644 --- a/core/plugins/org.eclipse.dltk.ui/ui refactoring/org/eclipse/dltk/internal/ui/refactoring/reorg/ReorgMoveWizard.java +++ b/core/plugins/org.eclipse.dltk.ui/ui refactoring/org/eclipse/dltk/internal/ui/refactoring/reorg/ReorgMoveWizard.java @@ -26,17 +26,12 @@ import org.eclipse.ltk.ui.refactoring.RefactoringWizard; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.TraverseEvent; -import org.eclipse.swt.events.TraverseListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; - - - public class ReorgMoveWizard extends RefactoringWizard { public ReorgMoveWizard(MoveRefactoring ref) { @@ -48,13 +43,16 @@ public class ReorgMoveWizard extends RefactoringWizard { } private static boolean isTextualMove(MoveRefactoring ref) { - ScriptMoveProcessor moveProcessor= (ScriptMoveProcessor) ref.getAdapter(ScriptMoveProcessor.class); + ScriptMoveProcessor moveProcessor = (ScriptMoveProcessor) ref + .getAdapter(ScriptMoveProcessor.class); return moveProcessor.isTextualMove(); } private static int computeHasPreviewPage(MoveRefactoring refactoring) { - ScriptMoveProcessor processor= (ScriptMoveProcessor)refactoring.getAdapter(ScriptMoveProcessor.class); - if (processor.canUpdateReferences() || processor.canEnableQualifiedNameUpdating()) + ScriptMoveProcessor processor = (ScriptMoveProcessor) refactoring + .getAdapter(ScriptMoveProcessor.class); + if (processor.canUpdateReferences() + || processor.canEnableQualifiedNameUpdating()) return NONE; return NO_PREVIEW_PAGE; } @@ -64,9 +62,9 @@ public class ReorgMoveWizard extends RefactoringWizard { addPage(new MoveInputPage()); } - private static class MoveInputPage extends ReorgUserInputPage{ + private static class MoveInputPage extends ReorgUserInputPage { - private static final String PAGE_NAME= "MoveInputPage"; //$NON-NLS-1$ + private static final String PAGE_NAME = "MoveInputPage"; //$NON-NLS-1$ private Button fReferenceCheckbox; private Button fQualifiedNameCheckbox; private QualifiedNameComponent fQualifiedNameComponent; @@ -78,8 +76,9 @@ public class ReorgMoveWizard extends RefactoringWizard { super(PAGE_NAME); } - private ScriptMoveProcessor getScriptMoveProcessor(){ - return (ScriptMoveProcessor)getRefactoring().getAdapter(ScriptMoveProcessor.class); + private ScriptMoveProcessor getScriptMoveProcessor() { + return (ScriptMoveProcessor) getRefactoring() + .getAdapter(ScriptMoveProcessor.class); } @Override @@ -104,91 +103,115 @@ public class ReorgMoveWizard extends RefactoringWizard { @Override protected boolean performFinish() { - return super.performFinish() || getScriptMoveProcessor().wasCanceled(); //close the dialog if canceled + return super.performFinish() + || getScriptMoveProcessor().wasCanceled(); // close the + // dialog if + // canceled } @Override - protected RefactoringStatus verifyDestination(Object selected) throws ModelException{ - ScriptMoveProcessor processor= getScriptMoveProcessor(); + protected RefactoringStatus verifyDestination(Object selected) + throws ModelException { + ScriptMoveProcessor processor = getScriptMoveProcessor(); final RefactoringStatus refactoringStatus; if (selected instanceof IModelElement) - refactoringStatus= processor.setDestination((IModelElement)selected); + refactoringStatus = processor + .setDestination((IModelElement) selected); else if (selected instanceof IResource) - refactoringStatus= processor.setDestination((IResource)selected); - else refactoringStatus= RefactoringStatus.createFatalErrorStatus(ReorgMessages.ReorgMoveWizard_4); + refactoringStatus = processor + .setDestination((IResource) selected); + else + refactoringStatus = RefactoringStatus.createFatalErrorStatus( + ReorgMessages.ReorgMoveWizard_4); updateUIStatus(); - fDestination= selected; + fDestination = selected; return refactoringStatus; } private void updateUIStatus() { getRefactoringWizard().setForcePreviewReview(false); - ScriptMoveProcessor processor= getScriptMoveProcessor(); - if (fReferenceCheckbox != null){ + ScriptMoveProcessor processor = getScriptMoveProcessor(); + if (fReferenceCheckbox != null) { fReferenceCheckbox.setEnabled(canUpdateReferences()); - processor.setUpdateReferences(fReferenceCheckbox.getEnabled() && fReferenceCheckbox.getSelection()); + processor.setUpdateReferences(fReferenceCheckbox.getEnabled() + && fReferenceCheckbox.getSelection()); } - if (fQualifiedNameCheckbox != null){ - boolean enabled= processor.canEnableQualifiedNameUpdating(); + if (fQualifiedNameCheckbox != null) { + boolean enabled = processor.canEnableQualifiedNameUpdating(); fQualifiedNameCheckbox.setEnabled(enabled); if (enabled) { - fQualifiedNameComponent.setEnabled(processor.getUpdateQualifiedNames()); + fQualifiedNameComponent + .setEnabled(processor.getUpdateQualifiedNames()); if (processor.getUpdateQualifiedNames()) getRefactoringWizard().setForcePreviewReview(true); } else { fQualifiedNameComponent.setEnabled(false); } - processor.setUpdateQualifiedNames(fQualifiedNameCheckbox.getEnabled() && fQualifiedNameCheckbox.getSelection()); + processor.setUpdateQualifiedNames( + fQualifiedNameCheckbox.getEnabled() + && fQualifiedNameCheckbox.getSelection()); } } private void addUpdateReferenceComponent(Composite result) { - final ScriptMoveProcessor processor= getScriptMoveProcessor(); - if (! processor.canUpdateReferences()) + final ScriptMoveProcessor processor = getScriptMoveProcessor(); + if (!processor.canUpdateReferences()) return; - fReferenceCheckbox= new Button(result, SWT.CHECK); - fReferenceCheckbox.setText(ReorgMessages.ScriptMoveAction_update_references); + fReferenceCheckbox = new Button(result, SWT.CHECK); + fReferenceCheckbox + .setText(ReorgMessages.ScriptMoveAction_update_references); fReferenceCheckbox.setSelection(processor.getUpdateReferences()); fReferenceCheckbox.setEnabled(canUpdateReferences()); fReferenceCheckbox.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - processor.setUpdateReferences(((Button)e.widget).getSelection()); + processor.setUpdateReferences( + ((Button) e.widget).getSelection()); updateUIStatus(); } }); } - private void addUpdateQualifiedNameComponent(Composite parent, int marginWidth) { - final ScriptMoveProcessor processor= getScriptMoveProcessor(); - if (!processor.canEnableQualifiedNameUpdating() || !processor.canUpdateQualifiedNames()) + private void addUpdateQualifiedNameComponent(Composite parent, + int marginWidth) { + final ScriptMoveProcessor processor = getScriptMoveProcessor(); + if (!processor.canEnableQualifiedNameUpdating() + || !processor.canUpdateQualifiedNames()) return; - fQualifiedNameCheckbox= new Button(parent, SWT.CHECK); - int indent= marginWidth + fQualifiedNameCheckbox.computeSize(SWT.DEFAULT, SWT.DEFAULT).x; - fQualifiedNameCheckbox.setText(RefactoringMessages.RenameInputWizardPage_update_qualified_names); - fQualifiedNameCheckbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fQualifiedNameCheckbox.setSelection(processor.getUpdateQualifiedNames()); - - fQualifiedNameComponent= new QualifiedNameComponent(parent, SWT.NONE, processor, getRefactoringSettings()); - fQualifiedNameComponent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - GridData gd= (GridData)fQualifiedNameComponent.getLayoutData(); - gd.horizontalAlignment= GridData.FILL; - gd.horizontalIndent= indent; - updateQualifiedNameUpdating(processor, processor.getUpdateQualifiedNames()); + fQualifiedNameCheckbox = new Button(parent, SWT.CHECK); + int indent = marginWidth + fQualifiedNameCheckbox + .computeSize(SWT.DEFAULT, SWT.DEFAULT).x; + fQualifiedNameCheckbox.setText( + RefactoringMessages.RenameInputWizardPage_update_qualified_names); + fQualifiedNameCheckbox + .setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + fQualifiedNameCheckbox + .setSelection(processor.getUpdateQualifiedNames()); + + fQualifiedNameComponent = new QualifiedNameComponent(parent, + SWT.NONE, processor, getRefactoringSettings()); + fQualifiedNameComponent + .setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + GridData gd = (GridData) fQualifiedNameComponent.getLayoutData(); + gd.horizontalAlignment = GridData.FILL; + gd.horizontalIndent = indent; + updateQualifiedNameUpdating(processor, + processor.getUpdateQualifiedNames()); fQualifiedNameCheckbox.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - boolean enabled= ((Button)e.widget).getSelection(); + boolean enabled = ((Button) e.widget).getSelection(); updateQualifiedNameUpdating(processor, enabled); } }); } - private void updateQualifiedNameUpdating(final ScriptMoveProcessor processor, boolean enabled) { + private void updateQualifiedNameUpdating( + final ScriptMoveProcessor processor, boolean enabled) { fQualifiedNameComponent.setEnabled(enabled); processor.setUpdateQualifiedNames(enabled); updateUIStatus(); @@ -198,21 +221,24 @@ public class ReorgMoveWizard extends RefactoringWizard { public void createControl(Composite parent) { Composite result; - boolean showDestinationTree= ! getScriptMoveProcessor().hasDestinationSet(); + boolean showDestinationTree = !getScriptMoveProcessor() + .hasDestinationSet(); if (showDestinationTree) { - fCreateTargetQuery= getScriptMoveProcessor().getCreateTargetQuery(); + fCreateTargetQuery = getScriptMoveProcessor() + .getCreateTargetQuery(); super.createControl(parent); getTreeViewer().getTree().setFocus(); - result= (Composite)super.getControl(); - } else { + result = (Composite) super.getControl(); + } else { initializeDialogUnits(parent); - result= new Composite(parent, SWT.NONE); + result = new Composite(parent, SWT.NONE); setControl(result); result.setLayout(new GridLayout()); Dialog.applyDialogFont(result); } addUpdateReferenceComponent(result); - addUpdateQualifiedNameComponent(result, ((GridLayout)result.getLayout()).marginWidth); + addUpdateQualifiedNameComponent(result, + ((GridLayout) result.getLayout()).marginWidth); setControl(result); Dialog.applyDialogFont(result); } @@ -220,26 +246,25 @@ public class ReorgMoveWizard extends RefactoringWizard { @Override protected Control addLabel(Composite parent) { if (fCreateTargetQuery != null) { - Composite firstLine= new Composite(parent, SWT.NONE); - GridLayout layout= new GridLayout(2, false); - layout.marginHeight= layout.marginWidth= 0; + Composite firstLine = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + layout.marginHeight = layout.marginWidth = 0; firstLine.setLayout(layout); firstLine.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - Control label= super.addLabel(firstLine); - label.addTraverseListener(new TraverseListener() { - @Override - public void keyTraversed(TraverseEvent e) { - if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) { - e.detail= SWT.TRAVERSE_NONE; - getTreeViewer().getTree().setFocus(); - } + Control label = super.addLabel(firstLine); + label.addTraverseListener(e -> { + if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) { + e.detail = SWT.TRAVERSE_NONE; + getTreeViewer().getTree().setFocus(); } }); - Button newButton= new Button(firstLine, SWT.PUSH); + Button newButton = new Button(firstLine, SWT.PUSH); newButton.setText(fCreateTargetQuery.getNewButtonLabel()); - GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); + GridData gd = new GridData( + GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL + | GridData.VERTICAL_ALIGN_BEGINNING); gd.widthHint = SWTUtil.getButtonWidthHint(newButton); newButton.setLayoutData(gd); newButton.addSelectionListener(new SelectionAdapter() { @@ -261,10 +286,12 @@ public class ReorgMoveWizard extends RefactoringWizard { } private void doNewButtonPressed() { - Object newElement= fCreateTargetQuery.getCreatedTarget(fDestination); + Object newElement = fCreateTargetQuery + .getCreatedTarget(fDestination); if (newElement != null) { - TreeViewer viewer= getTreeViewer(); - ITreeContentProvider contentProvider= (ITreeContentProvider) viewer.getContentProvider(); + TreeViewer viewer = getTreeViewer(); + ITreeContentProvider contentProvider = (ITreeContentProvider) viewer + .getContentProvider(); viewer.refresh(contentProvider.getParent(newElement)); viewer.setSelection(new StructuredSelection(newElement), true); viewer.getTree().setFocus(); |