Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / filter / FilterManager.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 java.io.FileNotFoundException;
16 import java.io.IOException;
17
18 import javax.xml.parsers.ParserConfigurationException;
19
20 import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
21 import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode;
22 import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLParser;
23 import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLWriter;
24 import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin;
25 import org.xml.sax.SAXException;
26
27 public class FilterManager {
28
29 private static final String SAVED_FILTERS_FILE_NAME = "saved_filters.xml"; //$NON-NLS-1$
30 private static final String SAVED_FILTERS_PATH_NAME =
31 TmfUiPlugin.getDefault().getStateLocation().addTrailingSeparator().append(SAVED_FILTERS_FILE_NAME).toString();
32
33 private static ITmfFilterTreeNode fRoot = new TmfFilterRootNode();
34 static {
35 try {
36 fRoot = new TmfFilterXMLParser(SAVED_FILTERS_PATH_NAME).getTree();
37 } catch (FileNotFoundException e) {
38 } catch (SAXException e) {
39 e.printStackTrace();
40 } catch (IOException e) {
41 e.printStackTrace();
42 }
43 }
44
45 public static ITmfFilterTreeNode[] getSavedFilters() {
46 return fRoot.clone().getChildren();
47 }
48
49 public static void setSavedFilters(ITmfFilterTreeNode[] filters) {
50 fRoot = new TmfFilterRootNode();
51 for (ITmfFilterTreeNode filter : filters) {
52 fRoot.addChild(filter.clone());
53 }
54 try {
55 TmfFilterXMLWriter writerXML = new TmfFilterXMLWriter(fRoot);
56 writerXML.saveTree(SAVED_FILTERS_PATH_NAME);
57 } catch (IOException e) {
58 e.printStackTrace();
59 } catch (ParserConfigurationException e) {
60 e.printStackTrace();
61 }
62 }
63 }
This page took 0.031514 seconds and 5 git commands to generate.