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 Group</p>
23   */
24  
25  package org.wsmostudio.choreography.editors;
26  
27  import java.util.Iterator;
28  import java.util.Set;
29  
30  import org.eclipse.swt.SWT;
31  import org.eclipse.swt.custom.SashForm;
32  import org.eclipse.swt.layout.GridData;
33  import org.eclipse.swt.layout.GridLayout;
34  import org.eclipse.swt.widgets.Composite;
35  import org.eclipse.ui.IEditorInput;
36  import org.eclipse.ui.IEditorSite;
37  import org.eclipse.ui.PartInitException;
38  import org.wsmo.service.*;
39  import org.wsmostudio.choreography.editors.model.ChoreographyModel;
40  import org.wsmostudio.ui.editors.WSMOEditor;
41  import org.wsmostudio.ui.editors.common.NFPPanel;
42  
43  /***
44   * An editor component, subclass of WSMOEditor, capable to handle with WSMO-API 
45   * extensions for Choreography.
46   * This editor appears as a part of the WSMO Studio workbench. It is the default
47   * editor implementation for this kind of objects and it can be replaced by 
48   * extending extension points <code>org.wsmostudio.ui.editors</code> and 
49   * <code>org.eclipse.ui.editors</code>.
50   *
51   * @author not attributable
52   * @version $Revision: 1042 $ $Date: 2007-02-13 17:46:57 +0200 $
53   */
54  
55  public class ChoreographyEditor extends WSMOEditor {
56  
57      public static final String id = "org.wsmostudio.ui.editors.choreographyEditor";
58      
59      private NFPPanel nfpPanel;
60      private ChoreographyModel uiModel;
61      
62      private StateSignatureEditor sSigPanel;
63      private RulesManagementPanel rulesPanel;
64      
65      public void createPartControl(Composite parent) {
66          GridLayout mainLayout = new GridLayout(1, false);
67          mainLayout.verticalSpacing = 0;
68          parent.setLayout(mainLayout);
69          
70          nfpPanel = new NFPPanel(parent, uiModel);
71          
72          SashForm splitter = new SashForm(parent, SWT.VERTICAL );
73          splitter.setLayoutData(new GridData(GridData.FILL_BOTH));
74          
75          sSigPanel = new StateSignatureEditor(uiModel, splitter);
76          rulesPanel = new RulesManagementPanel(splitter, uiModel);
77          splitter.setWeights(new int[] {3, 5});
78      }
79      
80      public void init(IEditorSite site, IEditorInput input) throws PartInitException {
81          super.init(site, input);
82          this.uiModel = (ChoreographyModel)input.getAdapter(ChoreographyModel.class);
83      }
84  
85      public void dispose() {
86          nfpPanel.dispose();
87          sSigPanel.dispose();
88          super.dispose();
89      }
90      
91      /***
92       * The method is invoked just before SAVE operation. 
93       * The internal state of the editor is merged with the wsmo4j model.
94       */
95      public void modelAboutToSave() throws Exception {
96          rulesPanel.updateEditedRule();
97      }
98  
99      protected void updateFromModel() {
100         nfpPanel.update();
101         sSigPanel.reloadContent();
102         rulesPanel.reloadRules();
103     }
104     
105     public boolean isInputEntityDead() {
106 
107         if (uiModel.getMasterModel().getAdapter(Interface.class) != null) {
108 
109             Interface iface = (Interface)
110                     uiModel.getMasterModel().getAdapter(Interface.class);
111             ServiceDescription service = (ServiceDescription)
112                     uiModel.getMasterModel().getMasterModel().getAdapter(
113                             ServiceDescription.class);
114             if (false == service.listInterfaces().contains(iface)) {
115                 return true; // the containing interface is removed
116             }
117             return (iface.getChoreography() != uiModel.getChoreography()
118                     && false == uiModel.getChoreography().equals(iface.getChoreography()));
119         }
120         if (uiModel.getMasterModel().getAdapter(ServiceDescription.class) != null) {
121             
122             ServiceDescription service = (ServiceDescription)
123                     uiModel.getMasterModel().getAdapter(ServiceDescription.class);
124             Set ifaces = service.listInterfaces();
125             for(Iterator it = ifaces.iterator(); it.hasNext();) {
126                 Interface testIface = (Interface)it.next();
127                 if (testIface.getChoreography() == uiModel.getChoreography()
128                         || uiModel.getChoreography().equals(testIface.getChoreography())) {
129                     return false; // for sure there's a link b/w Service and chor
130                 }
131             }
132             return true; // no connection interafce <-> choreography found
133         }
134         return super.isInputEntityDead();
135     }
136 
137 }
138 
139 /*
140  * $Log$
141  * Revision 1.18  2007/02/13 15:46:57  alex_simov
142  * bugfix[1312971]: The WSMO Text editor synchronizes the wsmo object
143  * model automatically with the other editors (if possible) or issues a warning
144  * message otherwise.
145  *
146  * Revision 1.17  2006/12/20 12:29:11  alex_simov
147  * no message
148  *
149  * Revision 1.16  2006/07/11 15:52:21  alex_simov
150  * imports customization
151  *
152  * Revision 1.15  2006/05/15 11:48:16  alex_simov
153  * pre/post save editors content notification model improved
154  *
155  * Revision 1.14  2006/04/18 07:20:00  alex_simov
156  * refactoring: the StateSignature editor extracted as a separate component
157  *
158  * Revision 1.13  2006/02/17 09:51:38  alex_simov
159  * obsolete  check removed in doTryToSave()
160  *
161  * Revision 1.12  2006/02/03 10:25:31  alex_simov
162  * no message
163  *
164  * Revision 1.11  2006/01/10 13:59:54  alex_simov
165  * bugfix: editor rejects choreographies without transiiton rules
166  *
167  * Revision 1.10  2006/01/09 15:22:29  alex_simov
168  * bugfix: current rule editor content update
169  *
170  * Revision 1.9  2006/01/09 12:51:11  alex_simov
171  * Copyright message in header updated
172  *
173  * Revision 1.8  2005/12/19 15:35:54  alex_simov
174  * update
175  *
176  * Revision 1.7  2005/11/30 15:04:04  alex_simov
177  * code refactoring
178  *
179  * Revision 1.6  2005/11/16 16:21:22  alex_simov
180  * choreography editor enriched with rules management support
181  *
182  * Revision 1.5  2005/11/10 13:33:24  alex_simov
183  * UIModels support added
184  *
185  * Revision 1.4  2005/11/03 13:37:59  alex_simov
186  * isDirty() fix
187  *
188  * Revision 1.3  2005/11/02 14:51:23  alex_simov
189  * moving to MVC architecture cont'd
190  *
191  * Revision 1.2  2005/11/02 08:43:11  alex_simov
192  * update
193  *
194  * Revision 1.1  2005/10/27 11:15:08  alex_simov
195  * initial plugin commit
196  *
197  *
198  */