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