ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / dialogs / TabContents.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs;
14
15 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter;
16 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.Messages;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.events.ModifyEvent;
19 import org.eclipse.swt.events.ModifyListener;
20 import org.eclipse.swt.events.SelectionEvent;
21 import org.eclipse.swt.events.SelectionListener;
22 import org.eclipse.swt.layout.GridData;
23 import org.eclipse.swt.layout.GridLayout;
24 import org.eclipse.swt.widgets.Button;
25 import org.eclipse.swt.widgets.Combo;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Group;
28 import org.eclipse.swt.widgets.Label;
29
30 /**
31 * Class implementation contains the controls that allows to create or update a find or filter Criteria.
32 *
33 * @version 1.0
34 * @author sveyrier
35 */
36 public class TabContents extends Composite {
37
38 // ------------------------------------------------------------------------
39 // Attributes
40 // ------------------------------------------------------------------------
41 /**
42 * The button for lifelines.
43 */
44 private Button fLifelineButton;
45 /**
46 * The button for stops.
47 */
48 private Button fStopButton = null;
49 /**
50 * The button for synchronous messages
51 */
52 private Button fSynMessageButton = null;
53 /**
54 * The button for synchronous return messages
55 */
56 private Button fSynMessageReturnButton = null;
57 /**
58 * The button for asynchronous messages
59 */
60 private Button fAsynMessageButton = null;
61 /**
62 * The button for asynchronous return messages
63 */
64 private Button fAsynMessageReturnButton = null;
65 /**
66 * The search text combo box.
67 */
68 private Combo fSearchText = null;
69 /**
70 * The button for case sensitive expressions.
71 */
72 private Button fCaseSensitive = null;
73 /**
74 * The label for the result string.
75 */
76 private Label fResult = null;
77 /**
78 * The button for notifying parent about valid data.
79 */
80 private Button fParentOkButton = null;
81
82 // ------------------------------------------------------------------------
83 // Constructors
84 // ------------------------------------------------------------------------
85
86 /**
87 * Creates the dialog contents
88 *
89 * @param parent the parent widget
90 * @param provider the provider which handle the action
91 * @param okButton of the dialog (to be enabled/disabled)
92 * @param expressionList list of strings already searched for
93 */
94 public TabContents(Composite parent, ISDGraphNodeSupporter provider, Button okButton, String[] expressionList) {
95 super(parent, SWT.NONE);
96 fParentOkButton = okButton;
97 setLayout(new GridLayout());
98
99 GraphNodeTypeListener graphNodeTypeListener = new GraphNodeTypeListener();
100 ExpressionListener expressionListener = new ExpressionListener();
101
102 // Inform the user how to fill the string to search
103 Label searchTitle = new Label(this, SWT.LEFT);
104 searchTitle.setText(Messages.SequenceDiagram_MatchingString);
105 Composite searchPart = new Composite(this, SWT.NONE);
106 GridData searchPartData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
107 GridLayout searchPartLayout = new GridLayout();
108 searchPartLayout.numColumns = 2;
109 searchPart.setLayout(searchPartLayout);
110 searchPart.setLayoutData(searchPartData);
111
112 // Create the user string input area
113 fSearchText = new Combo(searchPart, SWT.DROP_DOWN);
114 GridData comboData = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
115 /*
116 * GridData tabLayoutData2 = new GridData(GridData.HORIZONTAL_ALIGN_FILL| GridData.VERTICAL_ALIGN_FILL);
117 */
118 fSearchText.setLayoutData(comboData);
119 if (expressionList != null) {
120 for (int i = 0; i < expressionList.length; i++) {
121 fSearchText.add(expressionList[i]);
122 }
123 }
124 fSearchText.addModifyListener(expressionListener);
125
126 // Create the case sensitive check button
127 fCaseSensitive = new Button(searchPart, SWT.CHECK);
128 fCaseSensitive.setText(Messages.SequenceDiagram_CaseSensitive);
129
130 // Create the group for searched graph node kind selection
131 Group kindSelection = new Group(this, SWT.SHADOW_NONE);
132 kindSelection.setText(Messages.SequenceDiagram_SearchFor);
133 // kindSelection.setLayoutData(tabLayoutData2);
134 GridLayout kindSelectionLayout = new GridLayout();
135 kindSelectionLayout.numColumns = 1;
136 kindSelection.setLayout(kindSelectionLayout);
137 GridData kindSelectionData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
138 kindSelection.setLayoutData(kindSelectionData);
139
140 // Create the lifeline check button
141 if (provider != null && provider.isNodeSupported(ISDGraphNodeSupporter.LIFELINE)) {
142 fLifelineButton = new Button(kindSelection, SWT.CHECK);
143 String nodeName = provider.getNodeName(ISDGraphNodeSupporter.LIFELINE, null);
144 if (nodeName != null) {
145 fLifelineButton.setText(nodeName);
146 } else {
147 fLifelineButton.setText(Messages.SequenceDiagram_Lifeline);
148 }
149 fLifelineButton.setEnabled(true);
150 fLifelineButton.addSelectionListener(graphNodeTypeListener);
151 }
152
153 if (provider != null && provider.isNodeSupported(ISDGraphNodeSupporter.STOP)) {
154 // Create the stop check button
155 fStopButton = new Button(kindSelection, SWT.CHECK);
156 String nodeName = provider.getNodeName(ISDGraphNodeSupporter.STOP, null);
157 if (nodeName != null) {
158 fStopButton.setText(nodeName);
159 } else {
160 fStopButton.setText(Messages.SequenceDiagram_Stop);
161 }
162
163 fStopButton.setEnabled(true);
164 fStopButton.addSelectionListener(graphNodeTypeListener);
165 }
166
167 if (provider != null && provider.isNodeSupported(ISDGraphNodeSupporter.SYNCMESSAGE)) {
168 // Create the synchronous message check button
169 fSynMessageButton = new Button(kindSelection, SWT.CHECK);
170 String nodeName = provider.getNodeName(ISDGraphNodeSupporter.SYNCMESSAGE, null);
171 if (nodeName != null) {
172 fSynMessageButton.setText(nodeName);
173 } else {
174 fSynMessageButton.setText(Messages.SequenceDiagram_SynchronousMessage);
175 }
176 fSynMessageButton.setEnabled(true);
177 fSynMessageButton.addSelectionListener(graphNodeTypeListener);
178 }
179
180 if (provider != null && provider.isNodeSupported(ISDGraphNodeSupporter.SYNCMESSAGERETURN)) {
181 // Create the synchronous message return check button
182 fSynMessageReturnButton = new Button(kindSelection, SWT.CHECK);
183 String nodeName = provider.getNodeName(ISDGraphNodeSupporter.SYNCMESSAGERETURN, null);
184 if (nodeName != null) {
185 fSynMessageReturnButton.setText(nodeName);
186 } else {
187 fSynMessageReturnButton.setText(Messages.SequenceDiagram_SynchronousMessageReturn);
188 }
189 fSynMessageReturnButton.setEnabled(true);
190 fSynMessageReturnButton.addSelectionListener(graphNodeTypeListener);
191 }
192
193 if (provider != null && provider.isNodeSupported(ISDGraphNodeSupporter.ASYNCMESSAGE)) {
194 // Create the asynchronous message check button
195 fAsynMessageButton = new Button(kindSelection, SWT.CHECK);
196 String nodeName = provider.getNodeName(ISDGraphNodeSupporter.ASYNCMESSAGE, null);
197 if (nodeName != null) {
198 fAsynMessageButton.setText(nodeName);
199 } else {
200 fAsynMessageButton.setText(Messages.SequenceDiagram_AsynchronousMessage);
201 }
202 fAsynMessageButton.setEnabled(true);
203 fAsynMessageButton.addSelectionListener(graphNodeTypeListener);
204 }
205
206 if (provider != null && provider.isNodeSupported(ISDGraphNodeSupporter.ASYNCMESSAGERETURN)) {
207 // Create the asynchronous message return check button
208 fAsynMessageReturnButton = new Button(kindSelection, SWT.CHECK);
209 String nodeName = provider.getNodeName(ISDGraphNodeSupporter.ASYNCMESSAGERETURN, null);
210 if (nodeName != null) {
211 fAsynMessageReturnButton.setText(nodeName);
212 } else {
213 fAsynMessageReturnButton.setText(Messages.SequenceDiagram_AsynchronousMessageReturn);
214 }
215 fAsynMessageReturnButton.setEnabled(true);
216 fAsynMessageReturnButton.addSelectionListener(graphNodeTypeListener);
217 }
218
219 fResult = new Label(this, SWT.LEFT);
220 fResult.setText(Messages.SequenceDiagram_StringNotFound);
221 fResult.setVisible(false);
222 }
223
224 // ------------------------------------------------------------------------
225 // Methods
226 // ------------------------------------------------------------------------
227
228 /**
229 * Set result text visibility
230 * @param found <code>true</code> for found (enable visibility) else false
231 */
232 public void setResult(boolean found) {
233 fResult.setVisible(!found);
234 }
235
236 /**
237 * Updates parent OK button based on input data.
238 */
239 public void updateOkButton() {
240 if (fParentOkButton == null) {
241 return;
242 }
243 boolean enabled = (fSearchText.getText() != null && !fSearchText.getText().equals("")) && //$NON-NLS-1$
244 (isLifelineButtonSelected() || isStopButtonSelected() || isSynMessageButtonSelected() || isSynMessageReturnButtonSelected() || isAsynMessageButtonSelected() || isAsynMessageReturnButtonSelected());
245 fParentOkButton.setEnabled(enabled);
246 }
247
248 /**
249 * Sets the parent OK button reference.
250 *
251 * @param okButton The parent OK button
252 */
253 public void setOkButton(Button okButton) {
254 fParentOkButton = okButton;
255 }
256
257 /**
258 * Returns the asynchronous message check button state
259 *
260 * @return true if check, false otherwise
261 */
262 public boolean isAsynMessageButtonSelected() {
263 if (fAsynMessageButton != null) {
264 return fAsynMessageButton.getSelection();
265 }
266 return false;
267 }
268
269 /**
270 * Returns the asynchronous message return check button state
271 *
272 * @return true if check, false otherwise
273 */
274 public boolean isAsynMessageReturnButtonSelected() {
275 if (fAsynMessageReturnButton != null) {
276 return fAsynMessageReturnButton.getSelection();
277 }
278 return false;
279 }
280
281 /**
282 * Returns the case sensitive check button state
283 *
284 * @return true if check, false otherwise
285 */
286 public boolean isCaseSensitiveSelected() {
287 if (fCaseSensitive != null) {
288 return fCaseSensitive.getSelection();
289 }
290 return false;
291 }
292
293 /**
294 * Returns the lifeline check button state
295 *
296 * @return true if check, false otherwise
297 */
298 public boolean isLifelineButtonSelected() {
299 if (fLifelineButton != null) {
300 return fLifelineButton.getSelection();
301 }
302 return false;
303 }
304
305 /**
306 * Returns the user input string
307 *
308 * @return the string to search for
309 */
310 public String getSearchText() {
311 return fSearchText.getText();
312 }
313
314 /**
315 * Returns the stop check button state
316 *
317 * @return true if check, false otherwise
318 */
319 public boolean isStopButtonSelected() {
320 if (fStopButton != null) {
321 return fStopButton.getSelection();
322 }
323 return false;
324 }
325
326 /**
327 * Returns the synchronous message check button state
328 *
329 * @return true if check, false otherwise
330 */
331 public boolean isSynMessageButtonSelected() {
332 if (fSynMessageButton != null) {
333 return fSynMessageButton.getSelection();
334 }
335 return false;
336 }
337
338 /**
339 * Returns the synchronous message return check button state
340 *
341 * @return true if check, false otherwise
342 */
343 public boolean isSynMessageReturnButtonSelected() {
344 if (fSynMessageReturnButton != null) {
345 return fSynMessageReturnButton.getSelection();
346 }
347 return false;
348 }
349
350 /**
351 * Set the asynchronous message check button state
352 *
353 * @param state
354 * The new state to set
355 */
356 public void setAsynMessageButtonSelection(boolean state) {
357 if (fAsynMessageButton != null) {
358 fAsynMessageButton.setSelection(state);
359 }
360 }
361
362 /**
363 * Set the asynchronous message return check button state
364 *
365 * @param state
366 * The new state to set
367 */
368 public void setAsynMessageReturnButtonSelection(boolean state) {
369 if (fAsynMessageReturnButton != null) {
370 fAsynMessageReturnButton.setSelection(state);
371 }
372 }
373
374 /**
375 * Set the case sensitive check button state
376 *
377 * @param state
378 * The new state to set
379 */
380 public void setCaseSensitiveSelection(boolean state) {
381 if (fCaseSensitive != null) {
382 fCaseSensitive.setSelection(state);
383 }
384 }
385
386 /**
387 * Set the lifeline check button state
388 *
389 * @param state
390 * The new state to set
391 */
392 public void setLifelineButtonSelection(boolean state) {
393 if (fLifelineButton != null) {
394 fLifelineButton.setSelection(state);
395 }
396 }
397
398 /**
399 * Set the user input string
400 *
401 * @param text
402 * The search text
403 */
404 public void setSearchText(String text) {
405 fSearchText.setText(text);
406 }
407
408 /**
409 * Set the stop check button state
410 *
411 * @param state
412 * The new state to set
413 */
414 public void setStopButtonSelection(boolean state) {
415 if (fStopButton != null) {
416 fStopButton.setSelection(state);
417 }
418 }
419
420 /**
421 * Set the synchronous message check button state
422 *
423 * @param state
424 * The new state to set
425 */
426 public void setSynMessageButtonSelection(boolean state) {
427 if (fSynMessageButton != null) {
428 fSynMessageButton.setSelection(state);
429 }
430 }
431
432 /**
433 * Set the synchronous message return check button state
434 *
435 * @param state
436 * The new state to set
437 */
438 public void setSynMessageReturnButtonSelection(boolean state) {
439 if (fSynMessageReturnButton != null) {
440 fSynMessageReturnButton.setSelection(state);
441 }
442 }
443
444 // ------------------------------------------------------------------------
445 // Helper classes
446 // ------------------------------------------------------------------------
447
448 /**
449 * Selection listener implementation for graph node types.
450 * @version 1.0
451 */
452 protected class GraphNodeTypeListener implements SelectionListener {
453 @Override
454 public void widgetDefaultSelected(SelectionEvent e) {
455 // Nothing to do
456 }
457
458 @Override
459 public void widgetSelected(SelectionEvent e) {
460 updateOkButton();
461 }
462 }
463
464 /**
465 * Modify listener implementation for the expression field.
466 *
467 * @version 1.0
468 */
469 protected class ExpressionListener implements ModifyListener {
470 @Override
471 public void modifyText(ModifyEvent e) {
472 updateOkButton();
473 }
474 }
475
476 }
This page took 0.059331 seconds and 5 git commands to generate.