From 46ab8ce3124f69f29ea0bda4c16f90cf7f135878 Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Fri, 11 Mar 2011 16:04:31 -0500 Subject: [PATCH] Fix for Bug337914 --- .../META-INF/MANIFEST.MF | 1 + .../tmf/ui/editors/TmfEventsEditor.java | 11 +- .../tmf/ui/signal/TmfTraceClosedSignal.java | 38 ++++ .../tmf/ui/signal/TmfTraceOpenedSignal.java | 52 +++++ .../signal/TmfTraceParserUpdatedSignal.java | 38 ++++ .../events/ITmfEventsFilterListener.java | 24 +++ .../events/ITmfEventsFilterProvider.java | 21 ++ .../project/handlers/SelectParserHandler.java | 2 +- .../META-INF/MANIFEST.MF | 3 + .../linuxtools/tmf/filter/ITmfFilter.java | 28 +++ .../tmf/filter/model/ITmfFilterTreeNode.java | 122 ++++++++++++ .../tmf/filter/model/TmfFilterAndNode.java | 74 +++++++ .../filter/model/TmfFilterCompareNode.java | 176 +++++++++++++++++ .../filter/model/TmfFilterContainsNode.java | 113 +++++++++++ .../tmf/filter/model/TmfFilterEqualsNode.java | 114 +++++++++++ .../filter/model/TmfFilterEventTypeNode.java | 100 ++++++++++ .../filter/model/TmfFilterMatchesNode.java | 118 +++++++++++ .../tmf/filter/model/TmfFilterNode.java | 89 +++++++++ .../tmf/filter/model/TmfFilterOrNode.java | 73 +++++++ .../tmf/filter/model/TmfFilterRootNode.java | 53 +++++ .../tmf/filter/model/TmfFilterTreeNode.java | 177 +++++++++++++++++ .../filter/xml/TmfFilterContentHandler.java | 185 ++++++++++++++++++ .../tmf/filter/xml/TmfFilterXMLParser.java | 70 +++++++ .../tmf/filter/xml/TmfFilterXMLWriter.java | 161 +++++++++++++++ .../linuxtools/tmf/trace/TmfTrace.java | 10 - 25 files changed, 1836 insertions(+), 17 deletions(-) create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/signal/TmfTraceClosedSignal.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/signal/TmfTraceOpenedSignal.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/signal/TmfTraceParserUpdatedSignal.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/ITmfEventsFilterListener.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/ITmfEventsFilterProvider.java create mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/ITmfFilter.java create mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/ITmfFilterTreeNode.java create mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterAndNode.java create mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterCompareNode.java create mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterContainsNode.java create mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterEqualsNode.java create mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterEventTypeNode.java create mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterMatchesNode.java create mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterNode.java create mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterOrNode.java create mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterRootNode.java create mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterTreeNode.java create mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/xml/TmfFilterContentHandler.java create mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/xml/TmfFilterXMLParser.java create mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/xml/TmfFilterXMLWriter.java diff --git a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF index 3da4b5cf85..d54f8d256d 100644 --- a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF @@ -15,6 +15,7 @@ Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.linuxtools.tmf.ui, org.eclipse.linuxtools.tmf.ui.editors, org.eclipse.linuxtools.tmf.ui.parsers, + org.eclipse.linuxtools.tmf.ui.signal, org.eclipse.linuxtools.tmf.ui.viewers, org.eclipse.linuxtools.tmf.ui.viewers.events, org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis, diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java index 4999d72836..01d2bf20f3 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java @@ -16,12 +16,11 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler; -import org.eclipse.linuxtools.tmf.signal.TmfTraceClosedSignal; -import org.eclipse.linuxtools.tmf.signal.TmfTraceOpenedSignal; -import org.eclipse.linuxtools.tmf.signal.TmfTraceParserUpdatedSignal; import org.eclipse.linuxtools.tmf.signal.TmfTraceSelectedSignal; import org.eclipse.linuxtools.tmf.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.ui.parsers.ParserProviderManager; +import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceClosedSignal; +import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceParserUpdatedSignal; import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable; import org.eclipse.linuxtools.tmf.ui.views.project.ProjectView; import org.eclipse.swt.widgets.Composite; @@ -109,7 +108,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus if (fTrace != null) { fEventsTable = createEventsTable(fParent, fTrace.getCacheSize()); fEventsTable.setTrace(fTrace, true); - broadcast(new TmfTraceOpenedSignal(this, fTrace)); +// FIXME: broadcast(new TmfTraceOpenedSignal(this, fTrace)); } else { fEventsTable = new TmfEventsTable(fParent, 0); } @@ -124,7 +123,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus if (fTrace != null) { fEventsTable = createEventsTable(parent, fTrace.getCacheSize()); fEventsTable.setTrace(fTrace, true); - broadcast(new TmfTraceOpenedSignal(this, fTrace)); +// FIXME: broadcast(new TmfTraceOpenedSignal(this, fTrace)); } else { fEventsTable = new TmfEventsTable(parent, 0); } @@ -178,7 +177,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus if (fTrace != null) { fEventsTable = createEventsTable(fParent, fTrace.getCacheSize()); fEventsTable.setTrace(fTrace, true); - broadcast(new TmfTraceOpenedSignal(this, fTrace)); +// FIXME:broadcast(new TmfTraceOpenedSignal(this, fTrace, fResource, fEventsTable)); } else { fEventsTable = new TmfEventsTable(fParent, 0); } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/signal/TmfTraceClosedSignal.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/signal/TmfTraceClosedSignal.java new file mode 100644 index 0000000000..7ffe61980f --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/signal/TmfTraceClosedSignal.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.signal; + +import org.eclipse.linuxtools.tmf.signal.TmfSignal; +import org.eclipse.linuxtools.tmf.trace.ITmfTrace; + +/** + * TmfTraceClosedSignal + */ +public class TmfTraceClosedSignal extends TmfSignal { + + private final ITmfTrace fTrace; + + public TmfTraceClosedSignal(Object source, ITmfTrace trace) { + super(source); + fTrace = trace; + } + + public ITmfTrace getTrace() { + return fTrace; + } + + @Override + public String toString() { + return "[TmfTraceClosedSignal (" + fTrace.getName() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$ + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/signal/TmfTraceOpenedSignal.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/signal/TmfTraceOpenedSignal.java new file mode 100644 index 0000000000..557ee085bf --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/signal/TmfTraceOpenedSignal.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.signal; + +import org.eclipse.core.resources.IResource; +import org.eclipse.linuxtools.tmf.signal.TmfSignal; +import org.eclipse.linuxtools.tmf.trace.ITmfTrace; +import org.eclipse.linuxtools.tmf.ui.viewers.events.ITmfEventsFilterProvider; + +/** + * TmfTraceOpenedSignal + */ +public class TmfTraceOpenedSignal extends TmfSignal { + + private final ITmfTrace fTrace; + private final IResource fResource; + private final ITmfEventsFilterProvider fEventsFilterProvider; + + public TmfTraceOpenedSignal(Object source, ITmfTrace trace, IResource resource, ITmfEventsFilterProvider eventsFilterProvider) { + super(source); + fTrace = trace; + fResource = resource; + fEventsFilterProvider = eventsFilterProvider; + } + + public ITmfTrace getTrace() { + return fTrace; + } + + public IResource getResource() { + return fResource; + } + + public ITmfEventsFilterProvider getEventsFilterProvider() { + return fEventsFilterProvider; + } + + @Override + public String toString() { + return "[TmfTraceOpenedSignal (" + fTrace.getName() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$ + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/signal/TmfTraceParserUpdatedSignal.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/signal/TmfTraceParserUpdatedSignal.java new file mode 100644 index 0000000000..f614a9271c --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/signal/TmfTraceParserUpdatedSignal.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.signal; + +import org.eclipse.core.resources.IResource; +import org.eclipse.linuxtools.tmf.signal.TmfSignal; + +/** + * TmfTraceParserUpdatedSignal + */ +public class TmfTraceParserUpdatedSignal extends TmfSignal { + + private final IResource fTraceResource; + + public TmfTraceParserUpdatedSignal(Object source, IResource traceResource) { + super(source); + fTraceResource = traceResource; + } + + public IResource getTraceResource() { + return fTraceResource; + } + + @Override + public String toString() { + return "[TmfTraceParserUpdatedSignal (" + fTraceResource.getName() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$ + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/ITmfEventsFilterListener.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/ITmfEventsFilterListener.java new file mode 100644 index 0000000000..e3a59c9d68 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/ITmfEventsFilterListener.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.viewers.events; + +import org.eclipse.linuxtools.tmf.filter.ITmfFilter; +import org.eclipse.linuxtools.tmf.trace.ITmfTrace; + +public interface ITmfEventsFilterListener { + + public void filterApplied(ITmfFilter filter, ITmfTrace trace); + + public void searchApplied(ITmfFilter filter, ITmfTrace trace); + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/ITmfEventsFilterProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/ITmfEventsFilterProvider.java new file mode 100644 index 0000000000..43615f4990 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/ITmfEventsFilterProvider.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.viewers.events; + +public interface ITmfEventsFilterProvider { + + public void addEventsFilterListener (ITmfEventsFilterListener listener); + + public void removeEventsFilterListener (ITmfEventsFilterListener listener); + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/project/handlers/SelectParserHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/project/handlers/SelectParserHandler.java index 0f9be21242..b3a4c25b59 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/project/handlers/SelectParserHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/project/handlers/SelectParserHandler.java @@ -22,9 +22,9 @@ import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.linuxtools.tmf.event.TmfEvent; import org.eclipse.linuxtools.tmf.experiment.TmfExperiment; import org.eclipse.linuxtools.tmf.signal.TmfExperimentSelectedSignal; -import org.eclipse.linuxtools.tmf.signal.TmfTraceParserUpdatedSignal; import org.eclipse.linuxtools.tmf.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.ui.parsers.ParserProviderManager; +import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceParserUpdatedSignal; import org.eclipse.linuxtools.tmf.ui.views.project.ProjectView; import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfExperimentNode; import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfTraceNode; diff --git a/org.eclipse.linuxtools.tmf/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf/META-INF/MANIFEST.MF index f7224263e3..2cf31e32b2 100644 --- a/org.eclipse.linuxtools.tmf/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf/META-INF/MANIFEST.MF @@ -13,6 +13,9 @@ Export-Package: org.eclipse.linuxtools.tmf, org.eclipse.linuxtools.tmf.component, org.eclipse.linuxtools.tmf.event, org.eclipse.linuxtools.tmf.experiment, + org.eclipse.linuxtools.tmf.filter, + org.eclipse.linuxtools.tmf.filter.model, + org.eclipse.linuxtools.tmf.filter.xml, org.eclipse.linuxtools.tmf.io, org.eclipse.linuxtools.tmf.parser, org.eclipse.linuxtools.tmf.request, diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/ITmfFilter.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/ITmfFilter.java new file mode 100644 index 0000000000..02fa8d42e2 --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/ITmfFilter.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.filter; + +import org.eclipse.linuxtools.tmf.event.TmfEvent; + + +public interface ITmfFilter { + + /** + * Verify the filter conditions on an event + * + * @param event The event to verify. + * @return True if the event matches the filter conditions. + */ + public boolean matches(TmfEvent event); + +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/ITmfFilterTreeNode.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/ITmfFilterTreeNode.java new file mode 100644 index 0000000000..d77ffff6f3 --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/ITmfFilterTreeNode.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Francois Godin (copelnug@gmail.com) - Initial API + * Yuriy Vashchuk (yvashchuk@gmail.com) - Initial implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.filter.model; + +import java.util.List; + +import org.eclipse.linuxtools.tmf.filter.ITmfFilter; + + +/** + *

This is Node Interface in the Filter Tree

+ */ +public interface ITmfFilterTreeNode extends ITmfFilter { + + /** + *

Get the parent node of current node

+ * + * @return The parent node (null when the node has no parent). + */ + public ITmfFilterTreeNode getParent(); + + /** + *

Get the current node name

+ * + * @return The name of the current node. + */ + public String getNodeName(); + + /** + *

Tell if the node has children

+ * + * @return True if the node has children. + */ + public boolean hasChildren(); + + /** + *

Return the number of children

+ * + * @return The number of children. + */ + public int getChildrenCount(); + + /** + *

Get the array of children

+ * + * @return The array (possibly empty) of children nodes. + */ + public ITmfFilterTreeNode[] getChildren(); + + /** + *

Get the node by index

+ * + * @param index The index of node to return. + * @return The desired node (null if the node is not exists). + */ + public ITmfFilterTreeNode getChild(int index); + + /** + *

Remove the node from its parent

+ * + *

Shifts all nodes after the removed one to prevent having an empty spot. + * See {@link #replaceChildren(int, ITmfFilterTreeNode)} to replace a node.

+ * + * @return The removed node. + */ + public ITmfFilterTreeNode remove(); + + /** + *

Remove the child from the current node

+ * + *

Shifts all nodes after the removed one to prevent having an empty spot. + * See {@link #replaceChildren(int, ITmfFilterTreeNode)} to replace a node.

+ * + * @return The removed node. + */ + public ITmfFilterTreeNode removeChild(ITmfFilterTreeNode node); + + /** + *

Append a node to the current children

+ * + * @param node Node to append. + * @return Index of added node (-1 if the node cannot be added). + */ + public int addChild(ITmfFilterTreeNode node); + + /** + *

Replace a child node

+ * + * @param index Index of the node to replace. + * @param node Node who will replace. + * @return Node replaced. + */ + public ITmfFilterTreeNode replaceChild(int index, ITmfFilterTreeNode node); + + /** + *

Sets the parent of current node

+ * + * @param parent The parent of current node. + */ + public void setParent(ITmfFilterTreeNode parent); + + /** + *

Gets the list of valid children node names that could be added to the node

+ * + * @return The list of valid children node names. + */ + public List getValidChildren(); + + public ITmfFilterTreeNode clone(); + +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterAndNode.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterAndNode.java new file mode 100644 index 0000000000..673a373465 --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterAndNode.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.filter.model; + +import org.eclipse.linuxtools.tmf.event.TmfEvent; + + +public class TmfFilterAndNode extends TmfFilterTreeNode { + + public static final String NODE_NAME = "AND"; //$NON-NLS-1$ + public static final String NOT_ATTR = "not"; //$NON-NLS-1$ + + private boolean fNot = false; + + public TmfFilterAndNode(ITmfFilterTreeNode parent) { + super(parent); + } + + public boolean isNot() { + return fNot; + } + + public void setNot(boolean not) { + this.fNot = not; + } + + @Override + public String getNodeName() { + return NODE_NAME; + } + + @Override + public boolean matches(TmfEvent event) { + for (ITmfFilterTreeNode node : getChildren()) { + if (! node.matches(event)) { + return false ^ fNot; + } + } + return true ^ fNot; + } + + @Override + public String toString() { + StringBuffer buf = new StringBuffer(); + if (fNot) { + buf.append("not "); //$NON-NLS-1$ + } + if (getParent() != null && !(getParent() instanceof TmfFilterRootNode) && !(getParent() instanceof TmfFilterNode)) { + buf.append("( "); //$NON-NLS-1$ + } + for (int i = 0; i < getChildrenCount(); i++) { + ITmfFilterTreeNode node = getChildren()[i]; + buf.append(node.toString()); + if (i < getChildrenCount() - 1) { + buf.append(" and "); //$NON-NLS-1$ + } + } + if (getParent() != null && !(getParent() instanceof TmfFilterRootNode) && !(getParent() instanceof TmfFilterNode)) { + buf.append(" )"); //$NON-NLS-1$ + } + return buf.toString(); + } + +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterCompareNode.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterCompareNode.java new file mode 100644 index 0000000000..d1f9adc68d --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterCompareNode.java @@ -0,0 +1,176 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.filter.model; + +import java.text.NumberFormat; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.linuxtools.tmf.event.TmfEvent; +import org.eclipse.linuxtools.tmf.event.TmfNoSuchFieldException; +import org.eclipse.linuxtools.tmf.event.TmfTimestamp; + + +public class TmfFilterCompareNode extends TmfFilterTreeNode { + + public static final String NODE_NAME = "COMPARE"; //$NON-NLS-1$ + public static final String NOT_ATTR = "not"; //$NON-NLS-1$ + public static final String FIELD_ATTR = "field"; //$NON-NLS-1$ + public static final String RESULT_ATTR = "result"; //$NON-NLS-1$ + public static final String TYPE_ATTR = "type"; //$NON-NLS-1$ + public static final String VALUE_ATTR = "value"; //$NON-NLS-1$ + + public static enum Type { + NUM, + ALPHA, + TIMESTAMP + } + + private boolean fNot = false; + private String fField; + private int fResult; + private Type fType = Type.NUM; + private String fValue; + private Number fValueNumber; + private TmfTimestamp fValueTimestamp; + + public TmfFilterCompareNode(ITmfFilterTreeNode parent) { + super(parent); + } + + public boolean isNot() { + return fNot; + } + + public void setNot(boolean not) { + this.fNot = not; + } + + public String getField() { + return fField; + } + + public void setField(String field) { + this.fField = field; + } + + public int getResult() { + return fResult; + } + + public void setResult(int result) { + this.fResult = result; + } + + public Type getType() { + return fType; + } + + public void setType(Type type) { + this.fType = type; + setValue(fValue); + } + + public String getValue() { + return fValue; + } + + public void setValue(String value) { + this.fValue = value; + fValueNumber = null; + fValueTimestamp = null; + if (value == null) { + return; + } + if (fType == Type.NUM) { + try { + fValueNumber = NumberFormat.getInstance().parse(value).doubleValue(); + } catch (ParseException e) { + } + } else if (fType == Type.TIMESTAMP) { + try { + fValueTimestamp = new TmfTimestamp((long) (1E9 * NumberFormat.getInstance().parse(value.toString()).doubleValue())); + } catch (ParseException e) { + } + } + } + + @Override + public String getNodeName() { + return NODE_NAME; + } + + @Override + public boolean matches(TmfEvent event) { + try { + Object value = event.getContent().getField(fField); + if (value == null) { + return false ^ fNot; + } + if (fType == Type.NUM) { + if (fValueNumber instanceof Number) { + if (value instanceof Number) { + Double valueDouble = ((Number) value).doubleValue(); + return (valueDouble.compareTo(fValueNumber.doubleValue()) == fResult) ^ fNot; + } else { + try { + Double valueDouble = NumberFormat.getInstance().parse(value.toString()).doubleValue(); + return (valueDouble.compareTo(fValueNumber.doubleValue()) == fResult) ^ fNot; + } catch (ParseException e) { + } + } + } + } else if (fType == Type.ALPHA) { + String valueString = value.toString(); + return (valueString.compareTo(fValue.toString()) == fResult) ^ fNot; + } else if (fType == Type.TIMESTAMP) { + if (fValueTimestamp instanceof TmfTimestamp) { + if (value instanceof TmfTimestamp) { + TmfTimestamp valueTimestamp = (TmfTimestamp) value; + return (valueTimestamp.compareTo(fValueTimestamp, false) == fResult) ^ fNot; + } else { + try { + TmfTimestamp valueTimestamp = new TmfTimestamp((long) (1E9 * NumberFormat.getInstance().parse(value.toString()).doubleValue())); + return (valueTimestamp.compareTo(fValueTimestamp, false) == fResult) ^ fNot; + } catch (ParseException e) { + } + } + } + } + } catch (TmfNoSuchFieldException e) { + } + return false ^ fNot; + } + + @Override + public List getValidChildren() { + return new ArrayList(0); + } + + @Override + public String toString() { + String result = (fResult == 0 ? "= " : fResult < 0 ? "< " : "> "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + String open = (fType == Type.NUM ? "" : fType == Type.ALPHA ? "\"" : "["); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + String close = (fType == Type.NUM ? "" : fType == Type.ALPHA ? "\"" : "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + return fField + (fNot ? " not " : " ") + result + open + fValue + close; //$NON-NLS-1$ //$NON-NLS-2$ + } + + @Override + public ITmfFilterTreeNode clone() { + TmfFilterCompareNode clone = (TmfFilterCompareNode) super.clone(); + clone.fField = new String(fField); + clone.setValue(new String(fValue)); + return clone; + } +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterContainsNode.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterContainsNode.java new file mode 100644 index 0000000000..e2db82df88 --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterContainsNode.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.filter.model; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.linuxtools.tmf.event.TmfEvent; +import org.eclipse.linuxtools.tmf.event.TmfNoSuchFieldException; + + +public class TmfFilterContainsNode extends TmfFilterTreeNode { + + public static final String NODE_NAME = "CONTAINS"; //$NON-NLS-1$ + public static final String NOT_ATTR = "not"; //$NON-NLS-1$ + public static final String FIELD_ATTR = "field"; //$NON-NLS-1$ + public static final String VALUE_ATTR = "value"; //$NON-NLS-1$ + public static final String IGNORECASE_ATTR = "ignorecase"; //$NON-NLS-1$ + + private boolean fNot = false; + private String fField; + private String fValue; + private String fValueUpperCase; + private boolean fIgnoreCase = false; + + public TmfFilterContainsNode(ITmfFilterTreeNode parent) { + super(parent); + } + + public boolean isNot() { + return fNot; + } + + public void setNot(boolean not) { + this.fNot = not; + } + + public String getField() { + return fField; + } + + public void setField(String field) { + this.fField = field; + } + + public String getValue() { + return fValue; + } + + public void setValue(String value) { + this.fValue = value; + fValueUpperCase = value.toUpperCase(); + } + + public boolean isIgnoreCase() { + return fIgnoreCase; + } + + public void setIgnoreCase(boolean ignoreCase) { + this.fIgnoreCase = ignoreCase; + } + + @Override + public String getNodeName() { + return NODE_NAME; + } + + @Override + public boolean matches(TmfEvent event) { + try { + Object value = event.getContent().getField(fField); + if (value == null) { + return false ^ fNot; + } + String valueString = value.toString(); + if (fIgnoreCase) { + return valueString.toUpperCase().contains(fValueUpperCase) ^ fNot; + } else { + return valueString.contains(fValue) ^ fNot; + } + } catch (TmfNoSuchFieldException e) { + return false ^ fNot; + } + } + + @Override + public List getValidChildren() { + return new ArrayList(0); + } + + @Override + public String toString() { + return fField + (fNot ? " not" : "") + " contains \"" + fValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + } + + @Override + public ITmfFilterTreeNode clone() { + TmfFilterContainsNode clone = (TmfFilterContainsNode) super.clone(); + clone.fField = new String(fField); + clone.setValue(new String(fValue)); + return clone; + } +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterEqualsNode.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterEqualsNode.java new file mode 100644 index 0000000000..16b8aa3696 --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterEqualsNode.java @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.filter.model; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.linuxtools.tmf.event.TmfEvent; +import org.eclipse.linuxtools.tmf.event.TmfNoSuchFieldException; + + +public class TmfFilterEqualsNode extends TmfFilterTreeNode { + + public static final String NODE_NAME = "EQUALS"; //$NON-NLS-1$ + public static final String NOT_ATTR = "not"; //$NON-NLS-1$ + public static final String FIELD_ATTR = "field"; //$NON-NLS-1$ + public static final String VALUE_ATTR = "value"; //$NON-NLS-1$ + public static final String IGNORECASE_ATTR = "ignorecase"; //$NON-NLS-1$ + + private boolean fNot = false; + private String fField; + private String fValue; + private boolean fIgnoreCase = false; + + public TmfFilterEqualsNode(ITmfFilterTreeNode parent) { + super(parent); + } + + public boolean isNot() { + return fNot; + } + + public void setNot(boolean not) { + this.fNot = not; + } + + public String getField() { + return fField; + } + + public void setField(String field) { + this.fField = field; + } + + public String getValue() { + return fValue; + } + + public void setValue(String value) { + this.fValue = value; + } + + public boolean isIgnoreCase() { + return fIgnoreCase; + } + + public void setIgnoreCase(boolean ignoreCase) { + this.fIgnoreCase = ignoreCase; + } + + @Override + public String getNodeName() { + return NODE_NAME; + } + + @Override + public boolean matches(TmfEvent event) { + try { + Object value = event.getContent().getField(fField); + if (value == null) { + return false ^ fNot; + } + String valueString = value.toString(); + if (valueString == null) { + return false ^ fNot; + } + if (fIgnoreCase) { + return valueString.equalsIgnoreCase(fValue) ^ fNot; + } else { + return valueString.equals(fValue) ^ fNot; + } + } catch (TmfNoSuchFieldException e) { + return false ^ fNot; + } + } + + @Override + public List getValidChildren() { + return new ArrayList(0); + } + + @Override + public String toString() { + return fField + (fNot ? " not" : "") + " equals \"" + fValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + } + + @Override + public ITmfFilterTreeNode clone() { + TmfFilterEqualsNode clone = (TmfFilterEqualsNode) super.clone(); + clone.fField = new String(fField); + clone.fValue = new String(fValue); + return clone; + } +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterEventTypeNode.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterEventTypeNode.java new file mode 100644 index 0000000000..d2cadd30cb --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterEventTypeNode.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.filter.model; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.linuxtools.tmf.event.TmfEvent; + + +public class TmfFilterEventTypeNode extends TmfFilterTreeNode { + + public static final String NODE_NAME = "EVENTTYPE"; //$NON-NLS-1$ + public static final String TYPE_ATTR = "type"; //$NON-NLS-1$ + public static final String NAME_ATTR = "name"; //$NON-NLS-1$ + + private String fType; + private String fName; + + public TmfFilterEventTypeNode(ITmfFilterTreeNode parent) { + super(parent); + } + + @Override + public String getNodeName() { + return NODE_NAME; + } + + public String getEventType() { + return fType; + } + + public void setEventType(String type) { + this.fType = type; + } + + public String getName() { + return fName; + } + + public void setName(String name) { + this.fName = name; + } + + @Override + public boolean matches(TmfEvent event) { + if (event.getType().getTypeId().equals(fName)) { + // There should be at most one child + for (ITmfFilterTreeNode node : getChildren()) { + if (! node.matches(event)) { + return false; + } + } + return true; + } + return false; + } + + @Override + public List getValidChildren() { + if (getChildrenCount() == 0) { + return super.getValidChildren(); + } else { + return new ArrayList(0); // only one child allowed + } + } + + @Override + public String toString() { + StringBuffer buf = new StringBuffer(); + buf.append("EventType is " + fName); //$NON-NLS-1$ + if (getChildrenCount() > 0) { + buf.append(" and "); //$NON-NLS-1$ + } + if (getChildrenCount() > 1) { + buf.append("( "); //$NON-NLS-1$ + } + for (int i = 0; i < getChildrenCount(); i++) { + ITmfFilterTreeNode node = getChildren()[i]; + buf.append(node.toString()); + if (i < getChildrenCount() - 1) { + buf.append(" and "); //$NON-NLS-1$ + } + } + if (getChildrenCount() > 1) { + buf.append(" )"); //$NON-NLS-1$ + } + return buf.toString(); + } +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterMatchesNode.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterMatchesNode.java new file mode 100644 index 0000000000..c0b09cdf95 --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterMatchesNode.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.filter.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import org.eclipse.linuxtools.tmf.event.TmfEvent; +import org.eclipse.linuxtools.tmf.event.TmfNoSuchFieldException; + + +public class TmfFilterMatchesNode extends TmfFilterTreeNode { + + public static final String NODE_NAME = "MATCHES"; //$NON-NLS-1$ + public static final String NOT_ATTR = "not"; //$NON-NLS-1$ + public static final String FIELD_ATTR = "field"; //$NON-NLS-1$ + public static final String REGEX_ATTR = "regex"; //$NON-NLS-1$ + + private boolean fNot = false; + private String fField; + private String fRegex; + private Pattern fPattern; + + public TmfFilterMatchesNode(ITmfFilterTreeNode parent) { + super(parent); + } + + public boolean isNot() { + return fNot; + } + + public void setNot(boolean not) { + this.fNot = not; + } + + public String getField() { + return fField; + } + + public void setField(String field) { + this.fField = field; + } + + public String getRegex() { + return fRegex; + } + + public void setRegex(String regex) { + this.fRegex = regex; + try { + this.fPattern = Pattern.compile(regex); + } catch (PatternSyntaxException e) { + this.fPattern = null; + } + } + + @Override + public String getNodeName() { + return NODE_NAME; + } + + @Override + public boolean matches(TmfEvent event) { + if (fPattern == null) { + return false ^ fNot; + } + try { + Object value = event.getContent().getField(fField); + if (value == null) { + return false ^ fNot; + } + String valueString = value.toString(); + return fPattern.matcher(valueString).matches() ^ fNot; + } catch (TmfNoSuchFieldException e) { + return false ^ fNot; + } + } + + @Override + public List getValidChildren() { + return new ArrayList(0); + } + + @Override + public String toString() { + return fField + (fNot ? " not" : "") + " matches \"" + fRegex + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + } + + @Override + public ITmfFilterTreeNode clone() { + TmfFilterMatchesNode clone = (TmfFilterMatchesNode) super.clone(); + clone.fField = new String(fField); + clone.setRegex(new String(fRegex)); + return clone; + } + + public static String regexFix(String pattern) { + // if the pattern does not contain one of the expressions .* !^ + // (at the beginning) $ (at the end), then a .* is added at the + // beginning and at the end of the pattern + if (!(pattern.indexOf(".*") >= 0 || pattern.charAt(0) == '^' || pattern.charAt(pattern.length() - 1) == '$')) { //$NON-NLS-1$ + pattern = ".*" + pattern + ".*"; //$NON-NLS-1$ //$NON-NLS-2$ + } + return pattern; + } +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterNode.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterNode.java new file mode 100644 index 0000000000..63467419d1 --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterNode.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.filter.model; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.linuxtools.tmf.event.TmfEvent; + + +public class TmfFilterNode extends TmfFilterTreeNode { + + public static final String NODE_NAME = "FILTER"; //$NON-NLS-1$ + public static final String NAME_ATTR = "name"; //$NON-NLS-1$ + + String fFilterName; + + public TmfFilterNode(String filterName) { + super(null); + fFilterName = filterName; + } + + public TmfFilterNode(ITmfFilterTreeNode parent, String filterName) { + super(parent); + fFilterName = filterName; + } + + public String getFilterName() { + return fFilterName; + } + + public void setFilterName(String filterName) { + fFilterName = filterName; + } + + @Override + public String getNodeName() { + return NODE_NAME; + } + + @Override + public boolean matches(TmfEvent event) { + // There should be at most one child + for (ITmfFilterTreeNode node : getChildren()) { + if (node.matches(event)) { + return true; + } + } + return false; + } + + @Override + public List getValidChildren() { + if (getChildrenCount() == 0) { + return super.getValidChildren(); + } else { + return new ArrayList(0); // only one child allowed + } + } + + @Override + public String toString() { + StringBuffer buf = new StringBuffer(); + if (getChildrenCount() > 1) { + buf.append("( "); //$NON-NLS-1$ + } + for (int i = 0; i < getChildrenCount(); i++) { + ITmfFilterTreeNode node = getChildren()[i]; + buf.append(node.toString()); + if (i < getChildrenCount() - 1) { + buf.append(" and "); //$NON-NLS-1$ + } + } + if (getChildrenCount() > 1) { + buf.append(" )"); //$NON-NLS-1$ + } + return buf.toString(); + } +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterOrNode.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterOrNode.java new file mode 100644 index 0000000000..185508ee08 --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterOrNode.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.filter.model; + +import org.eclipse.linuxtools.tmf.event.TmfEvent; + + +public class TmfFilterOrNode extends TmfFilterTreeNode { + + public static final String NODE_NAME = "OR"; //$NON-NLS-1$ + public static final String NOT_ATTR = "not"; //$NON-NLS-1$ + + private boolean fNot = false; + + public TmfFilterOrNode(ITmfFilterTreeNode parent) { + super(parent); + } + + @Override + public String getNodeName() { + return NODE_NAME; + } + + public boolean isNot() { + return fNot; + } + + public void setNot(boolean not) { + this.fNot = not; + } + + @Override + public boolean matches(TmfEvent event) { + for (ITmfFilterTreeNode node : getChildren()) { + if (node.matches(event)) { + return true ^ fNot; + } + } + return false & fNot; + } + + @Override + public String toString() { + StringBuffer buf = new StringBuffer(); + if (fNot) { + buf.append("not "); //$NON-NLS-1$ + } + if (getParent() != null && !(getParent() instanceof TmfFilterRootNode) && !(getParent() instanceof TmfFilterNode)) { + buf.append("( "); //$NON-NLS-1$ + } + for (int i = 0; i < getChildrenCount(); i++) { + ITmfFilterTreeNode node = getChildren()[i]; + buf.append(node.toString()); + if (i < getChildrenCount() - 1) { + buf.append(" or "); //$NON-NLS-1$ + } + } + if (getParent() != null && !(getParent() instanceof TmfFilterRootNode) && !(getParent() instanceof TmfFilterNode)) { + buf.append(" )"); //$NON-NLS-1$ + } + return buf.toString(); + } +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterRootNode.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterRootNode.java new file mode 100644 index 0000000000..d31260f5c4 --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterRootNode.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.filter.model; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.linuxtools.tmf.event.TmfEvent; + + +public class TmfFilterRootNode extends TmfFilterTreeNode { + + public static final String NODE_NAME = "ROOT"; //$NON-NLS-1$ + + private static final String[] VALID_CHILDREN = { + TmfFilterNode.NODE_NAME + }; + + public TmfFilterRootNode() { + super(null); + } + + @Override + public String getNodeName() { + return NODE_NAME; + } + + @Override + public boolean matches(TmfEvent event) { + for (ITmfFilterTreeNode node : getChildren()) { + if (! node.matches(event)) { + return false; + } + } + return true; + } + + @Override + public List getValidChildren() { + return Arrays.asList(VALID_CHILDREN); + } + +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterTreeNode.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterTreeNode.java new file mode 100644 index 0000000000..88a2607955 --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/model/TmfFilterTreeNode.java @@ -0,0 +1,177 @@ +/******************************************************************************* + * Copyright (c) 2010 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 (yvashchuk@gmail.com) - Initial API and implementation + * Patrick Tasse - Refactoring + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.filter.model; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.linuxtools.tmf.event.TmfEvent; + +/** + * TmfFilterTreeNode + *

+ * The Filter Tree node + *

+ */ +public abstract class TmfFilterTreeNode implements ITmfFilterTreeNode, Cloneable { + + private static final String[] VALID_CHILDREN = { + TmfFilterEventTypeNode.NODE_NAME, + TmfFilterAndNode.NODE_NAME, + TmfFilterOrNode.NODE_NAME, + TmfFilterContainsNode.NODE_NAME, + TmfFilterEqualsNode.NODE_NAME, + TmfFilterMatchesNode.NODE_NAME, + TmfFilterCompareNode.NODE_NAME + }; + + private ITmfFilterTreeNode parent = null; + private ArrayList children = new ArrayList(); + + public TmfFilterTreeNode(final ITmfFilterTreeNode parent) { + if (parent != null) { + parent.addChild(this); + } + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getParent() + */ + @Override + public ITmfFilterTreeNode getParent() { + return parent; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getNodeName() + */ + @Override + public abstract String getNodeName(); + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#hasChildren() + */ + @Override + public boolean hasChildren() { + return (children.size() > 0); + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getChildrenCount() + */ + @Override + public int getChildrenCount() { + return children.size(); + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getChildren() + */ + @Override + public ITmfFilterTreeNode[] getChildren() { + return children.toArray(new ITmfFilterTreeNode[0]); + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getChild(int) + */ + @Override + public ITmfFilterTreeNode getChild(final int index) throws IndexOutOfBoundsException { + return children.get(index); + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#remove() + */ + @Override + public ITmfFilterTreeNode remove() { + if (getParent() != null) { + getParent().removeChild(this); + } + return this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#removeChild(org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode) + */ + @Override + public ITmfFilterTreeNode removeChild(ITmfFilterTreeNode node) { + children.remove(node); + node.setParent(null); + return node; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#addChild(org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode) + */ + @Override + public int addChild(final ITmfFilterTreeNode node) { + node.setParent(this); + if(children.add(node)) { + return (children.size() - 1); + } + return -1; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#replaceChild(int, org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode) + */ + @Override + public ITmfFilterTreeNode replaceChild(final int index, final ITmfFilterTreeNode node) throws IndexOutOfBoundsException { + node.setParent(this); + return children.set(index, node); + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#setParent(org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode) + */ + @Override + public void setParent(final ITmfFilterTreeNode parent) { + this.parent = parent; + } + + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#matches(org.eclipse.linuxtools.tmf.event.TmfEvent) + */ + @Override + public abstract boolean matches(TmfEvent event); + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getValidChildren() + * + * By default, all node types are valid children. Override if different. + */ + @Override + public List getValidChildren() { + return Arrays.asList(VALID_CHILDREN); + } + + @Override + public ITmfFilterTreeNode clone() { + try { + TmfFilterTreeNode clone = (TmfFilterTreeNode) super.clone(); + clone.parent = null; + clone.children = new ArrayList(children.size()); + for (ITmfFilterTreeNode child : getChildren()) { + clone.addChild(child.clone()); + } + return clone; + } catch (CloneNotSupportedException e) { + return null; + } + } +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/xml/TmfFilterContentHandler.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/xml/TmfFilterContentHandler.java new file mode 100644 index 0000000000..c405f72b9e --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/xml/TmfFilterContentHandler.java @@ -0,0 +1,185 @@ +/******************************************************************************* + * Copyright (c) 2010 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 (yvashchuk@gmail.com) - Initial API and implementation + * based on http://smeric.developpez.com/java/cours/xml/sax/ + * Patrick Tasse - Refactoring + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.filter.xml; + +import java.util.Stack; + +import org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterAndNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterCompareNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterCompareNode.Type; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterContainsNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterEqualsNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterEventTypeNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterMatchesNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterOrNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterRootNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterTreeNode; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * FilterContentHandler + *

+ * The Filter SAX Content Handler + *

+ */ +public class TmfFilterContentHandler extends DefaultHandler { + + private ITmfFilterTreeNode fRoot = null; + private Stack fFilterTreeStack = null; + + /** + * The default constructor + */ + public TmfFilterContentHandler() { + super(); + fFilterTreeStack = new Stack(); + } + + /** + * Getter of tree + * + * @return The builded tree + */ + public ITmfFilterTreeNode getTree() { + return fRoot; + } + + /* + * (non-Javadoc) + * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) + */ + @Override + public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { + ITmfFilterTreeNode node = null; + + if (localName.equalsIgnoreCase(TmfFilterRootNode.NODE_NAME)) { + + node = new TmfFilterRootNode(); + + } else if (localName.equals(TmfFilterNode.NODE_NAME)) { + + node = new TmfFilterNode(atts.getValue(TmfFilterNode.NAME_ATTR)); + + } else if (localName.equals(TmfFilterEventTypeNode.NODE_NAME)) { + + node = new TmfFilterEventTypeNode(null); + ((TmfFilterEventTypeNode) node).setEventType(atts.getValue(TmfFilterEventTypeNode.TYPE_ATTR)); + ((TmfFilterEventTypeNode) node).setName(atts.getValue(TmfFilterEventTypeNode.NAME_ATTR)); + + } else if (localName.equals(TmfFilterAndNode.NODE_NAME)) { + + node = new TmfFilterAndNode(null); + String value = atts.getValue(TmfFilterAndNode.NOT_ATTR); + if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) { + ((TmfFilterAndNode) node).setNot(true); + } + + } else if (localName.equals(TmfFilterOrNode.NODE_NAME)) { + + node = new TmfFilterOrNode(null); + String value = atts.getValue(TmfFilterOrNode.NOT_ATTR); + if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) { + ((TmfFilterOrNode) node).setNot(true); + } + + } else if (localName.equals(TmfFilterContainsNode.NODE_NAME)) { + + node = new TmfFilterContainsNode(null); + String value = atts.getValue(TmfFilterContainsNode.NOT_ATTR); + if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) { + ((TmfFilterContainsNode) node).setNot(true); + } + ((TmfFilterContainsNode) node).setField(atts.getValue(TmfFilterContainsNode.FIELD_ATTR)); + ((TmfFilterContainsNode) node).setValue(atts.getValue(TmfFilterContainsNode.VALUE_ATTR)); + value = atts.getValue(TmfFilterContainsNode.IGNORECASE_ATTR); + if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) { + ((TmfFilterContainsNode) node).setIgnoreCase(true); + } + + } else if (localName.equals(TmfFilterEqualsNode.NODE_NAME)) { + + node = new TmfFilterEqualsNode(null); + String value = atts.getValue(TmfFilterEqualsNode.NOT_ATTR); + if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) { + ((TmfFilterEqualsNode) node).setNot(true); + } + ((TmfFilterEqualsNode) node).setField(atts.getValue(TmfFilterEqualsNode.FIELD_ATTR)); + ((TmfFilterEqualsNode) node).setValue(atts.getValue(TmfFilterEqualsNode.VALUE_ATTR)); + value = atts.getValue(TmfFilterEqualsNode.IGNORECASE_ATTR); + if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) { + ((TmfFilterEqualsNode) node).setIgnoreCase(true); + } + + } else if (localName.equals(TmfFilterMatchesNode.NODE_NAME)) { + + node = new TmfFilterMatchesNode(null); + String value = atts.getValue(TmfFilterMatchesNode.NOT_ATTR); + if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) { + ((TmfFilterMatchesNode) node).setNot(true); + } + ((TmfFilterMatchesNode) node).setField(atts.getValue(TmfFilterMatchesNode.FIELD_ATTR)); + ((TmfFilterMatchesNode) node).setRegex(atts.getValue(TmfFilterMatchesNode.REGEX_ATTR)); + + } else if (localName.equals(TmfFilterCompareNode.NODE_NAME)) { + + node = new TmfFilterCompareNode(null); + String value = atts.getValue(TmfFilterCompareNode.NOT_ATTR); + if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) { + ((TmfFilterCompareNode) node).setNot(true); + } + ((TmfFilterCompareNode) node).setField(atts.getValue(TmfFilterCompareNode.FIELD_ATTR)); + value = atts.getValue(TmfFilterCompareNode.TYPE_ATTR); + if (value != null) { + ((TmfFilterCompareNode) node).setType(Type.valueOf(value)); + } + value = atts.getValue(TmfFilterCompareNode.RESULT_ATTR); + if (value != null) { + if (value.equals(Integer.toString(-1))) { + ((TmfFilterCompareNode) node).setResult(-1); + } else if (value.equals(Integer.toString(1))) { + ((TmfFilterCompareNode) node).setResult(1); + } else { + ((TmfFilterCompareNode) node).setResult(0); + } + } + ((TmfFilterCompareNode) node).setValue(atts.getValue(TmfFilterCompareNode.VALUE_ATTR)); + + } + + fFilterTreeStack.push(node); + } + + /* + * (non-Javadoc) + * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + ITmfFilterTreeNode node = fFilterTreeStack.pop(); + + if (fFilterTreeStack.isEmpty()) { + fRoot = node; + } else if (fFilterTreeStack.lastElement() instanceof TmfFilterTreeNode && + node instanceof TmfFilterTreeNode) { + fFilterTreeStack.lastElement().addChild(node); + } + + } + +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/xml/TmfFilterXMLParser.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/xml/TmfFilterXMLParser.java new file mode 100644 index 0000000000..f58ed8ccec --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/xml/TmfFilterXMLParser.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2010 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 (yvashchuk@gmail.com) - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.filter.xml; + +import java.io.IOException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; + +import org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode; + +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +/** + * FilterXMLParser + *

+ * This is SAX based XML parser + *

+ */ +public class TmfFilterXMLParser { + + private static ITmfFilterTreeNode fRoot = null; + + /** + * The XMLParser constructor + * + * @param uri The XML file to parse + */ + public TmfFilterXMLParser(final String uri) throws SAXException, IOException { + + SAXParserFactory m_parserFactory = null; + if (m_parserFactory == null) { + m_parserFactory = SAXParserFactory.newInstance(); + m_parserFactory.setNamespaceAware(true); + } + + XMLReader saxReader = null; + try { + + saxReader = m_parserFactory.newSAXParser().getXMLReader(); + saxReader.setContentHandler(new TmfFilterContentHandler()); + saxReader.parse(uri); + + fRoot = ((TmfFilterContentHandler) saxReader.getContentHandler()).getTree(); + + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } + } + + /** + * Getter of tree + * + * @return The builded tree + */ + public ITmfFilterTreeNode getTree() { + return fRoot; + } +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/xml/TmfFilterXMLWriter.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/xml/TmfFilterXMLWriter.java new file mode 100644 index 0000000000..ffd5585875 --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/filter/xml/TmfFilterXMLWriter.java @@ -0,0 +1,161 @@ +/******************************************************************************* + * Copyright (c) 2010 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 (yvashchuk@gmail.com) - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.filter.xml; + +import java.io.File; +import java.io.IOException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterAndNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterCompareNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterContainsNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterEqualsNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterEventTypeNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterMatchesNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterOrNode; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * FilterXMLParser + *

+ * This is SAX based XML parser + *

+ */ +public class TmfFilterXMLWriter { + + private Document document = null; + + /** + * The XMLParser constructor + * + * @param uri The XML file to parse + * @throws ParserConfigurationException + */ + public TmfFilterXMLWriter(final ITmfFilterTreeNode root) throws IOException, ParserConfigurationException { + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); + document = documentBuilder.newDocument(); + + Element rootElement = document.createElement(root.getNodeName()); + document.appendChild(rootElement); + + for (ITmfFilterTreeNode node : root.getChildren()) { + buildXMLTree(document, node, rootElement); + } + } + + /** + * The Tree to XML parser + * + * @param document The XML document + * @param treenode The node to write + * @param parentElement The XML element of the parent + */ + public static void buildXMLTree(final Document document, final ITmfFilterTreeNode treenode, Element parentElement) { + Element element = document.createElement(treenode.getNodeName()); + + if (treenode instanceof TmfFilterNode) { + + TmfFilterNode node = (TmfFilterNode) treenode; + element.setAttribute(TmfFilterNode.NAME_ATTR, node.getFilterName()); + + } else if (treenode instanceof TmfFilterEventTypeNode) { + + TmfFilterEventTypeNode node = (TmfFilterEventTypeNode) treenode; + element.setAttribute(TmfFilterEventTypeNode.TYPE_ATTR, node.getEventType()); + element.setAttribute(TmfFilterEventTypeNode.NAME_ATTR, node.getName()); + + } else if (treenode instanceof TmfFilterAndNode) { + + TmfFilterAndNode node = (TmfFilterAndNode) treenode; + element.setAttribute(TmfFilterAndNode.NOT_ATTR, Boolean.toString(node.isNot())); + + } else if (treenode instanceof TmfFilterOrNode) { + + TmfFilterOrNode node = (TmfFilterOrNode) treenode; + element.setAttribute(TmfFilterOrNode.NOT_ATTR, Boolean.toString(node.isNot())); + + } else if (treenode instanceof TmfFilterContainsNode) { + + TmfFilterContainsNode node = (TmfFilterContainsNode) treenode; + element.setAttribute(TmfFilterContainsNode.NOT_ATTR, Boolean.toString(node.isNot())); + element.setAttribute(TmfFilterContainsNode.FIELD_ATTR, node.getField()); + element.setAttribute(TmfFilterContainsNode.VALUE_ATTR, node.getValue()); + element.setAttribute(TmfFilterContainsNode.IGNORECASE_ATTR, Boolean.toString(node.isIgnoreCase())); + + } else if (treenode instanceof TmfFilterEqualsNode) { + + TmfFilterEqualsNode node = (TmfFilterEqualsNode) treenode; + element.setAttribute(TmfFilterEqualsNode.NOT_ATTR, Boolean.toString(node.isNot())); + element.setAttribute(TmfFilterEqualsNode.FIELD_ATTR, node.getField()); + element.setAttribute(TmfFilterEqualsNode.VALUE_ATTR, node.getValue()); + element.setAttribute(TmfFilterEqualsNode.IGNORECASE_ATTR, Boolean.toString(node.isIgnoreCase())); + + } else if (treenode instanceof TmfFilterMatchesNode) { + + TmfFilterMatchesNode node = (TmfFilterMatchesNode) treenode; + element.setAttribute(TmfFilterMatchesNode.NOT_ATTR, Boolean.toString(node.isNot())); + element.setAttribute(TmfFilterMatchesNode.FIELD_ATTR, node.getField()); + element.setAttribute(TmfFilterMatchesNode.REGEX_ATTR, node.getRegex()); + + } else if (treenode instanceof TmfFilterCompareNode) { + + TmfFilterCompareNode node = (TmfFilterCompareNode) treenode; + element.setAttribute(TmfFilterCompareNode.NOT_ATTR, Boolean.toString(node.isNot())); + element.setAttribute(TmfFilterCompareNode.FIELD_ATTR, node.getField()); + element.setAttribute(TmfFilterCompareNode.RESULT_ATTR, Integer.toString(node.getResult())); + element.setAttribute(TmfFilterCompareNode.TYPE_ATTR, node.getType().toString()); + element.setAttribute(TmfFilterCompareNode.VALUE_ATTR, node.getValue()); + + } + + parentElement.appendChild(element); + + for (int i = 0; i < treenode.getChildrenCount(); i++) { + buildXMLTree(document, treenode.getChild(i), element); + } + } + + /** + * Save the tree + * + * @param uri The new Filter XML path + */ + public void saveTree(final String uri) { + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + + try { + Transformer transformer = transformerFactory.newTransformer(); + DOMSource source = new DOMSource(document); + StreamResult result = new StreamResult(new File(uri)); + transformer.transform(source, result); + } catch (TransformerConfigurationException e) { + e.printStackTrace(); + } catch (TransformerException e) { + e.printStackTrace(); + } + } + +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java index 9df74bdeec..ece1fc32d2 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java @@ -30,8 +30,6 @@ import org.eclipse.linuxtools.tmf.request.ITmfDataRequest.ExecutionType; import org.eclipse.linuxtools.tmf.request.ITmfEventRequest; import org.eclipse.linuxtools.tmf.request.TmfDataRequest; import org.eclipse.linuxtools.tmf.request.TmfEventRequest; -import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler; -import org.eclipse.linuxtools.tmf.signal.TmfTraceOpenedSignal; import org.eclipse.linuxtools.tmf.signal.TmfTraceUpdatedSignal; /** @@ -501,14 +499,6 @@ public abstract class TmfTrace extends TmfEventProvider i broadcast(new TmfTraceUpdatedSignal(this, this, new TmfTimeRange(fStartTime, fEndTime))); } - @TmfSignalHandler - public void handleTraceOpen(TmfTraceOpenedSignal signal) { - ITmfTrace trace = signal.getTrace(); - if (trace == this) { - indexTrace(false); - } - } - // ------------------------------------------------------------------------ // TmfDataProvider // ------------------------------------------------------------------------ -- 2.34.1