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
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
;
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
;
31 * Class implementation contains the controls that allows to create or update a find or filter Criteria.
36 public class TabContents
extends Composite
{
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
42 * A graph node type listener implementation.
44 protected GraphNodeTypeListener fGraphNodeTypeListener
= null;
46 * A expression listener implementation.
48 protected ExpressionListener fExpressionListener
= null;
50 * The button for lifelines.
52 protected Button fLifelineButton
= null;
54 * The button for stops.
56 protected Button fStopButton
= null;
58 * The button for synchronous messages
60 protected Button fSynMessageButton
= null;
62 * The button for synchronous return messages
64 protected Button fSynMessageReturnButton
= null;
66 * The button for asynchronous messages
68 protected Button fAsynMessageButton
= null;
70 * The button for asynchronous return messages
72 protected Button fAsynMessageReturnButton
= null;
74 * The search text combo box.
76 protected Combo fSearchText
= null;
78 * The group for selection kind.
80 protected Group fKindSelection
= null;
82 * The button for case sensitive expressions.
84 protected Button fCaseSensitive
= null;
86 * The label for the result string.
88 protected Label fResult
= null;
90 * The button for notifying parent about valid data.
92 protected Button fParentOkButton
= null;
94 // ------------------------------------------------------------------------
96 // ------------------------------------------------------------------------
99 * Creates the dialog contents
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
106 public TabContents(Composite parent
, ISDGraphNodeSupporter provider
, Button okButton
, String
[] expressionList
) {
107 super(parent
, SWT
.NONE
);
108 fParentOkButton
= okButton
;
109 setLayout(new GridLayout());
111 fGraphNodeTypeListener
= new GraphNodeTypeListener();
112 fExpressionListener
= new ExpressionListener();
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
);
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
);
128 * GridData tabLayoutData2 = new GridData(GridData.HORIZONTAL_ALIGN_FILL| GridData.VERTICAL_ALIGN_FILL);
130 fSearchText
.setLayoutData(comboData
);
131 if (expressionList
!= null) {
132 for (int i
= 0; i
< expressionList
.length
; i
++) {
133 fSearchText
.add(expressionList
[i
]);
136 fSearchText
.addModifyListener(fExpressionListener
);
138 // Create the case sensitive check button
139 fCaseSensitive
= new Button(searchPart
, SWT
.CHECK
);
140 fCaseSensitive
.setText(SDMessages
._27
);
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
);
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
);
159 fLifelineButton
.setText(SDMessages
._28
);
161 fLifelineButton
.setEnabled(true);
162 fLifelineButton
.addSelectionListener(fGraphNodeTypeListener
);
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
);
172 fStopButton
.setText(SDMessages
._29
);
175 fStopButton
.setEnabled(true);
176 fStopButton
.addSelectionListener(fGraphNodeTypeListener
);
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
);
186 fSynMessageButton
.setText(SDMessages
._30
);
188 fSynMessageButton
.setEnabled(true);
189 fSynMessageButton
.addSelectionListener(fGraphNodeTypeListener
);
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
);
199 fSynMessageReturnButton
.setText(SDMessages
._31
);
201 fSynMessageReturnButton
.setEnabled(true);
202 fSynMessageReturnButton
.addSelectionListener(fGraphNodeTypeListener
);
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
);
212 fAsynMessageButton
.setText(SDMessages
._32
);
214 fAsynMessageButton
.setEnabled(true);
215 fAsynMessageButton
.addSelectionListener(fGraphNodeTypeListener
);
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
);
225 fAsynMessageReturnButton
.setText(SDMessages
._33
);
227 fAsynMessageReturnButton
.setEnabled(true);
228 fAsynMessageReturnButton
.addSelectionListener(fGraphNodeTypeListener
);
231 fResult
= new Label(this, SWT
.LEFT
);
232 fResult
.setText(SDMessages
._23
);
233 fResult
.setVisible(false);
236 // ------------------------------------------------------------------------
238 // ------------------------------------------------------------------------
241 * Set result text visibility
242 * @param found <code>true</code> for found (enable visibility) else false
244 public void setResult(boolean found
) {
245 fResult
.setVisible(!found
);
249 * Updates parent OK button based on input data.
251 public void updateOkButton() {
252 if (fParentOkButton
== null) {
255 boolean enabled
= (fSearchText
.getText() != null && !fSearchText
.getText().equals("")) && //$NON-NLS-1$
256 (isLifelineButtonSelected() || isStopButtonSelected() || isSynMessageButtonSelected() || isSynMessageReturnButtonSelected() || isAsynMessageButtonSelected() || isAsynMessageReturnButtonSelected());
257 fParentOkButton
.setEnabled(enabled
);
261 * Sets the parent OK button reference.
263 * @param okButton The parent OK button
265 public void setOkButton(Button okButton
) {
266 fParentOkButton
= okButton
;
270 * Returns the asynchronous message check button state
272 * @return true if check, false otherwise
274 public boolean isAsynMessageButtonSelected() {
275 if (fAsynMessageButton
!= null) {
276 return fAsynMessageButton
.getSelection();
282 * Returns the asynchronous message return check button state
284 * @return true if check, false otherwise
286 public boolean isAsynMessageReturnButtonSelected() {
287 if (fAsynMessageReturnButton
!= null) {
288 return fAsynMessageReturnButton
.getSelection();
294 * Returns the case sensitive check button state
296 * @return true if check, false otherwise
298 public boolean isCaseSensitiveSelected() {
299 if (fCaseSensitive
!= null) {
300 return fCaseSensitive
.getSelection();
306 * Returns the lifeline check button state
308 * @return true if check, false otherwise
310 public boolean isLifelineButtonSelected() {
311 if (fLifelineButton
!= null) {
312 return fLifelineButton
.getSelection();
318 * Returns the user input string
320 * @return the string to search for
322 public String
getSearchText() {
323 return fSearchText
.getText();
327 * Returns the stop check button state
329 * @return true if check, false otherwise
331 public boolean isStopButtonSelected() {
332 if (fStopButton
!= null) {
333 return fStopButton
.getSelection();
339 * Returns the synchronous message check button state
341 * @return true if check, false otherwise
343 public boolean isSynMessageButtonSelected() {
344 if (fSynMessageButton
!= null) {
345 return fSynMessageButton
.getSelection();
351 * Returns the synchronous message return check button state
353 * @return true if check, false otherwise
355 public boolean isSynMessageReturnButtonSelected() {
356 if (fSynMessageReturnButton
!= null) {
357 return fSynMessageReturnButton
.getSelection();
363 * Set the asynchronous message check button state
366 * The new state to set
368 public void setAsynMessageButtonSelection(boolean state
) {
369 if (fAsynMessageButton
!= null) {
370 fAsynMessageButton
.setSelection(state
);
375 * Set the asynchronous message return check button state
378 * The new state to set
380 public void setAsynMessageReturnButtonSelection(boolean state
) {
381 if (fAsynMessageReturnButton
!= null) {
382 fAsynMessageReturnButton
.setSelection(state
);
387 * Set the case sensitive check button state
390 * The new state to set
392 public void setCaseSensitiveSelection(boolean state
) {
393 if (fCaseSensitive
!= null) {
394 fCaseSensitive
.setSelection(state
);
399 * Set the lifeline check button state
402 * The new state to set
404 public void setLifelineButtonSelection(boolean state
) {
405 if (fLifelineButton
!= null) {
406 fLifelineButton
.setSelection(state
);
411 * Set the user input string
416 public void setSearchText(String text
) {
417 fSearchText
.setText(text
);
421 * Set the stop check button state
424 * The new state to set
426 public void setStopButtonSelection(boolean state
) {
427 if (fStopButton
!= null) {
428 fStopButton
.setSelection(state
);
433 * Set the synchronous message check button state
436 * The new state to set
438 public void setSynMessageButtonSelection(boolean state
) {
439 if (fSynMessageButton
!= null) {
440 fSynMessageButton
.setSelection(state
);
445 * Set the synchronous message return check button state
448 * The new state to set
450 public void setSynMessageReturnButtonSelection(boolean state
) {
451 if (fSynMessageReturnButton
!= null) {
452 fSynMessageReturnButton
.setSelection(state
);
456 // ------------------------------------------------------------------------
458 // ------------------------------------------------------------------------
461 * Selection listener implementation for graph node types.
464 protected class GraphNodeTypeListener
implements SelectionListener
{
467 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
470 public void widgetDefaultSelected(SelectionEvent e
) {
476 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
479 public void widgetSelected(SelectionEvent e
) {
485 * Modify listener implementation for the expression field.
489 protected class ExpressionListener
implements ModifyListener
{
493 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
496 public void modifyText(ModifyEvent e
) {