1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2006</p>
22 * <p>Company: OntoText Lab. / SIRMA </p>
23 */
24
25 package org.wsmostudio.choreography.navigator.actions;
26
27 import java.util.*;
28
29 import org.eclipse.jface.dialogs.Dialog;
30 import org.eclipse.swt.widgets.TreeItem;
31 import org.omwg.ontology.Value;
32 import org.wsmo.common.*;
33 import org.wsmo.common.exception.InvalidModelException;
34 import org.wsmo.service.choreography.Choreography;
35 import org.wsmo.service.choreography.rule.ChoreographyRules;
36 import org.wsmostudio.choreography.ChoreographyPlugin;
37 import org.wsmostudio.runtime.LogManager;
38 import org.wsmostudio.runtime.WSMORuntime;
39 import org.wsmostudio.ui.IdentifierInputDialog;
40 import org.wsmostudio.ui.Utils;
41 import org.wsmostudio.ui.editors.model.ObservableModel;
42 import org.wsmostudio.ui.views.navigator.actions.AbstractAction;
43
44 public class RenameChoreographyRules extends AbstractAction {
45
46 public void run() {
47
48 TreeItem[] selection = navigator.getTree().getTree().getSelection();
49 Choreography chor = (Choreography)selection[0].getParentItem().getData();
50
51 ObservableModel uiModel =
52 (ObservableModel)navigator.getWsmoInput().getAdapter(ObservableModel.class);
53
54 IdentifierInputDialog iriInputDialog = new IdentifierInputDialog(
55 navigator.getSite().getShell(),
56 "Rename Choreography Rules",
57 "New Choreography Rules Identifier (leave blank for anonymous):",
58 Utils.findTopContainer(uiModel),
59 WSMORuntime.getRuntime().getWsmoFactory(),
60 true);
61 if (iriInputDialog.open() != Dialog.OK) {
62 return;
63 }
64 Identifier chorRulesID = (Identifier)iriInputDialog.getIdentifier();
65 ChoreographyRules oldRules = chor.getRules();
66 if ((chorRulesID instanceof UnnumberedAnonymousID
67 && oldRules.getIdentifier() instanceof UnnumberedAnonymousID) ||
68 oldRules.getIdentifier().equals(chorRulesID)) {
69 return;
70 }
71
72 ChoreographyRules newRules =
73 ChoreographyPlugin.getFactory().containers.createRules(
74 chorRulesID,
75 oldRules.listRules());
76
77
78 Map nfps = oldRules.listNFPValues();
79 for(Iterator keysIt = nfps.keySet().iterator(); keysIt.hasNext();) {
80 IRI key = (IRI)keysIt.next();
81 Set values = oldRules.listNFPValues(key);
82 for(Iterator it = values.iterator(); it.hasNext();) {
83 Object val = it.next();
84 try {
85 if (val instanceof Identifier) {
86 newRules.addNFPValue(key, (Identifier)val);
87 }
88 else if (val instanceof Value) {
89 newRules.addNFPValue(key, (Value)val);
90 }
91 }
92 catch(InvalidModelException ime) {
93 LogManager.logError(ime);
94 }
95 }
96 }
97 chor.setRules(newRules);
98 uiModel.setChanged();
99 navigator.fireEntityChanged(chor);
100 }
101 }
102
103
104
105
106
107
108