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.ui.editors;
26  
27  import org.eclipse.swt.SWT;
28  import org.eclipse.swt.custom.SashForm;
29  import org.eclipse.swt.layout.*;
30  import org.eclipse.swt.widgets.*;
31  import org.eclipse.ui.*;
32  import org.wsmo.common.TopEntity;
33  import org.wsmostudio.runtime.WSMORuntime;
34  import org.wsmostudio.ui.editors.common.*;
35  import org.wsmostudio.ui.editors.model.*;
36  
37  /***
38   * An editor component, subclass of WSMOEditor, capable to handle with WSMO-API 
39   * Capability objects.
40   * This editor appears as a part of the WSMO Studio workbench. It is the default
41   * editor implementation for this kind of objects and it can be replaced by 
42   * extending extension points <code>org.wsmostudio.ui.editors</code> and 
43   * <code>org.eclipse.ui.editors</code>.
44   *
45   * @author not attributable
46   * @version $Revision: 1.12 $ $Date: 2006/01/09 12:51:13 $
47   */
48  
49  public class CapabilityEditor extends WSMOEditor {
50  
51      private NFPPanel nfpPanel;
52      private NamespacesPanel nsPanel;
53      private ImportOntologyPanel ontologiesPanel;
54      private SharedVarsPanel varsPanel;
55      private AxiomContainerPanel precondsPanel, 
56                                  postcondsPanel, 
57                                  effectsPanel, 
58                                  assumptionsPanel;
59      
60      private CapabilityModel capabilityModel;
61      
62      private TabFolder medsAndOntosFolder;
63      
64      @SuppressWarnings("unchecked")
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, capabilityModel);
71          
72          SashForm splitter = new SashForm(parent, SWT.VERTICAL );
73          splitter.setLayoutData(new GridData(GridData.FILL_BOTH));
74  
75          medsAndOntosFolder = new TabFolder(splitter, SWT.NONE);
76          ontologiesPanel = new ImportOntologyPanel(medsAndOntosFolder, 
77                                                    capabilityModel);
78          
79          varsPanel = new SharedVarsPanel(medsAndOntosFolder, 
80                                          capabilityModel);
81          
82          TabItem nsTempTab = new TabItem(medsAndOntosFolder, SWT.NONE);
83          nsTempTab.setText("Namespaces");
84          nsPanel = new NamespacesPanel(medsAndOntosFolder, 
85                                        false, // no component border
86                                        capabilityModel);
87  
88          nsTempTab.setControl(nsPanel.getControl());
89          
90          // preconditions & assumptions
91          SashForm splitter2 = new SashForm(splitter, SWT.HORIZONTAL );
92          splitter2.setLayoutData(new GridData(GridData.FILL_BOTH));
93          
94          TabFolder preCondFolder = new TabFolder(splitter2, SWT.NONE);
95          
96          precondsPanel = new AxiomContainerPanel(preCondFolder,
97                                  this,
98                                  capabilityModel, 
99                                  AxiomContainerPanel.PRECONDITIONS);
100 
101         TabFolder assumpsFolder = new TabFolder(splitter2, SWT.NONE);
102         assumptionsPanel = new AxiomContainerPanel(assumpsFolder, 
103                                    this,
104                                    capabilityModel, 
105                                    AxiomContainerPanel.ASSUMPTIONS);
106         
107         // postconditions & effects
108         SashForm splitter3 = new SashForm(splitter, SWT.HORIZONTAL );
109         splitter3.setLayoutData(new GridData(GridData.FILL_BOTH));
110         TabFolder postFolder = new TabFolder(splitter3, SWT.NONE);
111         postcondsPanel = new AxiomContainerPanel(postFolder, 
112                                  this,
113                                  capabilityModel, 
114                                  AxiomContainerPanel.POSTCONDITIONS);
115         
116         TabFolder effectsFolder = new TabFolder(splitter3, SWT.NONE);
117         effectsPanel = new AxiomContainerPanel(effectsFolder, 
118                                this,
119                                capabilityModel, 
120                                AxiomContainerPanel.EFFECTS);
121         
122         splitter.setWeights(new int[] {3, 3, 3});
123     }
124     
125     public void init(IEditorSite site, IEditorInput input) throws PartInitException {
126         super.init(site, input);
127         capabilityModel = (CapabilityModel)input.getAdapter(CapabilityModel.class);
128     }
129 
130     public void dispose() {
131         nsPanel.dispose();
132         nfpPanel.dispose();
133         super.dispose();
134     }
135     
136     @SuppressWarnings("unchecked")
137     protected void doTryToSave() throws Exception {
138         nsPanel.doUpdate();
139         ObservableModel mainModel = capabilityModel;
140         while (mainModel.getMasterModel() != null) { // find the topmost container
141             mainModel = mainModel.getMasterModel();
142         }
143         TopEntity topContainer = (TopEntity)mainModel.getAdapter(TopEntity.class); 
144         WSMORuntime.getRuntime().doUpdateEntity(topContainer);
145     }
146 
147     @SuppressWarnings("unchecked")
148     protected void updateFromModel() {
149         nsPanel.reloadNSInfo();
150         ontologiesPanel.reloadOntologies();
151         varsPanel.reloadVariables();
152         precondsPanel.reloadAxioms(); 
153         postcondsPanel.reloadAxioms();
154         effectsPanel.reloadAxioms();
155         assumptionsPanel.reloadAxioms();
156   
157     }
158 }
159 
160 /*
161  * $Log: CapabilityEditor.java,v $
162  * Revision 1.12  2006/01/09 12:51:13  alex_simov
163  * Copyright message in header updated
164  *
165  * Revision 1.11  2005/11/09 16:17:39  alex_simov
166  * UIModels notification improved
167  *
168  * Revision 1.10  2005/11/02 14:50:57  alex_simov
169  * moving to MVC architecture cont'd
170  *
171  * Revision 1.9  2005/09/08 16:46:25  alex_simov
172  * Migrating to Java 1.5
173  *
174  * Revision 1.8  2005/08/02 10:33:20  alex_simov
175  * minor code and/or javadoc fixes
176  *
177  * Revision 1.7  2005/07/29 15:08:02  alex_simov
178  * added javadoc: class description, footer
179  *
180  *
181  */