Java Doc and API clean up of TMF UML Sequence diagram framework
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / dialogs / TabContents.java
CommitLineData
73005152 1/**********************************************************************
df0b8ff4
BH
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
4 *
73005152
BH
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
73005152
BH
9 *
10 * Contributors:
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
df0b8ff4 14package org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs;
73005152
BH
15
16import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter;
17import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages;
18import org.eclipse.swt.SWT;
19import org.eclipse.swt.events.ModifyEvent;
20import org.eclipse.swt.events.ModifyListener;
21import org.eclipse.swt.events.SelectionEvent;
22import org.eclipse.swt.events.SelectionListener;
23import org.eclipse.swt.layout.GridData;
24import org.eclipse.swt.layout.GridLayout;
25import org.eclipse.swt.widgets.Button;
26import org.eclipse.swt.widgets.Combo;
27import org.eclipse.swt.widgets.Composite;
28import org.eclipse.swt.widgets.Group;
29import org.eclipse.swt.widgets.Label;
30
31/**
df0b8ff4
BH
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
73005152
BH
36 */
37public class TabContents extends Composite {
38
df0b8ff4
BH
39 // ------------------------------------------------------------------------
40 // Attributes
41 // ------------------------------------------------------------------------
42 /**
43 * A graph node type listener implementation.
44 */
73005152 45 GraphNodeTypeListener graphNodeTypeListener = null;
df0b8ff4
BH
46 /**
47 * A expression listener implementation.
48 */
73005152 49 ExpressionListener expressionListener = null;
df0b8ff4
BH
50 /**
51 * The button for lifelines.
52 */
73005152 53 Button lifelineButton = null;
df0b8ff4
BH
54 /**
55 * The button for stops.
56 */
73005152 57 Button stopButton = null;
df0b8ff4
BH
58 /**
59 * The button for synchronous messages
60 */
73005152 61 Button synMessageButton = null;
df0b8ff4
BH
62 /**
63 * The button for synchronous return messages
64 */
73005152 65 Button synMessageReturnButton = null;
df0b8ff4
BH
66 /**
67 * The button for asynchronous messages
68 */
73005152 69 Button asynMessageButton = null;
df0b8ff4
BH
70 /**
71 * The button for asynchronous return messages
72 */
73005152 73 Button asynMessageReturnButton = null;
df0b8ff4
BH
74 /**
75 * The search text combo box.
76 */
73005152 77 Combo searchText = null;
df0b8ff4
BH
78 /**
79 * The group for selection kind.
80 */
73005152 81 Group kindSelection = null;
df0b8ff4
BH
82 /**
83 * The button for case sensitive expressions.
84 */
73005152 85 Button caseSensitive = null;
df0b8ff4
BH
86 /**
87 * The label for the result string.
88 */
73005152 89 Label result = null;
df0b8ff4
BH
90 /**
91 * The button for notifying parent about valid data.
92 */
73005152
BH
93 Button parentOkButton = null;
94
df0b8ff4
BH
95 // ------------------------------------------------------------------------
96 // Constructors
97 // ------------------------------------------------------------------------
98
73005152
BH
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 */
73005152
BH
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 graphNodeTypeListener = new GraphNodeTypeListener();
113 expressionListener = 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 searchText = 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 searchText.setLayoutData(comboData);
132 if (expressionList != null) {
133 for (int i = 0; i < expressionList.length; i++) {
134 searchText.add(expressionList[i]);
135 }
136 }
137 searchText.addModifyListener(expressionListener);
138
139 // Create the case sensitive check button
140 caseSensitive = new Button(searchPart, SWT.CHECK);
141 caseSensitive.setText(SDMessages._27);
142
143 // Create the group for searched graph node kind selection
144 kindSelection = new Group(this, SWT.SHADOW_NONE);
145 kindSelection.setText(SDMessages._25);
146 // kindSelection.setLayoutData(tabLayoutData2);
147 GridLayout kindSelectionLayout = new GridLayout();
148 kindSelectionLayout.numColumns = 1;
149 kindSelection.setLayout(kindSelectionLayout);
150 GridData kindSelectionData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
151 kindSelection.setLayoutData(kindSelectionData);
152
153 // Create the lifeline check button
154 if (provider != null && provider.isNodeSupported(ISDGraphNodeSupporter.LIFELINE)) {
155 lifelineButton = new Button(kindSelection, SWT.CHECK);
156 String nodeName = provider.getNodeName(ISDGraphNodeSupporter.LIFELINE, null);
df0b8ff4 157 if (nodeName != null) {
73005152 158 lifelineButton.setText(nodeName);
df0b8ff4 159 } else {
73005152 160 lifelineButton.setText(SDMessages._28);
df0b8ff4 161 }
73005152
BH
162 lifelineButton.setEnabled(true);
163 lifelineButton.addSelectionListener(graphNodeTypeListener);
164 }
165
166 if (provider != null && provider.isNodeSupported(ISDGraphNodeSupporter.STOP)) {
167 // Create the stop check button
168 stopButton = new Button(kindSelection, SWT.CHECK);
169 String nodeName = provider.getNodeName(ISDGraphNodeSupporter.STOP, null);
df0b8ff4 170 if (nodeName != null) {
73005152 171 stopButton.setText(nodeName);
df0b8ff4 172 } else {
73005152 173 stopButton.setText(SDMessages._29);
df0b8ff4
BH
174 }
175
73005152
BH
176 stopButton.setEnabled(true);
177 stopButton.addSelectionListener(graphNodeTypeListener);
178 }
179
180 if (provider != null && provider.isNodeSupported(ISDGraphNodeSupporter.SYNCMESSAGE)) {
181 // Create the synchronous message check button
182 synMessageButton = new Button(kindSelection, SWT.CHECK);
183 String nodeName = provider.getNodeName(ISDGraphNodeSupporter.SYNCMESSAGE, null);
df0b8ff4 184 if (nodeName != null) {
73005152 185 synMessageButton.setText(nodeName);
df0b8ff4 186 } else {
73005152 187 synMessageButton.setText(SDMessages._30);
df0b8ff4 188 }
73005152
BH
189 synMessageButton.setEnabled(true);
190 synMessageButton.addSelectionListener(graphNodeTypeListener);
191 }
192
193 if (provider != null && provider.isNodeSupported(ISDGraphNodeSupporter.SYNCMESSAGERETURN)) {
194 // Create the synchronous message return check button
195 synMessageReturnButton = new Button(kindSelection, SWT.CHECK);
196 String nodeName = provider.getNodeName(ISDGraphNodeSupporter.SYNCMESSAGERETURN, null);
df0b8ff4 197 if (nodeName != null) {
73005152 198 synMessageReturnButton.setText(nodeName);
df0b8ff4 199 } else {
73005152 200 synMessageReturnButton.setText(SDMessages._31);
df0b8ff4 201 }
73005152
BH
202 synMessageReturnButton.setEnabled(true);
203 synMessageReturnButton.addSelectionListener(graphNodeTypeListener);
204 }
205
206 if (provider != null && provider.isNodeSupported(ISDGraphNodeSupporter.ASYNCMESSAGE)) {
207 // Create the asynchronous message check button
208 asynMessageButton = new Button(kindSelection, SWT.CHECK);
209 String nodeName = provider.getNodeName(ISDGraphNodeSupporter.ASYNCMESSAGE, null);
df0b8ff4 210 if (nodeName != null) {
73005152 211 asynMessageButton.setText(nodeName);
df0b8ff4 212 } else {
73005152 213 asynMessageButton.setText(SDMessages._32);
df0b8ff4 214 }
73005152
BH
215 asynMessageButton.setEnabled(true);
216 asynMessageButton.addSelectionListener(graphNodeTypeListener);
217 }
218
219 if (provider != null && provider.isNodeSupported(ISDGraphNodeSupporter.ASYNCMESSAGERETURN)) {
220 // Create the asynchronous message return check button
221 asynMessageReturnButton = new Button(kindSelection, SWT.CHECK);
222 String nodeName = provider.getNodeName(ISDGraphNodeSupporter.ASYNCMESSAGERETURN, null);
df0b8ff4 223 if (nodeName != null) {
73005152 224 asynMessageReturnButton.setText(nodeName);
df0b8ff4 225 } else {
73005152 226 asynMessageReturnButton.setText(SDMessages._33);
df0b8ff4 227 }
73005152
BH
228 asynMessageReturnButton.setEnabled(true);
229 asynMessageReturnButton.addSelectionListener(graphNodeTypeListener);
230 }
231
232 result = new Label(this, SWT.LEFT);
233 result.setText(SDMessages._23);
234 result.setVisible(false);
235 }
236
df0b8ff4
BH
237 // ------------------------------------------------------------------------
238 // Methods
239 // ------------------------------------------------------------------------
240
73005152 241 /**
df0b8ff4
BH
242 * Set result text visibility
243 * @param found <code>true</code> for found (enable visibility) else false
73005152
BH
244 */
245 public void setResult(boolean found) {
246 result.setVisible(!found);
247 }
248
249 /**
df0b8ff4 250 * Updates parent OK button based on input data.
73005152
BH
251 */
252 public void updateOkButton() {
253 if (parentOkButton == null) {
254 return;
255 }
256 boolean enabled = (searchText.getText() != null && !searchText.getText().equals("")) && //$NON-NLS-1$
257 (getLifelineButtonSelection() || getStopButtonSelection() || getSynMessageButtonSelection() || getSynMessageReturnButtonSelection() || getAsynMessageButtonSelection() || getAsynMessageReturnButtonSelection());
258 parentOkButton.setEnabled(enabled);
259 }
260
261 /**
df0b8ff4
BH
262 * Sets the parent OK button reference.
263 *
264 * @param okButton The parent OK button
73005152
BH
265 */
266 public void setOkButton(Button okButton) {
267 parentOkButton = okButton;
268 }
269
270 /**
271 * Returns the asynchronous message check button state
272 *
273 * @return true if check, false otherwise
274 */
275 public boolean getAsynMessageButtonSelection() {
df0b8ff4 276 if (asynMessageButton != null) {
73005152 277 return asynMessageButton.getSelection();
df0b8ff4
BH
278 }
279 return false;
73005152
BH
280 }
281
282 /**
283 * Returns the asynchronous message return check button state
284 *
285 * @return true if check, false otherwise
286 */
287 public boolean getAsynMessageReturnButtonSelection() {
df0b8ff4 288 if (asynMessageReturnButton != null) {
73005152 289 return asynMessageReturnButton.getSelection();
df0b8ff4
BH
290 }
291 return false;
73005152
BH
292 }
293
294 /**
295 * Returns the case sensitive check button state
296 *
297 * @return true if check, false otherwise
298 */
299 public boolean getCaseSensitiveSelection() {
df0b8ff4 300 if (caseSensitive != null) {
73005152 301 return caseSensitive.getSelection();
df0b8ff4
BH
302 }
303 return false;
73005152
BH
304 }
305
306 /**
307 * Returns the lifeline check button state
308 *
309 * @return true if check, false otherwise
310 */
311 public boolean getLifelineButtonSelection() {
df0b8ff4 312 if (lifelineButton != null) {
73005152 313 return lifelineButton.getSelection();
df0b8ff4
BH
314 }
315 return false;
73005152
BH
316 }
317
318 /**
319 * Returns the user input string
320 *
321 * @return the string to search for
322 */
323 public String getSearchText() {
324 return searchText.getText();
325 }
326
327 /**
328 * Returns the stop check button state
329 *
330 * @return true if check, false otherwise
331 */
332 public boolean getStopButtonSelection() {
df0b8ff4 333 if (stopButton != null) {
73005152 334 return stopButton.getSelection();
df0b8ff4
BH
335 }
336 return false;
73005152
BH
337 }
338
339 /**
340 * Returns the synchronous message check button state
341 *
342 * @return true if check, false otherwise
343 */
344 public boolean getSynMessageButtonSelection() {
df0b8ff4 345 if (synMessageButton != null) {
73005152 346 return synMessageButton.getSelection();
df0b8ff4
BH
347 }
348 return false;
73005152
BH
349 }
350
351 /**
352 * Returns the synchronous message return check button state
353 *
354 * @return true if check, false otherwise
355 */
356 public boolean getSynMessageReturnButtonSelection() {
df0b8ff4 357 if (synMessageReturnButton != null) {
73005152 358 return synMessageReturnButton.getSelection();
df0b8ff4
BH
359 }
360 return false;
73005152
BH
361 }
362
363 /**
364 * Set the asynchronous message check button state
365 */
366 public void setAsynMessageButtonSelection(boolean state) {
df0b8ff4 367 if (asynMessageButton != null) {
73005152 368 asynMessageButton.setSelection(state);
df0b8ff4 369 }
73005152
BH
370 }
371
372 /**
373 * Set the asynchronous message return check button state
374 */
375 public void setAsynMessageReturnButtonSelection(boolean state) {
df0b8ff4 376 if (asynMessageReturnButton != null) {
73005152 377 asynMessageReturnButton.setSelection(state);
df0b8ff4 378 }
73005152
BH
379 }
380
381 /**
382 * Set the case sensitive check button state
383 */
384 public void setCaseSensitiveSelection(boolean state) {
df0b8ff4 385 if (caseSensitive != null) {
73005152 386 caseSensitive.setSelection(state);
df0b8ff4 387 }
73005152
BH
388 }
389
390 /**
391 * Set the lifeline check button state
392 */
393 public void setLifelineButtonSelection(boolean state) {
df0b8ff4 394 if (lifelineButton != null) {
73005152 395 lifelineButton.setSelection(state);
df0b8ff4 396 }
73005152
BH
397 }
398
399 /**
400 * Set the user input string
401 */
402 public void setSearchText(String text) {
403 searchText.setText(text);
404 }
405
406 /**
407 * Set the stop check button state
408 */
409 public void setStopButtonSelection(boolean state) {
df0b8ff4 410 if (stopButton != null) {
73005152 411 stopButton.setSelection(state);
df0b8ff4 412 }
73005152
BH
413 }
414
415 /**
416 * Set the synchronous message check button state
417 */
418 public void setSynMessageButtonSelection(boolean state) {
df0b8ff4 419 if (synMessageButton != null) {
73005152 420 synMessageButton.setSelection(state);
df0b8ff4 421 }
73005152
BH
422 }
423
424 /**
425 * Set the synchronous message return check button state
426 */
427 public void setSynMessageReturnButtonSelection(boolean state) {
df0b8ff4 428 if (synMessageReturnButton != null) {
73005152 429 synMessageReturnButton.setSelection(state);
df0b8ff4
BH
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 }
73005152
BH
476 }
477
478}
This page took 0.054997 seconds and 5 git commands to generate.