1 /**********************************************************************
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
;
16 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDGraphNodeSupporter
;
17 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.SDMessages
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.events
.ModifyEvent
;
20 import org
.eclipse
.swt
.events
.ModifyListener
;
21 import org
.eclipse
.swt
.events
.SelectionEvent
;
22 import org
.eclipse
.swt
.events
.SelectionListener
;
23 import org
.eclipse
.swt
.layout
.GridData
;
24 import org
.eclipse
.swt
.layout
.GridLayout
;
25 import org
.eclipse
.swt
.widgets
.Button
;
26 import org
.eclipse
.swt
.widgets
.Combo
;
27 import org
.eclipse
.swt
.widgets
.Composite
;
28 import org
.eclipse
.swt
.widgets
.Group
;
29 import org
.eclipse
.swt
.widgets
.Label
;
32 * Class implementation contains the controls that allows to create or update a find or filter Criteria.
37 public class TabContents
extends Composite
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 * A graph node type listener implementation.
45 protected GraphNodeTypeListener fGraphNodeTypeListener
= null;
47 * A expression listener implementation.
49 protected ExpressionListener fExpressionListener
= null;
51 * The button for lifelines.
53 protected Button fLifelineButton
= null;
55 * The button for stops.
57 protected Button fStopButton
= null;
59 * The button for synchronous messages
61 protected Button fSynMessageButton
= null;
63 * The button for synchronous return messages
65 protected Button fSynMessageReturnButton
= null;
67 * The button for asynchronous messages
69 protected Button fAsynMessageButton
= null;
71 * The button for asynchronous return messages
73 protected Button fAsynMessageReturnButton
= null;
75 * The search text combo box.
77 protected Combo fSearchText
= null;
79 * The group for selection kind.
81 protected Group fKindSelection
= null;
83 * The button for case sensitive expressions.
85 protected Button fCaseSensitive
= null;
87 * The label for the result string.
89 protected Label fResult
= null;
91 * The button for notifying parent about valid data.
93 protected Button fParentOkButton
= null;
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
100 * Creates the dialog contents
102 * @param parent the parent widget
103 * @param provider the provider which handle the action
104 * @param okButton of the dialog (to be enabled/disabled)
105 * @param expressionList list of strings already searched for
107 public TabContents(Composite parent
, ISDGraphNodeSupporter provider
, Button okButton
, String
[] expressionList
) {
108 super(parent
, SWT
.NONE
);
109 fParentOkButton
= okButton
;
110 setLayout(new GridLayout());
112 fGraphNodeTypeListener
= new GraphNodeTypeListener();
113 fExpressionListener
= new ExpressionListener();
115 // Inform the user how to fill the string to search
116 Label searchTitle
= new Label(this, SWT
.LEFT
);
117 searchTitle
.setText(SDMessages
._26
);
118 Composite searchPart
= new Composite(this, SWT
.NONE
);
119 GridData searchPartData
= new GridData(GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.VERTICAL_ALIGN_FILL
);
120 GridLayout searchPartLayout
= new GridLayout();
121 searchPartLayout
.numColumns
= 2;
122 searchPart
.setLayout(searchPartLayout
);
123 searchPart
.setLayoutData(searchPartData
);
125 // Create the user string input area
126 fSearchText
= new Combo(searchPart
, SWT
.DROP_DOWN
);
127 GridData comboData
= new GridData(GridData
.GRAB_HORIZONTAL
| GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_VERTICAL
| GridData
.VERTICAL_ALIGN_FILL
);
129 * GridData tabLayoutData2 = new GridData(GridData.HORIZONTAL_ALIGN_FILL| GridData.VERTICAL_ALIGN_FILL);
131 fSearchText
.setLayoutData(comboData
);
132 if (expressionList
!= null) {
133 for (int i
= 0; i
< expressionList
.length
; i
++) {
134 fSearchText
.add(expressionList
[i
]);
137 fSearchText
.addModifyListener(fExpressionListener
);
139 // Create the case sensitive check button
140 fCaseSensitive
= new Button(searchPart
, SWT
.CHECK
);
141 fCaseSensitive
.setText(SDMessages
._27
);
143 // Create the group for searched graph node kind selection
144 fKindSelection
= new Group(this, SWT
.SHADOW_NONE
);
145 fKindSelection
.setText(SDMessages
._25
);
146 // kindSelection.setLayoutData(tabLayoutData2);
147 GridLayout kindSelectionLayout
= new GridLayout();
148 kindSelectionLayout
.numColumns
= 1;
149 fKindSelection
.setLayout(kindSelectionLayout
);
150 GridData kindSelectionData
= new GridData(GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_HORIZONTAL
| GridData
.VERTICAL_ALIGN_FILL
);
151 fKindSelection
.setLayoutData(kindSelectionData
);
153 // Create the lifeline check button
154 if (provider
!= null && provider
.isNodeSupported(ISDGraphNodeSupporter
.LIFELINE
)) {
155 fLifelineButton
= new Button(fKindSelection
, SWT
.CHECK
);
156 String nodeName
= provider
.getNodeName(ISDGraphNodeSupporter
.LIFELINE
, null);
157 if (nodeName
!= null) {
158 fLifelineButton
.setText(nodeName
);
160 fLifelineButton
.setText(SDMessages
._28
);
162 fLifelineButton
.setEnabled(true);
163 fLifelineButton
.addSelectionListener(fGraphNodeTypeListener
);
166 if (provider
!= null && provider
.isNodeSupported(ISDGraphNodeSupporter
.STOP
)) {
167 // Create the stop check button
168 fStopButton
= new Button(fKindSelection
, SWT
.CHECK
);
169 String nodeName
= provider
.getNodeName(ISDGraphNodeSupporter
.STOP
, null);
170 if (nodeName
!= null) {
171 fStopButton
.setText(nodeName
);
173 fStopButton
.setText(SDMessages
._29
);
176 fStopButton
.setEnabled(true);
177 fStopButton
.addSelectionListener(fGraphNodeTypeListener
);
180 if (provider
!= null && provider
.isNodeSupported(ISDGraphNodeSupporter
.SYNCMESSAGE
)) {
181 // Create the synchronous message check button
182 fSynMessageButton
= new Button(fKindSelection
, SWT
.CHECK
);
183 String nodeName
= provider
.getNodeName(ISDGraphNodeSupporter
.SYNCMESSAGE
, null);
184 if (nodeName
!= null) {
185 fSynMessageButton
.setText(nodeName
);
187 fSynMessageButton
.setText(SDMessages
._30
);
189 fSynMessageButton
.setEnabled(true);
190 fSynMessageButton
.addSelectionListener(fGraphNodeTypeListener
);
193 if (provider
!= null && provider
.isNodeSupported(ISDGraphNodeSupporter
.SYNCMESSAGERETURN
)) {
194 // Create the synchronous message return check button
195 fSynMessageReturnButton
= new Button(fKindSelection
, SWT
.CHECK
);
196 String nodeName
= provider
.getNodeName(ISDGraphNodeSupporter
.SYNCMESSAGERETURN
, null);
197 if (nodeName
!= null) {
198 fSynMessageReturnButton
.setText(nodeName
);
200 fSynMessageReturnButton
.setText(SDMessages
._31
);
202 fSynMessageReturnButton
.setEnabled(true);
203 fSynMessageReturnButton
.addSelectionListener(fGraphNodeTypeListener
);
206 if (provider
!= null && provider
.isNodeSupported(ISDGraphNodeSupporter
.ASYNCMESSAGE
)) {
207 // Create the asynchronous message check button
208 fAsynMessageButton
= new Button(fKindSelection
, SWT
.CHECK
);
209 String nodeName
= provider
.getNodeName(ISDGraphNodeSupporter
.ASYNCMESSAGE
, null);
210 if (nodeName
!= null) {
211 fAsynMessageButton
.setText(nodeName
);
213 fAsynMessageButton
.setText(SDMessages
._32
);
215 fAsynMessageButton
.setEnabled(true);
216 fAsynMessageButton
.addSelectionListener(fGraphNodeTypeListener
);
219 if (provider
!= null && provider
.isNodeSupported(ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
)) {
220 // Create the asynchronous message return check button
221 fAsynMessageReturnButton
= new Button(fKindSelection
, SWT
.CHECK
);
222 String nodeName
= provider
.getNodeName(ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
, null);
223 if (nodeName
!= null) {
224 fAsynMessageReturnButton
.setText(nodeName
);
226 fAsynMessageReturnButton
.setText(SDMessages
._33
);
228 fAsynMessageReturnButton
.setEnabled(true);
229 fAsynMessageReturnButton
.addSelectionListener(fGraphNodeTypeListener
);
232 fResult
= new Label(this, SWT
.LEFT
);
233 fResult
.setText(SDMessages
._23
);
234 fResult
.setVisible(false);
237 // ------------------------------------------------------------------------
239 // ------------------------------------------------------------------------
242 * Set result text visibility
243 * @param found <code>true</code> for found (enable visibility) else false
245 public void setResult(boolean found
) {
246 fResult
.setVisible(!found
);
250 * Updates parent OK button based on input data.
252 public void updateOkButton() {
253 if (fParentOkButton
== null) {
256 boolean enabled
= (fSearchText
.getText() != null && !fSearchText
.getText().equals("")) && //$NON-NLS-1$
257 (isLifelineButtonSelected() || isStopButtonSelected() || isSynMessageButtonSelected() || isSynMessageReturnButtonSelected() || isAsynMessageButtonSelected() || isAsynMessageReturnButtonSelected());
258 fParentOkButton
.setEnabled(enabled
);
262 * Sets the parent OK button reference.
264 * @param okButton The parent OK button
266 public void setOkButton(Button okButton
) {
267 fParentOkButton
= okButton
;
271 * Returns the asynchronous message check button state
273 * @return true if check, false otherwise
275 public boolean isAsynMessageButtonSelected() {
276 if (fAsynMessageButton
!= null) {
277 return fAsynMessageButton
.getSelection();
283 * Returns the asynchronous message return check button state
285 * @return true if check, false otherwise
287 public boolean isAsynMessageReturnButtonSelected() {
288 if (fAsynMessageReturnButton
!= null) {
289 return fAsynMessageReturnButton
.getSelection();
295 * Returns the case sensitive check button state
297 * @return true if check, false otherwise
299 public boolean isCaseSensitiveSelected() {
300 if (fCaseSensitive
!= null) {
301 return fCaseSensitive
.getSelection();
307 * Returns the lifeline check button state
309 * @return true if check, false otherwise
311 public boolean isLifelineButtonSelected() {
312 if (fLifelineButton
!= null) {
313 return fLifelineButton
.getSelection();
319 * Returns the user input string
321 * @return the string to search for
323 public String
getSearchText() {
324 return fSearchText
.getText();
328 * Returns the stop check button state
330 * @return true if check, false otherwise
332 public boolean isStopButtonSelected() {
333 if (fStopButton
!= null) {
334 return fStopButton
.getSelection();
340 * Returns the synchronous message check button state
342 * @return true if check, false otherwise
344 public boolean isSynMessageButtonSelected() {
345 if (fSynMessageButton
!= null) {
346 return fSynMessageButton
.getSelection();
352 * Returns the synchronous message return check button state
354 * @return true if check, false otherwise
356 public boolean isSynMessageReturnButtonSelected() {
357 if (fSynMessageReturnButton
!= null) {
358 return fSynMessageReturnButton
.getSelection();
364 * Set the asynchronous message check button state
367 * The new state to set
369 public void setAsynMessageButtonSelection(boolean state
) {
370 if (fAsynMessageButton
!= null) {
371 fAsynMessageButton
.setSelection(state
);
376 * Set the asynchronous message return check button state
379 * The new state to set
381 public void setAsynMessageReturnButtonSelection(boolean state
) {
382 if (fAsynMessageReturnButton
!= null) {
383 fAsynMessageReturnButton
.setSelection(state
);
388 * Set the case sensitive check button state
391 * The new state to set
393 public void setCaseSensitiveSelection(boolean state
) {
394 if (fCaseSensitive
!= null) {
395 fCaseSensitive
.setSelection(state
);
400 * Set the lifeline check button state
403 * The new state to set
405 public void setLifelineButtonSelection(boolean state
) {
406 if (fLifelineButton
!= null) {
407 fLifelineButton
.setSelection(state
);
412 * Set the user input string
417 public void setSearchText(String text
) {
418 fSearchText
.setText(text
);
422 * Set the stop check button state
425 * The new state to set
427 public void setStopButtonSelection(boolean state
) {
428 if (fStopButton
!= null) {
429 fStopButton
.setSelection(state
);
434 * Set the synchronous message check button state
437 * The new state to set
439 public void setSynMessageButtonSelection(boolean state
) {
440 if (fSynMessageButton
!= null) {
441 fSynMessageButton
.setSelection(state
);
446 * Set the synchronous message return check button state
449 * The new state to set
451 public void setSynMessageReturnButtonSelection(boolean state
) {
452 if (fSynMessageReturnButton
!= null) {
453 fSynMessageReturnButton
.setSelection(state
);
457 // ------------------------------------------------------------------------
459 // ------------------------------------------------------------------------
462 * Selection listener implementation for graph node types.
465 protected class GraphNodeTypeListener
implements SelectionListener
{
468 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
471 public void widgetDefaultSelected(SelectionEvent e
) {
477 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
480 public void widgetSelected(SelectionEvent e
) {
486 * Modify listener implementation for the expression field.
490 protected class ExpressionListener
implements ModifyListener
{
494 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
497 public void modifyText(ModifyEvent e
) {