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