import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.request.UniqueRead;\r
import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.adapter.ActionFactory;\r
return new Runnable() {\r
@Override\r
public void run() {\r
- final ComponentsRenamingModel model = new ComponentsRenamingModel();\r
try {\r
- Simantics.getSession().syncRequest(new ReadRequest() {\r
+ ComponentsRenamingModel model = Simantics.getSession().syncRequest(new UniqueRead<ComponentsRenamingModel>() {\r
@Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- model.read(graph, composite);\r
+ public ComponentsRenamingModel perform(ReadGraph graph) throws DatabaseException {\r
+ return new ComponentsRenamingModel().read(graph, composite);\r
}\r
});\r
ComponentsRenamingDialog dialog = new ComponentsRenamingDialog(\r
package org.simantics.modeling.ui.diagram.renaming;\r
\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
import org.eclipse.jface.dialogs.Dialog;\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.GridLayoutFactory;\r
import org.eclipse.jface.viewers.ArrayContentProvider;\r
+import org.eclipse.jface.viewers.CheckStateChangedEvent;\r
+import org.eclipse.jface.viewers.CheckboxTableViewer;\r
import org.eclipse.jface.viewers.ColumnLabelProvider;\r
-import org.eclipse.jface.viewers.TableViewer;\r
+import org.eclipse.jface.viewers.ICheckStateListener;\r
+import org.eclipse.jface.viewers.ICheckStateProvider;\r
+import org.eclipse.jface.viewers.StructuredSelection;\r
import org.eclipse.jface.viewers.TableViewerColumn;\r
import org.eclipse.swt.SWT;\r
import org.eclipse.swt.events.ModifyEvent;\r
import org.eclipse.swt.events.SelectionEvent;\r
import org.eclipse.swt.layout.GridData;\r
import org.eclipse.swt.layout.GridLayout;\r
+import org.eclipse.swt.layout.RowLayout;\r
import org.eclipse.swt.widgets.Button;\r
import org.eclipse.swt.widgets.Composite;\r
import org.eclipse.swt.widgets.Control;\r
import org.eclipse.swt.widgets.Label;\r
import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.swt.widgets.Text;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
\r
public class ComponentsRenamingDialog extends Dialog {\r
\r
Text newNamePrefix;\r
Label errorLabel;\r
Text error;\r
- TableViewer tableViewer;\r
+ CheckboxTableViewer tableViewer;\r
\r
public ComponentsRenamingDialog(Shell parentShell, ComponentsRenamingModel model) {\r
super(parentShell);\r
\r
// Name table\r
\r
- tableViewer = new TableViewer(composite);\r
+ tableViewer = CheckboxTableViewer.newCheckList(composite,\r
+ SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);\r
+\r
tableViewer.getTable().setHeaderVisible(true);\r
GridDataFactory.fillDefaults().grab(true, true).applyTo(tableViewer.getTable());\r
\r
tableViewer.setContentProvider(ArrayContentProvider.getInstance());\r
+ tableViewer.setCheckStateProvider(new ICheckStateProvider() {\r
+ @Override\r
+ public boolean isGrayed(Object element) {\r
+ return false;\r
+ }\r
+ @Override\r
+ public boolean isChecked(Object element) {\r
+ return model.selectedEntries.contains(element);\r
+ }\r
+ });\r
\r
TableViewerColumn oldNameColumn = new TableViewerColumn(tableViewer, SWT.NONE);\r
oldNameColumn.getColumn().setText("Old name");\r
return entry.newName;\r
}\r
});\r
+ tableViewer.addCheckStateListener(new ICheckStateListener() {\r
+ void addOrRemoveSelection(NameEntry entry, boolean add) {\r
+ if (add)\r
+ model.selectedEntries.add(entry);\r
+ else\r
+ model.selectedEntries.remove(entry);\r
+ }\r
+ @Override\r
+ public void checkStateChanged(CheckStateChangedEvent event) {\r
+ final boolean checked = event.getChecked();\r
+ NameEntry checkedNode = (NameEntry) event.getElement();\r
+\r
+ Set<NameEntry> entries = new HashSet<NameEntry>();\r
+ Set<NameEntry> selection = ISelectionUtils.filterSetSelection(tableViewer.getSelection(), NameEntry.class);\r
+ if (selection.contains(checkedNode))\r
+ entries.addAll(selection);\r
+ else\r
+ tableViewer.setSelection(StructuredSelection.EMPTY);\r
+ entries.add(checkedNode);\r
+\r
+ for (NameEntry entry : entries) {\r
+ addOrRemoveSelection(entry, checked);\r
+ }\r
+\r
+ tableViewer.refresh();\r
+ }\r
+ });\r
tableViewer.setInput(model.entries.toArray());\r
newNamePrefix.setFocus();\r
- \r
+\r
+ // Select All/None button bar\r
+ Composite bar = new Composite(composite, SWT.NONE);\r
+ GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(bar);\r
+ bar.setLayout(new RowLayout());\r
+ Button selectAll = new Button(bar, SWT.PUSH);\r
+ selectAll.setText("Select &All");\r
+ selectAll.addSelectionListener(new SelectionAdapter() {\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ model.selectedEntries.addAll(model.entries);\r
+ tableViewer.setAllChecked(true);\r
+ }\r
+ });\r
+ Button clearSelection = new Button(bar, SWT.PUSH);\r
+ clearSelection.setText("&Clear Selection");\r
+ clearSelection.addSelectionListener(new SelectionAdapter() {\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ model.selectedEntries.clear();\r
+ tableViewer.setAllChecked(false);\r
+ }\r
+ });\r
+\r
return composite;\r
}\r
\r
\r
import java.util.ArrayList;\r
import java.util.Collections;\r
+import java.util.HashSet;\r
import java.util.List;\r
+import java.util.Set;\r
\r
import org.eclipse.core.runtime.IStatus;\r
import org.eclipse.core.runtime.Status;\r
*/\r
public class ComponentsRenamingModel {\r
public ArrayList<NameEntry> entries = new ArrayList<NameEntry>();\r
+ public Set<NameEntry> selectedEntries = new HashSet<>();\r
public String oldNamePrefix;\r
public String newNamePrefix;\r
public boolean reset;\r
private Resource configuration;\r
private ComponentNamingStrategy namingStrategy;\r
\r
- public void read(ReadGraph g, Resource composite) throws DatabaseException {\r
+ public ComponentsRenamingModel read(ReadGraph g, Resource composite) throws DatabaseException {\r
this.session = g.getSession();\r
this.compositeVariable = Variables.getVariable(g, composite);\r
this.configuration = g.syncRequest(new Configuration(composite));\r
prefixValidator = displayValue.getPossiblePropertyValue(g, Variables.INPUT_VALIDATOR);\r
\r
this.namingStrategy = ComponentNamingUtil.findNamingStrategy(g, null, composite);\r
+\r
+ // By default, select all entries.\r
+ this.selectedEntries.addAll(entries);\r
+\r
+ return this;\r
}\r
\r
public void computeNewNames() {\r
Layer0 L0 = Layer0.getInstance(g);\r
Layer0X L0X = Layer0X.getInstance(g);\r
for(NameEntry entry : entries)\r
- if(!entry.oldName.equals(entry.newName))\r
+ if(!entry.oldName.equals(entry.newName) && selectedEntries.contains(entry))\r
g.claimLiteral(entry.resource, L0.HasName, entry.newName, Bindings.STRING);\r
if(!oldNamePrefix.equals(newNamePrefix))\r
compositeVariable.setPropertyValue(g, L0X.HasGeneratedNamePrefix, newNamePrefix, Bindings.STRING);\r