1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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;
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;
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134