Commit | Line | Data |
---|---|---|
be222f56 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2010, 2014 Ericsson |
be222f56 PT |
3 | * |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Patrick Tasse - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.ui.views.filter; |
be222f56 PT |
14 | |
15 | import org.eclipse.jface.dialogs.Dialog; | |
be222f56 PT |
16 | import org.eclipse.swt.SWT; |
17 | import org.eclipse.swt.widgets.Composite; | |
18 | import org.eclipse.swt.widgets.Control; | |
19 | import org.eclipse.swt.widgets.Shell; | |
2bdf0193 AM |
20 | import org.eclipse.tracecompass.internal.tmf.ui.Messages; |
21 | import org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode; | |
22 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode; | |
be222f56 PT |
23 | |
24 | /** | |
25 | * The dialog for user-defined filters. | |
26 | * | |
27 | * @version 1.0 | |
28 | * @author Patrick Tasse | |
29 | */ | |
30 | public class FilterDialog extends Dialog { | |
31 | ||
11252342 AM |
32 | TmfFilterNode fRoot; |
33 | FilterViewer fViewer; | |
be222f56 PT |
34 | |
35 | /** | |
36 | * Constructor. | |
37 | * | |
38 | * @param shell | |
39 | * The shell to which this dialog is attached | |
40 | */ | |
11252342 AM |
41 | public FilterDialog(Shell shell) { |
42 | super(shell); | |
43 | setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX); | |
44 | } | |
be222f56 | 45 | |
11252342 AM |
46 | @Override |
47 | protected Control createDialogArea(Composite parent) { | |
be222f56 | 48 | getShell().setText(Messages.FilterDialog_FilterDialogTitle); |
11252342 | 49 | getShell().setMinimumSize(getShell().computeSize(500, 200)); |
be222f56 PT |
50 | Composite composite = (Composite) super.createDialogArea(parent); |
51 | ||
52 | fViewer = new FilterViewer(composite, SWT.BORDER); | |
53 | fViewer.setInput(fRoot); | |
54 | return composite; | |
11252342 | 55 | } |
be222f56 | 56 | |
11252342 AM |
57 | /** |
58 | * @param filter | |
59 | * the filter to set | |
60 | */ | |
61 | public void setFilter(ITmfFilterTreeNode filter) { | |
62 | fRoot = new TmfFilterNode(null); | |
63 | if (filter != null) { | |
64 | fRoot.addChild(filter.clone()); | |
65 | } | |
66 | if (fViewer != null) { | |
67 | fViewer.setInput(fRoot); | |
68 | } | |
69 | } | |
be222f56 | 70 | |
11252342 AM |
71 | /** |
72 | * @return the filter | |
73 | */ | |
74 | public ITmfFilterTreeNode getFilter() { | |
75 | if (fRoot != null && fRoot.hasChildren()) { | |
76 | return fRoot.getChild(0).clone(); | |
77 | } | |
78 | return null; | |
79 | } | |
be222f56 PT |
80 | |
81 | } |