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.UniqueRead;
\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
34 ComponentsRenamingModel model = Simantics.getSession().syncRequest(new UniqueRead<ComponentsRenamingModel>() {
\r
36 public ComponentsRenamingModel perform(ReadGraph graph) throws DatabaseException {
\r
37 return new ComponentsRenamingModel().read(graph, composite);
\r
40 ComponentsRenamingDialog dialog = new ComponentsRenamingDialog(
\r
41 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
\r
43 if(dialog.open() == Dialog.OK) {
\r
44 Simantics.getSession().syncRequest(new WriteRequest() {
\r
46 public void perform(WriteGraph graph)
\r
47 throws DatabaseException {
\r
48 graph.markUndoPoint();
\r
53 } catch (DatabaseException e) {
\r
54 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "RenameDiagramComponents action failed, see exception for details", e));
\r