From 616eb447fb6c646628cb3515c5cf905045a30838 Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Mon, 17 Jun 2024 10:34:56 +0300 Subject: [PATCH 1/5] feat: change the mode when changing conf --- .../espressif/idf/ui/LaunchBarListener.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java index cd32ffea2..cea77230c 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java @@ -6,6 +6,8 @@ import java.io.File; import java.text.MessageFormat; +import java.util.Optional; +import java.util.stream.Stream; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.core.resources.IProject; @@ -17,6 +19,8 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.ILaunchMode; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.launchbar.core.ILaunchBarListener; import org.eclipse.launchbar.core.ILaunchBarManager; @@ -49,6 +53,37 @@ public static void setIgnoreTargetChange(boolean status) targetChangeIgnored = status; } + @Override + public void activeLaunchDescriptorChanged(ILaunchDescriptor descriptor) + { + descriptor.getAdapter(ILaunchConfiguration.class); + ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class); + + try + { + ILaunchConfiguration activeLaunchConfiguration = launchBarManager.getActiveLaunchConfiguration(); + + if (activeLaunchConfiguration != null && activeLaunchConfiguration.getType() != null) + { + String configTypeIdentifier = activeLaunchConfiguration.getType().getIdentifier(); + if (IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier)) + { + setMode(launchBarManager, ILaunchManager.RUN_MODE); + } + else if (IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier)) + { + setMode(launchBarManager, ILaunchManager.DEBUG_MODE); + } + } + } + catch (CoreException e) + { + Logger.log(e); + } + + ILaunchBarListener.super.activeLaunchDescriptorChanged(descriptor); + } + @Override public void activeLaunchTargetChanged(ILaunchTarget target) { @@ -218,4 +253,22 @@ private void cleanSdkConfig(IResource project) } } + private void setMode(ILaunchBarManager launchBarManager, String mode) + { + try + { + Optional runMode = Stream.of(launchBarManager.getLaunchModes()) + .filter(m -> m.getIdentifier().equals(mode)).findFirst(); + if (runMode.isPresent()) + { + launchBarManager.setActiveLaunchMode(runMode.get()); + } + + } + catch (CoreException e) + { + Logger.log(e); + } + } + } \ No newline at end of file From 4168bf8de0da5b808aebd399b83030c39507ba3a Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Tue, 2 Jul 2024 15:03:22 +0300 Subject: [PATCH 2/5] fix: ensure triggering listeners --- .../src/com/espressif/idf/ui/LaunchBarListener.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java index cea77230c..d6d5e3141 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java @@ -68,10 +68,14 @@ public void activeLaunchDescriptorChanged(ILaunchDescriptor descriptor) String configTypeIdentifier = activeLaunchConfiguration.getType().getIdentifier(); if (IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier)) { + // Set debug mode first to ensure a mode change, triggering listeners. + setMode(launchBarManager, ILaunchManager.DEBUG_MODE); setMode(launchBarManager, ILaunchManager.RUN_MODE); } else if (IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier)) { + // Set run mode first to ensure a mode change, triggering listeners. + setMode(launchBarManager, ILaunchManager.RUN_MODE); setMode(launchBarManager, ILaunchManager.DEBUG_MODE); } } From c0012e547abb789d6dc13921c63d8f0f1aa1cd49 Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Fri, 5 Jul 2024 11:35:55 +0300 Subject: [PATCH 3/5] fix: removing useless code --- .../src/com/espressif/idf/ui/LaunchBarListener.java | 1 - 1 file changed, 1 deletion(-) diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java index d6d5e3141..32fca72f5 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java @@ -56,7 +56,6 @@ public static void setIgnoreTargetChange(boolean status) @Override public void activeLaunchDescriptorChanged(ILaunchDescriptor descriptor) { - descriptor.getAdapter(ILaunchConfiguration.class); ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class); try From 3f20f9e0fe14f97655a848656db24f554c4e97b5 Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Fri, 5 Jul 2024 12:02:46 +0300 Subject: [PATCH 4/5] feat: eliminate popup if only one config available --- .../idf/ui/handlers/RunActionHandler.java | 74 ++++++++++++------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/RunActionHandler.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/RunActionHandler.java index 805a9aa32..dd87f1e17 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/RunActionHandler.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/RunActionHandler.java @@ -7,12 +7,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunchConfiguration; @@ -35,7 +36,6 @@ import com.espressif.idf.core.util.StringUtil; import com.espressif.idf.ui.UIPlugin; import com.espressif.idf.ui.dialogs.SelectDebugConfigDialog; -import com.espressif.idf.ui.dialogs.SelectLaunchConfigDialog; @SuppressWarnings("restriction") public class RunActionHandler extends LaunchActiveCommandHandler @@ -67,7 +67,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException Boolean isYes = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.RunActionHandler_NoProjectQuestionTitle, Messages.RunActionHandler_NoProjectQuestionText); - if (isYes) + if (Boolean.TRUE.equals(isYes)) { ILaunchBarUIManager uiManager = UIPlugin.getService(ILaunchBarUIManager.class); uiManager.openConfigurationEditor(launchBarManager.getActiveLaunchDescriptor()); @@ -84,16 +84,14 @@ public Object execute(ExecutionEvent event) throws ExecutionException showMessage(Messages.DebugConfigurationNotFoundMsg); return Status.CANCEL_STATUS; } - returnCode = new SelectDebugConfigDialog(Display.getDefault().getActiveShell(), suitableDescNames) - .open(); + returnCode = runActionBasedOnDescCount(launchBarManager, suitableDescNames); } else if (launchMode.getIdentifier().equals(ILaunchManager.RUN_MODE) && config.getType().getIdentifier().contentEquals(IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE)) { List suitableDescNames = findSuitableDescNames(projectName, IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE); - returnCode = new SelectLaunchConfigDialog(Display.getDefault().getActiveShell(), suitableDescNames) - .open(); + returnCode = runActionBasedOnDescCount(launchBarManager, suitableDescNames); } if (returnCode == Window.OK) { @@ -110,6 +108,31 @@ else if (launchMode.getIdentifier().equals(ILaunchManager.RUN_MODE) } } + private int runActionBasedOnDescCount(ILaunchBarManager launchBarManager, List suitableDescNames) + throws CoreException + { + return suitableDescNames.size() == 1 + ? setLaunchBarWithFirstAppropriateDescriptor(launchBarManager, suitableDescNames) + : new SelectDebugConfigDialog(Display.getDefault().getActiveShell(), suitableDescNames).open(); + } + + private int setLaunchBarWithFirstAppropriateDescriptor(ILaunchBarManager launchBarManager, + List suitableDescNames) throws CoreException + { + Stream.of(launchBarManager.getLaunchDescriptors()) + .filter(desc -> desc.getName().equals(suitableDescNames.get(0))).findFirst().ifPresent(desc -> { + try + { + launchBarManager.setActiveLaunchDescriptor(desc); + } + catch (CoreException e) + { + Logger.log(e); + } + }); + return IStatus.OK; + } + private List findSuitableDescNames(String projectName, String configType) { ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); @@ -135,33 +158,28 @@ private List findSuitableDescNames(String projectName, String configType Logger.log(e); } return false; - }).map(config -> config.getName()).collect(Collectors.toList()); + }).map(config -> config.getName()).toList(); } private void showMessage(final String message) { - Display.getDefault().asyncExec(new Runnable() - { - @Override - public void run() + Display.getDefault().asyncExec(() -> { + + Shell activeShell = Display.getDefault().getActiveShell(); + boolean isYes = MessageDialog.openQuestion(activeShell, Messages.MissingDebugConfigurationTitle, message); + if (isYes) { - Shell activeShell = Display.getDefault().getActiveShell(); - boolean isYes = MessageDialog.openQuestion(activeShell, Messages.MissingDebugConfigurationTitle, - message); - if (isYes) - { - NewLaunchConfigWizard wizard = new NewLaunchConfigWizard(); - WizardDialog dialog = new NewLaunchConfigWizardDialog(activeShell, wizard); - dialog.open(); - try - { - wizard.getWorkingCopy().doSave(); - } - catch (CoreException e) - { - Logger.log(e); - } + NewLaunchConfigWizard wizard = new NewLaunchConfigWizard(); + WizardDialog dialog = new NewLaunchConfigWizardDialog(activeShell, wizard); + dialog.open(); + try + { + wizard.getWorkingCopy().doSave(); + } + catch (CoreException e) + { + Logger.log(e); } } }); From cfc861d2d703e2444b1cba368623770f6d7ec903 Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Fri, 5 Jul 2024 12:39:18 +0300 Subject: [PATCH 5/5] fix: applying formatter to the DeleteResourceWizard --- .../idf/ui/dialogs/DeleteResourceWizard.java | 312 +++++++++++------- 1 file changed, 197 insertions(+), 115 deletions(-) diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/DeleteResourceWizard.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/DeleteResourceWizard.java index b0ecdf423..ed61aad62 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/DeleteResourceWizard.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/DeleteResourceWizard.java @@ -14,7 +14,6 @@ *******************************************************************************/ package com.espressif.idf.ui.dialogs; - import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.util.ArrayList; @@ -61,146 +60,197 @@ import com.espressif.idf.core.logging.Logger; @SuppressWarnings("restriction") -public class DeleteResourceWizard extends DeleteResourcesWizard { - +public class DeleteResourceWizard extends DeleteResourcesWizard +{ + private static IProject project; private static boolean doDeleteRelatedConfigurations; - - public DeleteResourceWizard(IResource[] resources) { + + public DeleteResourceWizard(IResource[] resources) + { super(resources); } - + @Override - protected void addUserInputPages() { - DeleteResourcesProcessor processor= getRefactoring().getAdapter(DeleteResourcesProcessor.class); + protected void addUserInputPages() + { + DeleteResourcesProcessor processor = getRefactoring().getAdapter(DeleteResourcesProcessor.class); addPage(new DeleteResourcesRefactoringConfigurationPage(processor)); } - - private static class DeleteResourcesRefactoringConfigurationPage extends UserInputWizardPage { + + private static class DeleteResourcesRefactoringConfigurationPage extends UserInputWizardPage + { private DeleteResourcesProcessor fRefactoringProcessor; private Button fDeleteContentsButton; - + private Button fDeleteAllRelatedConfigurationsButton; - + private StyledText fProjectLocationsList; private Label fProjectLocationsLabel; - public DeleteResourcesRefactoringConfigurationPage(DeleteResourcesProcessor processor) { + public DeleteResourcesRefactoringConfigurationPage(DeleteResourcesProcessor processor) + { super("DeleteResourcesRefactoringConfigurationPage"); //$NON-NLS-1$ - fRefactoringProcessor= processor; + fRefactoringProcessor = processor; } @Override - public void createControl(Composite parent) { + public void createControl(Composite parent) + { doDeleteRelatedConfigurations = false; initializeDialogUnits(parent); - Point defaultSpacing= LayoutConstants.getSpacing(); + Point defaultSpacing = LayoutConstants.getSpacing(); - Composite composite= new Composite(parent, SWT.NONE); - GridLayout gridLayout= new GridLayout(2, false); - gridLayout.horizontalSpacing= defaultSpacing.x * 2; - gridLayout.verticalSpacing= defaultSpacing.y; + Composite composite = new Composite(parent, SWT.NONE); + GridLayout gridLayout = new GridLayout(2, false); + gridLayout.horizontalSpacing = defaultSpacing.x * 2; + gridLayout.verticalSpacing = defaultSpacing.y; composite.setLayout(gridLayout); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - Image image= parent.getDisplay().getSystemImage(SWT.ICON_QUESTION); + Image image = parent.getDisplay().getSystemImage(SWT.ICON_QUESTION); Label imageLabel = new Label(composite, SWT.NULL); - if (image != null) { + if (image != null) + { imageLabel.setBackground(image.getBackground()); imageLabel.setImage(image); } imageLabel.setLayoutData(new GridData(SWT.CENTER, SWT.BEGINNING, false, false)); - final IResource[] initialResources= fRefactoringProcessor.getResourcesToDelete(); - Label label= new Label(composite, SWT.WRAP); + final IResource[] initialResources = fRefactoringProcessor.getResourcesToDelete(); + Label label = new Label(composite, SWT.WRAP); - boolean onlyProjects= Resources.containsOnlyProjects(initialResources); - if (onlyProjects) { - if (initialResources.length == 1) { - label.setText(Messages.format(RefactoringUIMessages.DeleteResourcesWizard_label_single_project, BasicElementLabels.getResourceName(initialResources[0]))); + boolean onlyProjects = Resources.containsOnlyProjects(initialResources); + if (onlyProjects) + { + if (initialResources.length == 1) + { + label.setText(Messages.format(RefactoringUIMessages.DeleteResourcesWizard_label_single_project, + BasicElementLabels.getResourceName(initialResources[0]))); project = (IProject) initialResources[0]; - } else { - label.setText(Messages.format(RefactoringUIMessages.DeleteResourcesWizard_label_multi_projects, Integer.valueOf(initialResources.length))); } - } else if (containsLinkedResource(initialResources)) { - if (initialResources.length == 1) { - label.setText(Messages.format(RefactoringUIMessages.DeleteResourcesWizard_label_single_linked, BasicElementLabels.getResourceName(initialResources[0]))); - } else { - label.setText(Messages.format(RefactoringUIMessages.DeleteResourcesWizard_label_multi_linked, Integer.valueOf(initialResources.length))); + else + { + label.setText(Messages.format(RefactoringUIMessages.DeleteResourcesWizard_label_multi_projects, + Integer.valueOf(initialResources.length))); } - } else { - if (initialResources.length == 1) { - label.setText(Messages.format(RefactoringUIMessages.DeleteResourcesWizard_label_single, BasicElementLabels.getResourceName(initialResources[0]))); - } else { - label.setText(Messages.format(RefactoringUIMessages.DeleteResourcesWizard_label_multi, Integer.valueOf(initialResources.length))); + } + else if (containsLinkedResource(initialResources)) + { + if (initialResources.length == 1) + { + label.setText(Messages.format(RefactoringUIMessages.DeleteResourcesWizard_label_single_linked, + BasicElementLabels.getResourceName(initialResources[0]))); + } + else + { + label.setText(Messages.format(RefactoringUIMessages.DeleteResourcesWizard_label_multi_linked, + Integer.valueOf(initialResources.length))); } } - GridData gridData= new GridData(SWT.FILL, SWT.FILL, true, false); - gridData.widthHint= convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); + else + { + if (initialResources.length == 1) + { + label.setText(Messages.format(RefactoringUIMessages.DeleteResourcesWizard_label_single, + BasicElementLabels.getResourceName(initialResources[0]))); + } + else + { + label.setText(Messages.format(RefactoringUIMessages.DeleteResourcesWizard_label_multi, + Integer.valueOf(initialResources.length))); + } + } + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false); + gridData.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); label.setLayoutData(gridData); - Composite supportArea= new Composite(composite, SWT.NONE); + Composite supportArea = new Composite(composite, SWT.NONE); supportArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); - gridLayout= new GridLayout(1, false); - gridLayout.horizontalSpacing= defaultSpacing.x * 2; - gridLayout.verticalSpacing= defaultSpacing.y; + gridLayout = new GridLayout(1, false); + gridLayout.horizontalSpacing = defaultSpacing.x * 2; + gridLayout.verticalSpacing = defaultSpacing.y; supportArea.setLayout(gridLayout); - if (onlyProjects) { + if (onlyProjects) + { Set nestedProjects = computeNestedProjects(initialResources); - fDeleteContentsButton= new Button(supportArea, SWT.CHECK); + fDeleteContentsButton = new Button(supportArea, SWT.CHECK); fDeleteContentsButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); fDeleteContentsButton.setText(RefactoringUIMessages.DeleteResourcesWizard_project_deleteContents); fDeleteContentsButton.setFocus(); fDeleteAllRelatedConfigurationsButton = new Button(supportArea, SWT.CHECK); - fDeleteAllRelatedConfigurationsButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - fDeleteAllRelatedConfigurationsButton.setText(com.espressif.idf.ui.dialogs.Messages.DeleteResourcesWizard_project_deleteConfigurations); + fDeleteAllRelatedConfigurationsButton + .setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + fDeleteAllRelatedConfigurationsButton.setText( + com.espressif.idf.ui.dialogs.Messages.DeleteResourcesWizard_project_deleteConfigurations); - if (!nestedProjects.isEmpty()) { - Set projectHierarchy = new HashSet<>(initialResources.length + nestedProjects.size(), (float)1.0); + if (!nestedProjects.isEmpty()) + { + Set projectHierarchy = new HashSet<>(initialResources.length + nestedProjects.size(), + (float) 1.0); projectHierarchy.addAll(Arrays.asList(fRefactoringProcessor.getResourcesToDelete())); projectHierarchy.addAll(nestedProjects); Button deleteNestedProjectsCheckbox = new Button(supportArea, SWT.CHECK); deleteNestedProjectsCheckbox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - deleteNestedProjectsCheckbox.setText( - nestedProjects.size() == 1 ? - RefactoringUIMessages.DeleteResourcesWizard_label_alsoDeleteOneNestedProject : - NLS.bind(RefactoringUIMessages.DeleteResourcesWizard_label_alsoDeleteNestedProjects, nestedProjects.size())); - SelectionAdapter deleteNestedProjectsCheckboxListener = new SelectionAdapter() { + deleteNestedProjectsCheckbox.setText(nestedProjects.size() == 1 + ? RefactoringUIMessages.DeleteResourcesWizard_label_alsoDeleteOneNestedProject + : NLS.bind(RefactoringUIMessages.DeleteResourcesWizard_label_alsoDeleteNestedProjects, + nestedProjects.size())); + SelectionAdapter deleteNestedProjectsCheckboxListener = new SelectionAdapter() + { @Override - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(SelectionEvent e) + { final boolean deleteNestedProjects = deleteNestedProjectsCheckbox.getSelection(); - try { + try + { getContainer().run(false, true, pm -> { - try { - fRefactoringProcessor.setResources(deleteNestedProjects ? projectHierarchy.toArray(new IResource[projectHierarchy.size()]) : initialResources, pm); - } catch (OperationCanceledException | CoreException ex) { + try + { + fRefactoringProcessor.setResources(deleteNestedProjects + ? projectHierarchy.toArray(new IResource[projectHierarchy.size()]) + : initialResources, pm); + } + catch ( + OperationCanceledException + | CoreException ex) + { throw new InvocationTargetException(ex); } }); updateListOfProjects(); - } catch (InvocationTargetException | InterruptedException ex) { + } + catch ( + InvocationTargetException + | InterruptedException ex) + { RefactoringUIPlugin.log(ex); } } }; deleteNestedProjectsCheckbox.addSelectionListener(deleteNestedProjectsCheckboxListener); - fDeleteContentsButton.addSelectionListener(new SelectionAdapter() { + fDeleteContentsButton.addSelectionListener(new SelectionAdapter() + { private boolean previousNestedProjectSelection; @Override - public void widgetSelected(SelectionEvent e) { - if (fDeleteContentsButton.getSelection()) { + public void widgetSelected(SelectionEvent e) + { + if (fDeleteContentsButton.getSelection()) + { previousNestedProjectSelection = deleteNestedProjectsCheckbox.getSelection(); deleteNestedProjectsCheckbox.setSelection(true); - } else { + } + else + { deleteNestedProjectsCheckbox.setSelection(previousNestedProjectSelection); } deleteNestedProjectsCheckbox.setEnabled(!fDeleteContentsButton.getSelection()); @@ -209,31 +259,35 @@ public void widgetSelected(SelectionEvent e) { }); fDeleteContentsButton.addSelectionListener(deleteNestedProjectsCheckboxListener); } - - fDeleteAllRelatedConfigurationsButton.addSelectionListener(new SelectionAdapter() { - + + fDeleteAllRelatedConfigurationsButton.addSelectionListener(new SelectionAdapter() + { + @Override - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(SelectionEvent e) + { doDeleteRelatedConfigurations = fDeleteAllRelatedConfigurationsButton.getSelection(); } - + }); - fProjectLocationsLabel= new Label(supportArea, SWT.NONE); - GridData labelData= new GridData(SWT.FILL, SWT.FILL, true, false); - labelData.verticalIndent= 5; + fProjectLocationsLabel = new Label(supportArea, SWT.NONE); + GridData labelData = new GridData(SWT.FILL, SWT.FILL, true, false); + labelData.verticalIndent = 5; fProjectLocationsLabel.setLayoutData(labelData); - int style= SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL; + int style = SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL; if (initialResources.length > 1 || !nestedProjects.isEmpty()) style |= SWT.BORDER; - fProjectLocationsList= new StyledText(supportArea, style); + fProjectLocationsList = new StyledText(supportArea, style); fProjectLocationsList.setAlwaysShowScrollBars(false); - labelData.horizontalIndent= fProjectLocationsList.getLeftMargin(); - gridData= new GridData(SWT.FILL, SWT.FILL, true, true); - gridData.heightHint= convertHeightInCharsToPixels(Math.min(initialResources.length + nestedProjects.size(), 5)); + labelData.horizontalIndent = fProjectLocationsList.getLeftMargin(); + gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + gridData.heightHint = convertHeightInCharsToPixels( + Math.min(initialResources.length + nestedProjects.size(), 5)); fProjectLocationsList.setLayoutData(gridData); - fProjectLocationsList.setBackground(fProjectLocationsList.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); + fProjectLocationsList + .setBackground(fProjectLocationsList.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); Dialog.applyDialogFont(fProjectLocationsList); updateListOfProjects(); @@ -241,12 +295,15 @@ public void widgetSelected(SelectionEvent e) { setControl(composite); } - private void updateListOfProjects() { + private void updateListOfProjects() + { IResource[] initialResources = fRefactoringProcessor.getResourcesToDelete(); - StringBuilder buf= new StringBuilder(); - for (IResource initialResource : initialResources) { - String location= getLocation(initialResource); - if (location != null) { + StringBuilder buf = new StringBuilder(); + for (IResource initialResource : initialResources) + { + String location = getLocation(initialResource); + if (location != null) + { if (buf.length() > 0) buf.append('\n'); buf.append(location); @@ -260,25 +317,29 @@ private void updateListOfProjects() { fProjectLocationsList.getParent().requestLayout(); } - private static String getLocation(IResource resource) { - IPath location= resource.getLocation(); + private static String getLocation(IResource resource) + { + IPath location = resource.getLocation(); if (location != null) return BasicElementLabels.getPathLabel(location, true); - URI uri= resource.getLocationURI(); + URI uri = resource.getLocationURI(); if (uri != null) return BasicElementLabels.getURLPart(uri.toString()); - URI rawLocationURI= resource.getRawLocationURI(); + URI rawLocationURI = resource.getRawLocationURI(); if (rawLocationURI != null) return BasicElementLabels.getURLPart(rawLocationURI.toString()); return BasicElementLabels.getResourceName(resource); } - private boolean containsLinkedResource(IResource[] resources) { - for (IResource resource : resources) { - if (resource != null && resource.isLinked()) { // paranoia code, can not be null + private boolean containsLinkedResource(IResource[] resources) + { + for (IResource resource : resources) + { + if (resource != null && resource.isLinked()) + { // paranoia code, can not be null return true; } } @@ -286,87 +347,108 @@ private boolean containsLinkedResource(IResource[] resources) { } @Override - protected boolean performFinish() { + protected boolean performFinish() + { initializeRefactoring(); storeSettings(); return super.performFinish(); } @Override - public IWizardPage getNextPage() { + public IWizardPage getNextPage() + { initializeRefactoring(); storeSettings(); return super.getNextPage(); } - private void initializeRefactoring() { - fRefactoringProcessor.setDeleteContents(fDeleteContentsButton == null ? false : fDeleteContentsButton.getSelection()); + private void initializeRefactoring() + { + fRefactoringProcessor + .setDeleteContents(fDeleteContentsButton == null ? false : fDeleteContentsButton.getSelection()); } - private void storeSettings() { + private void storeSettings() + { } } - - private static Set computeNestedProjects(final IResource[] initialResources) { - if (initialResources == null) { + + private static Set computeNestedProjects(final IResource[] initialResources) + { + if (initialResources == null) + { return Collections.emptySet(); } final List resources = new ArrayList<>(Arrays.asList(initialResources)); resources.removeIf(res -> res.getLocation() == null); - final Comparator pathComparator = (res1, res2) -> res1.getLocation().toString().compareTo(res2.getLocation().toString()); + final Comparator pathComparator = (res1, res2) -> res1.getLocation().toString() + .compareTo(res2.getLocation().toString()); resources.sort(pathComparator); - if (resources.isEmpty()) { + if (resources.isEmpty()) + { return Collections.emptySet(); } // need to be sorted - final List allProjects = new ArrayList<>(Arrays.asList(initialResources[0].getWorkspace().getRoot().getProjects())); + final List allProjects = new ArrayList<>( + Arrays.asList(initialResources[0].getWorkspace().getRoot().getProjects())); allProjects.removeIf(project -> project.getLocation() == null); allProjects.sort(pathComparator); int resourceIndex = 0; int projectIndex = 0; final Set res = new HashSet<>(); - while (resourceIndex < resources.size() && projectIndex < allProjects.size()) { + while (resourceIndex < resources.size() && projectIndex < allProjects.size()) + { final IPath resourcePath = resources.get(resourceIndex).getLocation(); final IProject project = allProjects.get(projectIndex); final IPath projectPath = project.getLocation(); - if (resourcePath.isPrefixOf(projectPath)) { + if (resourcePath.isPrefixOf(projectPath)) + { res.add(project); projectIndex++; continue; } int delta = resourcePath.toString().compareTo(projectPath.toString()); - if (delta < 0) { + if (delta < 0) + { resourceIndex++; - } else { + } + else + { projectIndex++; } } res.removeAll(resources); return res; } - + @Override - public boolean performFinish() { + public boolean performFinish() + { boolean performFinish = super.performFinish(); - if (doDeleteRelatedConfigurations) { + if (doDeleteRelatedConfigurations) + { deleteRelatedConfigurations(); } return performFinish; } - private void deleteRelatedConfigurations() { + private void deleteRelatedConfigurations() + { ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); - try { + try + { ILaunchConfiguration[] configs = launchManager.getLaunchConfigurations(); for (ILaunchConfiguration config : configs) { IResource[] mappedResource = config.getMappedResources(); - if (mappedResource != null && mappedResource[0].getProject() == project) + if (mappedResource != null && mappedResource[0].getProject().equals(project)) { config.delete(); } } - } catch (CoreException e) { + } + catch (CoreException e) + { Logger.log(e); } }