-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- * \r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- * \r
- * Contributors:\r
- * Yuriy Vashchuk - Initial API and implementation\r
- * based on Francois Chouinard ProjectView code.\r
- */\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.filter;\r
-\r
-import java.io.IOException;\r
-\r
-import javax.xml.parsers.ParserConfigurationException;\r
-\r
-import org.eclipse.core.resources.IResource;\r
-import org.eclipse.core.resources.IWorkspace;\r
-import org.eclipse.core.resources.ResourcesPlugin;\r
-import org.eclipse.core.runtime.CoreException;\r
-import org.eclipse.jface.action.Action;\r
-import org.eclipse.jface.action.IToolBarManager;\r
-import org.eclipse.jface.action.Separator;\r
-import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.eclipse.jface.viewers.ISelectionChangedListener;\r
-import org.eclipse.jface.viewers.IStructuredSelection;\r
-import org.eclipse.jface.viewers.SelectionChangedEvent;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLParser;\r
-import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLWriter;\r
-import org.eclipse.linuxtools.tmf.ui.views.TmfView;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.graphics.Image;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.FileDialog;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.ui.IActionBars;\r
-import org.xml.sax.SAXException;\r
-\r
-/**\r
- * <b><u>FilterView</u></b>\r
- * <p>\r
- * View that contain UI to the TMF filter.\r
- */\r
-public class FilterView extends TmfView {\r
-\r
- public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.filter"; //$NON-NLS-1$\r
-\r
- private static final Image SAVE_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/save_button.gif"); //$NON-NLS-1$\r
- private static final Image ADD_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$\r
- private static final Image DELETE_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$\r
- private static final Image IMPORT_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/import_button.gif"); //$NON-NLS-1$\r
- private static final Image EXPORT_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/export_button.gif"); //$NON-NLS-1$\r
- \r
- // ------------------------------------------------------------------------\r
- // Main data structures\r
- // ------------------------------------------------------------------------\r
-\r
- private FilterViewer fViewer;\r
- private ITmfFilterTreeNode fRoot;\r
-\r
- private IWorkspace fWorkspace;\r
-\r
- private SaveAction fSaveAction;\r
- private AddAction fAddAction;\r
- private DeleteAction fDeleteAction;\r
- private ExportAction fExportAction;\r
- private ImportAction fImportAction;\r
-\r
- /**\r
- * Getter for the Filter Tree Root\r
- * \r
- * @return The root of builded tree\r
- */\r
- public ITmfFilterTreeNode getFilterRoot() {\r
- return fRoot;\r
- }\r
-\r
- \r
- // ------------------------------------------------------------------------\r
- // Constructor\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Default Constructor\r
- */\r
- public FilterView() {\r
- super("Filter"); //$NON-NLS-1$\r
- \r
- fWorkspace = ResourcesPlugin.getWorkspace();\r
- try {\r
- fWorkspace.getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);\r
- } catch (CoreException e) {\r
- TmfUiPlugin.getDefault().logError("Error refreshing workspace", e); //$NON-NLS-1$\r
- }\r
- \r
- fRoot = new TmfFilterRootNode();\r
- for (ITmfFilterTreeNode node : FilterManager.getSavedFilters()) {\r
- fRoot.addChild(node);\r
- }\r
- }\r
-\r
- \r
- /**\r
- * Refresh the tree widget\r
- */\r
- public void refresh() {\r
- fViewer.refresh();\r
- }\r
- \r
- /**\r
- * Setter for selection\r
- * \r
- * @param node The node to select\r
- */\r
- public void setSelection(ITmfFilterTreeNode node) {\r
- fViewer.setSelection(node, true);\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // ViewPart\r
- // ------------------------------------------------------------------------\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(Composite)\r
- */\r
- @Override\r
- public void createPartControl(Composite parent) {\r
-\r
- fViewer = new FilterViewer(parent, SWT.NONE);\r
- fViewer.setInput(fRoot);\r
- \r
- contributeToActionBars();\r
- \r
- fViewer.addSelectionChangedListener(new ISelectionChangedListener() {\r
- @Override\r
- public void selectionChanged(SelectionChangedEvent event) {\r
- if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) {\r
- fDeleteAction.setEnabled(true);\r
- fExportAction.setEnabled(true);\r
- } else {\r
- fDeleteAction.setEnabled(false);\r
- fExportAction.setEnabled(false);\r
- }\r
- }\r
- });\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.ui.part.WorkbenchPart#setFocus()\r
- */\r
- @Override\r
- public void setFocus() {\r
- fViewer.setFocus();\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * @see java.lang.Object#toString()\r
- */\r
- @Override\r
- public String toString() {\r
- return "[FilterView]"; //$NON-NLS-1$\r
- } \r
-\r
- \r
- /**\r
- * Builds the menu toolbar\r
- */\r
- private void contributeToActionBars() {\r
- IActionBars bars = getViewSite().getActionBars();\r
- //fillLocalPullDown(bars.getMenuManager());\r
- fillLocalToolBar(bars.getToolBarManager());\r
- }\r
-\r
- \r
- /**\r
- * Build the popup menu\r
- * \r
- * @param manager The manager to build\r
- */\r
- private void fillLocalToolBar(IToolBarManager manager) {\r
- \r
- fSaveAction = new SaveAction();\r
- fSaveAction.setImageDescriptor(ImageDescriptor.createFromImage(SAVE_IMAGE));\r
- fSaveAction.setToolTipText(Messages.FilterView_SaveActionToolTipText);\r
- \r
- fAddAction = new AddAction();\r
- fAddAction.setImageDescriptor(ImageDescriptor.createFromImage(ADD_IMAGE));\r
- fAddAction.setToolTipText(Messages.FilterView_AddActionToolTipText); \r
-\r
- fDeleteAction = new DeleteAction();\r
- fDeleteAction.setImageDescriptor(ImageDescriptor.createFromImage(DELETE_IMAGE));\r
- fDeleteAction.setToolTipText(Messages.FilterView_DeleteActionToolTipText);\r
- fDeleteAction.setEnabled(false);\r
-\r
- fExportAction = new ExportAction();\r
- fExportAction.setImageDescriptor(ImageDescriptor.createFromImage(EXPORT_IMAGE));\r
- fExportAction.setToolTipText(Messages.FilterView_ExportActionToolTipText);\r
-\r
- fImportAction = new ImportAction();\r
- fImportAction.setImageDescriptor(ImageDescriptor.createFromImage(IMPORT_IMAGE));\r
- fImportAction.setToolTipText(Messages.FilterView_ImportActionToolTipText);\r
-\r
- manager.add(fSaveAction);\r
- manager.add(new Separator());\r
- manager.add(fAddAction);\r
- manager.add(fDeleteAction);\r
- manager.add(new Separator());\r
- manager.add(fExportAction);\r
- manager.add(fImportAction);\r
- }\r
-\r
- private class SaveAction extends Action {\r
- @Override\r
- public void run() {\r
- FilterManager.setSavedFilters(fRoot.getChildren());\r
- }\r
- }\r
- \r
- private class AddAction extends Action {\r
- @Override\r
- public void run() {\r
- \r
- TmfFilterNode newNode = new TmfFilterNode(fRoot, ""); //$NON-NLS-1$\r
- refresh();\r
- setSelection(newNode);\r
- }\r
- }\r
- \r
- private class DeleteAction extends Action {\r
- @Override\r
- public void run() {\r
- ITmfFilterTreeNode node = fViewer.getSelection();\r
- if (node != null) {\r
- node.remove();\r
- }\r
- refresh();\r
- }\r
- }\r
- \r
- private class ExportAction extends Action {\r
- @Override\r
- public void run() {\r
- try {\r
- FileDialog dlg = new FileDialog(new Shell(), SWT.SAVE);\r
- dlg.setFilterNames(new String[] {Messages.FilterView_FileDialogFilterName + " (*.filter.xml)"}); //$NON-NLS-1$\r
- dlg.setFilterExtensions(new String[] {"*.filter.xml"}); //$NON-NLS-1$\r
- \r
- String fn = dlg.open();\r
- if (fn != null) {\r
- TmfFilterXMLWriter writerXML = new TmfFilterXMLWriter(fRoot);\r
- writerXML.saveTree(fn);\r
- }\r
- \r
- } catch (ParserConfigurationException e) {\r
- TmfUiPlugin.getDefault().logError("Error parsing filter xml file", e); //$NON-NLS-1$\r
- } catch (IOException e) {\r
- TmfUiPlugin.getDefault().logError("Error parsing filter xml file", e); //$NON-NLS-1$\r
- }\r
- }\r
- }\r
- \r
- private class ImportAction extends Action {\r
- @Override\r
- public void run() {\r
- if (fViewer != null) {\r
- ITmfFilterTreeNode root = null;\r
- try {\r
- FileDialog dlg = new FileDialog(new Shell(), SWT.OPEN);\r
- dlg.setFilterNames(new String[] {Messages.FilterView_FileDialogFilterName + " (*.filter.xml)"}); //$NON-NLS-1$\r
- dlg.setFilterExtensions(new String[] {"*.filter.xml"}); //$NON-NLS-1$\r
- \r
- TmfFilterXMLParser parserXML = null;\r
- String fn = dlg.open();\r
- if (fn != null) {\r
- parserXML = new TmfFilterXMLParser(fn);\r
- root = parserXML.getTree();\r
- }\r
- \r
- } catch (SAXException e) {\r
- TmfUiPlugin.getDefault().logError("Error importing filter xml file", e); //$NON-NLS-1$\r
- } catch (IOException e) {\r
- TmfUiPlugin.getDefault().logError("Error importing filter xml file", e); //$NON-NLS-1$\r
- }\r
-\r
- if (root != null) {\r
- for (ITmfFilterTreeNode node : root.getChildren()) {\r
- if (node instanceof TmfFilterNode) {\r
- fRoot.addChild(node);\r
- refresh();\r
- fViewer.setSelection(node);\r
- }\r
- }\r
- }\r
- }\r
- }\r
- }\r
- \r
+/*******************************************************************************
+ * Copyright (c) 2010, 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Yuriy Vashchuk - Initial API and implementation
+ * based on Francois Chouinard ProjectView code.
+ */
+
+package org.eclipse.linuxtools.tmf.ui.views.filter;
+
+import java.io.IOException;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode;
+import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLParser;
+import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLWriter;
+import org.eclipse.linuxtools.tmf.ui.views.TmfView;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionBars;
+import org.xml.sax.SAXException;
+
+/**
+ * View that contain UI to the TMF filter.
+ *
+ * @version 1.0
+ * @author Yuriy Vashchuk
+ */
+public class FilterView extends TmfView {
+
+ /** ID for the Filter view */
+ public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.filter"; //$NON-NLS-1$
+
+ private static final Image SAVE_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/save_button.gif"); //$NON-NLS-1$
+ private static final Image ADD_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
+ private static final Image DELETE_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
+ private static final Image IMPORT_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/import_button.gif"); //$NON-NLS-1$
+ private static final Image EXPORT_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/export_button.gif"); //$NON-NLS-1$
+
+ // ------------------------------------------------------------------------
+ // Main data structures
+ // ------------------------------------------------------------------------
+
+ private FilterViewer fViewer;
+ private final ITmfFilterTreeNode fRoot;
+
+ private final IWorkspace fWorkspace;
+
+ private SaveAction fSaveAction;
+ private AddAction fAddAction;
+ private DeleteAction fDeleteAction;
+ private ExportAction fExportAction;
+ private ImportAction fImportAction;
+
+ /**
+ * Getter for the Filter Tree Root
+ *
+ * @return The root of builded tree
+ */
+ public ITmfFilterTreeNode getFilterRoot() {
+ return fRoot;
+ }
+
+
+ // ------------------------------------------------------------------------
+ // Constructor
+ // ------------------------------------------------------------------------
+
+ /**
+ * Default Constructor
+ */
+ public FilterView() {
+ super("Filter"); //$NON-NLS-1$
+
+ fWorkspace = ResourcesPlugin.getWorkspace();
+ try {
+ fWorkspace.getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ Activator.getDefault().logError("Error refreshing workspace", e); //$NON-NLS-1$
+ }
+
+ fRoot = new TmfFilterRootNode();
+ for (ITmfFilterTreeNode node : FilterManager.getSavedFilters()) {
+ fRoot.addChild(node);
+ }
+ }
+
+
+ /**
+ * Refresh the tree widget
+ */
+ public void refresh() {
+ fViewer.refresh();
+ }
+
+ /**
+ * Setter for selection
+ *
+ * @param node The node to select
+ */
+ public void setSelection(ITmfFilterTreeNode node) {
+ fViewer.setSelection(node, true);
+ }
+
+ // ------------------------------------------------------------------------
+ // ViewPart
+ // ------------------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(Composite)
+ */
+ @Override
+ public void createPartControl(Composite parent) {
+
+ fViewer = new FilterViewer(parent, SWT.NONE);
+ fViewer.setInput(fRoot);
+
+ contributeToActionBars();
+
+ fViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) {
+ fDeleteAction.setEnabled(true);
+ fExportAction.setEnabled(true);
+ } else {
+ fDeleteAction.setEnabled(false);
+ fExportAction.setEnabled(false);
+ }
+ }
+ });
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
+ */
+ @Override
+ public void setFocus() {
+ fViewer.setFocus();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "[FilterView]"; //$NON-NLS-1$
+ }
+
+
+ /**
+ * Builds the menu toolbar
+ */
+ private void contributeToActionBars() {
+ IActionBars bars = getViewSite().getActionBars();
+ //fillLocalPullDown(bars.getMenuManager());
+ fillLocalToolBar(bars.getToolBarManager());
+ }
+
+
+ /**
+ * Build the popup menu
+ *
+ * @param manager The manager to build
+ */
+ private void fillLocalToolBar(IToolBarManager manager) {
+
+ fSaveAction = new SaveAction();
+ fSaveAction.setImageDescriptor(ImageDescriptor.createFromImage(SAVE_IMAGE));
+ fSaveAction.setToolTipText(Messages.FilterView_SaveActionToolTipText);
+
+ fAddAction = new AddAction();
+ fAddAction.setImageDescriptor(ImageDescriptor.createFromImage(ADD_IMAGE));
+ fAddAction.setToolTipText(Messages.FilterView_AddActionToolTipText);
+
+ fDeleteAction = new DeleteAction();
+ fDeleteAction.setImageDescriptor(ImageDescriptor.createFromImage(DELETE_IMAGE));
+ fDeleteAction.setToolTipText(Messages.FilterView_DeleteActionToolTipText);
+ fDeleteAction.setEnabled(false);
+
+ fExportAction = new ExportAction();
+ fExportAction.setImageDescriptor(ImageDescriptor.createFromImage(EXPORT_IMAGE));
+ fExportAction.setToolTipText(Messages.FilterView_ExportActionToolTipText);
+
+ fImportAction = new ImportAction();
+ fImportAction.setImageDescriptor(ImageDescriptor.createFromImage(IMPORT_IMAGE));
+ fImportAction.setToolTipText(Messages.FilterView_ImportActionToolTipText);
+
+ manager.add(fSaveAction);
+ manager.add(new Separator());
+ manager.add(fAddAction);
+ manager.add(fDeleteAction);
+ manager.add(new Separator());
+ manager.add(fExportAction);
+ manager.add(fImportAction);
+ }
+
+ private class SaveAction extends Action {
+ @Override
+ public void run() {
+ FilterManager.setSavedFilters(fRoot.getChildren());
+ }
+ }
+
+ private class AddAction extends Action {
+ @Override
+ public void run() {
+
+ TmfFilterNode newNode = new TmfFilterNode(fRoot, ""); //$NON-NLS-1$
+ refresh();
+ setSelection(newNode);
+ }
+ }
+
+ private class DeleteAction extends Action {
+ @Override
+ public void run() {
+ ITmfFilterTreeNode node = fViewer.getSelection();
+ if (node != null) {
+ node.remove();
+ }
+ refresh();
+ }
+ }
+
+ private class ExportAction extends Action {
+ @Override
+ public void run() {
+ try {
+ FileDialog dlg = new FileDialog(new Shell(), SWT.SAVE);
+ dlg.setFilterNames(new String[] {Messages.FilterView_FileDialogFilterName + " (*.filter.xml)"}); //$NON-NLS-1$
+ dlg.setFilterExtensions(new String[] {"*.filter.xml"}); //$NON-NLS-1$
+
+ String fn = dlg.open();
+ if (fn != null) {
+ TmfFilterXMLWriter writerXML = new TmfFilterXMLWriter(fRoot);
+ writerXML.saveTree(fn);
+ }
+
+ } catch (ParserConfigurationException e) {
+ Activator.getDefault().logError("Error parsing filter xml file", e); //$NON-NLS-1$
+ }
+ }
+ }
+
+ private class ImportAction extends Action {
+ @Override
+ public void run() {
+ if (fViewer != null) {
+ ITmfFilterTreeNode root = null;
+ try {
+ FileDialog dlg = new FileDialog(new Shell(), SWT.OPEN);
+ dlg.setFilterNames(new String[] {Messages.FilterView_FileDialogFilterName + " (*.filter.xml)"}); //$NON-NLS-1$
+ dlg.setFilterExtensions(new String[] {"*.filter.xml"}); //$NON-NLS-1$
+
+ TmfFilterXMLParser parserXML = null;
+ String fn = dlg.open();
+ if (fn != null) {
+ parserXML = new TmfFilterXMLParser(fn);
+ root = parserXML.getTree();
+ }
+
+ } catch (SAXException e) {
+ Activator.getDefault().logError("Error importing filter xml file", e); //$NON-NLS-1$
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error importing filter xml file", e); //$NON-NLS-1$
+ }
+
+ if (root != null) {
+ for (ITmfFilterTreeNode node : root.getChildren()) {
+ if (node instanceof TmfFilterNode) {
+ fRoot.addChild(node);
+ refresh();
+ fViewer.setSelection(node);
+ }
+ }
+ }
+ }
+ }
+ }
+
}
\ No newline at end of file