Fix for Linux display bugs in TimeGraphCombo.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / dialogs / TabContents.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
4 *
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
9 *
10 * Contributors:
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs;
15
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;
30
31 /**
32 * Class implementation contains the controls that allows to create or update a find or filter Criteria.
33 *
34 * @version 1.0
35 * @author sveyrier
36 */
37 public class TabContents extends Composite {
38
39 // ------------------------------------------------------------------------
40 // Attributes
41 // ------------------------------------------------------------------------
42 /**
43 * A graph node type listener implementation.
44 */
45 protected GraphNodeTypeListener fGraphNodeTypeListener = null;
46 /**
47 * A expression listener implementation.
48 */
49 protected ExpressionListener fExpressionListener = null;
50 /**
51 * The button for lifelines.
52 */
53 protected Button fLifelineButton = null;
54 /**
55 * The button for stops.
56 */
57 protected Button fStopButton = null;
58 /**
59 * The button for synchronous messages
60 */
61 protected Button fSynMessageButton = null;
62 /**
63 * The button for synchronous return messages
64 */
65 protected Button fSynMessageReturnButton = null;
66 /**
67 * The button for asynchronous messages
68 */
69 protected Button fAsynMessageButton = null;
70 /**
71 * The button for asynchronous return messages
72 */
73 protected Button fAsynMessageReturnButton = null;
74 /**
75 * The search text combo box.
76 */
77 protected Combo fSearchText = null;
78 /**
79 * The group for selection kind.
80 */
81 protected Group fKindSelection = null;
82 /**
83 * The button for case sensitive expressions.
84 */
85 protected Button fCaseSensitive = null;
86 /**
87 * The label for the result string.
88 */
89 protected Label fResult = null;
90 /**
91 * The button for notifying parent about valid data.
92 */
93 protected Button fParentOkButton = null;
94
95 // ------------------------------------------------------------------------
96 // Constructors
97 // ------------------------------------------------------------------------
98
99 /**
100 * Creates the dialog contents
101 *
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
106 */
107 public TabContents(Composite parent, ISDGraphNodeSupporter provider, Button okButton, String[] expressionList) {
108 super(parent, SWT.NONE);
109 setOkButton(okButton);
110 setLayout(new GridLayout());
111
112 fGraphNodeTypeListener = new GraphNodeTypeListener();
113 fExpressionListener = new ExpressionListener();
114
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);
124
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);
128 /*
129 * GridData tabLayoutData2 = new GridData(GridData.HORIZONTAL_ALIGN_FILL| GridData.VERTICAL_ALIGN_FILL);
130 */
131 fSearchText.setLayoutData(comboData);
132 if (expressionList != null) {
133 for (int i = 0; i < expressionList.length; i++) {
134 fSearchText.add(expressionList[i]);
135 }
136 }
137 fSearchText.addModifyListener(fExpressionListener);
138
139 // Create the case sensitive check button
140 fCaseSensitive = new Button(searchPart, SWT.CHECK);
141 fCaseSensitive.setText(SDMessages._27);
142
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);
152
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);
159 } else {
160 fLifelineButton.setText(SDMessages._28);
161 }
162 fLifelineButton.setEnabled(true);
163 fLifelineButton.addSelectionListener(fGraphNodeTypeListener);
164 }
165
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);
172 } else {
173 fStopButton.setText(SDMessages._29);
174 }
175
176 fStopButton.setEnabled(true);
177 fStopButton.addSelectionListener(fGraphNodeTypeListener);
178 }
179
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);
186 } else {
187 fSynMessageButton.setText(SDMessages._30);
188 }
189 fSynMessageButton.setEnabled(true);
190 fSynMessageButton.addSelectionListener(fGraphNodeTypeListener);
191 }
192
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);
199 } else {
200 fSynMessageReturnButton.setText(SDMessages._31);
201 }
202 fSynMessageReturnButton.setEnabled(true);
203 fSynMessageReturnButton.addSelectionListener(fGraphNodeTypeListener);
204 }
205
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);
212 } else {
213 fAsynMessageButton.setText(SDMessages._32);
214 }
215 fAsynMessageButton.setEnabled(true);
216 fAsynMessageButton.addSelectionListener(fGraphNodeTypeListener);
217 }
218
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);
225 } else {
226 fAsynMessageReturnButton.setText(SDMessages._33);
227 }
228 fAsynMessageReturnButton.setEnabled(true);
229 fAsynMessageReturnButton.addSelectionListener(fGraphNodeTypeListener);
230 }
231
232 fResult = new Label(this, SWT.LEFT);
233 fResult.setText(SDMessages._23);
234 fResult.setVisible(false);
235 }
236
237 // ------------------------------------------------------------------------
238 // Methods
239 // ------------------------------------------------------------------------
240
241 /**
242 * Set result text visibility
243 * @param found <code>true</code> for found (enable visibility) else false
244 */
245 public void setResult(boolean found) {
246 fResult.setVisible(!found);
247 }
248
249 /**
250 * Updates parent OK button based on input data.
251 */
252 public void updateOkButton() {
253 if (fParentOkButton == null) {
254 return;
255 }
256 boolean enabled = (fSearchText.getText() != null && !fSearchText.getText().equals("")) && //$NON-NLS-1$
257 (isLifelineButtonSelected() || isStopButtonSelected() || isSynMessageButtonSelected() || isSynMessageReturnButtonSelected() || isAsynMessageButtonSelected() || isAsynMessageReturnButtonSelected());
258 fParentOkButton.setEnabled(enabled);
259 }
260
261 /**
262 * Sets the parent OK button reference.
263 *
264 * @param okButton The parent OK button
265 */
266 public void setOkButton(Button okButton) {
267 fParentOkButton = okButton;
268 }
269
270 /**
271 * Returns the asynchronous message check button state
272 *
273 * @return true if check, false otherwise
274 */
275 public boolean isAsynMessageButtonSelected() {
276 if (fAsynMessageButton != null) {
277 return fAsynMessageButton.getSelection();
278 }
279 return false;
280 }
281
282 /**
283 * Returns the asynchronous message return check button state
284 *
285 * @return true if check, false otherwise
286 */
287 public boolean isAsynMessageReturnButtonSelected() {
288 if (fAsynMessageReturnButton != null) {
289 return fAsynMessageReturnButton.getSelection();
290 }
291 return false;
292 }
293
294 /**
295 * Returns the case sensitive check button state
296 *
297 * @return true if check, false otherwise
298 */
299 public boolean isCaseSensitiveSelected() {
300 if (fCaseSensitive != null) {
301 return fCaseSensitive.getSelection();
302 }
303 return false;
304 }
305
306 /**
307 * Returns the lifeline check button state
308 *
309 * @return true if check, false otherwise
310 */
311 public boolean isLifelineButtonSelected() {
312 if (fLifelineButton != null) {
313 return fLifelineButton.getSelection();
314 }
315 return false;
316 }
317
318 /**
319 * Returns the user input string
320 *
321 * @return the string to search for
322 */
323 public String getSearchText() {
324 return fSearchText.getText();
325 }
326
327 /**
328 * Returns the stop check button state
329 *
330 * @return true if check, false otherwise
331 */
332 public boolean isStopButtonSelected() {
333 if (fStopButton != null) {
334 return fStopButton.getSelection();
335 }
336 return false;
337 }
338
339 /**
340 * Returns the synchronous message check button state
341 *
342 * @return true if check, false otherwise
343 */
344 public boolean isSynMessageButtonSelected() {
345 if (fSynMessageButton != null) {
346 return fSynMessageButton.getSelection();
347 }
348 return false;
349 }
350
351 /**
352 * Returns the synchronous message return check button state
353 *
354 * @return true if check, false otherwise
355 */
356 public boolean isSynMessageReturnButtonSelected() {
357 if (fSynMessageReturnButton != null) {
358 return fSynMessageReturnButton.getSelection();
359 }
360 return false;
361 }
362
363 /**
364 * Set the asynchronous message check button state
365 */
366 public void setAsynMessageButtonSelection(boolean state) {
367 if (fAsynMessageButton != null) {
368 fAsynMessageButton.setSelection(state);
369 }
370 }
371
372 /**
373 * Set the asynchronous message return check button state
374 */
375 public void setAsynMessageReturnButtonSelection(boolean state) {
376 if (fAsynMessageReturnButton != null) {
377 fAsynMessageReturnButton.setSelection(state);
378 }
379 }
380
381 /**
382 * Set the case sensitive check button state
383 */
384 public void setCaseSensitiveSelection(boolean state) {
385 if (fCaseSensitive != null) {
386 fCaseSensitive.setSelection(state);
387 }
388 }
389
390 /**
391 * Set the lifeline check button state
392 */
393 public void setLifelineButtonSelection(boolean state) {
394 if (fLifelineButton != null) {
395 fLifelineButton.setSelection(state);
396 }
397 }
398
399 /**
400 * Set the user input string
401 */
402 public void setSearchText(String text) {
403 fSearchText.setText(text);
404 }
405
406 /**
407 * Set the stop check button state
408 */
409 public void setStopButtonSelection(boolean state) {
410 if (fStopButton != null) {
411 fStopButton.setSelection(state);
412 }
413 }
414
415 /**
416 * Set the synchronous message check button state
417 */
418 public void setSynMessageButtonSelection(boolean state) {
419 if (fSynMessageButton != null) {
420 fSynMessageButton.setSelection(state);
421 }
422 }
423
424 /**
425 * Set the synchronous message return check button state
426 */
427 public void setSynMessageReturnButtonSelection(boolean state) {
428 if (fSynMessageReturnButton != null) {
429 fSynMessageReturnButton.setSelection(state);
430 }
431 }
432
433 // ------------------------------------------------------------------------
434 // Helper classes
435 // ------------------------------------------------------------------------
436
437 /**
438 * Selection listener implementation for graph node types.
439 * @version 1.0
440 */
441 protected class GraphNodeTypeListener implements SelectionListener {
442 /*
443 * (non-Javadoc)
444 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
445 */
446 @Override
447 public void widgetDefaultSelected(SelectionEvent e) {
448 // Nothing to do
449 }
450
451 /*
452 * (non-Javadoc)
453 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
454 */
455 @Override
456 public void widgetSelected(SelectionEvent e) {
457 updateOkButton();
458 }
459 }
460
461 /**
462 * Modify listener implementation for the expression field.
463 *
464 * @version 1.0
465 */
466 protected class ExpressionListener implements ModifyListener {
467
468 /*
469 * (non-Javadoc)
470 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
471 */
472 @Override
473 public void modifyText(ModifyEvent e) {
474 updateOkButton();
475 }
476 }
477
478 }
This page took 0.04211 seconds and 6 git commands to generate.