Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IEP-1376: Linux ESP-IDF Manager buttons issue #1092

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
Expand Down Expand Up @@ -75,7 +76,7 @@
GridLayout gridLayout = new GridLayout(numColumns, false);
container.setLayout(gridLayout);
createIdfTable(container);
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 refreshEditorUI()
Expand Down Expand Up @@ -140,6 +141,7 @@
tableComposite.setLayout(tableColumnLayout);
tableViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.H_SCROLL);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());

Table table = tableViewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
Expand All @@ -149,10 +151,12 @@
comparator = new ColumnViewerComparator();
tableViewer.setComparator(comparator);
setupColumns();
table.addListener(SWT.MeasureItem, e -> {
e.height = 30;
});

tableViewer.setInput(toolSetConfigurationManager.getIdfToolSets(true));
table.layout();

// Composite for the "Add" button
Composite buttonComposite = new Composite(idfToolsGroup, SWT.NONE);
GridData buttonCompositeGridData = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
Expand Down Expand Up @@ -267,7 +271,7 @@

removeColumn = new TableViewerColumn(tableViewer, SWT.NONE);
removeColumn.setLabelProvider(new IdfManagerTableColumnLabelProvider());
tableColumnLayout.setColumnData(removeColumn.getColumn(), new ColumnWeightData(2, 10, true));
tableColumnLayout.setColumnData(removeColumn.getColumn(), new ColumnWeightData(3, 100, true));
}

private void setComparatorForCols(TableViewerColumn column, int colIndex)
Expand Down Expand Up @@ -417,6 +421,7 @@
private void createButtonsForLastCol(ViewerCell cell)
{
TableItem item = (TableItem) cell.getItem();
Rectangle cellBounds = cell.getBounds();
// using a unique key to store the editor to avoid creating multiple editors for the same cell
String EDITOR_KEY = "action_editor_last";
if (item.getData(EDITOR_KEY) != null)
Expand All @@ -426,14 +431,13 @@
TableEditor editor = new TableEditor(tableViewer.getTable());
Composite buttonComposite = new Composite(tableViewer.getTable(), SWT.NONE);
FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);
fillLayout.marginWidth = 2;
fillLayout.spacing = 5;

buttonComposite.setLayout(fillLayout);

buttonComposite.redraw();
item.setData(EDITOR_KEY, editor);
IDFToolSet idfToolSet = (IDFToolSet) cell.getElement();

int buttonHeight = Math.min(cellBounds.height - 6, 30);

if (idfToolSet.isActive())
{
Button reloadButton = new Button(buttonComposite, SWT.PUSH | SWT.FLAT);
Expand All @@ -449,6 +453,10 @@
toolsActivationJob.addJobChangeListener(toolsActivationJobListener);
toolsActivationJob.schedule();
});

reloadButton.setSize(cellBounds.width, buttonHeight);
reloadButton.addListener(SWT.Paint, e-> e.gc.drawRectangle(reloadButton.getBounds()));
reloadButton.redraw();
}

Button removeButton = new Button(buttonComposite, SWT.PUSH | SWT.FLAT);
Expand All @@ -462,13 +470,20 @@
performDeleteOperation(selectedToolSet);
refreshEditorUI();
});

removeButton.setSize(cellBounds.width, buttonHeight);
removeButton.redraw();

editor.grabHorizontal = true;
editor.setEditor(buttonComposite, item, cell.getColumnIndex());
editor.grabVertical = true;
editor.horizontalAlignment = SWT.CENTER;
editor.verticalAlignment = SWT.CENTER;
editor.minimumWidth = buttonComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
editor.minimumHeight = buttonComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
editor.minimumHeight = removeButton.getSize().y;
editor.minimumWidth = removeButton.getSize().x;
editor.setEditor(buttonComposite, item, cell.getColumnIndex());
buttonComposite.layout(true, true);
buttonComposite.redraw();
editor.layout();
tableViewer.getTable().layout(true, true);
}

@Override
Expand All @@ -486,56 +501,56 @@
{
private int propertyIndex;
private static final int DESCENDING = 1;
private int direction = 0;

public ColumnViewerComparator()
{
this.propertyIndex = 0;
direction = DESCENDING;
}

public void setColumn(int column)
{
if (column == this.propertyIndex)
{
// If the same column is clicked again, toggle the direction
direction = 1 - direction;
}
else
{
// Else, sort the new column in ascending order
this.propertyIndex = column;
direction = DESCENDING;
}
}

@Override
public int compare(Viewer viewer, Object e1, Object e2)
{
IDFToolSet p1 = (IDFToolSet) e1;
IDFToolSet p2 = (IDFToolSet) e2;
int rc = 0;
switch (propertyIndex)
{
case 0:
rc = p1.getIdfVersion().compareTo(p2.getIdfVersion());
break;
case 1:
rc = p1.getIdfLocation().compareTo(p2.getIdfLocation());
break;
case 2:
Boolean p1State = p1.isActive();
Boolean p2State = p2.isActive();
rc = p1State.compareTo(p2State);
break;
default:
break;
}
if (direction == DESCENDING)
{
rc = -rc;
}
return rc;

Check warning on line 553 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

SIC_INNER_SHOULD_BE_STATIC

Should com.espressif.idf.ui.tools.manager.pages.ESPIDFMainTablePage$ColumnViewerComparator be a _static_ inner class?
Raw output
This class is an inner class, but does not use its embedded reference to the object which created it.  This reference makes the instances of the class larger, and may keep the reference to the creator object alive longer than necessary.  If possible, the class should be made static.
}

}
Expand Down
Loading