Skip to content

Commit

Permalink
IEP-1225: Adding option to remove all versions (#996)
Browse files Browse the repository at this point in the history
  • Loading branch information
alirana01 authored Jun 21, 2024
1 parent cf7455e commit 1a98b2a
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ public void delete(IDFToolSet idfToolSet)
{
reload = true;
getIdfToolSets(false);
// cleanup the env and toolchains
IDFEnvironmentVariables idfEnvironmentVariables = new IDFEnvironmentVariables();
idfEnvironmentVariables.removeAllEnvVariables();
try
{
ESPToolChainManager espToolChainManager = new ESPToolChainManager();
espToolChainManager.removeCmakeToolChains();
espToolChainManager.removeStdToolChains();
}
catch (Exception e)
{
Logger.log(e);
}

// update the json now to remove the idf from it.
List<IDFToolSet> idfToolSetsToExport = new ArrayList<IDFToolSet>();
for (IDFToolSet idfTool : idfToolSets)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public void done(IJobChangeEvent event)
Display.getDefault().asyncExec(() -> {
if (espidfMainTablePage != null)
{
espidfMainTablePage.refreshTable();
espidfMainTablePage.refreshEditorUI();
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ public class Messages extends NLS
public static String EspIdfManagerStateCol;
public static String EspIdfManagerActivateCol;
public static String EspIdfManagerAddToolsBtn;
public static String EspIdfManagerRemoveAllBtn;
public static String EspIdfManagerDeleteBtn;
public static String EspIdfManagerMessageBoxActiveToolchainDelete;
public static String EspIdfManagerMessageBoxActiveToolchainDeleteTitle;
public static String EspIdfManagerMessageBoxDeleteConfirmMessage;
public static String EspIdfManagerMessageBoxDeleteConfirmMessageTitle;
public static String EspIdfManagerMessageBoxDeleteAllConfirmMessage;
public static String EspIdfManagerMessageBoxDeleteAllConfirmMessageTitle;

public static String IDFDownloadHandler_ESPIDFConfiguration;
public static String IDFDownloadHandler_DownloadPage_Title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void done(IJobChangeEvent event)
Display.getDefault().asyncExec(() -> {
if (espidfMainTablePage != null)
{
espidfMainTablePage.refreshTable();
espidfMainTablePage.refreshEditorUI();
}
});
OpenDialogListenerSupport.getSupport().firePropertyChange(PopupDialog.ENABLE_LAUNCHBAR_EVENTS.name(), null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package com.espressif.idf.ui.tools.manager.pages;

import java.text.MessageFormat;
import java.util.List;

import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.viewers.ArrayContentProvider;
Expand Down Expand Up @@ -35,6 +36,7 @@
import com.espressif.idf.core.tools.ToolSetConfigurationManager;
import com.espressif.idf.core.tools.vo.IDFToolSet;
import com.espressif.idf.core.util.IDFUtil;
import com.espressif.idf.ui.LaunchBarListener;
import com.espressif.idf.ui.UIPlugin;
import com.espressif.idf.ui.install.IDFNewToolsWizard;
import com.espressif.idf.ui.tools.Messages;
Expand All @@ -58,14 +60,17 @@ public class ESPIDFMainTablePage
private TableViewerColumn removeColumn;
private TableColumnLayout tableColumnLayout;
private Composite tableComposite;

private List<IDFToolSet> idfToolSets;
private Button removeAllButton;

private static final String REMOVE_ICON = "icons/tools/delete.png"; //$NON-NLS-1$
private static final String RELOAD_ICON = "icons/tools/reload.png"; //$NON-NLS-1$
private static final String IDF_TOOL_SET_BTN_KEY = "IDFToolSet"; //$NON-NLS-1$

public Composite createPage(Composite composite)
{
toolSetConfigurationManager = new ToolSetConfigurationManager();
idfToolSets = toolSetConfigurationManager.getIdfToolSets(true);
container = new Composite(composite, SWT.NONE);
final int numColumns = 2;
GridLayout gridLayout = new GridLayout(numColumns, false);
Expand All @@ -74,7 +79,7 @@ public Composite createPage(Composite composite)
return container;

Check warning on line 79 in bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/manager/pages/ESPIDFMainTablePage.java

View workflow job for this annotation

GitHub Actions / spotbugs

EI_EXPOSE_REP

com.espressif.idf.ui.tools.manager.pages.ESPIDFMainTablePage.createPage(Composite) may expose internal representation by returning ESPIDFMainTablePage.container
Raw output
Returning a reference to a mutable object value stored in one of the object's fields exposes the internal representation of the object.  If instances are accessed by untrusted code, and unchecked changes to the mutable object would compromise security or other important properties, you will need to do something different. Returning a new copy of the object is better approach in many situations.
}

public void refreshTable()
public void refreshEditorUI()
{
for (TableItem item : tableViewer.getTable().getItems())
{
Expand Down Expand Up @@ -104,12 +109,22 @@ public void refreshTable()
}
}
toolSetConfigurationManager.setReload(true);
idfToolSets = toolSetConfigurationManager.getIdfToolSets(true);
setupColumns();
tableViewer.setInput(toolSetConfigurationManager.getIdfToolSets(true));
tableViewer.setInput(idfToolSets);
tableViewer.getControl().requestLayout();
tableViewer.refresh();
container.redraw();
toolSetConfigurationManager.setReload(false);

if (idfToolSets == null || idfToolSets.isEmpty())
{
removeAllButton.setEnabled(false);
}
else
{
removeAllButton.setEnabled(true);
}
}

private Composite createIdfTable(Composite parent)
Expand Down Expand Up @@ -144,15 +159,19 @@ private Composite createIdfTable(Composite parent)
GridData buttonCompositeGridData = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
buttonCompositeGridData.verticalAlignment = SWT.TOP; // Aligns the button composite at the top
buttonComposite.setLayoutData(buttonCompositeGridData);
buttonComposite.setLayout(new FillLayout());
buttonComposite.setLayout(new GridLayout(1, true));

// Creating the "Add" button
Button addButton = new Button(buttonComposite, SWT.PUSH);
addButton.setText(Messages.EspIdfManagerAddToolsBtn);
addButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IDFNewToolsWizard wizard = new IDFNewToolsWizard(ESPIDFMainTablePage.this);
GridData addButtonGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
addButton.setLayoutData(addButtonGridData);
addButton.addSelectionListener(new SelectionAdapter()
{
@Override
public void widgetSelected(SelectionEvent e)
{
IDFNewToolsWizard wizard = new IDFNewToolsWizard(ESPIDFMainTablePage.this);
wizard.setWindowTitle(Messages.IDFDownloadHandler_ESPIDFConfiguration);
WizardDialog wizDialog = new WizardDialog(container.getShell(), wizard);
wizDialog.create();
Expand All @@ -162,9 +181,43 @@ public void widgetSelected(SelectionEvent e) {
wizDialog.getShell().setSize(Math.max(850, wizDialog.getShell().getSize().x), 550);

wizDialog.open();
}
});
}
});

removeAllButton = new Button(buttonComposite, SWT.PUSH);
removeAllButton.setText(Messages.EspIdfManagerRemoveAllBtn);
removeAllButton.addSelectionListener(new SelectionAdapter()
{
@Override
public void widgetSelected(SelectionEvent e)
{
MessageBox messageBox = new MessageBox(Display.getDefault().getActiveShell(),
SWT.ICON_WARNING | SWT.YES | SWT.NO);
messageBox.setMessage(Messages.EspIdfManagerMessageBoxDeleteAllConfirmMessage);
messageBox.setText(Messages.EspIdfManagerMessageBoxDeleteAllConfirmMessageTitle);
int response = messageBox.open();
if (response == SWT.YES)
{
for(IDFToolSet idfToolSet : idfToolSets)
{
toolSetConfigurationManager.delete(idfToolSet);
}
refreshEditorUI();
}
}
});

GridData removeAllButtonGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
removeAllButton.setLayoutData(removeAllButtonGridData);
if (idfToolSets == null || idfToolSets.isEmpty())
{
removeAllButton.setEnabled(false);
}
else
{
removeAllButton.setEnabled(true);
}

return idfToolsGroup;
}

Expand Down Expand Up @@ -246,25 +299,14 @@ public void widgetSelected(SelectionEvent e)

private void performDeleteOperation(IDFToolSet idfToolSet)
{
if (idfToolSet.isActive())
MessageBox messageBox = new MessageBox(Display.getDefault().getActiveShell(),
SWT.ICON_WARNING | SWT.YES | SWT.NO);
messageBox.setMessage(MessageFormat.format(Messages.EspIdfManagerMessageBoxDeleteConfirmMessage, idfToolSet.getIdfVersion()));
messageBox.setText(Messages.EspIdfManagerMessageBoxDeleteConfirmMessageTitle);
int response = messageBox.open();
if (response == SWT.YES)
{
MessageBox messageBox = new MessageBox(Display.getDefault().getActiveShell(),
SWT.ICON_INFORMATION | SWT.OK);
messageBox.setMessage(Messages.EspIdfManagerMessageBoxActiveToolchainDelete);
messageBox.setText(Messages.EspIdfManagerMessageBoxActiveToolchainDeleteTitle);
messageBox.open();
}
else
{
MessageBox messageBox = new MessageBox(Display.getDefault().getActiveShell(),
SWT.ICON_WARNING | SWT.YES | SWT.NO);
messageBox.setMessage(MessageFormat.format(Messages.EspIdfManagerMessageBoxDeleteConfirmMessage, idfToolSet.getIdfVersion()));
messageBox.setText(Messages.EspIdfManagerMessageBoxDeleteConfirmMessageTitle);
int response = messageBox.open();
if (response == SWT.YES)
{
toolSetConfigurationManager.delete(idfToolSet);
}
toolSetConfigurationManager.delete(idfToolSet);
}
}

Expand Down Expand Up @@ -409,20 +451,18 @@ private void createButtonsForLastCol(ViewerCell cell)
toolsActivationJob.schedule();
});
}
else
{
Button removeButton = new Button(buttonComposite, SWT.PUSH | SWT.FLAT);
removeButton.pack();
removeButton.setData(IDF_TOOL_SET_BTN_KEY, idfToolSet);
removeButton.setImage(UIPlugin.getImage(REMOVE_ICON));
removeButton.setToolTipText(Messages.EspIdfManagerDeleteBtnToolTip);
removeButton.addListener(SWT.Selection, e -> {
Button btn = (Button) e.widget;
IDFToolSet selectedToolSet = (IDFToolSet) btn.getData(IDF_TOOL_SET_BTN_KEY);
performDeleteOperation(selectedToolSet);
refreshTable();
});
}

Button removeButton = new Button(buttonComposite, SWT.PUSH | SWT.FLAT);
removeButton.pack();
removeButton.setData(IDF_TOOL_SET_BTN_KEY, idfToolSet);
removeButton.setImage(UIPlugin.getImage(REMOVE_ICON));
removeButton.setToolTipText(Messages.EspIdfManagerDeleteBtnToolTip);
removeButton.addListener(SWT.Selection, e -> {
Button btn = (Button) e.widget;
IDFToolSet selectedToolSet = (IDFToolSet) btn.getData(IDF_TOOL_SET_BTN_KEY);
performDeleteOperation(selectedToolSet);
refreshEditorUI();
});

editor.grabHorizontal = true;
editor.setEditor(buttonComposite, item, cell.getColumnIndex());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ EspIdfManagerLocationCol=Location
EspIdfManagerStateCol=State
EspIdfManagerActivateCol=Active
EspIdfManagerAddToolsBtn=Add ESP-IDF
EspIdfManagerRemoveAllBtn=Remove All
EspIdfManagerDeleteBtn=Delete
EspIdfManagerMessageBoxActiveToolchainDelete=You are trying to delete active toolchain. Please switch active toolchain to delete.
EspIdfManagerMessageBoxActiveToolchainDeleteTitle=Cannot delete active toolchain
EspIdfManagerMessageBoxDeleteConfirmMessage=Do you want to delete the toolchain with ESP-IDF version: {0}
EspIdfManagerMessageBoxDeleteConfirmMessageTitle=Confirm Delete
EspIdfManagerMessageBoxDeleteConfirmMessage=Do you want to remove the toolchain with ESP-IDF version: {0}
EspIdfManagerMessageBoxDeleteConfirmMessageTitle=Confirm Remove
EspIdfManagerMessageBoxDeleteAllConfirmMessage=Do you want to remove all ESP-IDF versions from IDE
EspIdfManagerMessageBoxDeleteAllConfirmMessageTitle=Remove All ESP-IDF Versions
EspIdfManagerReloadBtnToolTip=Reload from disk
EspIdfManagerDeleteBtnToolTip=Delete ESP-IDF version from IDE

Expand Down

0 comments on commit 1a98b2a

Please sign in to comment.