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