1 package org.simantics.modeling.ui.actions;
\r
3 import org.eclipse.core.runtime.IStatus;
\r
4 import org.eclipse.core.runtime.Status;
\r
5 import org.eclipse.jface.dialogs.Dialog;
\r
6 import org.eclipse.ui.PlatformUI;
\r
7 import org.simantics.Simantics;
\r
8 import org.simantics.db.ReadGraph;
\r
9 import org.simantics.db.Resource;
\r
10 import org.simantics.db.WriteGraph;
\r
11 import org.simantics.db.common.request.ReadRequest;
\r
12 import org.simantics.db.common.request.WriteRequest;
\r
13 import org.simantics.db.exception.DatabaseException;
\r
14 import org.simantics.db.layer0.adapter.ActionFactory;
\r
15 import org.simantics.modeling.ui.Activator;
\r
16 import org.simantics.modeling.ui.diagram.renaming.ComponentsRenamingDialog;
\r
17 import org.simantics.modeling.ui.diagram.renaming.ComponentsRenamingModel;
\r
20 * @author Hannu Niemistö
\r
22 public class RenameDiagramComponents implements ActionFactory {
\r
25 public Runnable create(Object target) {
\r
26 if (!(target instanceof Resource))
\r
28 final Resource composite = (Resource)target;
\r
30 return new Runnable() {
\r
33 final ComponentsRenamingModel model = new ComponentsRenamingModel();
\r
35 Simantics.getSession().syncRequest(new ReadRequest() {
\r
37 public void run(ReadGraph graph) throws DatabaseException {
\r
38 model.read(graph, composite);
\r
41 ComponentsRenamingDialog dialog = new ComponentsRenamingDialog(
\r
42 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
\r
44 if(dialog.open() == Dialog.OK) {
\r
45 Simantics.getSession().syncRequest(new WriteRequest() {
\r
47 public void perform(WriteGraph graph)
\r
48 throws DatabaseException {
\r
49 graph.markUndoPoint();
\r
54 } catch (DatabaseException e) {
\r
55 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "RenameDiagramComponents action failed, see exception for details", e));
\r