1 /**********************************************************************
2 * Copyright (c) 2005, 2008, 2011 IBM Corporation and others.
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
7 * $Id: SearchFilterDialog.java,v 1.4 2008/01/24 02:29:09 apnan Exp $
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.widgets
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.jface
.dialogs
.Dialog
;
19 import org
.eclipse
.jface
.dialogs
.DialogSettings
;
20 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.AsyncMessage
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.AsyncMessageReturn
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Stop
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.SyncMessage
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.SyncMessageReturn
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFindProvider
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDGraphNodeSupporter
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.SDMessages
;
33 import org
.eclipse
.swt
.SWT
;
34 import org
.eclipse
.swt
.widgets
.Button
;
35 import org
.eclipse
.swt
.widgets
.Composite
;
36 import org
.eclipse
.swt
.widgets
.Control
;
37 import org
.eclipse
.swt
.widgets
.TabFolder
;
40 * This is the common dialog to define Find and/or Filter Criteria(s)
42 public class SearchFilterDialog
extends Dialog
{
44 protected static final String FIND_CRITERIA
= "findCriteria"; //$NON-NLS-1$
45 protected static final String FIND_EXPRESSION_LIST
= "findExpressionList"; //$NON-NLS-1$
46 protected static final String FILTER_CRITERIA
= "filterCriteria"; //$NON-NLS-1$
47 protected static final String FILTER_EXPRESSION_LIST
= "filterExpressionList"; //$NON-NLS-1$
48 protected static final int MAX_EXPRESSION_LIST
= 7;
53 protected SDView viewer
= null;
56 * tab with the controls for a Criteria
58 protected TabFolder tab
= null;
61 * Criteria updated by this dialog
63 protected Criteria criteria
= null;
66 * find/filter provider telling which graph nodes are supported
68 protected ISDGraphNodeSupporter provider
= null;
71 * okText is the text for the Ok button and title is the title of the dialog.<br>
72 * Both depend on the usage that is done of this dialog (find or filter).
74 protected String okText
, title
;
77 * List of string expressions that have been searched already
79 protected String
[] expressionList
;
82 * find is true if the dialog is for the find feature and false for filter feature
84 protected boolean find
;
88 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
91 public Control
createDialogArea(Composite arg0
) {
93 expressionList
= TmfUiPlugin
.getDefault().getDialogSettings().getArray(FIND_EXPRESSION_LIST
);
95 expressionList
= TmfUiPlugin
.getDefault().getDialogSettings().getArray(FILTER_EXPRESSION_LIST
);
96 if (expressionList
== null) {
97 expressionList
= new String
[0];
99 return new TabContents(arg0
, provider
, getButton(IDialogConstants
.OK_ID
), expressionList
);
106 public SearchFilterDialog(SDView view_
, ISDGraphNodeSupporter provider_
, boolean filter_
, int style
) {
107 super(view_
.getSDWidget().getShell());
108 setShellStyle(SWT
.DIALOG_TRIM
| style
);
109 provider
= provider_
;
115 * Open the dialog box
121 if (criteria
== null)
123 if (criteria
== null) {
124 criteria
= new Criteria();
125 criteria
.setLifeLineSelected(provider
.isNodeSupported(ISDGraphNodeSupporter
.LIFELINE
));
126 criteria
.setSyncMessageSelected(provider
.isNodeSupported(ISDGraphNodeSupporter
.SYNCMESSAGE
));
127 criteria
.setSyncMessageReturnSelected(provider
.isNodeSupported(ISDGraphNodeSupporter
.SYNCMESSAGERETURN
));
128 criteria
.setAsyncMessageSelected(provider
.isNodeSupported(ISDGraphNodeSupporter
.ASYNCMESSAGE
));
129 criteria
.setAsyncMessageReturnSelected(provider
.isNodeSupported(ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
));
130 criteria
.setStopSelected(provider
.isNodeSupported(ISDGraphNodeSupporter
.STOP
));
132 copyFromCriteria(criteria
);
134 if (okText
!= null) {
135 getButton(IDialogConstants
.OK_ID
).setText(okText
);
137 getButton(IDialogConstants
.OK_ID
).setText(SDMessages
._21
);
141 getButton(IDialogConstants
.CANCEL_ID
).setText(SDMessages
._22
);
144 Button okButton
= getButton(IDialogConstants
.OK_ID
);
145 ((TabContents
) getDialogArea()).setOkButton(okButton
);
146 if (criteria
== null || !((criteria
.getExpression() != null && !criteria
.getExpression().equals("")) && //$NON-NLS-1$
147 (criteria
.isAsyncMessageReturnSelected() || criteria
.isAsyncMessageSelected() || criteria
.isLifeLineSelected() || criteria
.isStopSelected() || criteria
.isSyncMessageReturnSelected() || criteria
.isSyncMessageSelected()))) {
148 okButton
.setEnabled(false);
152 getShell().setText(title
);
154 getShell().setText(SDMessages
._24
);
158 getShell().setLocation(getShell().getDisplay().getCursorLocation());
167 @SuppressWarnings("rawtypes")
168 protected void loadCriteria() {
170 String CRITERIA
= FIND_CRITERIA
;
172 CRITERIA
= FILTER_CRITERIA
;
174 DialogSettings section
= (DialogSettings
) TmfUiPlugin
.getDefault().getDialogSettings().getSection(CRITERIA
);
175 List selection
= viewer
.getSDWidget().getSelection();
176 if ((selection
== null || selection
.size() != 1) || (!find
)) {
177 if (section
!= null) {
178 criteria
= new Criteria();
179 criteria
.load(section
);
182 GraphNode gn
= (GraphNode
) selection
.get(0);
183 criteria
= new Criteria();
184 criteria
.setExpression(gn
.getName());
185 criteria
.setCaseSenstiveSelected(true);
186 if (gn
instanceof Lifeline
&& provider
.isNodeSupported(ISDGraphNodeSupporter
.LIFELINE
)) {
187 criteria
.setLifeLineSelected(true);
188 } else if (gn
instanceof SyncMessageReturn
&& provider
.isNodeSupported(ISDGraphNodeSupporter
.SYNCMESSAGERETURN
)) {
189 criteria
.setSyncMessageReturnSelected(true);
190 } else if ((gn
instanceof SyncMessageReturn
|| gn
instanceof SyncMessage
) && provider
.isNodeSupported(ISDGraphNodeSupporter
.SYNCMESSAGE
)) {
191 criteria
.setSyncMessageSelected(true);
192 } else if (gn
instanceof AsyncMessageReturn
&& provider
.isNodeSupported(ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
)) {
193 criteria
.setAsyncMessageReturnSelected(true);
194 } else if ((gn
instanceof AsyncMessageReturn
|| gn
instanceof AsyncMessage
) && provider
.isNodeSupported(ISDGraphNodeSupporter
.ASYNCMESSAGE
)) {
195 criteria
.setAsyncMessageSelected(true);
196 } else if (gn
instanceof Stop
&& provider
.isNodeSupported(ISDGraphNodeSupporter
.STOP
)) {
197 criteria
.setStopSelected(true);
203 * Called when the dialog box ok button is pressed and call back the appropriate action provider (ISDFilterProvider
204 * or ISDFindProvider)
207 public void okPressed() {
211 super.close(); // Filter is modal
213 if ((provider
!= null) && (provider
instanceof ISDFindProvider
) && find
) {
214 boolean result
= ((ISDFindProvider
) provider
).find(criteria
);
215 TabContents content
= getTabContents();
216 content
.setResult(result
);
224 public void cancelPressed() {
227 if (provider
instanceof ISDFindProvider
) {
228 ((ISDFindProvider
) provider
).cancel();
232 super.cancelPressed();
238 public void saveCriteria() {
239 String CRITERIA
= FIND_CRITERIA
;
240 String EXPRESSION_LIST
= FIND_EXPRESSION_LIST
;
242 CRITERIA
= FILTER_CRITERIA
;
243 EXPRESSION_LIST
= FILTER_EXPRESSION_LIST
;
245 DialogSettings settings
= (DialogSettings
) TmfUiPlugin
.getDefault().getDialogSettings();
246 DialogSettings section
= (DialogSettings
) settings
.getSection(CRITERIA
);
247 if (section
== null) {
248 section
= (DialogSettings
) settings
.addNewSection(CRITERIA
);
250 criteria
.save(section
);
252 if (criteria
.getExpression().length() > 0) {
253 ArrayList
<String
> list
= new ArrayList
<String
>();
254 for (int i
= 0; i
< expressionList
.length
; i
++) {
255 list
.add(expressionList
[i
]);
257 // Remove the used expression if one from the dropdown list
258 list
.remove(criteria
.getExpression());
259 // Put the new expression at the beginning
260 list
.add(0, criteria
.getExpression());
261 // Fill in the expressionList, truncating to MAX_EXPRESSION_LIST
262 int size
= Math
.min(list
.size(), MAX_EXPRESSION_LIST
);
263 String
[] temp
= new String
[size
];
264 for (int i
= 0; i
< size
; i
++) {
265 temp
[i
] = (String
) list
.get(i
);
267 expressionList
= temp
;
268 settings
.put(EXPRESSION_LIST
, expressionList
);
275 public Criteria
getCriteria() {
282 public void setCriteria(Criteria criteria_
) {
283 criteria
= criteria_
;
287 * Get the current end-user settings from the dialog to a Criteria
291 public void copyToCriteria() {
292 criteria
= new Criteria();
293 TabContents content
= getTabContents();
294 criteria
.setLifeLineSelected(content
.getLifelineButtonSelection());
295 criteria
.setSyncMessageSelected(content
.getSynMessageButtonSelection());
296 criteria
.setSyncMessageReturnSelected(content
.getSynMessageReturnButtonSelection());
297 criteria
.setAsyncMessageSelected(content
.getAsynMessageButtonSelection());
298 criteria
.setAsyncMessageReturnSelected(content
.getAsynMessageReturnButtonSelection());
299 criteria
.setStopSelected(content
.getStopButtonSelection());
300 criteria
.setCaseSenstiveSelected(content
.getCaseSensitiveSelection());
301 criteria
.setExpression(content
.getSearchText());
306 * @todo Generated comment
308 protected TabContents
getTabContents() {
309 TabContents content
= null;
311 content
= (TabContents
) getDialogArea();
313 content
= (TabContents
) tab
.getSelection()[0].getControl();
318 * Initialize the dialog with the settings of an existing Criteria<br>
319 * Criteria must not be null and the TabContents must have been created
323 public void copyFromCriteria(Criteria from
) {
324 TabContents content
= getTabContents();
325 content
.setLifelineButtonSelection(from
.isLifeLineSelected());
326 content
.setSynMessageButtonSelection(from
.isSyncMessageSelected());
327 content
.setSynMessageReturnButtonSelection(from
.isSyncMessageReturnSelected());
328 content
.setAsynMessageButtonSelection(from
.isAsyncMessageSelected());
329 content
.setAsynMessageReturnButtonSelection(from
.isSyncMessageReturnSelected());
330 content
.setStopButtonSelection(from
.isStopSelected());
331 content
.setCaseSensitiveSelection(from
.isCaseSenstiveSelected());
332 if (from
.getExpression() != null) {
333 content
.setSearchText(from
.getExpression());
340 public void setOkText(String okText_
) {
347 public void setTitle(String title_
) {