1 /**********************************************************************
2 * Copyright (c) 2005, 2013 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
.Messages
;
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 * The button for lifelines.
44 private Button fLifelineButton
;
46 * The button for stops.
48 private Button fStopButton
= null;
50 * The button for synchronous messages
52 private Button fSynMessageButton
= null;
54 * The button for synchronous return messages
56 private Button fSynMessageReturnButton
= null;
58 * The button for asynchronous messages
60 private Button fAsynMessageButton
= null;
62 * The button for asynchronous return messages
64 private Button fAsynMessageReturnButton
= null;
66 * The search text combo box.
68 private Combo fSearchText
= null;
70 * The button for case sensitive expressions.
72 private Button fCaseSensitive
= null;
74 * The label for the result string.
76 private Label fResult
= null;
78 * The button for notifying parent about valid data.
80 private Button fParentOkButton
= null;
82 // ------------------------------------------------------------------------
84 // ------------------------------------------------------------------------
87 * Creates the dialog contents
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
94 public TabContents(Composite parent
, ISDGraphNodeSupporter provider
, Button okButton
, String
[] expressionList
) {
95 super(parent
, SWT
.NONE
);
96 fParentOkButton
= okButton
;
97 setLayout(new GridLayout());
99 GraphNodeTypeListener graphNodeTypeListener
= new GraphNodeTypeListener();
100 ExpressionListener expressionListener
= new ExpressionListener();
102 // Inform the user how to fill the string to search
103 Label searchTitle
= new Label(this, SWT
.LEFT
);
104 searchTitle
.setText(Messages
.SequenceDiagram_MatchingString
);
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
);
112 // Create the user string input area
113 fSearchText
= new Combo(searchPart
, SWT
.DROP_DOWN
);
114 GridData comboData
= new GridData(GridData
.GRAB_HORIZONTAL
| GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_VERTICAL
| GridData
.VERTICAL_ALIGN_FILL
);
116 * GridData tabLayoutData2 = new GridData(GridData.HORIZONTAL_ALIGN_FILL| GridData.VERTICAL_ALIGN_FILL);
118 fSearchText
.setLayoutData(comboData
);
119 if (expressionList
!= null) {
120 for (int i
= 0; i
< expressionList
.length
; i
++) {
121 fSearchText
.add(expressionList
[i
]);
124 fSearchText
.addModifyListener(expressionListener
);
126 // Create the case sensitive check button
127 fCaseSensitive
= new Button(searchPart
, SWT
.CHECK
);
128 fCaseSensitive
.setText(Messages
.SequenceDiagram_CaseSensitive
);
130 // Create the group for searched graph node kind selection
131 Group kindSelection
= new Group(this, SWT
.SHADOW_NONE
);
132 kindSelection
.setText(Messages
.SequenceDiagram_SearchFor
);
133 // kindSelection.setLayoutData(tabLayoutData2);
134 GridLayout kindSelectionLayout
= new GridLayout();
135 kindSelectionLayout
.numColumns
= 1;
136 kindSelection
.setLayout(kindSelectionLayout
);
137 GridData kindSelectionData
= new GridData(GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_HORIZONTAL
| GridData
.VERTICAL_ALIGN_FILL
);
138 kindSelection
.setLayoutData(kindSelectionData
);
140 // Create the lifeline check button
141 if (provider
!= null && provider
.isNodeSupported(ISDGraphNodeSupporter
.LIFELINE
)) {
142 fLifelineButton
= new Button(kindSelection
, SWT
.CHECK
);
143 String nodeName
= provider
.getNodeName(ISDGraphNodeSupporter
.LIFELINE
, null);
144 if (nodeName
!= null) {
145 fLifelineButton
.setText(nodeName
);
147 fLifelineButton
.setText(Messages
.SequenceDiagram_Lifeline
);
149 fLifelineButton
.setEnabled(true);
150 fLifelineButton
.addSelectionListener(graphNodeTypeListener
);
153 if (provider
!= null && provider
.isNodeSupported(ISDGraphNodeSupporter
.STOP
)) {
154 // Create the stop check button
155 fStopButton
= new Button(kindSelection
, SWT
.CHECK
);
156 String nodeName
= provider
.getNodeName(ISDGraphNodeSupporter
.STOP
, null);
157 if (nodeName
!= null) {
158 fStopButton
.setText(nodeName
);
160 fStopButton
.setText(Messages
.SequenceDiagram_Stop
);
163 fStopButton
.setEnabled(true);
164 fStopButton
.addSelectionListener(graphNodeTypeListener
);
167 if (provider
!= null && provider
.isNodeSupported(ISDGraphNodeSupporter
.SYNCMESSAGE
)) {
168 // Create the synchronous message check button
169 fSynMessageButton
= new Button(kindSelection
, SWT
.CHECK
);
170 String nodeName
= provider
.getNodeName(ISDGraphNodeSupporter
.SYNCMESSAGE
, null);
171 if (nodeName
!= null) {
172 fSynMessageButton
.setText(nodeName
);
174 fSynMessageButton
.setText(Messages
.SequenceDiagram_SynchronousMessage
);
176 fSynMessageButton
.setEnabled(true);
177 fSynMessageButton
.addSelectionListener(graphNodeTypeListener
);
180 if (provider
!= null && provider
.isNodeSupported(ISDGraphNodeSupporter
.SYNCMESSAGERETURN
)) {
181 // Create the synchronous message return check button
182 fSynMessageReturnButton
= new Button(kindSelection
, SWT
.CHECK
);
183 String nodeName
= provider
.getNodeName(ISDGraphNodeSupporter
.SYNCMESSAGERETURN
, null);
184 if (nodeName
!= null) {
185 fSynMessageReturnButton
.setText(nodeName
);
187 fSynMessageReturnButton
.setText(Messages
.SequenceDiagram_SynchronousMessageReturn
);
189 fSynMessageReturnButton
.setEnabled(true);
190 fSynMessageReturnButton
.addSelectionListener(graphNodeTypeListener
);
193 if (provider
!= null && provider
.isNodeSupported(ISDGraphNodeSupporter
.ASYNCMESSAGE
)) {
194 // Create the asynchronous message check button
195 fAsynMessageButton
= new Button(kindSelection
, SWT
.CHECK
);
196 String nodeName
= provider
.getNodeName(ISDGraphNodeSupporter
.ASYNCMESSAGE
, null);
197 if (nodeName
!= null) {
198 fAsynMessageButton
.setText(nodeName
);
200 fAsynMessageButton
.setText(Messages
.SequenceDiagram_AsynchronousMessage
);
202 fAsynMessageButton
.setEnabled(true);
203 fAsynMessageButton
.addSelectionListener(graphNodeTypeListener
);
206 if (provider
!= null && provider
.isNodeSupported(ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
)) {
207 // Create the asynchronous message return check button
208 fAsynMessageReturnButton
= new Button(kindSelection
, SWT
.CHECK
);
209 String nodeName
= provider
.getNodeName(ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
, null);
210 if (nodeName
!= null) {
211 fAsynMessageReturnButton
.setText(nodeName
);
213 fAsynMessageReturnButton
.setText(Messages
.SequenceDiagram_AsynchronousMessageReturn
);
215 fAsynMessageReturnButton
.setEnabled(true);
216 fAsynMessageReturnButton
.addSelectionListener(graphNodeTypeListener
);
219 fResult
= new Label(this, SWT
.LEFT
);
220 fResult
.setText(Messages
.SequenceDiagram_StringNotFound
);
221 fResult
.setVisible(false);
224 // ------------------------------------------------------------------------
226 // ------------------------------------------------------------------------
229 * Set result text visibility
230 * @param found <code>true</code> for found (enable visibility) else false
232 public void setResult(boolean found
) {
233 fResult
.setVisible(!found
);
237 * Updates parent OK button based on input data.
239 public void updateOkButton() {
240 if (fParentOkButton
== null) {
243 boolean enabled
= (fSearchText
.getText() != null && !fSearchText
.getText().equals("")) && //$NON-NLS-1$
244 (isLifelineButtonSelected() || isStopButtonSelected() || isSynMessageButtonSelected() || isSynMessageReturnButtonSelected() || isAsynMessageButtonSelected() || isAsynMessageReturnButtonSelected());
245 fParentOkButton
.setEnabled(enabled
);
249 * Sets the parent OK button reference.
251 * @param okButton The parent OK button
253 public void setOkButton(Button okButton
) {
254 fParentOkButton
= okButton
;
258 * Returns the asynchronous message check button state
260 * @return true if check, false otherwise
262 public boolean isAsynMessageButtonSelected() {
263 if (fAsynMessageButton
!= null) {
264 return fAsynMessageButton
.getSelection();
270 * Returns the asynchronous message return check button state
272 * @return true if check, false otherwise
274 public boolean isAsynMessageReturnButtonSelected() {
275 if (fAsynMessageReturnButton
!= null) {
276 return fAsynMessageReturnButton
.getSelection();
282 * Returns the case sensitive check button state
284 * @return true if check, false otherwise
286 public boolean isCaseSensitiveSelected() {
287 if (fCaseSensitive
!= null) {
288 return fCaseSensitive
.getSelection();
294 * Returns the lifeline check button state
296 * @return true if check, false otherwise
298 public boolean isLifelineButtonSelected() {
299 if (fLifelineButton
!= null) {
300 return fLifelineButton
.getSelection();
306 * Returns the user input string
308 * @return the string to search for
310 public String
getSearchText() {
311 return fSearchText
.getText();
315 * Returns the stop check button state
317 * @return true if check, false otherwise
319 public boolean isStopButtonSelected() {
320 if (fStopButton
!= null) {
321 return fStopButton
.getSelection();
327 * Returns the synchronous message check button state
329 * @return true if check, false otherwise
331 public boolean isSynMessageButtonSelected() {
332 if (fSynMessageButton
!= null) {
333 return fSynMessageButton
.getSelection();
339 * Returns the synchronous message return check button state
341 * @return true if check, false otherwise
343 public boolean isSynMessageReturnButtonSelected() {
344 if (fSynMessageReturnButton
!= null) {
345 return fSynMessageReturnButton
.getSelection();
351 * Set the asynchronous message check button state
354 * The new state to set
356 public void setAsynMessageButtonSelection(boolean state
) {
357 if (fAsynMessageButton
!= null) {
358 fAsynMessageButton
.setSelection(state
);
363 * Set the asynchronous message return check button state
366 * The new state to set
368 public void setAsynMessageReturnButtonSelection(boolean state
) {
369 if (fAsynMessageReturnButton
!= null) {
370 fAsynMessageReturnButton
.setSelection(state
);
375 * Set the case sensitive check button state
378 * The new state to set
380 public void setCaseSensitiveSelection(boolean state
) {
381 if (fCaseSensitive
!= null) {
382 fCaseSensitive
.setSelection(state
);
387 * Set the lifeline check button state
390 * The new state to set
392 public void setLifelineButtonSelection(boolean state
) {
393 if (fLifelineButton
!= null) {
394 fLifelineButton
.setSelection(state
);
399 * Set the user input string
404 public void setSearchText(String text
) {
405 fSearchText
.setText(text
);
409 * Set the stop check button state
412 * The new state to set
414 public void setStopButtonSelection(boolean state
) {
415 if (fStopButton
!= null) {
416 fStopButton
.setSelection(state
);
421 * Set the synchronous message check button state
424 * The new state to set
426 public void setSynMessageButtonSelection(boolean state
) {
427 if (fSynMessageButton
!= null) {
428 fSynMessageButton
.setSelection(state
);
433 * Set the synchronous message return check button state
436 * The new state to set
438 public void setSynMessageReturnButtonSelection(boolean state
) {
439 if (fSynMessageReturnButton
!= null) {
440 fSynMessageReturnButton
.setSelection(state
);
444 // ------------------------------------------------------------------------
446 // ------------------------------------------------------------------------
449 * Selection listener implementation for graph node types.
452 protected class GraphNodeTypeListener
implements SelectionListener
{
454 public void widgetDefaultSelected(SelectionEvent e
) {
459 public void widgetSelected(SelectionEvent e
) {
465 * Modify listener implementation for the expression field.
469 protected class ExpressionListener
implements ModifyListener
{
471 public void modifyText(ModifyEvent e
) {