tmf: Update Javadoc throughout tmf.ui
[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.internal.tmf.ui.Activator;
21 import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
22 import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode;
23 import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLParser;
24 import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLWriter;
25 import org.xml.sax.SAXException;
26
27 /**
28 * Central filter manager
29 *
30 * @version 1.0
31 * @author Patrick Tasse
32 */
33 public class FilterManager {
34
35 private static final String SAVED_FILTERS_FILE_NAME = "saved_filters.xml"; //$NON-NLS-1$
36 private static final String SAVED_FILTERS_PATH_NAME =
37 Activator.getDefault().getStateLocation().addTrailingSeparator().append(SAVED_FILTERS_FILE_NAME).toString();
38
39 private static ITmfFilterTreeNode fRoot = new TmfFilterRootNode();
40 static {
41 try {
42 fRoot = new TmfFilterXMLParser(SAVED_FILTERS_PATH_NAME).getTree();
43 } catch (FileNotFoundException e) {
44 } catch (SAXException e) {
45 Activator.getDefault().logError("Error parsing saved filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$
46 } catch (IOException e) {
47 Activator.getDefault().logError("Error parsing saved filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$
48 }
49 }
50
51 public static ITmfFilterTreeNode[] getSavedFilters() {
52 return fRoot.clone().getChildren();
53 }
54
55 public static void setSavedFilters(ITmfFilterTreeNode[] filters) {
56 fRoot = new TmfFilterRootNode();
57 for (ITmfFilterTreeNode filter : filters) {
58 fRoot.addChild(filter.clone());
59 }
60 try {
61 TmfFilterXMLWriter writerXML = new TmfFilterXMLWriter(fRoot);
62 writerXML.saveTree(SAVED_FILTERS_PATH_NAME);
63 } catch (IOException e) {
64 Activator.getDefault().logError("Error saving filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$
65 } catch (ParserConfigurationException e) {
66 Activator.getDefault().logError("Error saving filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$
67 }
68 }
69 }
This page took 0.032578 seconds and 6 git commands to generate.