Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / filter / FilterDialog.java
1 /*******************************************************************************
2 * Copyright (c) 2010 Ericsson
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
13 package org.eclipse.linuxtools.tmf.ui.views.filter;
14
15 import org.eclipse.jface.dialogs.Dialog;
16 import org.eclipse.linuxtools.internal.tmf.ui.Messages;
17 import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
18 import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.swt.widgets.Shell;
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
32 TmfFilterNode fRoot;
33 FilterViewer fViewer;
34
35 /**
36 * Constructor.
37 *
38 * @param shell
39 * The shell to which this dialog is attached
40 */
41 public FilterDialog(Shell shell) {
42 super(shell);
43 setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX);
44 }
45
46 /* (non-Javadoc)
47 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
48 */
49 @Override
50 protected Control createDialogArea(Composite parent) {
51 getShell().setText(Messages.FilterDialog_FilterDialogTitle);
52 getShell().setMinimumSize(getShell().computeSize(500, 200));
53 Composite composite = (Composite) super.createDialogArea(parent);
54
55 fViewer = new FilterViewer(composite, SWT.BORDER);
56 fViewer.setInput(fRoot);
57 return composite;
58 }
59
60 /**
61 * @param filter the filter to set
62 */
63 public void setFilter(ITmfFilterTreeNode filter) {
64 fRoot = new TmfFilterNode(null);
65 if (filter != null) {
66 fRoot.addChild(filter.clone());
67 }
68 if (fViewer != null) {
69 fViewer.setInput(fRoot);
70 }
71 }
72
73 /**
74 * @return the filter
75 */
76 public ITmfFilterTreeNode getFilter() {
77 if (fRoot != null && fRoot.hasChildren()) {
78 return fRoot.getChild(0).clone();
79 }
80 return null;
81 }
82
83 }
This page took 0.043191 seconds and 5 git commands to generate.