View Javadoc

1   /*
2   WSMO Studio - a Semantic Web Service Editor
3   Copyright (c) 2004-2006, OntoText Lab. / SIRMA Group
4   
5   This library is free software; you can redistribute it and/or modify it under
6   the terms of the GNU Lesser General Public License as published by the Free
7   Software Foundation; either version 2.1 of the License, or (at your option)
8   any later version.
9   This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  details.
13  You should have received a copy of the GNU Lesser General Public License along
14  with this library; if not, write to the Free Software Foundation, Inc.,
15  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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         // Copy the non-functional properties
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 * $Log$
105 * Revision 1.1  2006/11/22 14:12:54  alex_simov
106 * ChoreographyRules container renaming functionality added in WSMO Navigator
107 *
108 */