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.common;
26  
27  import org.eclipse.swt.SWT;
28  import org.eclipse.swt.events.*;
29  import org.eclipse.swt.layout.*;
30  import org.eclipse.swt.widgets.*;
31  import org.wsmo.common.*;
32  import org.wsmostudio.runtime.IRIUtils;
33  import org.wsmostudio.ui.GUIHelper;
34  import org.wsmostudio.ui.Utils;
35  import org.wsmostudio.ui.editors.model.*;
36  import org.wsmostudio.ui.views.navigator.WSMONavigator;
37  
38  /***
39   * A common purpose GUI component, designed to maintain the UI support for
40   * identifiers and NonFunctionalProperties of the WSMO-API Entity objects.
41   * It is a sub-component of all WSMO editors whose target input objects
42   * have a "NonFunctionalProperties" property. From this panel the user can
43   * invoke the NFP Editor.
44   *
45   * @author not attributable
46   * @version $Revision: 1227 $ $Date: 2007-07-19 16:08:32 +0300 $
47   */
48  
49  public class NFPPanel {
50  
51      private Text idField, descrField;
52      private Group mainHolder;
53      private Combo wsmlVariantChooser;
54      private EntityModel model;
55  
56      
57      public NFPPanel(Composite parent, 
58                      EntityModel model) {
59          
60          this.model = model;
61  
62          mainHolder = new Group(parent, SWT.FLAT);
63          mainHolder.setText("Header");
64          GridLayout nfpLayout = new GridLayout(4, false);
65          mainHolder.setLayout(nfpLayout);
66          mainHolder.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
67          
68          new Label(mainHolder, SWT.LEFT).setText("Identifier : ");
69          idField = new Text(mainHolder, SWT.BORDER | SWT.SINGLE);
70          Entity entity = (Entity)model.getAdapter(Entity.class);
71          String idText = entity.getIdentifier().toString();
72          if (entity.listNFPValues(IRIUtils.titleNFP) != null 
73                  && entity.listNFPValues(IRIUtils.titleNFP).size() > 0) {
74              idText += "   (" 
75                  + Utils.normalizeSpaces(
76                          entity.listNFPValues(
77                                  IRIUtils.titleNFP).iterator().next().toString()) 
78                  + ")";
79          }
80          idField.setText(idText);
81          idField.setLayoutData(new GridData(GridData.FILL,
82                  GridData.VERTICAL_ALIGN_BEGINNING,
83                  true,
84                  false));
85          idField.setEditable(false);
86          idField.addTraverseListener(new TraverseListener() {
87              public void keyTraversed(TraverseEvent e) {
88                  if (e.character == SWT.ESC) {
89                      e.doit = false;
90                  }
91              }
92          });
93          
94          
95          new Label(mainHolder, SWT.FLAT).setText("   ");
96          Button nfpEditButton = new Button(mainHolder, SWT.PUSH | SWT.CENTER);
97          nfpEditButton.setText("Non Functional Properties");
98          nfpEditButton.addSelectionListener(new SelectionAdapter() {
99              public void widgetSelected(SelectionEvent se) {
100             	new NFPEditor(Display.getCurrent().getActiveShell(), NFPPanel.this.model).open();
101                 if (NFPPanel.this.model.isDirty()) {
102                     WSMONavigator.propsViewRefresh();
103                     update();
104                 }
105             }
106         });
107         new Label(mainHolder, SWT.NONE).setText("Description : ");
108         descrField = new Text(mainHolder, SWT.SINGLE | SWT.BORDER);
109         descrField.setEditable(false);
110         GridData gData = new GridData(GridData.FILL_HORIZONTAL);
111         gData.horizontalSpan = 3;
112         descrField.setLayoutData(gData);
113         if (entity.listNFPValues(IRIUtils.descrNFP) != null 
114                 && entity.listNFPValues(IRIUtils.descrNFP).size() > 0) {
115             Object value = entity.listNFPValues(IRIUtils.descrNFP).iterator().next();
116             descrField.setText(
117                     (value instanceof Entity) ? 
118                         ((Entity)value).getIdentifier().toString()
119                         : Utils.normalizeSpaces(value.toString()));
120         }
121         idField.setText(idText);
122         
123         
124         
125         final TopEntity targetHolder = (TopEntity)model.getAdapter(TopEntity.class);
126         if (targetHolder != null) {
127             new Label(mainHolder, SWT.NONE).setText("WSML Variant : ");
128             wsmlVariantChooser = GUIHelper.createWsmlVariantChooser(mainHolder,
129                     targetHolder.getWsmlVariant());
130             GridData comboLayoutData = new GridData(GridData.FILL_HORIZONTAL);
131             comboLayoutData.horizontalSpan = 3;
132             wsmlVariantChooser.setLayoutData(comboLayoutData);
133             wsmlVariantChooser.addSelectionListener(new SelectionAdapter() {
134                 public void widgetSelected(SelectionEvent se) {
135                     ((TopEntityModel)NFPPanel.this.model).setWsmlVariant(wsmlVariantChooser.getText());
136                 }
137             });
138         }
139     }
140     
141     public void update() {
142         Entity entity = (Entity)model.getAdapter(Entity.class);
143         String idText = entity.getIdentifier().toString();
144         if (entity.listNFPValues(IRIUtils.titleNFP) != null 
145                 && entity.listNFPValues(IRIUtils.titleNFP).size() > 0) {
146             idText += "   (" 
147                 + Utils.normalizeSpaces(
148                         entity.listNFPValues(
149                                 IRIUtils.titleNFP).iterator().next().toString()) 
150                 + ")";
151         }
152         idField.setText(idText);
153         if (entity.listNFPValues(IRIUtils.descrNFP) != null 
154                 && entity.listNFPValues(IRIUtils.descrNFP).size() > 0) {
155             Object value = entity.listNFPValues(IRIUtils.descrNFP).iterator().next();
156             descrField.setText(
157                     (value instanceof Entity) ? 
158                         ((Entity)value).getIdentifier().toString()
159                         : Utils.normalizeSpaces(value.toString()));
160         }
161         else {
162             descrField.setText("");
163         }
164 
165 
166         final TopEntity targetHolder = (TopEntity)model.getAdapter(TopEntity.class);
167         if (targetHolder == null) { // not need to update
168             return;
169         }
170         int selIndex = 0;
171         if (targetHolder.getWsmlVariant() != null) {
172             selIndex = wsmlVariantChooser.indexOf(targetHolder.getWsmlVariant());
173         }
174         wsmlVariantChooser.select(Math.max(selIndex, 0));
175 
176     }
177     
178     public void dispose() {
179         mainHolder.dispose();
180         idField.dispose();
181     }
182 }
183 
184 /*
185  * $Log$
186  * Revision 1.18  2007/07/19 13:08:31  alex_simov
187  * - rfe [1751326] Navigation through the editor tab
188  * - concepts/attributes which are from a different namespace are prefixed
189  *
190  * Revision 1.17  2007/02/22 13:04:02  alex_simov
191  * Feature request [1665303]: new line characters are filtered from the content in
192  * non-editable fields
193  *
194  * Revision 1.16  2007/02/14 11:31:22  alex_simov
195  * Feature request [1654112]: WSMO Navigator preserves its tree expansion
196  * state when the user switches between editors
197  *
198  * Revision 1.15  2007/02/13 15:53:16  alex_simov
199  * bugfix[1312971]: The WSMO Text editor synchronizes the wsmo object
200  * model automatically with the other editors (if possible) or issues a warning
201  * message otherwise.
202  *
203  * Revision 1.14  2006/12/19 14:00:27  alex_simov
204  * ui refreshing fix
205  *
206  * Revision 1.13  2006/11/29 14:06:06  alex_simov
207  * bugfix: Properties view was not updated after NFP modifications
208  *
209  * Revision 1.12  2006/11/24 16:54:04  alex_simov
210  * ui improvements
211  *
212  * Revision 1.11  2006/11/20 17:15:03  alex_simov
213  * no message
214  *
215  * Revision 1.10  2006/08/02 12:31:35  alex_simov
216  * no message
217  *
218  * Revision 1.9  2006/01/09 12:51:13  alex_simov
219  * Copyright message in header updated
220  *
221  * Revision 1.8  2005/11/09 16:16:27  alex_simov
222  * UIModels notification improved
223  *
224  * Revision 1.7  2005/09/16 14:25:11  alex_simov
225  * Identifier.asString() removed, use Object.toString() instead
226  *
227  * Revision 1.6  2005/09/14 14:48:21  alex_simov
228  * wsml variants UI support added
229  *
230  * Revision 1.5  2005/08/02 10:33:21  alex_simov
231  * minor code and/or javadoc fixes
232  *
233  * Revision 1.4  2005/07/29 15:08:02  alex_simov
234  * added javadoc: class description, footer
235  *
236  *
237  */