~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterManager.java

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2013-05-13 21:43:22 UTC
  • mfrom: (1.2.1) (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130513214322-6frgd9du1n0w2uo7
Tags: 1.2.1-1
* Team upload.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
}
 
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
    /**
 
52
     * Retrieve the currently saved filters
 
53
     *
 
54
     * @return The array of filters
 
55
     */
 
56
    public static ITmfFilterTreeNode[] getSavedFilters() {
 
57
        return fRoot.clone().getChildren();
 
58
    }
 
59
 
 
60
    /**
 
61
     * Set the passed filters as the currently saved ones.
 
62
     *
 
63
     * @param filters
 
64
     *            The filters to save
 
65
     */
 
66
    public static void setSavedFilters(ITmfFilterTreeNode[] filters) {
 
67
        fRoot = new TmfFilterRootNode();
 
68
        for (ITmfFilterTreeNode filter : filters) {
 
69
                fRoot.addChild(filter.clone());
 
70
        }
 
71
                try {
 
72
                TmfFilterXMLWriter writerXML = new TmfFilterXMLWriter(fRoot);
 
73
                writerXML.saveTree(SAVED_FILTERS_PATH_NAME);
 
74
        } catch (ParserConfigurationException e) {
 
75
            Activator.getDefault().logError("Error saving filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$
 
76
        }
 
77
    }
 
78
}