X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Fdiagram%2Frenaming%2FComponentsRenamingDialog.java;h=2af483185079ad8be63143c1a39aab49b5f0abf1;hp=8a73bed10bec36ea7acadaa0e1340cb71624cfba;hb=d1a82fe;hpb=bb1507f2eaee879439d355bf6b052e16d0df1bff diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/renaming/ComponentsRenamingDialog.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/renaming/ComponentsRenamingDialog.java index 8a73bed10..2af483185 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/renaming/ComponentsRenamingDialog.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/renaming/ComponentsRenamingDialog.java @@ -1,11 +1,18 @@ package org.simantics.modeling.ui.diagram.renaming; +import java.util.HashSet; +import java.util.Set; + import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ColumnLabelProvider; -import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.ICheckStateProvider; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; @@ -14,6 +21,7 @@ import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; @@ -21,6 +29,7 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import org.simantics.utils.ui.ISelectionUtils; public class ComponentsRenamingDialog extends Dialog { @@ -33,7 +42,7 @@ public class ComponentsRenamingDialog extends Dialog { Text newNamePrefix; Label errorLabel; Text error; - TableViewer tableViewer; + CheckboxTableViewer tableViewer; public ComponentsRenamingDialog(Shell parentShell, ComponentsRenamingModel model) { super(parentShell); @@ -126,11 +135,23 @@ public class ComponentsRenamingDialog extends Dialog { // Name table - tableViewer = new TableViewer(composite); + tableViewer = CheckboxTableViewer.newCheckList(composite, + SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); + tableViewer.getTable().setHeaderVisible(true); GridDataFactory.fillDefaults().grab(true, true).applyTo(tableViewer.getTable()); tableViewer.setContentProvider(ArrayContentProvider.getInstance()); + tableViewer.setCheckStateProvider(new ICheckStateProvider() { + @Override + public boolean isGrayed(Object element) { + return false; + } + @Override + public boolean isChecked(Object element) { + return model.selectedEntries.contains(element); + } + }); TableViewerColumn oldNameColumn = new TableViewerColumn(tableViewer, SWT.NONE); oldNameColumn.getColumn().setText("Old name"); @@ -153,9 +174,59 @@ public class ComponentsRenamingDialog extends Dialog { return entry.newName; } }); + tableViewer.addCheckStateListener(new ICheckStateListener() { + void addOrRemoveSelection(NameEntry entry, boolean add) { + if (add) + model.selectedEntries.add(entry); + else + model.selectedEntries.remove(entry); + } + @Override + public void checkStateChanged(CheckStateChangedEvent event) { + final boolean checked = event.getChecked(); + NameEntry checkedNode = (NameEntry) event.getElement(); + + Set entries = new HashSet(); + Set selection = ISelectionUtils.filterSetSelection(tableViewer.getSelection(), NameEntry.class); + if (selection.contains(checkedNode)) + entries.addAll(selection); + else + tableViewer.setSelection(StructuredSelection.EMPTY); + entries.add(checkedNode); + + for (NameEntry entry : entries) { + addOrRemoveSelection(entry, checked); + } + + tableViewer.refresh(); + } + }); tableViewer.setInput(model.entries.toArray()); newNamePrefix.setFocus(); - + + // Select All/None button bar + Composite bar = new Composite(composite, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(bar); + bar.setLayout(new RowLayout()); + Button selectAll = new Button(bar, SWT.PUSH); + selectAll.setText("Select &All"); + selectAll.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + model.selectedEntries.addAll(model.entries); + tableViewer.setAllChecked(true); + } + }); + Button clearSelection = new Button(bar, SWT.PUSH); + clearSelection.setText("&Clear Selection"); + clearSelection.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + model.selectedEntries.clear(); + tableViewer.setAllChecked(false); + } + }); + return composite; }