From 8e4a4ad8f119dadd94951f4349e960c0fb41f970 Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Tue, 29 May 2012 16:42:08 -0400 Subject: [PATCH] Fix for bug 380961: Filter viewer not getting fields for CTF traces --- .../linuxtools/internal/tmf/ui/Messages.java | 2 + .../internal/tmf/ui/messages.properties | 2 + .../tmf/ui/views/filter/FilterViewer.java | 60 +++++++++++++++---- 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java index e70aa882b7..e367528427 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java @@ -237,6 +237,8 @@ public class Messages extends NLS { public static String FilterView_FileDialogFilterName; public static String FilterView_ImportActionToolTipText; public static String FilterView_SaveActionToolTipText; + public static String FilterViewer_EmptyTreeHintText; + public static String FilterViewer_CommonCategory; public static String FilterViewer_AlphaButtonText; public static String FilterViewer_DeleteActionText; public static String FilterViewer_FieldLabel; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties index 525db62243..20e0417031 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties @@ -240,6 +240,8 @@ FilterView_ExportActionToolTipText=Export filters FilterView_FileDialogFilterName=TMF Filter files FilterView_ImportActionToolTipText=Import filters FilterView_SaveActionToolTipText=Save filters +FilterViewer_EmptyTreeHintText= +FilterViewer_EmptyTreeHintText=[common] FilterViewer_AlphaButtonText=Alpha FilterViewer_DeleteActionText=Delete FilterViewer_FieldLabel=field: 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 index c611080d1d..7fb527de7d 100644 --- 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 @@ -49,6 +49,7 @@ import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterMatchesNode; import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode; import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterOrNode; import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode; +import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterTreeNode; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceType; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; @@ -56,6 +57,8 @@ 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.PaintEvent; +import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; @@ -118,6 +121,17 @@ class FilterViewer extends Composite { } } }); + + fViewer.getTree().addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + TmfFilterTreeNode root = (TmfFilterTreeNode) fViewer.getInput(); + if (root == null || root.getChildrenCount() == 0) { + e.gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); + e.gc.drawText(Messages.FilterViewer_EmptyTreeHintText, 5, 0); + } + } + }); } /** @@ -347,10 +361,17 @@ class FilterViewer extends Composite { } } catch (CoreException e) { } + if (fieldsList.size() == 0) { + fieldsList.add(ITmfEvent.EVENT_FIELD_TIMESTAMP); + fieldsList.add(ITmfEvent.EVENT_FIELD_SOURCE); + fieldsList.add(ITmfEvent.EVENT_FIELD_TYPE); + fieldsList.add(ITmfEvent.EVENT_FIELD_REFERENCE); + fieldsList.add(ITmfEvent.EVENT_FIELD_CONTENT); + } return fieldsList.toArray(new String[0]); } } - if (eventTypeNode.getEventType().startsWith(CustomTxtEvent.class.getCanonicalName())) { + if (eventTypeNode.getEventType() != null && eventTypeNode.getEventType().startsWith(CustomTxtEvent.class.getCanonicalName())) { for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { if (eventTypeNode.getEventType().equals(CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ for (OutputColumn output : def.outputs) { @@ -360,7 +381,7 @@ class FilterViewer extends Composite { } } } - if (eventTypeNode.getEventType().startsWith(CustomXmlEvent.class.getCanonicalName())) { + if (eventTypeNode.getEventType() != null && eventTypeNode.getEventType().startsWith(CustomXmlEvent.class.getCanonicalName())) { for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { if (eventTypeNode.getEventType().equals(CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ for (OutputColumn output : def.outputs) { @@ -373,11 +394,20 @@ class FilterViewer extends Composite { } node = node.getParent(); } + + fieldsList.add(Messages.FilterViewer_CommonCategory); + fieldsList.add(ITmfEvent.EVENT_FIELD_TIMESTAMP); + fieldsList.add(ITmfEvent.EVENT_FIELD_SOURCE); + fieldsList.add(ITmfEvent.EVENT_FIELD_TYPE); + fieldsList.add(ITmfEvent.EVENT_FIELD_REFERENCE); + fieldsList.add(ITmfEvent.EVENT_FIELD_CONTENT); + fieldsList.add(""); //$NON-NLS-1$ + for (IConfigurationElement ce : TmfTraceType.getTypeElements()) { try { ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR); ITmfEventType eventType = event.getType(); - if (eventType != null) { + if (eventType != null && eventType.getFieldNames().length > 0) { fieldsList.add("[" + TmfTraceType.getCategoryName(ce.getAttribute(TmfTraceType.CATEGORY_ATTR)) + //$NON-NLS-1$ " : " + ce.getAttribute(TmfTraceType.NAME_ATTR) + "]"); //$NON-NLS-1$ //$NON-NLS-2$ for (String field : eventType.getFieldNames()) { @@ -389,20 +419,24 @@ class FilterViewer extends Composite { } } for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { - fieldsList.add("[" + CUSTOM_TXT_CATEGORY + //$NON-NLS-1$ - " : " + def.definitionName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - for (OutputColumn output : def.outputs) { - fieldsList.add(output.name); + if (def.outputs.size() > 0) { + fieldsList.add("[" + CUSTOM_TXT_CATEGORY + //$NON-NLS-1$ + " : " + def.definitionName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ + for (OutputColumn output : def.outputs) { + fieldsList.add(output.name); + } + fieldsList.add(""); //$NON-NLS-1$ } - fieldsList.add(""); //$NON-NLS-1$ } for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { - fieldsList.add("[" + CUSTOM_XML_CATEGORY + //$NON-NLS-1$ - " : " + def.definitionName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - for (OutputColumn output : def.outputs) { - fieldsList.add(output.name); + if (def.outputs.size() > 0) { + fieldsList.add("[" + CUSTOM_XML_CATEGORY + //$NON-NLS-1$ + " : " + def.definitionName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ + for (OutputColumn output : def.outputs) { + fieldsList.add(output.name); + } + fieldsList.add(""); //$NON-NLS-1$ } - fieldsList.add(""); //$NON-NLS-1$ } return fieldsList.toArray(new String[0]); } -- 2.34.1