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

Improvements to Nodegroup view #114

Merged
merged 10 commits into from
Mar 27, 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 @@ -49,9 +49,13 @@
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
Expand Down Expand Up @@ -91,6 +95,9 @@ public class NodegroupsView extends ViewPart implements INodegroupView {

private Table table;
private Button selectAllButton;
private ScrolledComposite topComposite;
private Composite composite;
private Composite floatContainer;

public String getProjectPath() {
return "";
Expand All @@ -113,19 +120,33 @@ public void setFocus() {

@Override
public void createPartControl(Composite parent) {


// Notes:
// The table starts with an extra column. This appears to be a known WON'T FIX.
// The extra column can be resized to zero width.
// The code below sets each of the nested composite to fill out horizontally.
// Then the table does also. This appears to be necessary when there is an encapsulating ScrolledComposite.

final Display display = Display.getCurrent();

final ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
final Composite composite = new Composite(sc, SWT.NONE);
sc.setLayout(new FillLayout());
this.topComposite = sc;
composite = new Composite(sc, SWT.NONE);
sc.setExpandHorizontal(true);
sc.setContent(composite);

GridLayout layout = new GridLayout();
layout.numColumns = 1;
layout.verticalSpacing = 10;
var gdata = new GridData();
gdata.grabExcessHorizontalSpace = true;
gdata.grabExcessVerticalSpace = true;
gdata.horizontalAlignment = SWT.FILL;
gdata.verticalAlignment = SWT.FILL;
gdata.widthHint = SWT.FILL;
composite.setLayout(layout);

composite.setSize(1130 / 2, 600);
composite.setLayoutData(gdata);

if (!ConnectionUtil.ping()) {
return;
Expand Down Expand Up @@ -178,59 +199,55 @@ public void handleEvent(Event arg0) {
}
});

/* Select All Button not supported in SWT table - float workaround */
final Composite floatContainer = new Composite(composite, SWT.BORDER);
floatContainer.setLayout(new FormLayout());
final FormData tableFloatPosition = new FormData();
tableFloatPosition.top = new FormAttachment(0);
tableFloatPosition.left = new FormAttachment(0);
tableFloatPosition.right = new FormAttachment(100);
tableFloatPosition.bottom = new FormAttachment(100);
floatContainer = new Composite(composite, SWT.NONE);
var floatLayout = new GridLayout(1, true);
var floatData = new GridData();
floatData.horizontalAlignment = SWT.FILL;
floatData.grabExcessHorizontalSpace = true;
floatContainer.setLayoutData(floatData);
floatContainer.setLayout(floatLayout);

table = new Table(floatContainer, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
table = new Table(floatContainer, SWT.MULTI | SWT.NO_SCROLL);
table.removeAll();
table.setSize(1130, 600);
table.setHeaderVisible(true);
table.setLinesVisible(true);
table.setHeaderBackground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));

table.setHeaderForeground(display.getSystemColor(SWT.COLOR_TITLE_FOREGROUND));

table.setFocus();
table.setLayoutData(tableFloatPosition);
// table.addSelectionListener(new NodegroupSelectionListener());

// final FormData selectAllButtonPosition = new FormData();
// selectAllButtonPosition.left = new FormAttachment(table, 1, SWT.LEFT);
// selectAllButtonPosition.top = new FormAttachment(table, 2, SWT.TOP);
//
// selectAllButton = new Button(floatContainer, SWT.CHECK);
// selectAllButton.setLayoutData(selectAllButtonPosition);
// selectAllButton.moveAbove(table);
// selectAllButton.addSelectionListener(new NodegroupSelectAllListener());
var tableData = new GridData();
tableData.horizontalAlignment = SWT.FILL;
// Setting FILL here allows the table to fill out the horizontal width of the view window.
// But it also makes the ScrolledComposite think horizontal scrollbars are never needed
// so we have to rely on the table's own scrollbars.
tableData.grabExcessHorizontalSpace = true;
table.setLayoutData(tableData);

makeActions();
hookContextMenu();

final TableColumn col1 = new TableColumn(table, SWT.CENTER);
col1.setText("Nodegroup ID"); // Accommodate select all button buffer
table.showColumn(col1);

Stream.of("Comments", "Creation Data", "Creator")
Stream.of("Nodegroup ID", "Comments", "Creation Data", "Creator")
.forEach(
header -> {
final TableColumn col = new TableColumn(table, SWT.CENTER | SWT.WRAP);

final TableColumn col = new TableColumn(table, SWT.LEFT);
col.setText(header);
table.showColumn(col);
col.addControlListener( new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
resetScrollbarSize();
}
});
});

refreshNodegroupList();

// Initially show all columns for visibility / view reset
Arrays.stream(table.getColumns()).forEach(c -> c.setWidth(150));
}

private void resetScrollbarSize() {
int minwidth = 20; // To account for margins
for (int k=0; k< table.getColumnCount(); k++) minwidth += table.getColumn(k).getWidth();

composite.pack();
topComposite.setMinSize(composite.computeSize(minwidth, SWT.DEFAULT));
}

private void refreshNodegroupList() {
Expand All @@ -242,16 +259,21 @@ private void refreshNodegroupList() {
.forEach(
row -> {
final TableItem item = new TableItem(table, SWT.NONE);
item.setData(row);
row.remove(4); // Remove application data "semTK"
item.setData(row);
for (int j = 0; j < row.size(); j++) {
item.setText(j, row.get(j));
}
});

table.setEnabled(table.getItemCount() > 0);
Arrays.stream(table.getColumns()).forEach(TableColumn::pack);

table.pack();
floatContainer.pack();
composite.pack();
resetScrollbarSize();
topComposite.pack();

} catch (final Exception e) {
ErrorMessageUtil.warning(UPDATE_NODEGROUP_LIST_ERROR);
Expand Down Expand Up @@ -285,7 +307,12 @@ private void filterNodegroups(String searchTerm) {

table.setEnabled(table.getItemCount() > 0);
// Arrays.stream(table.getColumns()).forEach(TableColumn::pack);
// table.pack();
table.pack();
floatContainer.pack();
composite.pack();
resetScrollbarSize();
//topComposite.pack(); // With this pack, the scrollbars disappear when the filter is changed.
// though they reappear if the view window is resized.

} catch (final Exception e) {
ErrorMessageUtil.warning(UPDATE_NODEGROUP_LIST_ERROR);
Expand Down Expand Up @@ -331,13 +358,6 @@ public ArrayList<String> getSelectedNodegroups() {
.filter(d -> !d.isEmpty())
.map(d -> (String) d.get(0))
.collect(Collectors.toCollection(ArrayList::new));

// return Arrays.stream(table.getItems())
// .filter(ng -> ng.getChecked())
// .map(ng -> (List<?>) ng.getData())
// .filter(d -> !d.isEmpty())
// .map(d -> (String) d.get(0))
// .collect(Collectors.toCollection(ArrayList::new));
}

private class DeleteSelectedNodeGroupsAction extends Action {
Expand Down Expand Up @@ -430,34 +450,4 @@ protected IStatus run(IProgressMonitor monitor) {
return Status.OK_STATUS;
}
}

// private class NodegroupSelectAllListener implements SelectionListener {
//
// @Override
// public void widgetSelected(final SelectionEvent e) {
// if (null == table) {
// return;
// }
// final boolean selectAll = ((Button) e.getSource()).getSelection();
// Arrays.stream(table.getItems()).forEach(i -> i.setChecked(selectAll));
// }
//
// @Override
// public void widgetDefaultSelected(final SelectionEvent e) {}
// }
//
// private class NodegroupSelectionListener implements SelectionListener {
//
// @Override
// public void widgetSelected(final SelectionEvent e) {
// if (null == selectAllButton) {
// return;
// }
// selectAllButton.setSelection(
// Arrays.stream(table.getItems()).allMatch(p -> p.getChecked()));
// }
//
// @Override
// public void widgetDefaultSelected(final SelectionEvent e) {}
// }
}
Loading