00001 package edu.rice.cs.hpc.traceviewer.filter;
00002
00003 import java.util.ArrayList;
00004
00005 import org.eclipse.jface.dialogs.Dialog;
00006 import org.eclipse.jface.dialogs.MessageDialog;
00007 import org.eclipse.jface.dialogs.TitleAreaDialog;
00008 import org.eclipse.jface.layout.GridDataFactory;
00009 import org.eclipse.jface.layout.GridLayoutFactory;
00010 import org.eclipse.swt.SWT;
00011 import org.eclipse.swt.events.SelectionAdapter;
00012 import org.eclipse.swt.events.SelectionEvent;
00013 import org.eclipse.swt.widgets.Button;
00014 import org.eclipse.swt.widgets.Combo;
00015 import org.eclipse.swt.widgets.Composite;
00016 import org.eclipse.swt.widgets.Control;
00017 import org.eclipse.swt.widgets.Group;
00018 import org.eclipse.swt.widgets.Label;
00019 import org.eclipse.swt.widgets.List;
00020 import org.eclipse.swt.widgets.Shell;
00021
00022 import edu.rice.cs.hpc.common.util.UserInputHistory;
00023 import edu.rice.cs.hpc.data.experiment.extdata.Filter;
00024 import edu.rice.cs.hpc.data.experiment.extdata.FilterSet;
00025 import edu.rice.cs.hpc.data.experiment.extdata.IFilteredData;
00026
00027
00028
00029
00030
00031
00032
00033 public class FilterDialog extends TitleAreaDialog {
00034
00035 private List list;
00036 private IFilteredData filterData;
00037 private Button btnRemove;
00038 private Button btnShow;
00039
00040 private static final String THREAD_FILTER_KEY = "thread_filter";
00041 private static final String PROCESS_FILTER_KEY = "process_filter";
00042
00043
00044
00045
00046 public FilterDialog(Shell parentShell, IFilteredData filteredBaseData) {
00047 super(parentShell);
00048 filterData = filteredBaseData;
00049 }
00050
00051
00052
00053
00054
00055 protected Control createDialogArea(Composite parent) {
00056 Composite composite = (Composite) super.createDialogArea(parent);
00057
00058 Group grpMode = new Group(composite, SWT.NONE);
00059 grpMode.setText("Mode of filter");
00060
00061 btnShow = new Button(grpMode, SWT.RADIO);
00062 btnShow.setText("To show");
00063 btnShow.setToolTipText("An option to show matching patterns");
00064
00065 Button btnHide = new Button(grpMode, SWT.RADIO);
00066 btnHide.setText("To hide");
00067 btnHide.setToolTipText("An option to hide matching patterns");
00068
00069
00070 FilterSet filter = null;
00071 if (filterData != null) {
00072 filter = filterData.getFilter();
00073
00074 if (filter != null && filter.isShownMode())
00075 btnShow.setSelection(true);
00076 else
00077 btnHide.setSelection(true);
00078 }
00079
00080 Label lblMode = new Label(grpMode, SWT.LEFT | SWT.WRAP);
00081 lblMode.setText("Selecting the 'To show' radio button will show matching processes, " +
00082 "while selecting the 'To hide' button \nwill hide them.");
00083
00084 GridDataFactory.swtDefaults().span(2, 1).grab(true, false).applyTo(lblMode);
00085
00086 GridDataFactory.swtDefaults().grab(true, false).applyTo(grpMode);
00087 GridLayoutFactory.fillDefaults().numColumns(2).applyTo(grpMode);
00088
00089 Group grpFilter = new Group(composite, SWT.NONE);
00090 grpFilter.setText("Filter");
00091
00092 GridDataFactory.fillDefaults().grab(true, true).applyTo(grpFilter);
00093 GridLayoutFactory.fillDefaults().numColumns(2).applyTo(grpFilter);
00094
00095 Composite coButtons = new Composite(grpFilter, SWT.NONE);
00096
00097 GridDataFactory.fillDefaults().grab(false, true).applyTo(coButtons);
00098 GridLayoutFactory.fillDefaults().numColumns(1).applyTo(coButtons);
00099
00100 Button btnAdd = new Button(coButtons, SWT.PUSH | SWT.FLAT);
00101 btnAdd.setText("Add");
00102 btnAdd.setToolTipText("Add a new filtering pattern");
00103 btnAdd.addSelectionListener( new SelectionAdapter(){
00104 public void widgetSelected(SelectionEvent e) {
00105 String thread_title = null, process_title = "Rank";
00106 String message;
00107
00108 if (filterData.isHybridRank()) {
00109 thread_title = "Thread";
00110 process_title = "Process";
00111 message = "Please type a pattern in the format minimum:maximum:stride.\n" +
00112 "Any omitted or invalid sections will match as many processes \nor threads as possible.\n\n" +
00113 "For instance, 3:7:2 in the process box with the thread box empty \nwill match all threads of processes 3, 5, and 7.\n"+
00114 "1 in the thread box with the process box empty will match \nthread 1 of all processes.\n"+
00115 "1::2 in the process box and 2:4:2 in the thread box will match \n1.2, 1.4, 3.2, 3.4, 5.2 ...";
00116 } else {
00117 message = "Please type a pattern in the format minimum:maximum:stride.\n" +
00118 "Any omitted or invalid sections will match as many ranks as possible.\n\n" +
00119 "For instance, 3:7:2 will match all ranks 3, 5, and 7.\n";
00120 }
00121 DualInputDialog dlg = new DualInputDialog(getShell(), "Add a pattern", message,
00122 process_title, thread_title, PROCESS_FILTER_KEY, THREAD_FILTER_KEY);
00123 if (dlg.open() == Dialog.OK) {
00124 list.add(dlg.getValue());
00125 checkButtons();
00126 }
00127 }
00128 });
00129 GridDataFactory.fillDefaults().grab(true, false).applyTo(btnAdd);
00130
00131
00132 btnRemove = new Button(coButtons, SWT.PUSH | SWT.FLAT);
00133 btnRemove.setText("Remove");
00134 btnRemove.setToolTipText("Remove a selected filtering pattern");
00135 btnRemove.addSelectionListener( new SelectionAdapter() {
00136 public void widgetSelected(SelectionEvent e) {
00137 int i = list.getSelectionCount();
00138 if (i > 0) {
00139 final String item = list.getSelection()[0];
00140 list.remove(item);
00141 checkButtons();
00142 }
00143 }
00144 });
00145 GridDataFactory.fillDefaults().grab(true, false).applyTo(btnRemove);
00146
00147
00148 final Button btnRemoveAll = new Button(coButtons, SWT.PUSH | SWT.FLAT);
00149 btnRemoveAll.setText("Remove all");
00150 btnRemoveAll.setToolTipText("Remove all filtering patterns");
00151 btnRemoveAll.addSelectionListener(new SelectionAdapter() {
00152 public void widgetSelected(SelectionEvent e) {
00153 int count = list.getItemCount();
00154 if (count>0) {
00155 if (MessageDialog.openQuestion(getShell(), "Remove all patterns",
00156 "Are you sure to remove all " + count + " patterns ?")) {
00157 list.removeAll();
00158 checkButtons();
00159 }
00160 }
00161 }
00162 }) ;
00163 GridDataFactory.fillDefaults().grab(true, false).applyTo(btnRemoveAll);
00164
00165
00166 list = new List(grpFilter, SWT.SINGLE | SWT.V_SCROLL);
00167 list.addSelectionListener(new SelectionAdapter(){
00168 public void widgetSelected(SelectionEvent e) {
00169 checkButtons();
00170 }
00171 });
00172 GridDataFactory.fillDefaults().grab(true, true).hint(40, 80).applyTo(list);
00173
00174 this.setMessage("Add/remove glob patterns to filter displayed processes");
00175 this.setTitle("Filter patterns");
00176
00177
00178 if (filterData != null && filter != null && filter.getPatterns() != null) {
00179 for (Filter flt : filter.getPatterns()) {
00180 list.add(flt.toString());
00181 }
00182 }
00183
00184 checkButtons();
00185
00186 return parent;
00187 }
00188
00189
00190 private void checkButtons() {
00191 boolean selected = (list.getSelectionCount()>0);
00192 btnRemove.setEnabled(selected);
00193 }
00194
00195
00196
00197
00198
00199 protected void setShellStyle(int newShellStyle) {
00200 super.setShellStyle(newShellStyle | SWT.RESIZE);
00201 }
00202
00203
00204
00205
00206
00207 protected void okPressed() {
00208 ArrayList<Filter> filterList = new ArrayList<Filter>();
00209 for(int i=0; i<list.getItemCount(); i++) {
00210 String item = list.getItem(i);
00211 filterList.add(new Filter(item));
00212 }
00213 FilterSet filterSet = filterData.getFilter();
00214
00215
00216 filterSet.setPatterns(filterList);
00217
00218 filterSet.setShowMode( btnShow.getSelection() );
00219
00220
00221 filterData.setFilter(filterSet);
00222 if (filterData.isGoodFilter())
00223 super.okPressed();
00224 else {
00225
00226 MessageDialog.openError(getShell(), "Error",
00227 "The result of filter is empty ranks.\nIt isn't allowed to filter all the ranks.");
00228 }
00229 }
00230
00231 static public void main(String []args) {
00232 Shell shell = new Shell();
00233 FilterDialog dlgMain = new FilterDialog(shell, null);
00234 dlgMain.open();
00235 }
00236 }
00237
00238
00239
00240
00241
00242
00243 class DualInputDialog extends Dialog{
00244 private Combo firstEntry;
00245 private Combo secondEntry;
00246 final String message;
00247 final String prompt1;
00248 final String prompt2;
00249 final String title;
00250 final UserInputHistory firstHistory;
00251 final UserInputHistory secondHistory;
00252 String value;
00253
00254
00255 public DualInputDialog(Shell parentShell, String dialogTitle,
00256 String dialogMessage, String firstPrompt, String secondPrompt, String firstHistoryKey, String secondHistoryKey) {
00257 super(parentShell);
00258 title = dialogTitle;
00259 message = dialogMessage;
00260 prompt1 = firstPrompt;
00261 prompt2 = secondPrompt;
00262
00263 firstHistory = new UserInputHistory(firstHistoryKey);
00264 secondHistory = new UserInputHistory(secondHistoryKey);
00265
00266 }
00267 @Override
00268 protected Control createDialogArea(Composite parent) {
00269 Composite composite = (Composite) super.createDialogArea(parent);
00270 GridLayoutFactory.fillDefaults().numColumns(1).applyTo(composite);
00271 GridDataFactory.swtDefaults().grab(true, true).align(SWT.CENTER, SWT.CENTER).applyTo(composite);
00272
00273 Label prompt = new Label(composite, SWT.NONE);
00274 prompt.setText(message);
00275
00276
00277 Group fieldArea = new Group(composite, SWT.SHADOW_IN);
00278
00279 Label firstLabel = new Label(fieldArea, SWT.NONE);
00280 firstLabel.setText(prompt1);
00281 firstEntry = new Combo(fieldArea, SWT.SINGLE | SWT.BORDER);
00282 firstEntry.setItems(firstHistory.getHistory());
00283
00284 if (prompt2 != null)
00285 {
00286 Label secondLabel = new Label(fieldArea, SWT.NONE);
00287 secondLabel.setText(prompt2);
00288 secondEntry = new Combo(fieldArea, SWT.SINGLE | SWT.BORDER);
00289 secondEntry.setItems(secondHistory.getHistory());
00290 }
00291
00292 GridLayoutFactory.fillDefaults().numColumns(2).extendedMargins(2, 4, 3, 5).generateLayout(fieldArea);
00293 GridLayoutFactory.fillDefaults().numColumns(1).extendedMargins(10, 10, 10, 10).generateLayout(composite);
00294 return composite;
00295 }
00296
00297 @Override
00298 protected void okPressed() {
00299 value = firstEntry.getText() + Filter.PROCESS_THREAD_SEPARATOR;
00300 if (secondEntry != null) {
00301 value += secondEntry.getText();
00302 secondHistory.addLine(secondEntry.getText());
00303 }
00304 firstHistory.addLine(firstEntry.getText());
00305 super.okPressed();
00306 }
00307 public String getValue() {
00308 return value;
00309 }
00310
00311 static public void main(String []argv) {
00312 Shell shell = new Shell();
00313 DualInputDialog dlg = new DualInputDialog(shell, "test input",
00314 "just a message asd srjt jlkbdfkrejldf ajlwi more asdkhuiq eger \n\n more text alks jlrk adsgf\nja reiotp", "Process", "Threads", "hist_1", "hist_2");
00315 dlg.open();
00316 }
00317 }
00318