Skip to content

Commit

Permalink
[Properties] Don't use virtual table for MultipleAddDialog
Browse files Browse the repository at this point in the history
- On Windows you can select multiple rows using Shift/Ctrl keys and then use the space bar to set the check boxes in a CheckboxTableViewer

- A virtual table doesn't support this

- So let's lose the virtual table and hope that there aren't thousands of properties
  • Loading branch information
Phillipus committed Jan 19, 2024
1 parent cb86dfe commit 6c30188
Showing 1 changed file with 26 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ColumnViewerEditor;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.ILazyContentProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TableViewerEditor;
Expand Down Expand Up @@ -95,7 +96,6 @@
import com.archimatetool.editor.ui.components.ExtendedTitleAreaDialog;
import com.archimatetool.editor.ui.components.GlobalActionDisablementHandler;
import com.archimatetool.editor.ui.components.StringComboBoxCellEditor;
import com.archimatetool.editor.ui.components.TableCheckListener;
import com.archimatetool.editor.utils.HTMLUtils;
import com.archimatetool.editor.utils.StringUtils;
import com.archimatetool.model.IArchimateFactory;
Expand Down Expand Up @@ -1102,6 +1102,10 @@ public void run() {
MultipleAddDialog dialog = new MultipleAddDialog(fPage.getSite().getShell(), getAllUniquePropertyKeysForModel(MAX_ITEMS_ALL));
if(dialog.open() == Window.OK) {
List<String> newKeys = dialog.getSelectedKeys();
if(newKeys == null || newKeys.isEmpty()) {
return;
}

CompoundCommand cmd = isMultiSelection() ? new CompoundCommand(Messages.UserPropertiesSection_20) :
new EObjectNonNotifyingCompoundCommand(getFirstSelectedElement(), Messages.UserPropertiesSection_20);

Expand Down Expand Up @@ -1349,11 +1353,11 @@ public void dispose() {
// -----------------------------------------------------------------------------------------------------------------

private static class MultipleAddDialog extends ExtendedTitleAreaDialog {
private TableViewer tableViewer;
private CheckboxTableViewer tableViewer;
private Button buttonSelectAll, buttonDeselectAll;

private String[] keys;
private Set<String> selectedKeys = new LinkedHashSet<>(); // LinkedHashSet is faster when sorting
private List<String> selectedKeys;

public MultipleAddDialog(Shell parentShell, String[] keys) {
super(parentShell, "ArchimatePropertiesMultipleAddDialog"); //$NON-NLS-1$
Expand Down Expand Up @@ -1406,7 +1410,7 @@ private void createTableControl(Composite parent) {
tableComp.setLayout(tableLayout);
tableComp.setLayoutData(new GridData(GridData.FILL_BOTH));

tableViewer = new TableViewer(tableComp, SWT.FULL_SELECTION | SWT.VIRTUAL);
tableViewer = CheckboxTableViewer.newCheckList(tableComp, SWT.MULTI | SWT.FULL_SELECTION);
tableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));

// Mac Silicon Item height
Expand All @@ -1419,17 +1423,14 @@ private void createTableControl(Composite parent) {
tableLayout.setColumnData(columnKey.getColumn(), new ColumnWeightData(100, true));

// Content Provider
tableViewer.setContentProvider(new ILazyContentProvider() {
tableViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
if(newInput != null) {
tableViewer.setItemCount(keys.length);
}
}

@Override
public void updateElement(int index) {
tableViewer.replace(keys[index], index);
public Object[] getElements(Object inputElement) {
return keys;
}

@Override
Expand All @@ -1438,30 +1439,7 @@ public void dispose() {
});

// Label Provider
tableViewer.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
String key = (String)cell.getElement();
cell.setText(key);
cell.setImage(selectedKeys.contains(key) ? IArchiImages.ImageFactory.getImage(IArchiImages.ICON_CHECKED)
: IArchiImages.ImageFactory.getImage(IArchiImages.ICON_UNCHECKED));
}
});

// Mouse click in Assets table - did we click the checkbox?
new TableCheckListener(tableViewer.getTable()) {
@Override
protected void hit(Object object) {
String key = (String)object;
if(selectedKeys.contains(key)) {
selectedKeys.remove(key);
}
else {
selectedKeys.add(key);
}
}
};

tableViewer.setLabelProvider(new LabelProvider());
tableViewer.setInput(keys);
}

Expand All @@ -1481,26 +1459,30 @@ private void createButtonPanel(Composite parent) {
gd = new GridData(GridData.FILL_HORIZONTAL);
buttonSelectAll.setLayoutData(gd);
buttonSelectAll.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
for(String key : keys) {
selectedKeys.add(key);
}
tableViewer.setInput(keys);
tableViewer.setCheckedElements(keys);
}));

buttonDeselectAll = new Button(client, SWT.PUSH);
buttonDeselectAll.setText(Messages.UserPropertiesSection_19);
gd = new GridData(GridData.FILL_HORIZONTAL);
buttonDeselectAll.setLayoutData(gd);
buttonDeselectAll.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
selectedKeys = new HashSet<>();
tableViewer.setInput(keys);
tableViewer.setCheckedElements(new Object[] {});
}));
}

@Override
protected void okPressed() {
selectedKeys = new ArrayList<>();
for(Object o : tableViewer.getCheckedElements()) {
selectedKeys.add((String)o);
}

super.okPressed();
}

List<String> getSelectedKeys() {
List<String> list = new ArrayList<>(selectedKeys);
Collections.sort(list, (s1, s2) -> s1.compareToIgnoreCase(s2));
return list;
return selectedKeys;
}

@Override
Expand Down

0 comments on commit 6c30188

Please sign in to comment.