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.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) {
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237