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