From 90e2b925f92cd3476c56cbce7a862a4c2db386c0 Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Mon, 14 Mar 2011 11:14:16 -0400 Subject: [PATCH] Fix for Bug338151 --- .../lttng/stubs/LTTngTraceStub.java | 12 + .../ui/model/trange/TimeRangeComponent.java | 20 +- .../ui/model/trange/TimeRangeComposite.java | 23 +- .../lttng/trace/LTTngTextTrace.java | 14 +- .../linuxtools/lttng/trace/LTTngTrace.java | 12 + .../META-INF/MANIFEST.MF | 1 + .../icons/eview16/colors_view.gif | Bin 0 -> 350 bytes .../icons/eview16/filters_view.gif | Bin 0 -> 94 bytes .../plugin.properties | 1 + org.eclipse.linuxtools.tmf.ui/plugin.xml | 9 + .../tmf/ui/parsers/IParserProvider.java | 63 +- .../tmf/ui/parsers/ParserProviderManager.java | 20 + .../parsers/custom/CustomParserProvider.java | 42 + .../tmf/ui/views/filter/FilterDialog.java | 71 ++ .../tmf/ui/views/filter/FilterManager.java | 63 ++ .../filter/FilterTreeContentProvider.java | 95 ++ .../views/filter/FilterTreeLabelProvider.java | 150 +++ .../tmf/ui/views/filter/FilterView.java | 301 ++++++ .../tmf/ui/views/filter/FilterViewer.java | 970 ++++++++++++++++++ 19 files changed, 1861 insertions(+), 6 deletions(-) create mode 100644 org.eclipse.linuxtools.tmf.ui/icons/eview16/colors_view.gif create mode 100644 org.eclipse.linuxtools.tmf.ui/icons/eview16/filters_view.gif create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterDialog.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterManager.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterTreeContentProvider.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterTreeLabelProvider.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterView.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterViewer.java diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java index bb9916cb69..7a3f84e1a3 100644 --- a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java @@ -115,6 +115,18 @@ public class LTTngTraceStub extends TmfTrace { return context; } + @Override + public TmfContext seekLocation(double ratio) { + // TODO Auto-generated method stub + return null; + } + + @Override + public double getLocationRatio(ITmfLocation location) { + // TODO Auto-generated method stub + return 0; + } + /* (non-Javadoc) * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation() */ diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/model/trange/TimeRangeComponent.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/model/trange/TimeRangeComponent.java index e4c8dec30f..64c51df0cf 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/model/trange/TimeRangeComponent.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/model/trange/TimeRangeComponent.java @@ -11,12 +11,15 @@ *******************************************************************************/ package org.eclipse.linuxtools.lttng.ui.model.trange; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry; + /** * @author alvaro * */ -public abstract class TimeRangeComponent implements ITimeRangeComponent { +public abstract class TimeRangeComponent implements ITimeRangeComponent, ITimeEvent { // ======================================================================== // Data @@ -98,6 +101,21 @@ public abstract class TimeRangeComponent implements ITimeRangeComponent { return visible; } + @Override + public ITmfTimeAnalysisEntry getEntry() { + return eventParent; + } + + @Override + public long getTime() { + return startTime; + } + + @Override + public long getDuration() { + return stopTime - startTime; + } + @Override @SuppressWarnings("nls") public String toString() { diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/model/trange/TimeRangeComposite.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/model/trange/TimeRangeComposite.java index 3a299f09b4..c5e364362d 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/model/trange/TimeRangeComposite.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/model/trange/TimeRangeComposite.java @@ -11,8 +11,10 @@ *******************************************************************************/ package org.eclipse.linuxtools.lttng.ui.model.trange; +import java.util.Iterator; import java.util.Vector; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent; import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry; public class TimeRangeComposite extends TimeRangeComponent implements @@ -157,11 +159,28 @@ ITmfTimeAnalysisEntry { */ @Override @SuppressWarnings("unchecked") - public Vector getTraceEvents() { + @Deprecated public Vector getTraceEvents() { return ChildEventLeafs; } - /** + @Override + public Iterator getTraceEventsIterator() { + return ChildEventLeafs.iterator(); + } + + @Override + public Iterator getTraceEventsIterator(long startTime, long stopTime, long visibleDuration) { + return ChildEventLeafs.iterator(); + } + + @Override + public void addTraceEvent(ITimeEvent event) { + if (event instanceof TimeRangeComponent) { + ChildEventLeafs.add((TimeRangeComponent) event); + } + } + + /** * @return */ public Vector getChildEventComposites() { diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTextTrace.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTextTrace.java index e2e8c4e890..0a01c454a1 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTextTrace.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTextTrace.java @@ -192,7 +192,19 @@ public class LTTngTextTrace extends TmfTrace implements ITmfTrace { return tmpTraceContext; } - private LttngEvent parseMyNextEvent(TmfContext context) { + @Override + public TmfContext seekLocation(double ratio) { + // TODO Auto-generated method stub + return null; + } + + @Override + public double getLocationRatio(ITmfLocation location) { + // TODO Auto-generated method stub + return 0; + } + + private LttngEvent parseMyNextEvent(TmfContext context) { // All parsing variables declared here so to be able to print them into the catch if needed String tmpContent = null; diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTrace.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTrace.java index 8d2e6701fe..01026ce102 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTrace.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTrace.java @@ -604,6 +604,18 @@ public class LTTngTrace extends TmfTrace { return new TmfContext(curLocation); } + @Override + public TmfContext seekLocation(double ratio) { + // TODO Auto-generated method stub + return null; + } + + @Override + public double getLocationRatio(ITmfLocation location) { + // TODO Auto-generated method stub + return 0; + } + /** * Return the event in the trace according to the given context. Read it if * necessary. diff --git a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF index 4d77a653ec..67976142e5 100644 --- a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF @@ -24,6 +24,7 @@ Export-Package: org.eclipse.linuxtools.tmf.ui, org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets, org.eclipse.linuxtools.tmf.ui.views, org.eclipse.linuxtools.tmf.ui.views.colors, + org.eclipse.linuxtools.tmf.ui.views.filter, org.eclipse.linuxtools.tmf.ui.views.project, org.eclipse.linuxtools.tmf.ui.views.timechart, org.eclipse.linuxtools.tmf.ui.widgets diff --git a/org.eclipse.linuxtools.tmf.ui/icons/eview16/colors_view.gif b/org.eclipse.linuxtools.tmf.ui/icons/eview16/colors_view.gif new file mode 100644 index 0000000000000000000000000000000000000000..cc168a42517239a41dd86d853aa1bc4d57962ecd GIT binary patch literal 350 zcmZ?wbhEHb6krfwSgOSE_tV6`pXdL3s`T%P^7q@y|DL=4dsDD|%Yvhaw|>1YcW_7J zqPY!E4~oA!p|)sl>x#uaS2xN&I;g*JR?Y4iYBMJk{l42gxjk*p#De)#O17<^-QO6u za9U+ssc%np=)4I9b9;08Tk>YkocSLF7#M&U48dIL5Q;xp7#SGs8FUzc0OThIw(0|u z3OsoJ_8p&4bkao5P-tR_SE-Zul{F_STut`hWzO``OIP7Ok{FmbSx@4t)2CP~IrcL$ z$*+F@<`orTXP1|dtFLQhWDpY)l2M57W?*BL5|WjUoHC7xSIRv^P_$0wADG2l;u + + diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/parsers/IParserProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/parsers/IParserProvider.java index 099653272d..c47964c0bf 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/parsers/IParserProvider.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/parsers/IParserProvider.java @@ -21,16 +21,75 @@ import org.eclipse.swt.widgets.Composite; public interface IParserProvider { + /** + * Return the readable category name for this parser provider + * + * @return the category name + */ public String getCategory(); + /** + * Return a trace instance for a resource given a parser id + * + * @param parser the parser id + * @param resource the resource + * @return a trace instance or null if the parser id is not handled by this parser provider + */ public ITmfTrace getTraceForParser(String parser, IResource resource); + /** + * Return a trace instance for a resource given a content type id + * + * @param contentTypeId the content type id + * @param resource the resource + * @return a trace instance or null if the content type id is not handled by this parser provider + */ public ITmfTrace getTraceForContentType(String contentTypeId, IResource resource); - public String getEditorIdForParser(String parser); - + /** + * Return the parser map for this parser provider + * Map key: readable parser name + * Map value: unique parser id + * + * @return the parser map + */ public Map getParserMap(); + /** + * Return the event type map given a parser id + * Map key: readable event type name + * Map value: unique event type id + * + * @param parser the parser id + * @return the event type map or null if the parser id is not handled by this parser provider + */ + public Map getEventTypeMapForParser(String parser); + + /** + * Return the field label array given an event type id + * Array value: readable field label + * + * @param eventType the event type id + * @return the field label array or null if the event type id is not handled by this parser provider + */ + public String[] getFieldLabelsForEventType(String eventType); + + /** + * Return the editor id given a parser id + * + * @param parser the parser id + * @return an editor id or null to use the default trace editor + */ + public String getEditorIdForParser(String parser); + + /** + * Return an events table instance for a given trace + * + * @param parser the parser id + * @param parent the parent composite for the table + * @param cacheSize the desired cache size for the table + * @return an events table instance or null if the trace is not handled by this parser provider + */ public TmfEventsTable getEventsTable(ITmfTrace trace, Composite parent, int cacheSize); } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/parsers/ParserProviderManager.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/parsers/ParserProviderManager.java index ada2a704e7..a48cd70373 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/parsers/ParserProviderManager.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/parsers/ParserProviderManager.java @@ -123,6 +123,26 @@ public class ParserProviderManager { return parserMap; } + public static Map getEventTypeMapForParser(String parser) { + for (IParserProvider parserProvider : fParserProviders) { + Map map = parserProvider.getEventTypeMapForParser(parser); + if (map != null) { + return map; + } + } + return new LinkedHashMap(0); + } + + public static String[] getFieldLabelsForEventType(String eventType) { + for (IParserProvider parserProvider : fParserProviders) { + String[] fieldLabels = parserProvider.getFieldLabelsForEventType(eventType); + if (fieldLabels != null) { + return fieldLabels; + } + } + return new String[0]; + } + public static TmfEventsTable getEventsTable(ITmfTrace trace, Composite parent, int cacheSize) { for (IParserProvider parserProvider : fParserProviders) { if (parserProvider != null) { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/parsers/custom/CustomParserProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/parsers/custom/CustomParserProvider.java index d70f135e3a..04761eef7d 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/parsers/custom/CustomParserProvider.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/parsers/custom/CustomParserProvider.java @@ -60,6 +60,48 @@ public class CustomParserProvider implements IParserProvider { return null; } + @Override + public Map getEventTypeMapForParser(String parser) { + for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { + if (parser.equals(CustomTxtTrace.class.getCanonicalName() + "." + def.definitionName)) { //$NON-NLS-1$ + Map eventTypeMap = new LinkedHashMap(); + eventTypeMap.put(def.definitionName, CustomTxtEventType.class.getCanonicalName() + "." + def.definitionName); //$NON-NLS-1$ + return eventTypeMap; + } + } + for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { + if (parser.equals(CustomXmlTrace.class.getCanonicalName() + "." + def.definitionName)) { //$NON-NLS-1$ + Map eventTypeMap = new LinkedHashMap(); + eventTypeMap.put(def.definitionName, CustomXmlEventType.class.getCanonicalName() + "." + def.definitionName); //$NON-NLS-1$ + return eventTypeMap; + } + } + return null; + } + + @Override + public String[] getFieldLabelsForEventType(String eventType) { + for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { + if (eventType.equals(CustomTxtEventType.class.getCanonicalName() + "." + def.definitionName)) { //$NON-NLS-1$ + String[] labels = new String[def.outputs.size()]; + for (int i = 0; i < labels.length; i++) { + labels[i] = def.outputs.get(i).name; + } + return labels; + } + } + for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { + if (eventType.equals(CustomXmlEventType.class.getCanonicalName() + "." + def.definitionName)) { //$NON-NLS-1$ + String[] labels = new String[def.outputs.size()]; + for (int i = 0; i < labels.length; i++) { + labels[i] = def.outputs.get(i).name; + } + return labels; + } + } + return null; + } + @Override public Map getParserMap() { Map parserMap = new LinkedHashMap(); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterDialog.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterDialog.java new file mode 100644 index 0000000000..a1d8c0cf63 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterDialog.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * 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.views.filter; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterNode; +import org.eclipse.linuxtools.tmf.ui.internal.Messages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + +public class FilterDialog extends Dialog { + + TmfFilterNode fRoot; + FilterViewer fViewer; + + public FilterDialog(Shell shell) { + super(shell); + setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createDialogArea(Composite parent) { + getShell().setText(Messages.FilterDialog_FilterDialogTitle); + getShell().setMinimumSize(getShell().computeSize(500, 200)); + Composite composite = (Composite) super.createDialogArea(parent); + + fViewer = new FilterViewer(composite, SWT.BORDER); + fViewer.setInput(fRoot); + return composite; + } + + /** + * @param fFilter the filter to set + */ + public void setFilter(ITmfFilterTreeNode filter) { + fRoot = new TmfFilterNode(null); + if (filter != null) { + fRoot.addChild(filter.clone()); + } + if (fViewer != null) { + fViewer.setInput(fRoot); + } + } + + /** + * @return the fFilter + */ + public ITmfFilterTreeNode getFilter() { + if (fRoot != null && fRoot.hasChildren()) { + return fRoot.getChild(0).clone(); + } + return null; + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterManager.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterManager.java new file mode 100644 index 0000000000..a1849aa9d5 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterManager.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * 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.views.filter; + +import java.io.FileNotFoundException; +import java.io.IOException; + +import javax.xml.parsers.ParserConfigurationException; + +import org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterRootNode; +import org.eclipse.linuxtools.tmf.filter.xml.TmfFilterXMLParser; +import org.eclipse.linuxtools.tmf.filter.xml.TmfFilterXMLWriter; +import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin; +import org.xml.sax.SAXException; + +public class FilterManager { + + private static final String SAVED_FILTERS_FILE_NAME = "saved_filters.xml"; //$NON-NLS-1$ + private static final String SAVED_FILTERS_PATH_NAME = + TmfUiPlugin.getDefault().getStateLocation().addTrailingSeparator().append(SAVED_FILTERS_FILE_NAME).toString(); + + private static ITmfFilterTreeNode fRoot = new TmfFilterRootNode(); + static { + try { + fRoot = new TmfFilterXMLParser(SAVED_FILTERS_PATH_NAME).getTree(); + } catch (FileNotFoundException e) { + } catch (SAXException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static ITmfFilterTreeNode[] getSavedFilters() { + return fRoot.clone().getChildren(); + } + + public static void setSavedFilters(ITmfFilterTreeNode[] filters) { + fRoot = new TmfFilterRootNode(); + for (ITmfFilterTreeNode filter : filters) { + fRoot.addChild(filter.clone()); + } + try { + TmfFilterXMLWriter writerXML = new TmfFilterXMLWriter(fRoot); + writerXML.saveTree(SAVED_FILTERS_PATH_NAME); + } catch (IOException e) { + e.printStackTrace(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterTreeContentProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterTreeContentProvider.java new file mode 100644 index 0000000000..d5e349715d --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterTreeContentProvider.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * 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 - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.views.filter; + +import java.util.ArrayList; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode; + +/** + * FilterTreeContentProvider + *

+ * This is the Content Provider of our tree + *

+ */ +public class FilterTreeContentProvider implements ITreeContentProvider { + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + @Override + public void dispose() { + // TODO Auto-generated method stub + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // TODO Auto-generated method stub + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object) + */ + @Override + public Object[] getElements(Object inputElement) { + if (inputElement instanceof ITmfFilterTreeNode) { + ArrayList result = new ArrayList(); + for(int i = 0; i < ((ITmfFilterTreeNode)inputElement).getChildrenCount(); i++) { + result.add(((ITmfFilterTreeNode)inputElement).getChild(i)); + } + + return result.toArray(); + } + return null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) + */ + @Override + public Object[] getChildren(Object parentElement) { + ArrayList result = new ArrayList(); + for(int i = 0; i < ((ITmfFilterTreeNode)parentElement).getChildrenCount(); i++) { + result.add(((ITmfFilterTreeNode)parentElement).getChild(i)); + } + return result.toArray(); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) + */ + @Override + public Object getParent(Object element) { + return ((ITmfFilterTreeNode) element).getParent(); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) + */ + @Override + public boolean hasChildren(Object element) { + return ((ITmfFilterTreeNode) element).hasChildren(); + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterTreeLabelProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterTreeLabelProvider.java new file mode 100644 index 0000000000..fc61d2c495 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterTreeLabelProvider.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * 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 - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.views.filter; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +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.swt.graphics.Image; + +/** + * FilterTreeLabelProvider + *

+ * This is the Label Provider for our Filter Tree + *

+ */ +public class FilterTreeLabelProvider implements ILabelProvider { + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener) + */ + @Override + public void addListener(ILabelProviderListener listener) { + // TODO Auto-generated method stub + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose() + */ + @Override + public void dispose() { + // TODO Auto-generated method stub + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String) + */ + @Override + public boolean isLabelProperty(Object element, String property) { + // TODO Auto-generated method stub + return false; + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener) + */ + @Override + public void removeListener(ILabelProviderListener listener) { + // TODO Auto-generated method stub + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) + */ + @Override + public Image getImage(Object element) { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) + */ + @Override + public String getText(Object element) { + String label = null; + + if (element instanceof TmfFilterNode) { + + TmfFilterNode node = (TmfFilterNode) element; + label = node.getNodeName() + " " + node.getFilterName(); //$NON-NLS-1$ + + } else if (element instanceof TmfFilterEventTypeNode) { + + TmfFilterEventTypeNode node = (TmfFilterEventTypeNode) element; + label = "WITH " + node.getNodeName() + (node.getName() != null ? " " + node.getName() : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + } else if (element instanceof TmfFilterAndNode) { + + TmfFilterAndNode node = (TmfFilterAndNode) element; + label = (node.isNot() ? "NOT " : "") + node.getNodeName(); //$NON-NLS-1$ //$NON-NLS-2$ + + } else if (element instanceof TmfFilterOrNode) { + + TmfFilterOrNode node = (TmfFilterOrNode) element; + label = (node.isNot() ? "NOT " : "") + node.getNodeName(); //$NON-NLS-1$ //$NON-NLS-2$ + + } else if (element instanceof TmfFilterContainsNode) { + + TmfFilterContainsNode node = (TmfFilterContainsNode) element; + label = (node.isNot() ? "NOT " : "") + //$NON-NLS-1$ //$NON-NLS-2$ + (node.getField() != null ? node.getField() + " " : "") + //$NON-NLS-1$ //$NON-NLS-2$ + node.getNodeName() + + (node.getValue() != null && node.getValue().length() > 0 ? " \"" + node.getValue() + "\"" : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + } else if (element instanceof TmfFilterEqualsNode) { + + TmfFilterEqualsNode node = (TmfFilterEqualsNode) element; + label = (node.isNot() ? "NOT " : "") + //$NON-NLS-1$ //$NON-NLS-2$ + (node.getField() != null ? node.getField() + " " : "") + //$NON-NLS-1$ //$NON-NLS-2$ + node.getNodeName() + + (node.getValue() != null && node.getValue().length() > 0 ? " \"" + node.getValue() + "\"" : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + } else if (element instanceof TmfFilterMatchesNode) { + + TmfFilterMatchesNode node = (TmfFilterMatchesNode) element; + label = (node.isNot() ? "NOT " : "") + //$NON-NLS-1$ //$NON-NLS-2$ + (node.getField() != null ? node.getField() + " " : "") + //$NON-NLS-1$ //$NON-NLS-2$ + node.getNodeName() + + (node.getRegex() != null && node.getRegex().length() > 0 ? " \"" + node.getRegex() + "\"" : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + } else if (element instanceof TmfFilterCompareNode) { + + TmfFilterCompareNode node = (TmfFilterCompareNode) element; + label = (node.isNot() ? "NOT " : "") + //$NON-NLS-1$ //$NON-NLS-2$ + (node.getField() != null ? node.getField() + " " : "") + //$NON-NLS-1$ //$NON-NLS-2$ + (node.getResult() < 0 ? "<" : (node.getResult() > 0 ? ">" : "=")) + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + (node.getValue() != null && node.getValue().length() > 0 ? + (node.getType() == Type.ALPHA ? " \"" + node.getValue() + "\"" : //$NON-NLS-1$ //$NON-NLS-2$ + (node.getType() == Type.TIMESTAMP ? " [" + node.getValue() + "]" : //$NON-NLS-1$ //$NON-NLS-2$ + " " + node.getValue())) : ""); //$NON-NLS-1$//$NON-NLS-2$ + + } + return label; + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterView.java new file mode 100644 index 0000000000..ea7cd81611 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterView.java @@ -0,0 +1,301 @@ +/******************************************************************************* + * 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 - 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.tmf.filter.model.ITmfFilterTreeNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterNode; +import org.eclipse.linuxtools.tmf.filter.model.TmfFilterRootNode; +import org.eclipse.linuxtools.tmf.filter.xml.TmfFilterXMLParser; +import org.eclipse.linuxtools.tmf.filter.xml.TmfFilterXMLWriter; +import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin; +import org.eclipse.linuxtools.tmf.ui.internal.Messages; +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; + +/** + * FilterView + *

+ * View that contain UI to the TMF filter. + */ +public class FilterView extends TmfView { + + public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.filter"; //$NON-NLS-1$ + + private static final Image SAVE_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/save_button.gif"); //$NON-NLS-1$ + private static final Image ADD_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$ + private static final Image DELETE_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$ + private static final Image IMPORT_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/import_button.gif"); //$NON-NLS-1$ + private static final Image EXPORT_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/export_button.gif"); //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Main data structures + // ------------------------------------------------------------------------ + + private FilterViewer fViewer; + private ITmfFilterTreeNode fRoot; + + private 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) { + e.printStackTrace(); + } + + 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); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.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); + } + } + }); + } + + + // ------------------------------------------------------------------------ + // ViewPart + // ------------------------------------------------------------------------ + + /* + * (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) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + 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) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + 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 diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterViewer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterViewer.java new file mode 100644 index 0000000000..db8a97f804 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterViewer.java @@ -0,0 +1,970 @@ +/******************************************************************************* + * 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.views.filter; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +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.ui.internal.Messages; +import org.eclipse.linuxtools.tmf.ui.parsers.ParserProviderManager; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.TreeItem; + +class FilterViewer extends Composite { + + private static final Map> EVENT_TYPES_MAP; + static { + Map> eventTypesMap = new LinkedHashMap>(); + for (Entry> categoryEntry : ParserProviderManager.getParserMap().entrySet()) { + for (Entry parserEntry : categoryEntry.getValue().entrySet()) { + String prefix = categoryEntry.getKey() + " - " + parserEntry.getKey() + " - "; //$NON-NLS-1$ //$NON-NLS-2$ + for (Entry eventTypeEntry : ParserProviderManager.getEventTypeMapForParser(parserEntry.getValue()).entrySet()) { + eventTypesMap.put(prefix + eventTypeEntry.getKey(), eventTypeEntry); + } + } + } + EVENT_TYPES_MAP = eventTypesMap; + } + + private static final String[] FIELDS_LIST; + static { + ArrayList fieldsList = new ArrayList(); + for (Entry> categoryEntry : ParserProviderManager.getParserMap().entrySet()) { + for (Entry parserEntry : categoryEntry.getValue().entrySet()) { + fieldsList.add(""); //$NON-NLS-1$ + fieldsList.add("["+ categoryEntry.getKey() +" - " + parserEntry.getKey() +"]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + for (String eventType : ParserProviderManager.getEventTypeMapForParser(parserEntry.getValue()).values()) { + for (String field : ParserProviderManager.getFieldLabelsForEventType(eventType)) { + fieldsList.add(field); + } + } + } + } + FIELDS_LIST = fieldsList.toArray(new String[0]); + } + + private TreeViewer fViewer; + private Composite fComposite; + + public FilterViewer(Composite parent, int style) { + super(parent, style); + + setLayout(new FillLayout()); + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); + setLayoutData(gd); + + final SashForm sash = new SashForm(this, SWT.HORIZONTAL); + + // Create the tree viewer to display the filter tree + fViewer = new TreeViewer(sash, SWT.NONE); + fViewer.setContentProvider(new FilterTreeContentProvider()); + fViewer.setLabelProvider(new FilterTreeLabelProvider()); + fViewer.setInput(new TmfFilterRootNode()); + + // Create the empty filter node properties panel + fComposite = new Composite(sash, SWT.NONE); + GridLayout gl = new GridLayout(); + gl.marginHeight = 0; + gl.marginWidth = 0; + fComposite.setLayout(gl); + + createContextMenu(); + + fViewer.addSelectionChangedListener(new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) { + // Update the filter node properties panel to the selection + IStructuredSelection selection = (IStructuredSelection) event.getSelection(); + ITmfFilterTreeNode node = (ITmfFilterTreeNode) selection.getFirstElement(); + updateFilterNodeComposite(node); + // Highlight the selection's children + highlightTreeItems(fViewer.getTree().getSelection()[0].getItems()); + } else { + updateFilterNodeComposite(null); + } + } + }); + } + + /** + * Create the context menu for the tree viewer + */ + private void createContextMenu() { + // Adds root context menu + MenuManager menuManager = new MenuManager(); + menuManager.setRemoveAllWhenShown(true); + menuManager.addMenuListener(new IMenuListener() { + @Override + public void menuAboutToShow(IMenuManager manager) { + fillContextMenu(manager); + } + }); + + // Context + Menu contextMenu = menuManager.createContextMenu(fViewer.getTree()); + + // Publish it + fViewer.getTree().setMenu(contextMenu); + } + + /** + * Fill the context menu for the tree viewer + */ + protected void fillContextMenu(IMenuManager manager) { + final ISelection selection = fViewer.getSelection(); + ITmfFilterTreeNode filterTreeNode = null; + if (selection instanceof StructuredSelection) { + Object element = ((StructuredSelection) selection).getFirstElement(); + if (element instanceof ITmfFilterTreeNode) { + filterTreeNode = (ITmfFilterTreeNode) element; + } + } + + final ITmfFilterTreeNode selectedNode = filterTreeNode; + + if (selectedNode != null) { + + fillContextMenuForNode(selectedNode, manager); + + if (selectedNode.getValidChildren().size() > 0) { + manager.add(new Separator()); + } + + Action deleteAction = new Action() { + @Override + public void run() { + selectedNode.remove(); + fViewer.refresh(); + } + }; + deleteAction.setText(Messages.FilterViewer_DeleteActionText); + manager.add(deleteAction); + + manager.add(new Separator()); + } + + if (fViewer.getInput() instanceof TmfFilterRootNode || selectedNode == null) { + final ITmfFilterTreeNode root = (ITmfFilterTreeNode) fViewer.getInput(); + + fillContextMenuForNode(root, manager); + } + } + + /** + * Fill the context menu with the valid children of the provided node + */ + protected void fillContextMenuForNode(final ITmfFilterTreeNode node, IMenuManager manager) { + for (final String child : node.getValidChildren()) { + final Action action = new Action() { + @Override + public void run() { + ITmfFilterTreeNode newNode = null; + if (TmfFilterNode.NODE_NAME.equals(child)) { + newNode = new TmfFilterNode(node, ""); //$NON-NLS-1$ + } else if (TmfFilterEventTypeNode.NODE_NAME.equals(child)) { + newNode = new TmfFilterEventTypeNode(node); + } else if (TmfFilterAndNode.NODE_NAME.equals(child)) { + newNode = new TmfFilterAndNode(node); + } else if (TmfFilterOrNode.NODE_NAME.equals(child)) { + newNode = new TmfFilterOrNode(node); + } else if (TmfFilterContainsNode.NODE_NAME.equals(child)) { + newNode = new TmfFilterContainsNode(node); + } else if (TmfFilterEqualsNode.NODE_NAME.equals(child)) { + newNode = new TmfFilterEqualsNode(node); + } else if (TmfFilterMatchesNode.NODE_NAME.equals(child)) { + newNode = new TmfFilterMatchesNode(node); + } else if (TmfFilterCompareNode.NODE_NAME.equals(child)) { + newNode = new TmfFilterCompareNode(node); + } + if (newNode != null) { + fViewer.refresh(); + fViewer.setSelection(new StructuredSelection(newNode), true); + } + } + }; + if (TmfFilterNode.NODE_NAME.equals(child)) { + action.setText(Messages.FilterViewer_NewPrefix + " " + child); //$NON-NLS-1$ + } else { + action.setText(child); + } + manager.add(action); + } + } + + /** + * Create the appropriate filter node properties composite + */ + private void updateFilterNodeComposite(ITmfFilterTreeNode node) { + for (Control control : fComposite.getChildren()) { + control.dispose(); + } + + if (node instanceof TmfFilterNode) { + new FilterNodeComposite(fComposite, (TmfFilterNode) node); + } else if (node instanceof TmfFilterEventTypeNode) { + new FilterEventTypeNodeComposite(fComposite, (TmfFilterEventTypeNode) node); + } else if (node instanceof TmfFilterAndNode) { + new FilterAndNodeComposite(fComposite, (TmfFilterAndNode) node); + } else if (node instanceof TmfFilterOrNode) { + new FilterOrNodeComposite(fComposite, (TmfFilterOrNode) node); + } else if (node instanceof TmfFilterContainsNode) { + new FilterContainsNodeComposite(fComposite, (TmfFilterContainsNode) node); + } else if (node instanceof TmfFilterEqualsNode) { + new FilterEqualsNodeComposite(fComposite, (TmfFilterEqualsNode) node); + } else if (node instanceof TmfFilterMatchesNode) { + new FilterMatchesNodeComposite(fComposite, (TmfFilterMatchesNode) node); + } else if (node instanceof TmfFilterCompareNode) { + new FilterCompareNodeComposite(fComposite, (TmfFilterCompareNode) node); + } else { + new FilterBaseNodeComposite(fComposite); + } + fComposite.layout(); + } + + /** + * Highlight the provided tree items + */ + private void highlightTreeItems(TreeItem[] items) { + resetTreeItems(fViewer.getTree().getItems()); + for (TreeItem item : items) { + item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE)); + } + + } + + /** + * Reset the provided tree items (remove highlight) + */ + private void resetTreeItems(TreeItem[] items) { + for (TreeItem item : items) { + item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); + resetTreeItems(item.getItems()); + } + } + + public void setInput(ITmfFilterTreeNode root) { + fViewer.setInput(root); + fViewer.expandAll(); + + updateFilterNodeComposite(null); + } + + public ITmfFilterTreeNode getInput() { + return (ITmfFilterTreeNode) fViewer.getInput(); + } + + public void refresh() { + fViewer.refresh(); + } + + public void setSelection(ITmfFilterTreeNode node, boolean reveal) { + fViewer.setSelection(new StructuredSelection(node), reveal); + } + + public void setSelection(ITmfFilterTreeNode node) { + fViewer.setSelection(new StructuredSelection(node)); + } + + public ITmfFilterTreeNode getSelection() { + final ISelection selection = fViewer.getSelection(); + ITmfFilterTreeNode filterTreeNode = null; + if (selection instanceof StructuredSelection) { + Object element = ((StructuredSelection) selection).getFirstElement(); + if (element instanceof ITmfFilterTreeNode) { + filterTreeNode = (ITmfFilterTreeNode) element; + } + } + + final ITmfFilterTreeNode selectedNode = filterTreeNode; + return selectedNode; + } + + public void addSelectionChangedListener(ISelectionChangedListener listener) { + fViewer.addSelectionChangedListener(listener); + } + + public void removeSelectionChangedListener(ISelectionChangedListener listener) { + fViewer.removeSelectionChangedListener(listener); + } + + private class FilterBaseNodeComposite extends Composite { + + FilterBaseNodeComposite(Composite parent) { + super(parent, SWT.NONE); + setLayout(new GridLayout(2, false)); + setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + protected String[] getFieldsList(ITmfFilterTreeNode node) { + while (node != null) { + if (node instanceof TmfFilterEventTypeNode) { + TmfFilterEventTypeNode eventTypeNode = (TmfFilterEventTypeNode) node; + return ParserProviderManager.getFieldLabelsForEventType(eventTypeNode.getEventType()); + } + node = node.getParent(); + } + return FIELDS_LIST; + } + } + + private class FilterNodeComposite extends FilterBaseNodeComposite { + TmfFilterNode fNode; + Text fNameText; + + FilterNodeComposite(Composite parent, TmfFilterNode node) { + super(parent); + fNode = node; + + Label label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_NameLabel); + + fNameText = new Text(this, SWT.BORDER); + fNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + if (node.getFilterName() != null && node.getFilterName().length() > 0) { + fNameText.setText(node.getFilterName()); + } else { + fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); + fNameText.setText(Messages.FilterViewer_FilterNameHint); + } + fNameText.addFocusListener(new FocusListener() { + @Override + public void focusLost(FocusEvent e) { + if (fNode.getFilterName() == null || fNode.getFilterName().length() == 0) { + fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); + fNameText.setText(Messages.FilterViewer_FilterNameHint); + } + } + @Override + public void focusGained(FocusEvent e) { + if (fNameText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { + fNameText.setText(""); //$NON-NLS-1$ + } + fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); + } + }); + fNameText.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + if (! fNameText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { + fNode.setFilterName(fNameText.getText()); + fViewer.refresh(fNode); + } + } + }); + } + } + + private class FilterEventTypeNodeComposite extends FilterBaseNodeComposite { + TmfFilterEventTypeNode fNode; + Combo fTypeCombo; + + FilterEventTypeNodeComposite(Composite parent, TmfFilterEventTypeNode node) { + super(parent); + fNode = node; + + Label label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_TypeLabel); + + fTypeCombo = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY); + fTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + fTypeCombo.setItems(EVENT_TYPES_MAP.keySet().toArray(new String[0])); + if (fNode.getEventType() != null) { + for (Entry > eventTypeEntry : EVENT_TYPES_MAP.entrySet()) { + if (eventTypeEntry.getValue().getValue().equals(fNode.getEventType())) { + fTypeCombo.setText(eventTypeEntry.getKey()); + } + } + } + fTypeCombo.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + for (Entry > eventTypeEntry : EVENT_TYPES_MAP.entrySet()) { + if (eventTypeEntry.getKey().equals(fTypeCombo.getText())) { + fNode.setEventType(eventTypeEntry.getValue().getValue()); + fNode.setName(eventTypeEntry.getValue().getKey()); + fViewer.refresh(fNode); + break; + } + } + } + }); + } + } + + private class FilterAndNodeComposite extends FilterBaseNodeComposite { + TmfFilterAndNode fNode; + Button fNotButton; + + FilterAndNodeComposite(Composite parent, TmfFilterAndNode node) { + super(parent); + fNode = node; + + Label label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_NotLabel); + + fNotButton = new Button(this, SWT.CHECK); + fNotButton.setSelection(fNode.isNot()); + fNotButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fNode.setNot(fNotButton.getSelection()); + fViewer.refresh(fNode); + } + }); + } + } + + private class FilterOrNodeComposite extends FilterBaseNodeComposite { + TmfFilterOrNode fNode; + Button fNotButton; + + FilterOrNodeComposite(Composite parent, TmfFilterOrNode node) { + super(parent); + fNode = node; + + Label label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_NotLabel); + + fNotButton = new Button(this, SWT.CHECK); + fNotButton.setSelection(fNode.isNot()); + fNotButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fNode.setNot(fNotButton.getSelection()); + fViewer.refresh(fNode); + } + }); + } + } + + private class FilterContainsNodeComposite extends FilterBaseNodeComposite { + TmfFilterContainsNode fNode; + Button fNotButton; + Combo fFieldCombo; + Text fValueText; + Button fIgnoreCaseButton; + + FilterContainsNodeComposite(Composite parent, TmfFilterContainsNode node) { + super(parent); + fNode = node; + + Label label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_NotLabel); + + fNotButton = new Button(this, SWT.CHECK); + fNotButton.setSelection(fNode.isNot()); + fNotButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fNode.setNot(fNotButton.getSelection()); + fViewer.refresh(fNode); + } + }); + + label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_FieldLabel); + + fFieldCombo = new Combo(this, SWT.DROP_DOWN); + fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + fFieldCombo.setItems(getFieldsList(fNode)); + if (fNode.getField() != null) { + fFieldCombo.setText(fNode.getField()); + } + fFieldCombo.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + fNode.setField(fFieldCombo.getText()); + fViewer.refresh(fNode); + } + }); + + label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_ValueLabel); + + fValueText = new Text(this, SWT.BORDER); + fValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + if (node.getValue() != null && node.getValue().length() > 0) { + fValueText.setText(node.getValue()); + } else { + fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); + fValueText.setText(Messages.FilterViewer_ValueHint); + } + fValueText.addFocusListener(new FocusListener() { + @Override + public void focusLost(FocusEvent e) { + if (fNode.getValue() == null || fNode.getValue().length() == 0) { + fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); + fValueText.setText(Messages.FilterViewer_ValueHint); + } + } + @Override + public void focusGained(FocusEvent e) { + if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { + fValueText.setText(""); //$NON-NLS-1$ + } + fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); + } + }); + fValueText.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + if (! fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { + fNode.setValue(fValueText.getText()); + fViewer.refresh(fNode); + } + } + }); + + label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + + fIgnoreCaseButton = new Button(this, SWT.CHECK); + fIgnoreCaseButton.setSelection(fNode.isIgnoreCase()); + fIgnoreCaseButton.setText(Messages.FilterViewer_IgnoreCaseButtonText); + fIgnoreCaseButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + fIgnoreCaseButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fNode.setIgnoreCase(fIgnoreCaseButton.getSelection()); + fViewer.refresh(fNode); + } + }); + } + } + + private class FilterEqualsNodeComposite extends FilterBaseNodeComposite { + TmfFilterEqualsNode fNode; + Button fNotButton; + Combo fFieldCombo; + Text fValueText; + Button fIgnoreCaseButton; + + FilterEqualsNodeComposite(Composite parent, TmfFilterEqualsNode node) { + super(parent); + fNode = node; + + Label label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_NotLabel); + + fNotButton = new Button(this, SWT.CHECK); + fNotButton.setSelection(fNode.isNot()); + fNotButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fNode.setNot(fNotButton.getSelection()); + fViewer.refresh(fNode); + } + }); + + label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_FieldLabel); + + fFieldCombo = new Combo(this, SWT.DROP_DOWN); + fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + fFieldCombo.setItems(getFieldsList(fNode)); + if (fNode.getField() != null) { + fFieldCombo.setText(fNode.getField()); + } + fFieldCombo.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + fNode.setField(fFieldCombo.getText()); + fViewer.refresh(fNode); + } + }); + + label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_ValueLabel); + + fValueText = new Text(this, SWT.BORDER); + fValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + if (node.getValue() != null && node.getValue().length() > 0) { + fValueText.setText(node.getValue()); + } else { + fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); + fValueText.setText(Messages.FilterViewer_ValueHint); + } + fValueText.addFocusListener(new FocusListener() { + @Override + public void focusLost(FocusEvent e) { + if (fNode.getValue() == null || fNode.getValue().length() == 0) { + fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); + fValueText.setText(Messages.FilterViewer_ValueHint); + } + } + @Override + public void focusGained(FocusEvent e) { + if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { + fValueText.setText(""); //$NON-NLS-1$ + } + fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); + } + }); + fValueText.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + if (! fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { + fNode.setValue(fValueText.getText()); + fViewer.refresh(fNode); + } + } + }); + + label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + + fIgnoreCaseButton = new Button(this, SWT.CHECK); + fIgnoreCaseButton.setSelection(fNode.isIgnoreCase()); + fIgnoreCaseButton.setText(Messages.FilterViewer_IgnoreCaseButtonText); + fIgnoreCaseButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + fIgnoreCaseButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fNode.setIgnoreCase(fIgnoreCaseButton.getSelection()); + fViewer.refresh(fNode); + } + }); + } + } + + private class FilterMatchesNodeComposite extends FilterBaseNodeComposite { + TmfFilterMatchesNode fNode; + Button fNotButton; + Combo fFieldCombo; + Text fRegexText; + + FilterMatchesNodeComposite(Composite parent, TmfFilterMatchesNode node) { + super(parent); + fNode = node; + + Label label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_NotLabel); + + fNotButton = new Button(this, SWT.CHECK); + fNotButton.setSelection(fNode.isNot()); + fNotButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fNode.setNot(fNotButton.getSelection()); + fViewer.refresh(fNode); + } + }); + + label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_FieldLabel); + + fFieldCombo = new Combo(this, SWT.DROP_DOWN); + fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + fFieldCombo.setItems(getFieldsList(fNode)); + if (fNode.getField() != null) { + fFieldCombo.setText(fNode.getField()); + } + fFieldCombo.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + fNode.setField(fFieldCombo.getText()); + fViewer.refresh(fNode); + } + }); + + label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_RegexLabel); + + fRegexText = new Text(this, SWT.BORDER); + fRegexText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + if (node.getRegex() != null && node.getRegex().length() > 0) { + fRegexText.setText(node.getRegex()); + } else { + fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); + fRegexText.setText(Messages.FilterViewer_RegexHint); + } + fRegexText.addFocusListener(new FocusListener() { + @Override + public void focusLost(FocusEvent e) { + if (fNode.getRegex() == null || fNode.getRegex().length() == 0) { + fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); + fRegexText.setText(Messages.FilterViewer_RegexHint); + } + } + @Override + public void focusGained(FocusEvent e) { + if (fRegexText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { + fRegexText.setText(""); //$NON-NLS-1$ + } + fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); + } + }); + fRegexText.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + if (! fRegexText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { + fNode.setRegex(fRegexText.getText()); + fViewer.refresh(fNode); + } + } + }); + } + } + + private class FilterCompareNodeComposite extends FilterBaseNodeComposite { + TmfFilterCompareNode fNode; + Button fNotButton; + Combo fFieldCombo; + Text fValueText; + Button fLTButton; + Button fEQButton; + Button fGTButton; + Button fNumButton; + Button fAlphaButton; + Button fTimestampButton; + + FilterCompareNodeComposite(Composite parent, TmfFilterCompareNode node) { + super(parent); + fNode = node; + + Label label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_NotLabel); + + fNotButton = new Button(this, SWT.CHECK); + fNotButton.setSelection(fNode.isNot()); + fNotButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fNode.setNot(fNotButton.getSelection()); + fViewer.refresh(fNode); + } + }); + + label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_FieldLabel); + + fFieldCombo = new Combo(this, SWT.DROP_DOWN); + fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + fFieldCombo.setItems(getFieldsList(fNode)); + if (fNode.getField() != null) { + fFieldCombo.setText(fNode.getField()); + } + fFieldCombo.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + fNode.setField(fFieldCombo.getText()); + fViewer.refresh(fNode); + } + }); + + label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_ResultLabel); + + Composite resultGroup = new Composite(this, SWT.NONE); + GridLayout rggl = new GridLayout(3, true); + rggl.marginHeight = 0; + rggl.marginWidth = 0; + resultGroup.setLayout(rggl); + resultGroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + + fLTButton = new Button(resultGroup, SWT.RADIO); + fLTButton.setSelection(fNode.getResult() < 0); + fLTButton.setText("<"); //$NON-NLS-1$ + fLTButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + fLTButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (fLTButton.getSelection()) { + fNode.setResult(-1); + } + fViewer.refresh(fNode); + } + }); + + fEQButton = new Button(resultGroup, SWT.RADIO); + fEQButton.setSelection(fNode.getResult() == 0); + fEQButton.setText("="); //$NON-NLS-1$ + fEQButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + fEQButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (fEQButton.getSelection()) { + fNode.setResult(0); + } + fViewer.refresh(fNode); + } + }); + + fGTButton = new Button(resultGroup, SWT.RADIO); + fGTButton.setSelection(fNode.getResult() > 0); + fGTButton.setText(">"); //$NON-NLS-1$ + fGTButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + fGTButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (fGTButton.getSelection()) { + fNode.setResult(1); + } + fViewer.refresh(fNode); + } + }); + + label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_TypeLabel); + + Composite typeGroup = new Composite(this, SWT.NONE); + GridLayout tggl = new GridLayout(3, false); + tggl.marginHeight = 0; + tggl.marginWidth = 0; + typeGroup.setLayout(tggl); + typeGroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + + fNumButton = new Button(typeGroup, SWT.RADIO); + fNumButton.setSelection(fNode.getType() == Type.NUM); + fNumButton.setText(Messages.FilterViewer_NumButtonText); + fNumButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + fNumButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (fNumButton.getSelection()) { + fNode.setType(Type.NUM); + } + fViewer.refresh(fNode); + } + }); + + fAlphaButton = new Button(typeGroup, SWT.RADIO); + fAlphaButton.setSelection(fNode.getType() == Type.ALPHA); + fAlphaButton.setText(Messages.FilterViewer_AlphaButtonText); + fAlphaButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + fAlphaButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (fAlphaButton.getSelection()) { + fNode.setType(Type.ALPHA); + } + fViewer.refresh(fNode); + } + }); + + fTimestampButton = new Button(typeGroup, SWT.RADIO); + fTimestampButton.setSelection(fNode.getType() == Type.TIMESTAMP); + fTimestampButton.setText(Messages.FilterViewer_TimestampButtonText); + fTimestampButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + fTimestampButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (fTimestampButton.getSelection()) { + fNode.setType(Type.TIMESTAMP); + } + fViewer.refresh(fNode); + } + }); + + label = new Label(this, SWT.NONE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + label.setText(Messages.FilterViewer_ValueLabel); + + fValueText = new Text(this, SWT.BORDER); + fValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + if (node.getValue() != null && node.getValue().length() > 0) { + fValueText.setText(node.getValue()); + } else { + fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); + fValueText.setText(Messages.FilterViewer_ValueHint); + } + fValueText.addFocusListener(new FocusListener() { + @Override + public void focusLost(FocusEvent e) { + if (fNode.getValue() == null || fNode.getValue().length() == 0) { + fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); + fValueText.setText(Messages.FilterViewer_ValueHint); + } + } + @Override + public void focusGained(FocusEvent e) { + if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { + fValueText.setText(""); //$NON-NLS-1$ + } + fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); + } + }); + fValueText.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + if (! fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { + fNode.setValue(fValueText.getText()); + fViewer.refresh(fNode); + } + } + }); + } + } + +} -- 2.34.1