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 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.exception.InvalidModelException;
32  import org.wsmo.factory.LogicalExpressionFactory;
33  import org.wsmo.service.choreography.rule.*;
34  import org.wsmo.service.rule.ChoreographyRule;
35  import org.wsmo.service.rule.Condition;
36  import org.wsmo.wsml.ParserException;
37  import org.wsmostudio.choreography.ChoreographyPlugin;
38  import org.wsmostudio.choreography.editors.model.ChoreographyModel;
39  import org.wsmostudio.runtime.WSMORuntime;
40  import org.wsmostudio.ui.Utils;
41  
42  public class IfThenEditor extends RuleFormEditor {
43  
44      private Text exprContainer;
45      private boolean dirty = false;
46      
47      public IfThenEditor(ChoreographyRule rule, ChoreographyModel model) {
48          super(rule, model);
49      }
50      
51      public Composite initUI(Composite parent) {
52          Composite mainContainer = new Composite(parent, SWT.BORDER);
53          mainContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
54          mainContainer.setLayout(new GridLayout(1, false));
55          Composite header = new Composite(mainContainer, SWT.NONE);
56          header.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
57          header.setLayout(new GridLayout(2, false));
58          
59          new Label(header, SWT.NONE).setImage(RulesManagementPanel.iconForRule(rule));
60          Label lab = new Label(header, SWT.NONE);
61          lab.setText(labelForRule());
62          lab.setForeground(
63                  parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
64          lab.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
65          
66          new Label(mainContainer, SWT.NONE).setText("Condition :");
67          
68          exprContainer = new Text(mainContainer, 
69                  SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
70          
71          exprContainer.setText(
72                  ((ChoreographyIfThen)rule).getCondition().getRestrictedLogicalExpression().toString(
73                          Utils.findTopContainer(uiModel)));
74          exprContainer.addModifyListener(new ModifyListener() {
75              public void modifyText(ModifyEvent me) {
76                  uiModel.setChanged();
77                  dirty = true;
78              }
79          });
80          exprContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
81  
82          return mainContainer;
83      }
84  
85      @Override
86      public void updateRule() throws ParserException, InvalidModelException {
87          if (dirty == false) {
88              return; // no update is needed
89          }
90          String newConditionText = exprContainer.getText().trim();
91          ChoreographyTransitionRule theRule = (ChoreographyTransitionRule)getRule();
92          if (theRule.getCondition() != null 
93                  && theRule.getCondition().toString().equals(newConditionText)) {
94              return; // no change
95          }
96          
97          LogicalExpressionFactory leFactory = WSMORuntime.getRuntime().getLogExprFactory();
98          Condition condition = 
99              ChoreographyPlugin.getFactory().transitionRules.createConditionFromLogicalExpression(
100                     leFactory.createLogicalExpression(newConditionText,
101                             Utils.findTopContainer(uiModel)));
102         
103         theRule.setCondition(condition);
104     }
105 
106     public void dispose() {
107         exprContainer.dispose();
108     }
109 
110 }
111 
112 /*
113  * $Log$
114  * Revision 1.8  2006/11/22 14:11:06  alex_simov
115  * Code refactoring: the plug-in is synchronized with the latest wsmo4j changes
116  *
117  * Revision 1.7  2006/04/18 07:14:37  alex_simov
118  * Adapting to the recent choreography-api changes
119  *
120  * Revision 1.6  2006/01/09 12:51:11  alex_simov
121  * Copyright message in header updated
122  *
123  * Revision 1.5  2005/12/21 15:25:35  alex_simov
124  * choreography managment implementation completed
125  *
126  * Revision 1.4  2005/12/19 15:35:54  alex_simov
127  * update
128  *
129  * Revision 1.3  2005/11/24 13:48:16  alex_simov
130  * logical expression field contains now wrapped text
131  * (instead of horizontal scroll bar)
132  * [bug issue 1365441]
133  *
134  */