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.editors;
26  
27  import java.lang.reflect.*;
28  
29  import org.eclipse.swt.SWT;
30  import org.eclipse.swt.custom.SashForm;
31  import org.eclipse.swt.layout.*;
32  import org.eclipse.swt.widgets.*;
33  import org.omwg.ontology.Ontology;
34  import org.wsmo.common.TopEntity;
35  import org.wsmo.service.signature.StateSignature;
36  import org.wsmostudio.choreography.editors.model.ChoreographyModel;
37  import org.wsmostudio.ui.editors.common.ImportOntologyPanel;
38  import org.wsmostudio.ui.editors.model.TopEntityModel;
39  
40  public class StateSignatureEditor {
41  
42      private ImportOntologyPanel ontologiesPanel;
43  
44      private TabFolder importsOntosFolder,
45                        groundedModesFolder;
46  
47      private SigModesContainer inModesContainer,
48                                outModesContainer,
49                                sharedModesContainer,
50                                staticModesContainer,
51                                ctrlModesContainer;
52  
53      private ChoreographyModel uiModel;
54      private TopEntityModel proxyModel;// used for reuse of ImportOntologyPanel only
55      private Group sigPanel;
56      
57      public StateSignatureEditor(ChoreographyModel model,
58                                  Composite parentComp) {
59          
60          this.uiModel = model; 
61          this.proxyModel = createProxyModel();
62  
63          sigPanel = new Group(parentComp, SWT.NONE);
64          sigPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
65          sigPanel.setLayout(new GridLayout(1, false));
66          updatePanelTitle();        
67  
68          SashForm splitter = new SashForm(sigPanel, SWT.VERTICAL );
69          splitter.setLayoutData(new GridData(GridData.FILL_BOTH));
70  
71          importsOntosFolder = new TabFolder(splitter, SWT.NONE);
72          
73  
74          ontologiesPanel = new ImportOntologyPanel(importsOntosFolder, 
75                  (uiModel.getStateSignature() != null) ? proxyModel : null);
76          
77          groundedModesFolder = new TabFolder(splitter, SWT.NONE);
78          inModesContainer = new SigModesContainer(groundedModesFolder, 
79                                                   uiModel,
80                                                   SigModesContainer.IN_MODES);
81          outModesContainer = new SigModesContainer(groundedModesFolder, 
82                                                   uiModel,
83                                                   SigModesContainer.OUT_MODES);
84          sharedModesContainer = new SigModesContainer(groundedModesFolder, 
85                                                   uiModel,
86                                                   SigModesContainer.SHARED_MODES);
87          
88          staticModesContainer = new SigModesContainer(groundedModesFolder, 
89                                                   uiModel,
90                                                   SigModesContainer.STATIC_MODES);
91          ctrlModesContainer = new SigModesContainer(groundedModesFolder, 
92                                                   uiModel,
93                                                   SigModesContainer.CONTROLLED_MODES);
94          splitter.setWeights(new int[] {1, 2});
95      }
96      
97      public void reloadContent() {
98          ontologiesPanel.setUIModel(
99                  (uiModel.getStateSignature() != null) ? proxyModel : null);
100         updatePanelTitle();
101         inModesContainer.reloadModes();
102         outModesContainer.reloadModes();
103         sharedModesContainer.reloadModes();
104         staticModesContainer.reloadModes();
105         ctrlModesContainer.reloadModes();
106     }
107     
108     public void dispose() {
109         ontologiesPanel.dispose();
110         inModesContainer.dispose();
111         outModesContainer.dispose();
112         sharedModesContainer.dispose();
113         staticModesContainer.dispose();
114         ctrlModesContainer.dispose();
115     }
116     
117     private void updatePanelTitle() {
118         StateSignature sSig = uiModel.getStateSignature();
119         if (sSig == null) {
120             sigPanel.setText("No State Signature");
121         }
122         else {
123             sigPanel.setText("State Signature - " + sSig.getIdentifier().toString());
124         }
125     }
126    
127     private TopEntityModel createProxyModel() {
128         
129         final TopEntity teProxy = (TopEntity)Proxy.newProxyInstance(TopEntity.class.getClassLoader(),
130                 new Class[] { TopEntity.class }, 
131                 new InvocationHandler() {
132             public Object invoke(Object proxy, Method method, Object[] args)
133                     throws Throwable {
134                 if (method.getName().equals("listOntologies")) {
135                     return uiModel.getStateSignature().listOntologies();
136                 }
137                 return null;
138             }
139         } );
140         TopEntityModel proxyModel = new TopEntityModel(uiModel.getChoreography()) {
141             public TopEntity getTopEntity() {
142                 return teProxy;
143             }
144             public void addOntology(Ontology ontology) {
145                 uiModel.addOntology(ontology);
146             }
147             public void removeOntology(Ontology onto) {
148                 uiModel.removeOntology(onto);
149             }
150         };
151         return proxyModel;
152     }
153 }
154 
155 /*
156  * $Log$
157  * Revision 1.3  2007/04/17 14:27:07  alex_simov
158  * migration to the latest wsmo4j (java 5)
159  *
160  * Revision 1.2  2006/11/22 14:11:06  alex_simov
161  * Code refactoring: the plug-in is synchronized with the latest wsmo4j changes
162  *
163  * Revision 1.1  2006/04/18 07:19:19  alex_simov
164  * refactoring: the StateSignature editor extracted as a separate component
165  *
166  */