long logLevel = parseUnaryInteger((CommonTree) rightNode.getChild(0));
event.setLogLevel(logLevel);
} else {
- throw new ParseException("Unknown event attribute : " + left); //$NON-NLS-1$
+ /* Unknown event attribute, we'll simply ignore it */
+ // FIXME log this?
}
}
<?xml version="1.0" encoding="UTF-8"?>
-<site
- mirrorsURL="http://www.eclipse.org/downloads/download.php?file=/linuxtools/updates-nightly-juno/site.xml&format=xml">
- <description url="http://download.eclipse.org/linuxtools/updates-nightly-juno">
- Nightly builds of Linux Tools project.
+<site>
+ <description>
+ Nightly builds of LTTng project.
</description>
<feature url="features/org.eclipse.linuxtools.lttng2.kernel_0.0.0.qualifier.jar" id="org.eclipse.linuxtools.lttng2.kernel" version="0.0.0">
<category name="LTTng"/>
/* Sub-attributes of the CPU nodes */
public static final String CURRENT_THREAD = "Current_thread";
- public static final String STATUS = "Status";\r
+ public static final String STATUS = "Status";
/* Sub-attributes of the Thread nodes */
public static final String PPID = "PPID";
- //public static final String STATUS = "Status"\r
+ //public static final String STATUS = "Status"
public static final String EXEC_NAME = "Exec_name";
public static final String SYSTEM_CALL = "System_call";
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Francois Chouinard - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.lttng2.kernel.ui.viewers.events;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEventField;\r
-import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.widgets.Composite;\r
-\r
-/**\r
- * Events table specific for LTTng 2.0 kernel traces\r
- */\r
-public class LTTng2EventsTable extends TmfEventsTable {\r
-\r
- // ------------------------------------------------------------------------\r
- // Table data\r
- // ------------------------------------------------------------------------\r
-\r
- // Table column names\r
- static private final String TIMESTAMP_COLUMN = Messages.EventsTable_timestampColumn;\r
- static private final String CHANNEL_COLUMN = Messages.EventsTable_channelColumn;\r
- static private final String TYPE_COLUMN = Messages.EventsTable_typeColumn;\r
- static private final String CONTENT_COLUMN = Messages.EventsTable_contentColumn;\r
- static private final String[] COLUMN_NAMES = new String[] {\r
- TIMESTAMP_COLUMN,\r
- CHANNEL_COLUMN,\r
- TYPE_COLUMN,\r
- CONTENT_COLUMN\r
- };\r
-\r
- static private final ColumnData[] COLUMN_DATA = new ColumnData[] {\r
- new ColumnData(COLUMN_NAMES[0], 150, SWT.LEFT),\r
- new ColumnData(COLUMN_NAMES[1], 120, SWT.LEFT),\r
- new ColumnData(COLUMN_NAMES[2], 200, SWT.LEFT),\r
- new ColumnData(COLUMN_NAMES[3], 100, SWT.LEFT)\r
- };\r
-\r
- // ------------------------------------------------------------------------\r
- // Constructor\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Constructor\r
- *\r
- * @param parent\r
- * The parent composite\r
- * @param cacheSize\r
- * The size of the rows cache\r
- */\r
- public LTTng2EventsTable(Composite parent, int cacheSize) {\r
- super(parent, cacheSize, COLUMN_DATA);\r
- fTable.getColumns()[0].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_TIMESTAMP);\r
- fTable.getColumns()[1].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_REFERENCE);\r
- fTable.getColumns()[2].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_TYPE);\r
- fTable.getColumns()[3].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_CONTENT);\r
- }\r
-\r
- /**\r
- * @param event\r
- * @return\r
- */\r
- @Override\r
- protected ITmfEventField[] extractItemFields(ITmfEvent event) {\r
- ITmfEventField[] fields = new TmfEventField[0];\r
- if (event != null) {\r
- fields = new TmfEventField[] {\r
- new TmfEventField(ITmfEvent.EVENT_FIELD_TIMESTAMP, event.getTimestamp().toString()),\r
- new TmfEventField(ITmfEvent.EVENT_FIELD_REFERENCE, event.getReference()),\r
- new TmfEventField(ITmfEvent.EVENT_FIELD_TYPE, event.getType().getName()),\r
- new TmfEventField(ITmfEvent.EVENT_FIELD_CONTENT, event.getContent().toString())\r
- };\r
- }\r
- return fields;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.kernel.ui.viewers.events;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
+import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
+import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Events table specific for LTTng 2.0 kernel traces
+ */
+public class LTTng2EventsTable extends TmfEventsTable {
+
+ // ------------------------------------------------------------------------
+ // Table data
+ // ------------------------------------------------------------------------
+
+ // Table column names
+ static private final String TIMESTAMP_COLUMN = Messages.EventsTable_timestampColumn;
+ static private final String CHANNEL_COLUMN = Messages.EventsTable_channelColumn;
+ static private final String TYPE_COLUMN = Messages.EventsTable_typeColumn;
+ static private final String CONTENT_COLUMN = Messages.EventsTable_contentColumn;
+ static private final String[] COLUMN_NAMES = new String[] {
+ TIMESTAMP_COLUMN,
+ CHANNEL_COLUMN,
+ TYPE_COLUMN,
+ CONTENT_COLUMN
+ };
+
+ static private final ColumnData[] COLUMN_DATA = new ColumnData[] {
+ new ColumnData(COLUMN_NAMES[0], 150, SWT.LEFT),
+ new ColumnData(COLUMN_NAMES[1], 120, SWT.LEFT),
+ new ColumnData(COLUMN_NAMES[2], 200, SWT.LEFT),
+ new ColumnData(COLUMN_NAMES[3], 100, SWT.LEFT)
+ };
+
+ // ------------------------------------------------------------------------
+ // Constructor
+ // ------------------------------------------------------------------------
+
+ /**
+ * Constructor
+ *
+ * @param parent
+ * The parent composite
+ * @param cacheSize
+ * The size of the rows cache
+ */
+ public LTTng2EventsTable(Composite parent, int cacheSize) {
+ super(parent, cacheSize, COLUMN_DATA);
+ fTable.getColumns()[0].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_TIMESTAMP);
+ fTable.getColumns()[1].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_REFERENCE);
+ fTable.getColumns()[2].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_TYPE);
+ fTable.getColumns()[3].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_CONTENT);
+ }
+
+ /**
+ * @param event
+ * @return
+ */
+ @Override
+ protected ITmfEventField[] extractItemFields(ITmfEvent event) {
+ ITmfEventField[] fields = new TmfEventField[0];
+ if (event != null) {
+ fields = new TmfEventField[] {
+ new TmfEventField(ITmfEvent.EVENT_FIELD_TIMESTAMP, event.getTimestamp().toString()),
+ new TmfEventField(ITmfEvent.EVENT_FIELD_REFERENCE, event.getReference()),
+ new TmfEventField(ITmfEvent.EVENT_FIELD_TYPE, event.getType().getName()),
+ new TmfEventField(ITmfEvent.EVENT_FIELD_CONTENT, event.getContent().toString())
+ };
+ }
+ return fields;
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.common;\r
-\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.NoSuchElementException;\r
-\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;\r
-\r
-/**\r
- * An iterator for time events\r
- */\r
-public class EventIterator implements Iterator<ITimeEvent> {\r
-\r
- private final long fStartTime;\r
- private final long fEndTime;\r
- private List<ITimeEvent> fEventList;\r
- private List<ITimeEvent> fZoomedEventList;\r
- private long fZoomedStartTime;\r
- private long fZoomedEndTime;\r
- private int fIndex = 0;\r
- private int fZoomedIndex= 0;\r
- private ITimeEvent fNext = null;\r
- private ITimeEvent fZoomedNext = null;\r
-\r
- /**\r
- * Basic constructor, with start time and end times equal to the lowest and\r
- * highest values possible, respectively.\r
- *\r
- * @param eventList\r
- * The list on which this iterator will iterate\r
- * @param zoomedEventList\r
- * The "zoomed" list\r
- */\r
- public EventIterator(List<ITimeEvent> eventList, List<ITimeEvent> zoomedEventList) {\r
- this(eventList, zoomedEventList, Long.MIN_VALUE, Long.MAX_VALUE);\r
- }\r
-\r
- /**\r
- * Complete constructor, where we specify start and end times.\r
- *\r
- * @param eventList\r
- * The list on which this iterator will iterate\r
- * @param zoomedEventList\r
- * The "zoomed" list\r
- * @param startTime\r
- * The start time\r
- * @param endTime\r
- * The end time\r
- */\r
- public EventIterator(List<ITimeEvent> eventList,\r
- List<ITimeEvent> zoomedEventList, long startTime, long endTime) {\r
- fEventList = eventList;\r
- fZoomedEventList = zoomedEventList;\r
- if (zoomedEventList != null && zoomedEventList.size() > 0) {\r
- fZoomedStartTime = zoomedEventList.get(0).getTime();\r
- ITimeEvent lastEvent = zoomedEventList.get(zoomedEventList.size() - 1);\r
- fZoomedEndTime = lastEvent.getTime() + lastEvent.getDuration();\r
- } else {\r
- fZoomedStartTime = Long.MAX_VALUE;\r
- fZoomedEndTime = Long.MIN_VALUE;\r
- }\r
- fStartTime = startTime;\r
- fEndTime = endTime;\r
- }\r
-\r
- @Override\r
- public boolean hasNext() {\r
- if (fNext == null && fEventList != null) {\r
- while (fIndex < fEventList.size()) {\r
- ITimeEvent event = fEventList.get(fIndex++);\r
- if (event.getTime() + event.getDuration() >= fStartTime && event.getTime() <= fEndTime) {\r
- fNext = event;\r
- break;\r
- }\r
- }\r
- if (fNext == null) {\r
- fEventList = null;\r
- }\r
- }\r
-\r
- if (fZoomedNext == null && fZoomedEventList != null) {\r
- while (fZoomedIndex < fZoomedEventList.size()) {\r
- ITimeEvent event = fZoomedEventList.get(fZoomedIndex++);\r
- if (event.getTime() + event.getDuration() >= fStartTime && event.getTime() <= fEndTime) {\r
- fZoomedNext = event;\r
- break;\r
- }\r
- }\r
- if (fZoomedNext == null) {\r
- fZoomedEventList = null;\r
- }\r
- }\r
-\r
- return fNext != null || fZoomedNext != null;\r
- }\r
-\r
- @Override\r
- public ITimeEvent next() {\r
- if (hasNext()) {\r
- if (fZoomedNext != null && (fNext == null || fZoomedNext.getTime() <= fNext.getTime())) {\r
- if (fNext != null && fNext.getTime() == fZoomedNext.getTime()) {\r
- long duration = fNext.getTime() + fNext.getDuration() - fZoomedEndTime;\r
- if (duration > 0) {\r
- fNext = new TimeEvent(fNext.getEntry(), fZoomedEndTime, duration);\r
- } else {\r
- fNext = null;\r
- }\r
- }\r
- ITimeEvent event = fZoomedNext;\r
- fZoomedNext = null;\r
- return event;\r
- }\r
- if (fNext.getTime() < fZoomedEndTime && fNext.getTime() + fNext.getDuration() > fZoomedStartTime) {\r
- ITimeEvent event = new TimeEvent(fNext.getEntry(), fNext.getTime(), fZoomedStartTime - fNext.getTime());\r
- long duration = fNext.getTime() + fNext.getDuration() - fZoomedEndTime;\r
- if (duration > 0) {\r
- fNext = new TimeEvent(fNext.getEntry(), fZoomedEndTime, duration);\r
- } else {\r
- fNext = null;\r
- }\r
- return event;\r
- }\r
- ITimeEvent event = fNext;\r
- fNext = null;\r
- return event;\r
- }\r
- throw new NoSuchElementException();\r
- }\r
-\r
- @Override\r
- public void remove() {\r
- throw new UnsupportedOperationException();\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.common;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;
+
+/**
+ * An iterator for time events
+ */
+public class EventIterator implements Iterator<ITimeEvent> {
+
+ private final long fStartTime;
+ private final long fEndTime;
+ private List<ITimeEvent> fEventList;
+ private List<ITimeEvent> fZoomedEventList;
+ private long fZoomedStartTime;
+ private long fZoomedEndTime;
+ private int fIndex = 0;
+ private int fZoomedIndex= 0;
+ private ITimeEvent fNext = null;
+ private ITimeEvent fZoomedNext = null;
+
+ /**
+ * Basic constructor, with start time and end times equal to the lowest and
+ * highest values possible, respectively.
+ *
+ * @param eventList
+ * The list on which this iterator will iterate
+ * @param zoomedEventList
+ * The "zoomed" list
+ */
+ public EventIterator(List<ITimeEvent> eventList, List<ITimeEvent> zoomedEventList) {
+ this(eventList, zoomedEventList, Long.MIN_VALUE, Long.MAX_VALUE);
+ }
+
+ /**
+ * Complete constructor, where we specify start and end times.
+ *
+ * @param eventList
+ * The list on which this iterator will iterate
+ * @param zoomedEventList
+ * The "zoomed" list
+ * @param startTime
+ * The start time
+ * @param endTime
+ * The end time
+ */
+ public EventIterator(List<ITimeEvent> eventList,
+ List<ITimeEvent> zoomedEventList, long startTime, long endTime) {
+ fEventList = eventList;
+ fZoomedEventList = zoomedEventList;
+ if (zoomedEventList != null && zoomedEventList.size() > 0) {
+ fZoomedStartTime = zoomedEventList.get(0).getTime();
+ ITimeEvent lastEvent = zoomedEventList.get(zoomedEventList.size() - 1);
+ fZoomedEndTime = lastEvent.getTime() + lastEvent.getDuration();
+ } else {
+ fZoomedStartTime = Long.MAX_VALUE;
+ fZoomedEndTime = Long.MIN_VALUE;
+ }
+ fStartTime = startTime;
+ fEndTime = endTime;
+ }
+
+ @Override
+ public boolean hasNext() {
+ if (fNext == null && fEventList != null) {
+ while (fIndex < fEventList.size()) {
+ ITimeEvent event = fEventList.get(fIndex++);
+ if (event.getTime() + event.getDuration() >= fStartTime && event.getTime() <= fEndTime) {
+ fNext = event;
+ break;
+ }
+ }
+ if (fNext == null) {
+ fEventList = null;
+ }
+ }
+
+ if (fZoomedNext == null && fZoomedEventList != null) {
+ while (fZoomedIndex < fZoomedEventList.size()) {
+ ITimeEvent event = fZoomedEventList.get(fZoomedIndex++);
+ if (event.getTime() + event.getDuration() >= fStartTime && event.getTime() <= fEndTime) {
+ fZoomedNext = event;
+ break;
+ }
+ }
+ if (fZoomedNext == null) {
+ fZoomedEventList = null;
+ }
+ }
+
+ return fNext != null || fZoomedNext != null;
+ }
+
+ @Override
+ public ITimeEvent next() {
+ if (hasNext()) {
+ if (fZoomedNext != null && (fNext == null || fZoomedNext.getTime() <= fNext.getTime())) {
+ if (fNext != null && fNext.getTime() == fZoomedNext.getTime()) {
+ long duration = fNext.getTime() + fNext.getDuration() - fZoomedEndTime;
+ if (duration > 0) {
+ fNext = new TimeEvent(fNext.getEntry(), fZoomedEndTime, duration);
+ } else {
+ fNext = null;
+ }
+ }
+ ITimeEvent event = fZoomedNext;
+ fZoomedNext = null;
+ return event;
+ }
+ if (fNext.getTime() < fZoomedEndTime && fNext.getTime() + fNext.getDuration() > fZoomedStartTime) {
+ ITimeEvent event = new TimeEvent(fNext.getEntry(), fNext.getTime(), fZoomedStartTime - fNext.getTime());
+ long duration = fNext.getTime() + fNext.getDuration() - fZoomedEndTime;
+ if (duration > 0) {
+ fNext = new TimeEvent(fNext.getEntry(), fZoomedEndTime, duration);
+ } else {
+ fNext = null;
+ }
+ return event;
+ }
+ ITimeEvent event = fNext;
+ fNext = null;
+ return event;
+ }
+ throw new NoSuchElementException();
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.common.EventIterator;\r
-import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-\r
-/**\r
- * An entry in the Control Flow view\r
- */\r
-public class ControlFlowEntry implements ITimeGraphEntry {\r
- private final int fThreadQuark;\r
- private final CtfKernelTrace fTrace;\r
- private ControlFlowEntry fParent = null;\r
- private final ArrayList<ControlFlowEntry> fChildren = new ArrayList<ControlFlowEntry>();\r
- private final String fName;\r
- private final int fThreadId;\r
- private final int fParentThreadId;\r
- private long fBirthTime = -1;\r
- private long fStartTime = -1;\r
- private long fEndTime = -1;\r
- private List<ITimeEvent> fEventList = new ArrayList<ITimeEvent>();\r
- private List<ITimeEvent> fZoomedEventList = null;\r
-\r
- /**\r
- * Constructor\r
- *\r
- * @param threadQuark\r
- * The attribute quark matching the thread\r
- * @param trace\r
- * The trace on which we are working\r
- * @param execName\r
- * The exec_name of this entry\r
- * @param threadId\r
- * The TID of the thread\r
- * @param parentThreadId\r
- * the Parent_TID of this thread\r
- * @param birthTime\r
- * The birth time of this entry (this allows separating different\r
- * process that could have the same TID)\r
- * @param startTime\r
- * The start time of this process's lifetime\r
- * @param endTime\r
- * The end time of this process\r
- */\r
- public ControlFlowEntry(int threadQuark, CtfKernelTrace trace, String execName, int threadId, int parentThreadId, long birthTime, long startTime, long endTime) {\r
- fThreadQuark = threadQuark;\r
- fTrace = trace;\r
- fName = execName;\r
- fThreadId = threadId;\r
- fParentThreadId = parentThreadId;\r
- fBirthTime = birthTime;\r
- fStartTime = startTime;\r
- fEndTime = endTime;\r
- }\r
-\r
- @Override\r
- public ITimeGraphEntry getParent() {\r
- return fParent;\r
- }\r
-\r
- @Override\r
- public boolean hasChildren() {\r
- return fChildren != null && fChildren.size() > 0;\r
- }\r
-\r
- @Override\r
- public ControlFlowEntry[] getChildren() {\r
- return fChildren.toArray(new ControlFlowEntry[0]);\r
- }\r
-\r
- @Override\r
- public String getName() {\r
- return fName;\r
- }\r
-\r
- @Override\r
- public long getStartTime() {\r
- return fStartTime;\r
- }\r
-\r
- @Override\r
- public long getEndTime() {\r
- return fEndTime;\r
- }\r
-\r
- @Override\r
- public boolean hasTimeEvents() {\r
- return true;\r
- }\r
-\r
- @Override\r
- public Iterator<ITimeEvent> getTimeEventsIterator() {\r
- return new EventIterator(fEventList, fZoomedEventList);\r
- }\r
-\r
- @Override\r
- public Iterator<ITimeEvent> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration) {\r
- return new EventIterator(fEventList, fZoomedEventList, startTime, stopTime);\r
- }\r
-\r
- /**\r
- * Get the quark of the attribute matching this thread's TID\r
- *\r
- * @return The quark\r
- */\r
- public int getThreadQuark() {\r
- return fThreadQuark;\r
- }\r
-\r
- /**\r
- * Get the CTF trace object\r
- *\r
- * @return The trace\r
- */\r
- public CtfKernelTrace getTrace() {\r
- return fTrace;\r
- }\r
-\r
- /**\r
- * Get this entry's thread ID\r
- *\r
- * @return The TID\r
- */\r
- public int getThreadId() {\r
- return fThreadId;\r
- }\r
-\r
- /**\r
- * Get this thread's parent TID\r
- *\r
- * @return The "PTID"\r
- */\r
- public int getParentThreadId() {\r
- return fParentThreadId;\r
- }\r
-\r
- /**\r
- * Get the birth time of this entry/process\r
- *\r
- * @return The birth time\r
- */\r
- public long getBirthTime() {\r
- return fBirthTime;\r
- }\r
-\r
- /**\r
- * Add an event to this process's timeline\r
- *\r
- * @param event\r
- * The time event\r
- */\r
- public void addEvent(ITimeEvent event) {\r
- long start = event.getTime();\r
- long end = start + event.getDuration();\r
- synchronized (fEventList) {\r
- fEventList.add(event);\r
- if (fStartTime == -1 || start < fStartTime) {\r
- fStartTime = start;\r
- }\r
- if (fEndTime == -1 || end > fEndTime) {\r
- fEndTime = end;\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Set the general event list of this entry\r
- *\r
- * @param eventList\r
- * The list of time events\r
- */\r
- public void setEventList(List<ITimeEvent> eventList) {\r
- fEventList = eventList;\r
- }\r
-\r
- /**\r
- * Set the zoomed event list of this entry\r
- *\r
- * @param eventList\r
- * The list of time events\r
- */\r
- public void setZoomedEventList(List<ITimeEvent> eventList) {\r
- fZoomedEventList = eventList;\r
- }\r
-\r
- /**\r
- * Add a child entry to this one (to show relationships between processes as\r
- * a tree)\r
- *\r
- * @param child\r
- * The child entry\r
- */\r
- public void addChild(ControlFlowEntry child) {\r
- child.fParent = this;\r
- fChildren.add(child);\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.common.EventIterator;
+import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+
+/**
+ * An entry in the Control Flow view
+ */
+public class ControlFlowEntry implements ITimeGraphEntry {
+ private final int fThreadQuark;
+ private final CtfKernelTrace fTrace;
+ private ControlFlowEntry fParent = null;
+ private final ArrayList<ControlFlowEntry> fChildren = new ArrayList<ControlFlowEntry>();
+ private final String fName;
+ private final int fThreadId;
+ private final int fParentThreadId;
+ private long fBirthTime = -1;
+ private long fStartTime = -1;
+ private long fEndTime = -1;
+ private List<ITimeEvent> fEventList = new ArrayList<ITimeEvent>();
+ private List<ITimeEvent> fZoomedEventList = null;
+
+ /**
+ * Constructor
+ *
+ * @param threadQuark
+ * The attribute quark matching the thread
+ * @param trace
+ * The trace on which we are working
+ * @param execName
+ * The exec_name of this entry
+ * @param threadId
+ * The TID of the thread
+ * @param parentThreadId
+ * the Parent_TID of this thread
+ * @param birthTime
+ * The birth time of this entry (this allows separating different
+ * process that could have the same TID)
+ * @param startTime
+ * The start time of this process's lifetime
+ * @param endTime
+ * The end time of this process
+ */
+ public ControlFlowEntry(int threadQuark, CtfKernelTrace trace, String execName, int threadId, int parentThreadId, long birthTime, long startTime, long endTime) {
+ fThreadQuark = threadQuark;
+ fTrace = trace;
+ fName = execName;
+ fThreadId = threadId;
+ fParentThreadId = parentThreadId;
+ fBirthTime = birthTime;
+ fStartTime = startTime;
+ fEndTime = endTime;
+ }
+
+ @Override
+ public ITimeGraphEntry getParent() {
+ return fParent;
+ }
+
+ @Override
+ public boolean hasChildren() {
+ return fChildren != null && fChildren.size() > 0;
+ }
+
+ @Override
+ public ControlFlowEntry[] getChildren() {
+ return fChildren.toArray(new ControlFlowEntry[0]);
+ }
+
+ @Override
+ public String getName() {
+ return fName;
+ }
+
+ @Override
+ public long getStartTime() {
+ return fStartTime;
+ }
+
+ @Override
+ public long getEndTime() {
+ return fEndTime;
+ }
+
+ @Override
+ public boolean hasTimeEvents() {
+ return true;
+ }
+
+ @Override
+ public Iterator<ITimeEvent> getTimeEventsIterator() {
+ return new EventIterator(fEventList, fZoomedEventList);
+ }
+
+ @Override
+ public Iterator<ITimeEvent> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration) {
+ return new EventIterator(fEventList, fZoomedEventList, startTime, stopTime);
+ }
+
+ /**
+ * Get the quark of the attribute matching this thread's TID
+ *
+ * @return The quark
+ */
+ public int getThreadQuark() {
+ return fThreadQuark;
+ }
+
+ /**
+ * Get the CTF trace object
+ *
+ * @return The trace
+ */
+ public CtfKernelTrace getTrace() {
+ return fTrace;
+ }
+
+ /**
+ * Get this entry's thread ID
+ *
+ * @return The TID
+ */
+ public int getThreadId() {
+ return fThreadId;
+ }
+
+ /**
+ * Get this thread's parent TID
+ *
+ * @return The "PTID"
+ */
+ public int getParentThreadId() {
+ return fParentThreadId;
+ }
+
+ /**
+ * Get the birth time of this entry/process
+ *
+ * @return The birth time
+ */
+ public long getBirthTime() {
+ return fBirthTime;
+ }
+
+ /**
+ * Add an event to this process's timeline
+ *
+ * @param event
+ * The time event
+ */
+ public void addEvent(ITimeEvent event) {
+ long start = event.getTime();
+ long end = start + event.getDuration();
+ synchronized (fEventList) {
+ fEventList.add(event);
+ if (fStartTime == -1 || start < fStartTime) {
+ fStartTime = start;
+ }
+ if (fEndTime == -1 || end > fEndTime) {
+ fEndTime = end;
+ }
+ }
+ }
+
+ /**
+ * Set the general event list of this entry
+ *
+ * @param eventList
+ * The list of time events
+ */
+ public void setEventList(List<ITimeEvent> eventList) {
+ fEventList = eventList;
+ }
+
+ /**
+ * Set the zoomed event list of this entry
+ *
+ * @param eventList
+ * The list of time events
+ */
+ public void setZoomedEventList(List<ITimeEvent> eventList) {
+ fZoomedEventList = eventList;
+ }
+
+ /**
+ * Add a child entry to this one (to show relationships between processes as
+ * a tree)
+ *
+ * @param child
+ * The child entry
+ */
+ public void addChild(ControlFlowEntry child) {
+ child.fParent = this;
+ fChildren.add(child);
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow;\r
-\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;\r
-\r
-/**\r
- * Time Event specific to the control flow view\r
- */\r
-public class ControlFlowEvent extends TimeEvent {\r
-\r
- private final int fStatus;\r
-\r
- /**\r
- * Constructor\r
- *\r
- * @param entry\r
- * The entry to which this time event is assigned\r
- * @param time\r
- * The timestamp of this event\r
- * @param duration\r
- * The duration of this event\r
- * @param status\r
- * The status assigned to the event\r
- */\r
- public ControlFlowEvent(ITimeGraphEntry entry, long time, long duration,\r
- int status) {\r
- super(entry, time, duration);\r
- fStatus = status;\r
- }\r
-\r
- /**\r
- * Get this event's status\r
- *\r
- * @return The integer matching this status\r
- */\r
- public int getStatus() {\r
- return fStatus;\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow;
+
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;
+
+/**
+ * Time Event specific to the control flow view
+ */
+public class ControlFlowEvent extends TimeEvent {
+
+ private final int fStatus;
+
+ /**
+ * Constructor
+ *
+ * @param entry
+ * The entry to which this time event is assigned
+ * @param time
+ * The timestamp of this event
+ * @param duration
+ * The duration of this event
+ * @param status
+ * The status assigned to the event
+ */
+ public ControlFlowEvent(ITimeGraphEntry entry, long time, long duration,
+ int status) {
+ super(entry, time, duration);
+ fStatus = status;
+ }
+
+ /**
+ * Get this event's status
+ *
+ * @return The integer matching this status
+ */
+ public int getStatus() {
+ return fStatus;
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow;\r
-\r
-import java.util.LinkedHashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues;\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;\r
-import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;\r
-import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;\r
-import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.swt.graphics.RGB;\r
-\r
-/**\r
- * Presentation provider for the control flow view\r
- */\r
-public class ControlFlowPresentationProvider extends TimeGraphPresentationProvider {\r
-\r
- private enum State {\r
- UNKNOWN (new RGB(100, 100, 100)),\r
- WAIT (new RGB(200, 200, 0)),\r
- USERMODE (new RGB(0, 200, 0)),\r
- SYSCALL (new RGB(0, 0, 200)),\r
- INTERRUPTED (new RGB(200, 100, 100));\r
-\r
- public final RGB rgb;\r
-\r
- private State (RGB rgb) {\r
- this.rgb = rgb;\r
- }\r
- }\r
-\r
- @Override\r
- public String getStateTypeName() {\r
- return Messages.ControlFlowView_stateTypeName;\r
- }\r
-\r
- @Override\r
- public StateItem[] getStateTable() {\r
- StateItem[] stateTable = new StateItem[State.values().length];\r
- for (int i = 0; i < stateTable.length; i++) {\r
- State state = State.values()[i];\r
- stateTable[i] = new StateItem(state.rgb, state.toString());\r
- }\r
- return stateTable;\r
- }\r
-\r
- @Override\r
- public int getStateTableIndex(ITimeEvent event) {\r
- if (event instanceof ControlFlowEvent) {\r
- int status = ((ControlFlowEvent) event).getStatus();\r
- if (status == StateValues.PROCESS_STATUS_WAIT) {\r
- return State.WAIT.ordinal();\r
- } else if (status == StateValues.PROCESS_STATUS_RUN_USERMODE) {\r
- return State.USERMODE.ordinal();\r
- } else if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {\r
- return State.SYSCALL.ordinal();\r
- } else if (status == StateValues.PROCESS_STATUS_INTERRUPTED) {\r
- return State.INTERRUPTED.ordinal();\r
- }\r
- }\r
- return State.UNKNOWN.ordinal();\r
- }\r
-\r
- @Override\r
- public String getEventName(ITimeEvent event) {\r
- if (event instanceof ControlFlowEvent) {\r
- int status = ((ControlFlowEvent) event).getStatus();\r
- if (status == StateValues.PROCESS_STATUS_WAIT) {\r
- return State.WAIT.toString();\r
- } else if (status == StateValues.PROCESS_STATUS_RUN_USERMODE) {\r
- return State.USERMODE.toString();\r
- } else if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {\r
- return State.SYSCALL.toString();\r
- } else if (status == StateValues.PROCESS_STATUS_INTERRUPTED) {\r
- return State.INTERRUPTED.toString();\r
- }\r
- }\r
- return State.UNKNOWN.toString();\r
- }\r
-\r
- @Override\r
- public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) {\r
- Map<String, String> retMap = new LinkedHashMap<String, String>();\r
- if (event instanceof ControlFlowEvent) {\r
- ControlFlowEntry entry = (ControlFlowEntry) event.getEntry();\r
- IStateSystemQuerier ssq = entry.getTrace().getStateSystem();\r
- int tid = entry.getThreadId();\r
-\r
- try {\r
- //Find every CPU first, then get the current thread\r
- int cpusQuark = ssq.getQuarkAbsolute(Attributes.CPUS);\r
- List<Integer> cpuQuarks = ssq.getSubAttributes(cpusQuark, false);\r
- for (Integer cpuQuark : cpuQuarks) {\r
- int currentThreadQuark = ssq.getQuarkRelative(cpuQuark, Attributes.CURRENT_THREAD);\r
- ITmfStateInterval interval = ssq.querySingleState(event.getTime(), currentThreadQuark);\r
- if (!interval.getStateValue().isNull()) {\r
- ITmfStateValue state = interval.getStateValue();\r
- int currentThreadId = state.unboxInt();\r
- if (tid == currentThreadId) {\r
- retMap.put(Messages.ControlFlowView_attributeCpuName, ssq.getAttributeName(cpuQuark));\r
- break;\r
- }\r
- }\r
- }\r
-\r
- } catch (AttributeNotFoundException e) {\r
- e.printStackTrace();\r
- } catch (TimeRangeException e) {\r
- e.printStackTrace();\r
- } catch (StateValueTypeException e) {\r
- e.printStackTrace();\r
- }\r
- int status = ((ControlFlowEvent) event).getStatus();\r
- if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {\r
- try {\r
- int syscallQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.SYSTEM_CALL);\r
- ITmfStateInterval value = ssq.querySingleState(event.getTime(), syscallQuark);\r
- if (!value.getStateValue().isNull()) {\r
- ITmfStateValue state = value.getStateValue();\r
- retMap.put(Messages.ControlFlowView_attributeSyscallName, state.toString());\r
- }\r
-\r
- } catch (AttributeNotFoundException e) {\r
- e.printStackTrace();\r
- } catch (TimeRangeException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- }\r
-\r
- return retMap;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
+import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues;
+import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;
+import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
+import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
+import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
+import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
+import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;
+import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.swt.graphics.RGB;
+
+/**
+ * Presentation provider for the control flow view
+ */
+public class ControlFlowPresentationProvider extends TimeGraphPresentationProvider {
+
+ private enum State {
+ UNKNOWN (new RGB(100, 100, 100)),
+ WAIT (new RGB(200, 200, 0)),
+ USERMODE (new RGB(0, 200, 0)),
+ SYSCALL (new RGB(0, 0, 200)),
+ INTERRUPTED (new RGB(200, 100, 100));
+
+ public final RGB rgb;
+
+ private State (RGB rgb) {
+ this.rgb = rgb;
+ }
+ }
+
+ @Override
+ public String getStateTypeName() {
+ return Messages.ControlFlowView_stateTypeName;
+ }
+
+ @Override
+ public StateItem[] getStateTable() {
+ StateItem[] stateTable = new StateItem[State.values().length];
+ for (int i = 0; i < stateTable.length; i++) {
+ State state = State.values()[i];
+ stateTable[i] = new StateItem(state.rgb, state.toString());
+ }
+ return stateTable;
+ }
+
+ @Override
+ public int getStateTableIndex(ITimeEvent event) {
+ if (event instanceof ControlFlowEvent) {
+ int status = ((ControlFlowEvent) event).getStatus();
+ if (status == StateValues.PROCESS_STATUS_WAIT) {
+ return State.WAIT.ordinal();
+ } else if (status == StateValues.PROCESS_STATUS_RUN_USERMODE) {
+ return State.USERMODE.ordinal();
+ } else if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {
+ return State.SYSCALL.ordinal();
+ } else if (status == StateValues.PROCESS_STATUS_INTERRUPTED) {
+ return State.INTERRUPTED.ordinal();
+ }
+ }
+ return State.UNKNOWN.ordinal();
+ }
+
+ @Override
+ public String getEventName(ITimeEvent event) {
+ if (event instanceof ControlFlowEvent) {
+ int status = ((ControlFlowEvent) event).getStatus();
+ if (status == StateValues.PROCESS_STATUS_WAIT) {
+ return State.WAIT.toString();
+ } else if (status == StateValues.PROCESS_STATUS_RUN_USERMODE) {
+ return State.USERMODE.toString();
+ } else if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {
+ return State.SYSCALL.toString();
+ } else if (status == StateValues.PROCESS_STATUS_INTERRUPTED) {
+ return State.INTERRUPTED.toString();
+ }
+ }
+ return State.UNKNOWN.toString();
+ }
+
+ @Override
+ public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) {
+ Map<String, String> retMap = new LinkedHashMap<String, String>();
+ if (event instanceof ControlFlowEvent) {
+ ControlFlowEntry entry = (ControlFlowEntry) event.getEntry();
+ IStateSystemQuerier ssq = entry.getTrace().getStateSystem();
+ int tid = entry.getThreadId();
+
+ try {
+ //Find every CPU first, then get the current thread
+ int cpusQuark = ssq.getQuarkAbsolute(Attributes.CPUS);
+ List<Integer> cpuQuarks = ssq.getSubAttributes(cpusQuark, false);
+ for (Integer cpuQuark : cpuQuarks) {
+ int currentThreadQuark = ssq.getQuarkRelative(cpuQuark, Attributes.CURRENT_THREAD);
+ ITmfStateInterval interval = ssq.querySingleState(event.getTime(), currentThreadQuark);
+ if (!interval.getStateValue().isNull()) {
+ ITmfStateValue state = interval.getStateValue();
+ int currentThreadId = state.unboxInt();
+ if (tid == currentThreadId) {
+ retMap.put(Messages.ControlFlowView_attributeCpuName, ssq.getAttributeName(cpuQuark));
+ break;
+ }
+ }
+ }
+
+ } catch (AttributeNotFoundException e) {
+ e.printStackTrace();
+ } catch (TimeRangeException e) {
+ e.printStackTrace();
+ } catch (StateValueTypeException e) {
+ e.printStackTrace();
+ }
+ int status = ((ControlFlowEvent) event).getStatus();
+ if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {
+ try {
+ int syscallQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.SYSTEM_CALL);
+ ITmfStateInterval value = ssq.querySingleState(event.getTime(), syscallQuark);
+ if (!value.getStateValue().isNull()) {
+ ITmfStateValue state = value.getStateValue();
+ retMap.put(Messages.ControlFlowView_attributeSyscallName, state.toString());
+ }
+
+ } catch (AttributeNotFoundException e) {
+ e.printStackTrace();
+ } catch (TimeRangeException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ return retMap;
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.Collections;\r
-import java.util.Comparator;\r
-import java.util.List;\r
-\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.core.runtime.NullProgressMonitor;\r
-import org.eclipse.jface.action.Action;\r
-import org.eclipse.jface.action.IToolBarManager;\r
-import org.eclipse.jface.action.Separator;\r
-import org.eclipse.jface.viewers.ILabelProviderListener;\r
-import org.eclipse.jface.viewers.ITableLabelProvider;\r
-import org.eclipse.jface.viewers.ITreeContentProvider;\r
-import org.eclipse.jface.viewers.Viewer;\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;\r
-import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;\r
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;\r
-import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfStateSystemBuildCompleted;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;\r
-import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;\r
-import org.eclipse.linuxtools.tmf.ui.views.TmfView;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphSelectionListener;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphCombo;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphSelectionEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.graphics.Image;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.TreeColumn;\r
-import org.eclipse.ui.IActionBars;\r
-\r
-/**\r
- * The Control Flow view main object\r
- *\r
- */\r
-public class ControlFlowView extends TmfView {\r
-\r
- // ------------------------------------------------------------------------\r
- // Constants\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * View ID.\r
- */\r
- public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.controlflow"; //$NON-NLS-1$\r
-\r
- /**\r
- * Initial time range\r
- */\r
- private static final long INITIAL_WINDOW_OFFSET = (1L * 100 * 1000 * 1000); // .1sec\r
-\r
- private static final String PROCESS_COLUMN = Messages.ControlFlowView_processColumn;\r
- private static final String TID_COLUMN = Messages.ControlFlowView_tidColumn;\r
- private static final String PTID_COLUMN = Messages.ControlFlowView_ptidColumn;\r
- private static final String BIRTH_TIME_COLUMN = Messages.ControlFlowView_birthTimeColumn;\r
- private static final String TRACE_COLUMN = Messages.ControlFlowView_traceColumn;\r
-\r
- private final String[] COLUMN_NAMES = new String[] {\r
- PROCESS_COLUMN,\r
- TID_COLUMN,\r
- PTID_COLUMN,\r
- BIRTH_TIME_COLUMN,\r
- TRACE_COLUMN\r
- };\r
-\r
- /**\r
- * Redraw state enum\r
- */\r
- private enum State { IDLE, BUSY, PENDING }\r
-\r
- // ------------------------------------------------------------------------\r
- // Fields\r
- // ------------------------------------------------------------------------\r
-\r
- // The timegraph combo\r
- private TimeGraphCombo fTimeGraphCombo;\r
-\r
- // The selected experiment\r
- private TmfExperiment fSelectedExperiment;\r
-\r
- // The timegraph entry list\r
- private ArrayList<ControlFlowEntry> fEntryList;\r
-\r
- // The time graph entry list synchronization object\r
- final private Object fEntryListSyncObj = new Object();\r
-\r
- // The start time\r
- private long fStartTime;\r
-\r
- // The end time\r
- private long fEndTime;\r
-\r
- // The display width\r
- private final int fDisplayWidth;\r
-\r
- // The zoom thread\r
- private ZoomThread fZoomThread;\r
-\r
- // The next resource action\r
- private Action fNextResourceAction;\r
-\r
- // The previous resource action\r
- private Action fPreviousResourceAction;\r
-\r
- // A comparator class\r
- private final ControlFlowEntryComparator fControlFlowEntryComparator = new ControlFlowEntryComparator();\r
-\r
- // The redraw state used to prevent unnecessary queuing of display runnables\r
- private State fRedrawState = State.IDLE;\r
-\r
- // The redraw synchronization object\r
- final private Object fSyncObj = new Object();\r
-\r
- // ------------------------------------------------------------------------\r
- // Classes\r
- // ------------------------------------------------------------------------\r
-\r
- private class TreeContentProvider implements ITreeContentProvider {\r
-\r
- @Override\r
- public void dispose() {\r
- }\r
-\r
- @Override\r
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {\r
- }\r
-\r
- @Override\r
- public Object[] getElements(Object inputElement) {\r
- return (ITimeGraphEntry[]) inputElement;\r
- }\r
-\r
- @Override\r
- public Object[] getChildren(Object parentElement) {\r
- ITimeGraphEntry entry = (ITimeGraphEntry) parentElement;\r
- return entry.getChildren();\r
- }\r
-\r
- @Override\r
- public Object getParent(Object element) {\r
- ITimeGraphEntry entry = (ITimeGraphEntry) element;\r
- return entry.getParent();\r
- }\r
-\r
- @Override\r
- public boolean hasChildren(Object element) {\r
- ITimeGraphEntry entry = (ITimeGraphEntry) element;\r
- return entry.hasChildren();\r
- }\r
-\r
- }\r
-\r
- private class TreeLabelProvider implements ITableLabelProvider {\r
-\r
- @Override\r
- public void addListener(ILabelProviderListener listener) {\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- }\r
-\r
- @Override\r
- public boolean isLabelProperty(Object element, String property) {\r
- return false;\r
- }\r
-\r
- @Override\r
- public void removeListener(ILabelProviderListener listener) {\r
- }\r
-\r
- @Override\r
- public Image getColumnImage(Object element, int columnIndex) {\r
- return null;\r
- }\r
-\r
- @Override\r
- public String getColumnText(Object element, int columnIndex) {\r
- ControlFlowEntry entry = (ControlFlowEntry) element;\r
- if (columnIndex == 0) {\r
- return entry.getName();\r
- } else if (columnIndex == 1) {\r
- return Integer.toString(entry.getThreadId());\r
- } else if (columnIndex == 2) {\r
- if (entry.getParentThreadId() > 0) {\r
- return Integer.toString(entry.getParentThreadId());\r
- }\r
- } else if (columnIndex == 3) {\r
- return Utils.formatTime(entry.getBirthTime(), TimeFormat.ABSOLUTE, Resolution.NANOSEC);\r
- } else if (columnIndex == 4) {\r
- return entry.getTrace().getName();\r
- }\r
- return ""; //$NON-NLS-1$\r
- }\r
-\r
- }\r
-\r
- private static class ControlFlowEntryComparator implements Comparator<ITimeGraphEntry> {\r
-\r
- @Override\r
- public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {\r
- int result = 0;\r
-\r
- if ((o1 instanceof ControlFlowEntry) && (o2 instanceof ControlFlowEntry)) {\r
- ControlFlowEntry entry1 = (ControlFlowEntry) o1;\r
- ControlFlowEntry entry2 = (ControlFlowEntry) o2;\r
- result = entry1.getTrace().getStartTime().compareTo(entry2.getTrace().getStartTime());\r
- if (result == 0) {\r
- result = entry1.getTrace().getName().compareTo(entry2.getTrace().getName());\r
- }\r
- if (result == 0) {\r
- result = entry1.getThreadId() < entry2.getThreadId() ? -1 : entry1.getThreadId() > entry2.getThreadId() ? 1 : 0;\r
- }\r
- }\r
-\r
- if (result == 0) {\r
- result = o1.getStartTime() < o2.getStartTime() ? -1 : o1.getStartTime() > o2.getStartTime() ? 1 : 0;\r
- }\r
-\r
- return result;\r
- }\r
- }\r
-\r
-\r
- private class ZoomThread extends Thread {\r
- private final long fZoomStartTime;\r
- private final long fZoomEndTime;\r
- private final long fResolution;\r
- private final IProgressMonitor fMonitor;\r
-\r
- public ZoomThread(long startTime, long endTime) {\r
- super("ControlFlowView zoom"); //$NON-NLS-1$\r
- fZoomStartTime = startTime;\r
- fZoomEndTime = endTime;\r
- fResolution = Math.max(1, (fZoomEndTime - fZoomStartTime) / fDisplayWidth);\r
- fMonitor = new NullProgressMonitor();\r
- }\r
-\r
- @Override\r
- public void run() {\r
- ArrayList<ControlFlowEntry> entryList = null;\r
- synchronized (fEntryListSyncObj) {\r
- entryList = (ArrayList<ControlFlowEntry>) fEntryList.clone();\r
- }\r
- if (entryList == null) {\r
- return;\r
- }\r
- for (ControlFlowEntry entry : entryList) {\r
- if (fMonitor.isCanceled()) {\r
- break;\r
- }\r
- zoom(entry, fMonitor);\r
- }\r
- }\r
-\r
- private void zoom(ControlFlowEntry entry, IProgressMonitor monitor) {\r
- if (fZoomStartTime <= fStartTime && fZoomEndTime >= fEndTime) {\r
- entry.setZoomedEventList(null);\r
- } else {\r
- List<ITimeEvent> zoomedEventList = getEventList(entry, fZoomStartTime, fZoomEndTime, fResolution, monitor);\r
- if (zoomedEventList != null) {\r
- entry.setZoomedEventList(zoomedEventList);\r
- }\r
- }\r
- redraw();\r
- for (ControlFlowEntry child : entry.getChildren()) {\r
- if (fMonitor.isCanceled()) {\r
- return;\r
- }\r
- zoom(child, monitor);\r
- }\r
- }\r
-\r
- public void cancel() {\r
- fMonitor.setCanceled(true);\r
- }\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Constructors\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Constructor\r
- */\r
- public ControlFlowView() {\r
- super(ID);\r
- fDisplayWidth = Display.getDefault().getBounds().width;\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // ViewPart\r
- // ------------------------------------------------------------------------\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite)\r
- */\r
- @Override\r
- public void createPartControl(Composite parent) {\r
- fTimeGraphCombo = new TimeGraphCombo(parent, SWT.NONE);\r
-\r
- fTimeGraphCombo.setTreeContentProvider(new TreeContentProvider());\r
-\r
- fTimeGraphCombo.setTreeLabelProvider(new TreeLabelProvider());\r
-\r
- fTimeGraphCombo.setTimeGraphProvider(new ControlFlowPresentationProvider());\r
-\r
- fTimeGraphCombo.setTreeColumns(COLUMN_NAMES);\r
-\r
- fTimeGraphCombo.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {\r
- @Override\r
- public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) {\r
- final long startTime = event.getStartTime();\r
- final long endTime = event.getEndTime();\r
- TmfTimeRange range = new TmfTimeRange(new CtfTmfTimestamp(startTime), new CtfTmfTimestamp(endTime));\r
- TmfTimestamp time = new CtfTmfTimestamp(fTimeGraphCombo.getTimeGraphViewer().getSelectedTime());\r
- broadcast(new TmfRangeSynchSignal(ControlFlowView.this, range, time));\r
- if (fZoomThread != null) {\r
- fZoomThread.cancel();\r
- }\r
- startZoomThread(startTime, endTime);\r
- }\r
- });\r
-\r
- fTimeGraphCombo.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {\r
- @Override\r
- public void timeSelected(TimeGraphTimeEvent event) {\r
- long time = event.getTime();\r
- broadcast(new TmfTimeSynchSignal(ControlFlowView.this, new CtfTmfTimestamp(time)));\r
- }\r
- });\r
-\r
- fTimeGraphCombo.addSelectionListener(new ITimeGraphSelectionListener() {\r
- @Override\r
- public void selectionChanged(TimeGraphSelectionEvent event) {\r
- //ITimeGraphEntry selection = event.getSelection();\r
- }\r
- });\r
-\r
- fTimeGraphCombo.getTimeGraphViewer().setTimeCalendarFormat(true);\r
-\r
- final Thread thread = new Thread("ControlFlowView build") { //$NON-NLS-1$\r
- @Override\r
- public void run() {\r
- if (TmfExperiment.getCurrentExperiment() != null) {\r
- selectExperiment(TmfExperiment.getCurrentExperiment());\r
- }\r
- }\r
- };\r
- thread.start();\r
-\r
- // View Action Handling\r
- makeActions();\r
- contributeToActionBars();\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.ui.part.WorkbenchPart#setFocus()\r
- */\r
- @Override\r
- public void setFocus() {\r
- fTimeGraphCombo.setFocus();\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Signal handlers\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Handler for the experiment selected signal\r
- *\r
- * @param signal\r
- * The signal that's received\r
- */\r
- @TmfSignalHandler\r
- public void experimentSelected(final TmfExperimentSelectedSignal signal) {\r
- if (signal.getExperiment().equals(fSelectedExperiment)) {\r
- return;\r
- }\r
-\r
- final Thread thread = new Thread("ControlFlowView build") { //$NON-NLS-1$\r
- @Override\r
- public void run() {\r
- selectExperiment(signal.getExperiment());\r
- }\r
- };\r
- thread.start();\r
- }\r
-\r
- /**\r
- * Experiment is disposed: clear the data structures and the view\r
- *\r
- * @param signal the signal received\r
- */\r
- @TmfSignalHandler\r
- public void experimentDisposed(final TmfExperimentDisposedSignal signal) {\r
- if (signal.getExperiment().equals(fSelectedExperiment)) {\r
- fSelectedExperiment = null;\r
- fStartTime = 0;\r
- fEndTime = 0;\r
- fZoomThread.cancel();\r
- synchronized(fEntryListSyncObj) {\r
- fEntryList.clear();\r
- }\r
- refresh(INITIAL_WINDOW_OFFSET);\r
- }\r
- }\r
-\r
- /**\r
- * Handler for the synch signal\r
- *\r
- * @param signal\r
- * The signal that's received\r
- */\r
- @TmfSignalHandler\r
- public void synchToTime(final TmfTimeSynchSignal signal) {\r
- if (signal.getSource() == this || fSelectedExperiment == null || fSelectedExperiment.getTraces() == null) {\r
- return;\r
- }\r
- final long time = signal.getCurrentTime().normalize(0, -9).getValue();\r
-\r
- int thread = -1;\r
- for (ITmfTrace trace : fSelectedExperiment.getTraces()) {\r
- if (thread > 0) {\r
- break;\r
- }\r
- if (trace instanceof CtfKernelTrace) {\r
- CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) trace;\r
- IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();\r
- if (time >= ssq.getStartTime() && time <= ssq.getCurrentEndTime()) {\r
- List<Integer> currentThreadQuarks = ssq.getQuarks(Attributes.CPUS, "*", Attributes.CURRENT_THREAD); //$NON-NLS-1$\r
- for (int currentThreadQuark : currentThreadQuarks) {\r
- try {\r
- ITmfStateInterval currentThreadInterval = ssq.querySingleState(time, currentThreadQuark);\r
- int currentThread = currentThreadInterval.getStateValue().unboxInt();\r
- if (currentThread > 0) {\r
- int statusQuark = ssq.getQuarkAbsolute(Attributes.THREADS, Integer.toString(currentThread), Attributes.STATUS);\r
- ITmfStateInterval statusInterval = ssq.querySingleState(time, statusQuark);\r
- if (statusInterval.getStartTime() == time) {\r
- thread = currentThread;\r
- break;\r
- }\r
- }\r
- } catch (AttributeNotFoundException e) {\r
- e.printStackTrace();\r
- } catch (TimeRangeException e) {\r
- e.printStackTrace();\r
- } catch (StateValueTypeException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- }\r
- }\r
- }\r
- final int selectedThread = thread;\r
-\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- if (fTimeGraphCombo.isDisposed()) {\r
- return;\r
- }\r
- fTimeGraphCombo.getTimeGraphViewer().setSelectedTime(time, true);\r
- startZoomThread(fTimeGraphCombo.getTimeGraphViewer().getTime0(), fTimeGraphCombo.getTimeGraphViewer().getTime1());\r
-\r
- if (selectedThread > 0) {\r
- for (Object element : fTimeGraphCombo.getTimeGraphViewer().getExpandedElements()) {\r
- if (element instanceof ControlFlowEntry) {\r
- ControlFlowEntry entry = (ControlFlowEntry) element;\r
- if (entry.getThreadId() == selectedThread) {\r
- fTimeGraphCombo.setSelection(entry);\r
- break;\r
- }\r
- }\r
- }\r
- }\r
- }\r
- });\r
- }\r
-\r
- /**\r
- * Handler for the range sync signal\r
- *\r
- * @param signal\r
- * The signal that's received\r
- */\r
- @TmfSignalHandler\r
- public void synchToRange(final TmfRangeSynchSignal signal) {\r
- if (signal.getSource() == this || fSelectedExperiment == null) {\r
- return;\r
- }\r
- final long startTime = signal.getCurrentRange().getStartTime().normalize(0, -9).getValue();\r
- final long endTime = signal.getCurrentRange().getEndTime().normalize(0, -9).getValue();\r
- final long time = signal.getCurrentTime().normalize(0, -9).getValue();\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- if (fTimeGraphCombo.isDisposed()) {\r
- return;\r
- }\r
- fTimeGraphCombo.getTimeGraphViewer().setStartFinishTime(startTime, endTime);\r
- fTimeGraphCombo.getTimeGraphViewer().setSelectedTime(time, false);\r
- startZoomThread(startTime, endTime);\r
- }\r
- });\r
- }\r
-\r
- /**\r
- * Handler for the state system build completed signal\r
- *\r
- * @param signal\r
- * The signal that's received\r
- */\r
- @TmfSignalHandler\r
- public void stateSystemBuildCompleted (final TmfStateSystemBuildCompleted signal) {\r
- final TmfExperiment selectedExperiment = fSelectedExperiment;\r
- if (selectedExperiment == null || selectedExperiment.getTraces() == null) {\r
- return;\r
- }\r
- for (ITmfTrace trace : selectedExperiment.getTraces()) {\r
- if (trace == signal.getTrace() && trace instanceof CtfKernelTrace) {\r
- final Thread thread = new Thread("ControlFlowView build") { //$NON-NLS-1$\r
- @Override\r
- public void run() {\r
- // rebuild the model\r
- selectExperiment(selectedExperiment);\r
- }\r
- };\r
- thread.start();\r
- }\r
- }\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Internal\r
- // ------------------------------------------------------------------------\r
-\r
- private void selectExperiment(TmfExperiment experiment) {\r
- fStartTime = Long.MAX_VALUE;\r
- fEndTime = Long.MIN_VALUE;\r
- fSelectedExperiment = experiment;\r
- ArrayList<ControlFlowEntry> rootList = new ArrayList<ControlFlowEntry>();\r
- for (ITmfTrace trace : experiment.getTraces()) {\r
- if (trace instanceof CtfKernelTrace) {\r
- ArrayList<ControlFlowEntry> entryList = new ArrayList<ControlFlowEntry>();\r
- CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) trace;\r
- IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();\r
- long start = ssq.getStartTime();\r
- long end = ssq.getCurrentEndTime() + 1;\r
- fStartTime = Math.min(fStartTime, start);\r
- fEndTime = Math.max(fEndTime, end);\r
- List<Integer> threadQuarks = ssq.getQuarks(Attributes.THREADS, "*"); //$NON-NLS-1$\r
- for (int threadQuark : threadQuarks) {\r
- String threadName = ssq.getAttributeName(threadQuark);\r
- int threadId = -1;\r
- try {\r
- threadId = Integer.parseInt(threadName);\r
- } catch (NumberFormatException e1) {\r
- continue;\r
- }\r
- if (threadId == 0) { // ignore the swapper thread\r
- continue;\r
- }\r
- int execNameQuark = -1;\r
- try {\r
- try {\r
- execNameQuark = ssq.getQuarkRelative(threadQuark, Attributes.EXEC_NAME);\r
- } catch (AttributeNotFoundException e) {\r
- continue;\r
- }\r
- int ppidQuark = ssq.getQuarkRelative(threadQuark, Attributes.PPID);\r
- List<ITmfStateInterval> execNameIntervals = ssq.queryHistoryRange(execNameQuark, start, end - 1);\r
- long birthTime = -1;\r
- for (ITmfStateInterval execNameInterval : execNameIntervals) {\r
- if (!execNameInterval.getStateValue().isNull() && execNameInterval.getStateValue().getType() == 1) {\r
- String execName = execNameInterval.getStateValue().unboxStr();\r
- long startTime = execNameInterval.getStartTime();\r
- long endTime = execNameInterval.getEndTime() + 1;\r
- if (birthTime == -1) {\r
- birthTime = startTime;\r
- }\r
- int ppid = -1;\r
- if (ppidQuark != -1) {\r
- ITmfStateInterval ppidInterval = ssq.querySingleState(startTime, ppidQuark);\r
- ppid = ppidInterval.getStateValue().unboxInt();\r
- }\r
- ControlFlowEntry entry = new ControlFlowEntry(threadQuark, ctfKernelTrace, execName, threadId, ppid, birthTime, startTime, endTime);\r
- entryList.add(entry);\r
- entry.addEvent(new TimeEvent(entry, startTime, endTime - startTime));\r
- } else {\r
- birthTime = -1;\r
- }\r
- }\r
- } catch (AttributeNotFoundException e) {\r
- e.printStackTrace();\r
- } catch (TimeRangeException e) {\r
- e.printStackTrace();\r
- } catch (StateValueTypeException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- buildTree(entryList, rootList);\r
- }\r
- Collections.sort(rootList, fControlFlowEntryComparator);\r
- synchronized (fEntryListSyncObj) {\r
- fEntryList = (ArrayList<ControlFlowEntry>) rootList.clone();\r
- }\r
- refresh(INITIAL_WINDOW_OFFSET);\r
- }\r
- for (ControlFlowEntry entry : rootList) {\r
- buildStatusEvents(entry);\r
- }\r
- }\r
-\r
- private static void buildTree(ArrayList<ControlFlowEntry> entryList,\r
- ArrayList<ControlFlowEntry> rootList) {\r
- for (ControlFlowEntry entry : entryList) {\r
- boolean root = true;\r
- if (entry.getParentThreadId() > 0) {\r
- for (ControlFlowEntry parent : entryList) {\r
- if (parent.getThreadId() == entry.getParentThreadId() &&\r
- entry.getStartTime() >= parent.getStartTime() &&\r
- entry.getStartTime() <= parent.getEndTime()) {\r
- parent.addChild(entry);\r
- root = false;\r
- break;\r
- }\r
- }\r
- }\r
- if (root) {\r
- rootList.add(entry);\r
- }\r
- }\r
- }\r
-\r
- private void buildStatusEvents(ControlFlowEntry entry) {\r
- IStateSystemQuerier ssq = entry.getTrace().getStateSystem();\r
- long start = ssq.getStartTime();\r
- long end = ssq.getCurrentEndTime() + 1;\r
- long resolution = Math.max(1, (end - start) / fDisplayWidth);\r
- List<ITimeEvent> eventList = getEventList(entry, entry.getStartTime(), entry.getEndTime(), resolution, new NullProgressMonitor());\r
- entry.setEventList(eventList);\r
- redraw();\r
- for (ITimeGraphEntry child : entry.getChildren()) {\r
- buildStatusEvents((ControlFlowEntry) child);\r
- }\r
- }\r
-\r
- private static List<ITimeEvent> getEventList(ControlFlowEntry entry,\r
- long startTime, long endTime, long resolution,\r
- IProgressMonitor monitor) {\r
- startTime = Math.max(startTime, entry.getStartTime());\r
- endTime = Math.min(endTime, entry.getEndTime());\r
- if (endTime <= startTime) {\r
- return null;\r
- }\r
- IStateSystemQuerier ssq = entry.getTrace().getStateSystem();\r
- List<ITimeEvent> eventList = null;\r
- try {\r
- int statusQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.STATUS);\r
- List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, startTime, endTime - 1, resolution, monitor);\r
- eventList = new ArrayList<ITimeEvent>(statusIntervals.size());\r
- long lastEndTime = -1;\r
- for (ITmfStateInterval statusInterval : statusIntervals) {\r
- if (monitor.isCanceled()) {\r
- return null;\r
- }\r
- long time = statusInterval.getStartTime();\r
- long duration = statusInterval.getEndTime() - time + 1;\r
- int status = -1;\r
- try {\r
- status = statusInterval.getStateValue().unboxInt();\r
- } catch (StateValueTypeException e) {\r
- e.printStackTrace();\r
- }\r
- if (lastEndTime != time && lastEndTime != -1) {\r
- eventList.add(new ControlFlowEvent(entry, lastEndTime, time - lastEndTime, 0));\r
- }\r
- eventList.add(new ControlFlowEvent(entry, time, duration, status));\r
- lastEndTime = time + duration;\r
- }\r
- } catch (AttributeNotFoundException e) {\r
- e.printStackTrace();\r
- } catch (TimeRangeException e) {\r
- e.printStackTrace();\r
- }\r
- return eventList;\r
- }\r
-\r
- private void refresh(final long windowRange) {\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- if (fTimeGraphCombo.isDisposed()) {\r
- return;\r
- }\r
- ITimeGraphEntry[] entries = null;\r
- synchronized (fEntryListSyncObj) {\r
- entries = fEntryList.toArray(new ITimeGraphEntry[0]);\r
- }\r
- Arrays.sort(entries, fControlFlowEntryComparator);\r
- fTimeGraphCombo.setInput(entries);\r
- fTimeGraphCombo.getTimeGraphViewer().setTimeBounds(fStartTime, fEndTime);\r
-\r
- long endTime = fStartTime + windowRange;\r
-\r
- if (fEndTime < endTime) {\r
- endTime = fEndTime;\r
- }\r
- fTimeGraphCombo.getTimeGraphViewer().setStartFinishTime(fStartTime, endTime);\r
- for (TreeColumn column : fTimeGraphCombo.getTreeViewer().getTree().getColumns()) {\r
- column.pack();\r
- }\r
-\r
- startZoomThread(fStartTime, endTime);\r
- }\r
- });\r
- }\r
-\r
- private void redraw() {\r
- synchronized (fSyncObj) {\r
- if (fRedrawState == State.IDLE) {\r
- fRedrawState = State.BUSY;\r
- } else {\r
- fRedrawState = State.PENDING;\r
- return;\r
- }\r
- }\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- if (fTimeGraphCombo.isDisposed()) {\r
- return;\r
- }\r
- fTimeGraphCombo.redraw();\r
- fTimeGraphCombo.update();\r
- synchronized (fSyncObj) {\r
- if (fRedrawState == State.PENDING) {\r
- fRedrawState = State.IDLE;\r
- redraw();\r
- } else {\r
- fRedrawState = State.IDLE;\r
- }\r
- }\r
- }\r
- });\r
- }\r
-\r
- private void startZoomThread(long startTime, long endTime) {\r
- if (fZoomThread != null) {\r
- fZoomThread.cancel();\r
- }\r
- fZoomThread = new ZoomThread(startTime, endTime);\r
- fZoomThread.start();\r
- }\r
-\r
- private void makeActions() {\r
- fPreviousResourceAction = fTimeGraphCombo.getTimeGraphViewer().getPreviousItemAction();\r
- fPreviousResourceAction.setText(Messages.ControlFlowView_previousProcessActionNameText);\r
- fPreviousResourceAction.setToolTipText(Messages.ControlFlowView_previousProcessActionToolTipText);\r
- fNextResourceAction = fTimeGraphCombo.getTimeGraphViewer().getNextItemAction();\r
- fNextResourceAction.setText(Messages.ControlFlowView_nextProcessActionNameText);\r
- fNextResourceAction.setToolTipText(Messages.ControlFlowView_nextProcessActionToolTipText);\r
- }\r
-\r
- private void contributeToActionBars() {\r
- IActionBars bars = getViewSite().getActionBars();\r
- fillLocalToolBar(bars.getToolBarManager());\r
- }\r
-\r
- private void fillLocalToolBar(IToolBarManager manager) {\r
- manager.add(fTimeGraphCombo.getTimeGraphViewer().getShowLegendAction());\r
- manager.add(new Separator());\r
- manager.add(fTimeGraphCombo.getTimeGraphViewer().getResetScaleAction());\r
- manager.add(fTimeGraphCombo.getTimeGraphViewer().getPreviousEventAction());\r
- manager.add(fTimeGraphCombo.getTimeGraphViewer().getNextEventAction());\r
- manager.add(fPreviousResourceAction);\r
- manager.add(fNextResourceAction);\r
- manager.add(fTimeGraphCombo.getTimeGraphViewer().getZoomInAction());\r
- manager.add(fTimeGraphCombo.getTimeGraphViewer().getZoomOutAction());\r
- manager.add(new Separator());\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
+import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;
+import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
+import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
+import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
+import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
+import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.linuxtools.tmf.core.signal.TmfStateSystemBuildCompleted;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
+import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
+import org.eclipse.linuxtools.tmf.ui.views.TmfView;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphSelectionListener;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphCombo;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphSelectionEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.ui.IActionBars;
+
+/**
+ * The Control Flow view main object
+ *
+ */
+public class ControlFlowView extends TmfView {
+
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+
+ /**
+ * View ID.
+ */
+ public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.controlflow"; //$NON-NLS-1$
+
+ /**
+ * Initial time range
+ */
+ private static final long INITIAL_WINDOW_OFFSET = (1L * 100 * 1000 * 1000); // .1sec
+
+ private static final String PROCESS_COLUMN = Messages.ControlFlowView_processColumn;
+ private static final String TID_COLUMN = Messages.ControlFlowView_tidColumn;
+ private static final String PTID_COLUMN = Messages.ControlFlowView_ptidColumn;
+ private static final String BIRTH_TIME_COLUMN = Messages.ControlFlowView_birthTimeColumn;
+ private static final String TRACE_COLUMN = Messages.ControlFlowView_traceColumn;
+
+ private final String[] COLUMN_NAMES = new String[] {
+ PROCESS_COLUMN,
+ TID_COLUMN,
+ PTID_COLUMN,
+ BIRTH_TIME_COLUMN,
+ TRACE_COLUMN
+ };
+
+ /**
+ * Redraw state enum
+ */
+ private enum State { IDLE, BUSY, PENDING }
+
+ // ------------------------------------------------------------------------
+ // Fields
+ // ------------------------------------------------------------------------
+
+ // The timegraph combo
+ private TimeGraphCombo fTimeGraphCombo;
+
+ // The selected experiment
+ private TmfExperiment fSelectedExperiment;
+
+ // The timegraph entry list
+ private ArrayList<ControlFlowEntry> fEntryList;
+
+ // The time graph entry list synchronization object
+ final private Object fEntryListSyncObj = new Object();
+
+ // The start time
+ private long fStartTime;
+
+ // The end time
+ private long fEndTime;
+
+ // The display width
+ private final int fDisplayWidth;
+
+ // The zoom thread
+ private ZoomThread fZoomThread;
+
+ // The next resource action
+ private Action fNextResourceAction;
+
+ // The previous resource action
+ private Action fPreviousResourceAction;
+
+ // A comparator class
+ private final ControlFlowEntryComparator fControlFlowEntryComparator = new ControlFlowEntryComparator();
+
+ // The redraw state used to prevent unnecessary queuing of display runnables
+ private State fRedrawState = State.IDLE;
+
+ // The redraw synchronization object
+ final private Object fSyncObj = new Object();
+
+ // ------------------------------------------------------------------------
+ // Classes
+ // ------------------------------------------------------------------------
+
+ private class TreeContentProvider implements ITreeContentProvider {
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return (ITimeGraphEntry[]) inputElement;
+ }
+
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ ITimeGraphEntry entry = (ITimeGraphEntry) parentElement;
+ return entry.getChildren();
+ }
+
+ @Override
+ public Object getParent(Object element) {
+ ITimeGraphEntry entry = (ITimeGraphEntry) element;
+ return entry.getParent();
+ }
+
+ @Override
+ public boolean hasChildren(Object element) {
+ ITimeGraphEntry entry = (ITimeGraphEntry) element;
+ return entry.hasChildren();
+ }
+
+ }
+
+ private class TreeLabelProvider implements ITableLabelProvider {
+
+ @Override
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ @Override
+ public void removeListener(ILabelProviderListener listener) {
+ }
+
+ @Override
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ @Override
+ public String getColumnText(Object element, int columnIndex) {
+ ControlFlowEntry entry = (ControlFlowEntry) element;
+ if (columnIndex == 0) {
+ return entry.getName();
+ } else if (columnIndex == 1) {
+ return Integer.toString(entry.getThreadId());
+ } else if (columnIndex == 2) {
+ if (entry.getParentThreadId() > 0) {
+ return Integer.toString(entry.getParentThreadId());
+ }
+ } else if (columnIndex == 3) {
+ return Utils.formatTime(entry.getBirthTime(), TimeFormat.ABSOLUTE, Resolution.NANOSEC);
+ } else if (columnIndex == 4) {
+ return entry.getTrace().getName();
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ }
+
+ private static class ControlFlowEntryComparator implements Comparator<ITimeGraphEntry> {
+
+ @Override
+ public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {
+ int result = 0;
+
+ if ((o1 instanceof ControlFlowEntry) && (o2 instanceof ControlFlowEntry)) {
+ ControlFlowEntry entry1 = (ControlFlowEntry) o1;
+ ControlFlowEntry entry2 = (ControlFlowEntry) o2;
+ result = entry1.getTrace().getStartTime().compareTo(entry2.getTrace().getStartTime());
+ if (result == 0) {
+ result = entry1.getTrace().getName().compareTo(entry2.getTrace().getName());
+ }
+ if (result == 0) {
+ result = entry1.getThreadId() < entry2.getThreadId() ? -1 : entry1.getThreadId() > entry2.getThreadId() ? 1 : 0;
+ }
+ }
+
+ if (result == 0) {
+ result = o1.getStartTime() < o2.getStartTime() ? -1 : o1.getStartTime() > o2.getStartTime() ? 1 : 0;
+ }
+
+ return result;
+ }
+ }
+
+
+ private class ZoomThread extends Thread {
+ private final long fZoomStartTime;
+ private final long fZoomEndTime;
+ private final long fResolution;
+ private final IProgressMonitor fMonitor;
+
+ public ZoomThread(long startTime, long endTime) {
+ super("ControlFlowView zoom"); //$NON-NLS-1$
+ fZoomStartTime = startTime;
+ fZoomEndTime = endTime;
+ fResolution = Math.max(1, (fZoomEndTime - fZoomStartTime) / fDisplayWidth);
+ fMonitor = new NullProgressMonitor();
+ }
+
+ @Override
+ public void run() {
+ ArrayList<ControlFlowEntry> entryList = null;
+ synchronized (fEntryListSyncObj) {
+ entryList = (ArrayList<ControlFlowEntry>) fEntryList.clone();
+ }
+ if (entryList == null) {
+ return;
+ }
+ for (ControlFlowEntry entry : entryList) {
+ if (fMonitor.isCanceled()) {
+ break;
+ }
+ zoom(entry, fMonitor);
+ }
+ }
+
+ private void zoom(ControlFlowEntry entry, IProgressMonitor monitor) {
+ if (fZoomStartTime <= fStartTime && fZoomEndTime >= fEndTime) {
+ entry.setZoomedEventList(null);
+ } else {
+ List<ITimeEvent> zoomedEventList = getEventList(entry, fZoomStartTime, fZoomEndTime, fResolution, monitor);
+ if (zoomedEventList != null) {
+ entry.setZoomedEventList(zoomedEventList);
+ }
+ }
+ redraw();
+ for (ControlFlowEntry child : entry.getChildren()) {
+ if (fMonitor.isCanceled()) {
+ return;
+ }
+ zoom(child, monitor);
+ }
+ }
+
+ public void cancel() {
+ fMonitor.setCanceled(true);
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Constructor
+ */
+ public ControlFlowView() {
+ super(ID);
+ fDisplayWidth = Display.getDefault().getBounds().width;
+ }
+
+ // ------------------------------------------------------------------------
+ // ViewPart
+ // ------------------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void createPartControl(Composite parent) {
+ fTimeGraphCombo = new TimeGraphCombo(parent, SWT.NONE);
+
+ fTimeGraphCombo.setTreeContentProvider(new TreeContentProvider());
+
+ fTimeGraphCombo.setTreeLabelProvider(new TreeLabelProvider());
+
+ fTimeGraphCombo.setTimeGraphProvider(new ControlFlowPresentationProvider());
+
+ fTimeGraphCombo.setTreeColumns(COLUMN_NAMES);
+
+ fTimeGraphCombo.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
+ @Override
+ public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) {
+ final long startTime = event.getStartTime();
+ final long endTime = event.getEndTime();
+ TmfTimeRange range = new TmfTimeRange(new CtfTmfTimestamp(startTime), new CtfTmfTimestamp(endTime));
+ TmfTimestamp time = new CtfTmfTimestamp(fTimeGraphCombo.getTimeGraphViewer().getSelectedTime());
+ broadcast(new TmfRangeSynchSignal(ControlFlowView.this, range, time));
+ if (fZoomThread != null) {
+ fZoomThread.cancel();
+ }
+ startZoomThread(startTime, endTime);
+ }
+ });
+
+ fTimeGraphCombo.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
+ @Override
+ public void timeSelected(TimeGraphTimeEvent event) {
+ long time = event.getTime();
+ broadcast(new TmfTimeSynchSignal(ControlFlowView.this, new CtfTmfTimestamp(time)));
+ }
+ });
+
+ fTimeGraphCombo.addSelectionListener(new ITimeGraphSelectionListener() {
+ @Override
+ public void selectionChanged(TimeGraphSelectionEvent event) {
+ //ITimeGraphEntry selection = event.getSelection();
+ }
+ });
+
+ fTimeGraphCombo.getTimeGraphViewer().setTimeCalendarFormat(true);
+
+ final Thread thread = new Thread("ControlFlowView build") { //$NON-NLS-1$
+ @Override
+ public void run() {
+ if (TmfExperiment.getCurrentExperiment() != null) {
+ selectExperiment(TmfExperiment.getCurrentExperiment());
+ }
+ }
+ };
+ thread.start();
+
+ // View Action Handling
+ makeActions();
+ contributeToActionBars();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
+ */
+ @Override
+ public void setFocus() {
+ fTimeGraphCombo.setFocus();
+ }
+
+ // ------------------------------------------------------------------------
+ // Signal handlers
+ // ------------------------------------------------------------------------
+
+ /**
+ * Handler for the experiment selected signal
+ *
+ * @param signal
+ * The signal that's received
+ */
+ @TmfSignalHandler
+ public void experimentSelected(final TmfExperimentSelectedSignal signal) {
+ if (signal.getExperiment().equals(fSelectedExperiment)) {
+ return;
+ }
+
+ final Thread thread = new Thread("ControlFlowView build") { //$NON-NLS-1$
+ @Override
+ public void run() {
+ selectExperiment(signal.getExperiment());
+ }
+ };
+ thread.start();
+ }
+
+ /**
+ * Experiment is disposed: clear the data structures and the view
+ *
+ * @param signal the signal received
+ */
+ @TmfSignalHandler
+ public void experimentDisposed(final TmfExperimentDisposedSignal signal) {
+ if (signal.getExperiment().equals(fSelectedExperiment)) {
+ fSelectedExperiment = null;
+ fStartTime = 0;
+ fEndTime = 0;
+ fZoomThread.cancel();
+ synchronized(fEntryListSyncObj) {
+ fEntryList.clear();
+ }
+ refresh(INITIAL_WINDOW_OFFSET);
+ }
+ }
+
+ /**
+ * Handler for the synch signal
+ *
+ * @param signal
+ * The signal that's received
+ */
+ @TmfSignalHandler
+ public void synchToTime(final TmfTimeSynchSignal signal) {
+ if (signal.getSource() == this || fSelectedExperiment == null || fSelectedExperiment.getTraces() == null) {
+ return;
+ }
+ final long time = signal.getCurrentTime().normalize(0, -9).getValue();
+
+ int thread = -1;
+ for (ITmfTrace trace : fSelectedExperiment.getTraces()) {
+ if (thread > 0) {
+ break;
+ }
+ if (trace instanceof CtfKernelTrace) {
+ CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) trace;
+ IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();
+ if (time >= ssq.getStartTime() && time <= ssq.getCurrentEndTime()) {
+ List<Integer> currentThreadQuarks = ssq.getQuarks(Attributes.CPUS, "*", Attributes.CURRENT_THREAD); //$NON-NLS-1$
+ for (int currentThreadQuark : currentThreadQuarks) {
+ try {
+ ITmfStateInterval currentThreadInterval = ssq.querySingleState(time, currentThreadQuark);
+ int currentThread = currentThreadInterval.getStateValue().unboxInt();
+ if (currentThread > 0) {
+ int statusQuark = ssq.getQuarkAbsolute(Attributes.THREADS, Integer.toString(currentThread), Attributes.STATUS);
+ ITmfStateInterval statusInterval = ssq.querySingleState(time, statusQuark);
+ if (statusInterval.getStartTime() == time) {
+ thread = currentThread;
+ break;
+ }
+ }
+ } catch (AttributeNotFoundException e) {
+ e.printStackTrace();
+ } catch (TimeRangeException e) {
+ e.printStackTrace();
+ } catch (StateValueTypeException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+ final int selectedThread = thread;
+
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (fTimeGraphCombo.isDisposed()) {
+ return;
+ }
+ fTimeGraphCombo.getTimeGraphViewer().setSelectedTime(time, true);
+ startZoomThread(fTimeGraphCombo.getTimeGraphViewer().getTime0(), fTimeGraphCombo.getTimeGraphViewer().getTime1());
+
+ if (selectedThread > 0) {
+ for (Object element : fTimeGraphCombo.getTimeGraphViewer().getExpandedElements()) {
+ if (element instanceof ControlFlowEntry) {
+ ControlFlowEntry entry = (ControlFlowEntry) element;
+ if (entry.getThreadId() == selectedThread) {
+ fTimeGraphCombo.setSelection(entry);
+ break;
+ }
+ }
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * Handler for the range sync signal
+ *
+ * @param signal
+ * The signal that's received
+ */
+ @TmfSignalHandler
+ public void synchToRange(final TmfRangeSynchSignal signal) {
+ if (signal.getSource() == this || fSelectedExperiment == null) {
+ return;
+ }
+ final long startTime = signal.getCurrentRange().getStartTime().normalize(0, -9).getValue();
+ final long endTime = signal.getCurrentRange().getEndTime().normalize(0, -9).getValue();
+ final long time = signal.getCurrentTime().normalize(0, -9).getValue();
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (fTimeGraphCombo.isDisposed()) {
+ return;
+ }
+ fTimeGraphCombo.getTimeGraphViewer().setStartFinishTime(startTime, endTime);
+ fTimeGraphCombo.getTimeGraphViewer().setSelectedTime(time, false);
+ startZoomThread(startTime, endTime);
+ }
+ });
+ }
+
+ /**
+ * Handler for the state system build completed signal
+ *
+ * @param signal
+ * The signal that's received
+ */
+ @TmfSignalHandler
+ public void stateSystemBuildCompleted (final TmfStateSystemBuildCompleted signal) {
+ final TmfExperiment selectedExperiment = fSelectedExperiment;
+ if (selectedExperiment == null || selectedExperiment.getTraces() == null) {
+ return;
+ }
+ for (ITmfTrace trace : selectedExperiment.getTraces()) {
+ if (trace == signal.getTrace() && trace instanceof CtfKernelTrace) {
+ final Thread thread = new Thread("ControlFlowView build") { //$NON-NLS-1$
+ @Override
+ public void run() {
+ // rebuild the model
+ selectExperiment(selectedExperiment);
+ }
+ };
+ thread.start();
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Internal
+ // ------------------------------------------------------------------------
+
+ private void selectExperiment(TmfExperiment experiment) {
+ fStartTime = Long.MAX_VALUE;
+ fEndTime = Long.MIN_VALUE;
+ fSelectedExperiment = experiment;
+ ArrayList<ControlFlowEntry> rootList = new ArrayList<ControlFlowEntry>();
+ for (ITmfTrace trace : experiment.getTraces()) {
+ if (trace instanceof CtfKernelTrace) {
+ ArrayList<ControlFlowEntry> entryList = new ArrayList<ControlFlowEntry>();
+ CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) trace;
+ IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();
+ long start = ssq.getStartTime();
+ long end = ssq.getCurrentEndTime() + 1;
+ fStartTime = Math.min(fStartTime, start);
+ fEndTime = Math.max(fEndTime, end);
+ List<Integer> threadQuarks = ssq.getQuarks(Attributes.THREADS, "*"); //$NON-NLS-1$
+ for (int threadQuark : threadQuarks) {
+ String threadName = ssq.getAttributeName(threadQuark);
+ int threadId = -1;
+ try {
+ threadId = Integer.parseInt(threadName);
+ } catch (NumberFormatException e1) {
+ continue;
+ }
+ if (threadId == 0) { // ignore the swapper thread
+ continue;
+ }
+ int execNameQuark = -1;
+ try {
+ try {
+ execNameQuark = ssq.getQuarkRelative(threadQuark, Attributes.EXEC_NAME);
+ } catch (AttributeNotFoundException e) {
+ continue;
+ }
+ int ppidQuark = ssq.getQuarkRelative(threadQuark, Attributes.PPID);
+ List<ITmfStateInterval> execNameIntervals = ssq.queryHistoryRange(execNameQuark, start, end - 1);
+ long birthTime = -1;
+ for (ITmfStateInterval execNameInterval : execNameIntervals) {
+ if (!execNameInterval.getStateValue().isNull() && execNameInterval.getStateValue().getType() == 1) {
+ String execName = execNameInterval.getStateValue().unboxStr();
+ long startTime = execNameInterval.getStartTime();
+ long endTime = execNameInterval.getEndTime() + 1;
+ if (birthTime == -1) {
+ birthTime = startTime;
+ }
+ int ppid = -1;
+ if (ppidQuark != -1) {
+ ITmfStateInterval ppidInterval = ssq.querySingleState(startTime, ppidQuark);
+ ppid = ppidInterval.getStateValue().unboxInt();
+ }
+ ControlFlowEntry entry = new ControlFlowEntry(threadQuark, ctfKernelTrace, execName, threadId, ppid, birthTime, startTime, endTime);
+ entryList.add(entry);
+ entry.addEvent(new TimeEvent(entry, startTime, endTime - startTime));
+ } else {
+ birthTime = -1;
+ }
+ }
+ } catch (AttributeNotFoundException e) {
+ e.printStackTrace();
+ } catch (TimeRangeException e) {
+ e.printStackTrace();
+ } catch (StateValueTypeException e) {
+ e.printStackTrace();
+ }
+ }
+ buildTree(entryList, rootList);
+ }
+ Collections.sort(rootList, fControlFlowEntryComparator);
+ synchronized (fEntryListSyncObj) {
+ fEntryList = (ArrayList<ControlFlowEntry>) rootList.clone();
+ }
+ refresh(INITIAL_WINDOW_OFFSET);
+ }
+ for (ControlFlowEntry entry : rootList) {
+ buildStatusEvents(entry);
+ }
+ }
+
+ private static void buildTree(ArrayList<ControlFlowEntry> entryList,
+ ArrayList<ControlFlowEntry> rootList) {
+ for (ControlFlowEntry entry : entryList) {
+ boolean root = true;
+ if (entry.getParentThreadId() > 0) {
+ for (ControlFlowEntry parent : entryList) {
+ if (parent.getThreadId() == entry.getParentThreadId() &&
+ entry.getStartTime() >= parent.getStartTime() &&
+ entry.getStartTime() <= parent.getEndTime()) {
+ parent.addChild(entry);
+ root = false;
+ break;
+ }
+ }
+ }
+ if (root) {
+ rootList.add(entry);
+ }
+ }
+ }
+
+ private void buildStatusEvents(ControlFlowEntry entry) {
+ IStateSystemQuerier ssq = entry.getTrace().getStateSystem();
+ long start = ssq.getStartTime();
+ long end = ssq.getCurrentEndTime() + 1;
+ long resolution = Math.max(1, (end - start) / fDisplayWidth);
+ List<ITimeEvent> eventList = getEventList(entry, entry.getStartTime(), entry.getEndTime(), resolution, new NullProgressMonitor());
+ entry.setEventList(eventList);
+ redraw();
+ for (ITimeGraphEntry child : entry.getChildren()) {
+ buildStatusEvents((ControlFlowEntry) child);
+ }
+ }
+
+ private static List<ITimeEvent> getEventList(ControlFlowEntry entry,
+ long startTime, long endTime, long resolution,
+ IProgressMonitor monitor) {
+ startTime = Math.max(startTime, entry.getStartTime());
+ endTime = Math.min(endTime, entry.getEndTime());
+ if (endTime <= startTime) {
+ return null;
+ }
+ IStateSystemQuerier ssq = entry.getTrace().getStateSystem();
+ List<ITimeEvent> eventList = null;
+ try {
+ int statusQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.STATUS);
+ List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, startTime, endTime - 1, resolution, monitor);
+ eventList = new ArrayList<ITimeEvent>(statusIntervals.size());
+ long lastEndTime = -1;
+ for (ITmfStateInterval statusInterval : statusIntervals) {
+ if (monitor.isCanceled()) {
+ return null;
+ }
+ long time = statusInterval.getStartTime();
+ long duration = statusInterval.getEndTime() - time + 1;
+ int status = -1;
+ try {
+ status = statusInterval.getStateValue().unboxInt();
+ } catch (StateValueTypeException e) {
+ e.printStackTrace();
+ }
+ if (lastEndTime != time && lastEndTime != -1) {
+ eventList.add(new ControlFlowEvent(entry, lastEndTime, time - lastEndTime, 0));
+ }
+ eventList.add(new ControlFlowEvent(entry, time, duration, status));
+ lastEndTime = time + duration;
+ }
+ } catch (AttributeNotFoundException e) {
+ e.printStackTrace();
+ } catch (TimeRangeException e) {
+ e.printStackTrace();
+ }
+ return eventList;
+ }
+
+ private void refresh(final long windowRange) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (fTimeGraphCombo.isDisposed()) {
+ return;
+ }
+ ITimeGraphEntry[] entries = null;
+ synchronized (fEntryListSyncObj) {
+ entries = fEntryList.toArray(new ITimeGraphEntry[0]);
+ }
+ Arrays.sort(entries, fControlFlowEntryComparator);
+ fTimeGraphCombo.setInput(entries);
+ fTimeGraphCombo.getTimeGraphViewer().setTimeBounds(fStartTime, fEndTime);
+
+ long endTime = fStartTime + windowRange;
+
+ if (fEndTime < endTime) {
+ endTime = fEndTime;
+ }
+ fTimeGraphCombo.getTimeGraphViewer().setStartFinishTime(fStartTime, endTime);
+ for (TreeColumn column : fTimeGraphCombo.getTreeViewer().getTree().getColumns()) {
+ column.pack();
+ }
+
+ startZoomThread(fStartTime, endTime);
+ }
+ });
+ }
+
+ private void redraw() {
+ synchronized (fSyncObj) {
+ if (fRedrawState == State.IDLE) {
+ fRedrawState = State.BUSY;
+ } else {
+ fRedrawState = State.PENDING;
+ return;
+ }
+ }
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (fTimeGraphCombo.isDisposed()) {
+ return;
+ }
+ fTimeGraphCombo.redraw();
+ fTimeGraphCombo.update();
+ synchronized (fSyncObj) {
+ if (fRedrawState == State.PENDING) {
+ fRedrawState = State.IDLE;
+ redraw();
+ } else {
+ fRedrawState = State.IDLE;
+ }
+ }
+ }
+ });
+ }
+
+ private void startZoomThread(long startTime, long endTime) {
+ if (fZoomThread != null) {
+ fZoomThread.cancel();
+ }
+ fZoomThread = new ZoomThread(startTime, endTime);
+ fZoomThread.start();
+ }
+
+ private void makeActions() {
+ fPreviousResourceAction = fTimeGraphCombo.getTimeGraphViewer().getPreviousItemAction();
+ fPreviousResourceAction.setText(Messages.ControlFlowView_previousProcessActionNameText);
+ fPreviousResourceAction.setToolTipText(Messages.ControlFlowView_previousProcessActionToolTipText);
+ fNextResourceAction = fTimeGraphCombo.getTimeGraphViewer().getNextItemAction();
+ fNextResourceAction.setText(Messages.ControlFlowView_nextProcessActionNameText);
+ fNextResourceAction.setToolTipText(Messages.ControlFlowView_nextProcessActionToolTipText);
+ }
+
+ private void contributeToActionBars() {
+ IActionBars bars = getViewSite().getActionBars();
+ fillLocalToolBar(bars.getToolBarManager());
+ }
+
+ private void fillLocalToolBar(IToolBarManager manager) {
+ manager.add(fTimeGraphCombo.getTimeGraphViewer().getShowLegendAction());
+ manager.add(new Separator());
+ manager.add(fTimeGraphCombo.getTimeGraphViewer().getResetScaleAction());
+ manager.add(fTimeGraphCombo.getTimeGraphViewer().getPreviousEventAction());
+ manager.add(fTimeGraphCombo.getTimeGraphViewer().getNextEventAction());
+ manager.add(fPreviousResourceAction);
+ manager.add(fNextResourceAction);
+ manager.add(fTimeGraphCombo.getTimeGraphViewer().getZoomInAction());
+ manager.add(fTimeGraphCombo.getTimeGraphViewer().getZoomOutAction());
+ manager.add(new Separator());
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.common.EventIterator;\r
-import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-\r
-/**\r
- * An entry, or row, in the resource view\r
- *\r
- * @author Patrick Tasse\r
- */\r
-public class ResourcesEntry implements ITimeGraphEntry {\r
-\r
- /** Type of resource */\r
- public static enum Type {\r
- /** Null resources (filler rows, etc.) */\r
- NULL,\r
- /** Entries for CPUs */\r
- CPU,\r
- /** Entries for IRQs */\r
- IRQ,\r
- /** Entries for Soft IRQ */\r
- SOFT_IRQ }\r
-\r
- private final int fQuark;\r
- private final CtfKernelTrace fTrace;\r
- private ITimeGraphEntry fParent = null;\r
- private final ITimeGraphEntry[] children = null;\r
- private final String fName;\r
- private final Type fType;\r
- private final int fId;\r
- private long fStartTime;\r
- private long fEndTime;\r
- private List<ITimeEvent> fEventList = new ArrayList<ITimeEvent>();\r
- private List<ITimeEvent> fZoomedEventList = null;\r
-\r
- /**\r
- * Standard constructor\r
- *\r
- * @param quark\r
- * The quark of the state system attribute whose state is shown\r
- * on this row\r
- * @param trace\r
- * The trace that this view is talking about\r
- * @param type\r
- * Type of entry, see the Type enum\r
- * @param id\r
- * The integer id associated with this entry or row\r
- */\r
- public ResourcesEntry(int quark, CtfKernelTrace trace, Type type, int id) {\r
- fQuark = quark;\r
- fTrace = trace;\r
- fType = type;\r
- fId = id;\r
- fName = type.toString() + ' ' + Integer.toString(id);\r
- }\r
-\r
- @Override\r
- public ITimeGraphEntry getParent() {\r
- return fParent;\r
- }\r
-\r
- @Override\r
- public boolean hasChildren() {\r
- return children != null && children.length > 0;\r
- }\r
-\r
- @Override\r
- public ITimeGraphEntry[] getChildren() {\r
- return children;\r
- }\r
-\r
- @Override\r
- public String getName() {\r
- return fName;\r
- }\r
-\r
- @Override\r
- public long getStartTime() {\r
- return fStartTime;\r
- }\r
-\r
- @Override\r
- public long getEndTime() {\r
- return fEndTime;\r
- }\r
-\r
- @Override\r
- public boolean hasTimeEvents() {\r
- return true;\r
- }\r
-\r
- @Override\r
- public Iterator<ITimeEvent> getTimeEventsIterator() {\r
- return new EventIterator(fEventList, fZoomedEventList);\r
- }\r
-\r
- @Override\r
- public Iterator<ITimeEvent> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration) {\r
- return new EventIterator(fEventList, fZoomedEventList, startTime, stopTime);\r
- }\r
-\r
- /**\r
- * Assign a parent entry to this one, to organize them in a tree in the\r
- * view.\r
- *\r
- * @param parent\r
- * The parent entry\r
- */\r
- public void setParent(ITimeGraphEntry parent) {\r
- fParent = parent;\r
- }\r
-\r
- /**\r
- * Retrieve the attribute quark that's represented by this entry.\r
- *\r
- * @return The integer quark\r
- */\r
- public int getQuark() {\r
- return fQuark;\r
- }\r
-\r
- /**\r
- * Retrieve the trace that is associated to this Resource view.\r
- *\r
- * @return The LTTng 2 kernel trace\r
- */\r
- public CtfKernelTrace getTrace() {\r
- return fTrace;\r
- }\r
-\r
- /**\r
- * Get the entry Type of this entry. Uses the inner Type enum.\r
- *\r
- * @return The entry type\r
- */\r
- public Type getType() {\r
- return fType;\r
- }\r
-\r
- /**\r
- * Get the integer ID associated with this entry.\r
- *\r
- * @return The ID\r
- */\r
- public int getId() {\r
- return fId;\r
- }\r
-\r
- /**\r
- * Assign the target event list to this view.\r
- *\r
- * @param eventList\r
- * The list of time events\r
- */\r
- public void setEventList(List<ITimeEvent> eventList) {\r
- fEventList = eventList;\r
- if (eventList != null && eventList.size() > 0) {\r
- fStartTime = eventList.get(0).getTime();\r
- ITimeEvent lastEvent = eventList.get(eventList.size() - 1);\r
- fEndTime = lastEvent.getTime() + lastEvent.getDuration();\r
- }\r
- }\r
-\r
- /**\r
- * Assign the zoomed event list to this view.\r
- *\r
- * @param eventList\r
- * The list of "zoomed" time events\r
- */\r
- public void setZoomedEventList(List<ITimeEvent> eventList) {\r
- fZoomedEventList = eventList;\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.common.EventIterator;
+import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+
+/**
+ * An entry, or row, in the resource view
+ *
+ * @author Patrick Tasse
+ */
+public class ResourcesEntry implements ITimeGraphEntry {
+
+ /** Type of resource */
+ public static enum Type {
+ /** Null resources (filler rows, etc.) */
+ NULL,
+ /** Entries for CPUs */
+ CPU,
+ /** Entries for IRQs */
+ IRQ,
+ /** Entries for Soft IRQ */
+ SOFT_IRQ }
+
+ private final int fQuark;
+ private final CtfKernelTrace fTrace;
+ private ITimeGraphEntry fParent = null;
+ private final ITimeGraphEntry[] children = null;
+ private final String fName;
+ private final Type fType;
+ private final int fId;
+ private long fStartTime;
+ private long fEndTime;
+ private List<ITimeEvent> fEventList = new ArrayList<ITimeEvent>();
+ private List<ITimeEvent> fZoomedEventList = null;
+
+ /**
+ * Standard constructor
+ *
+ * @param quark
+ * The quark of the state system attribute whose state is shown
+ * on this row
+ * @param trace
+ * The trace that this view is talking about
+ * @param type
+ * Type of entry, see the Type enum
+ * @param id
+ * The integer id associated with this entry or row
+ */
+ public ResourcesEntry(int quark, CtfKernelTrace trace, Type type, int id) {
+ fQuark = quark;
+ fTrace = trace;
+ fType = type;
+ fId = id;
+ fName = type.toString() + ' ' + Integer.toString(id);
+ }
+
+ @Override
+ public ITimeGraphEntry getParent() {
+ return fParent;
+ }
+
+ @Override
+ public boolean hasChildren() {
+ return children != null && children.length > 0;
+ }
+
+ @Override
+ public ITimeGraphEntry[] getChildren() {
+ return children;
+ }
+
+ @Override
+ public String getName() {
+ return fName;
+ }
+
+ @Override
+ public long getStartTime() {
+ return fStartTime;
+ }
+
+ @Override
+ public long getEndTime() {
+ return fEndTime;
+ }
+
+ @Override
+ public boolean hasTimeEvents() {
+ return true;
+ }
+
+ @Override
+ public Iterator<ITimeEvent> getTimeEventsIterator() {
+ return new EventIterator(fEventList, fZoomedEventList);
+ }
+
+ @Override
+ public Iterator<ITimeEvent> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration) {
+ return new EventIterator(fEventList, fZoomedEventList, startTime, stopTime);
+ }
+
+ /**
+ * Assign a parent entry to this one, to organize them in a tree in the
+ * view.
+ *
+ * @param parent
+ * The parent entry
+ */
+ public void setParent(ITimeGraphEntry parent) {
+ fParent = parent;
+ }
+
+ /**
+ * Retrieve the attribute quark that's represented by this entry.
+ *
+ * @return The integer quark
+ */
+ public int getQuark() {
+ return fQuark;
+ }
+
+ /**
+ * Retrieve the trace that is associated to this Resource view.
+ *
+ * @return The LTTng 2 kernel trace
+ */
+ public CtfKernelTrace getTrace() {
+ return fTrace;
+ }
+
+ /**
+ * Get the entry Type of this entry. Uses the inner Type enum.
+ *
+ * @return The entry type
+ */
+ public Type getType() {
+ return fType;
+ }
+
+ /**
+ * Get the integer ID associated with this entry.
+ *
+ * @return The ID
+ */
+ public int getId() {
+ return fId;
+ }
+
+ /**
+ * Assign the target event list to this view.
+ *
+ * @param eventList
+ * The list of time events
+ */
+ public void setEventList(List<ITimeEvent> eventList) {
+ fEventList = eventList;
+ if (eventList != null && eventList.size() > 0) {
+ fStartTime = eventList.get(0).getTime();
+ ITimeEvent lastEvent = eventList.get(eventList.size() - 1);
+ fEndTime = lastEvent.getTime() + lastEvent.getDuration();
+ }
+ }
+
+ /**
+ * Assign the zoomed event list to this view.
+ *
+ * @param eventList
+ * The list of "zoomed" time events
+ */
+ public void setZoomedEventList(List<ITimeEvent> eventList) {
+ fZoomedEventList = eventList;
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;\r
-\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;\r
-\r
-/**\r
- * Time Event implementation specific to the Resource View\r
- *\r
- * @author Patrick Tasse\r
- */\r
-public class ResourcesEvent extends TimeEvent {\r
-\r
- private final Type fType;\r
- private int fValue;\r
-\r
- /**\r
- * Standard constructor\r
- *\r
- * @param entry\r
- * The entry that this event affects\r
- * @param time\r
- * The start time of the event\r
- * @param duration\r
- * The duration of the event\r
- * @param value\r
- * The value type associated to this event\r
- */\r
- public ResourcesEvent(ResourcesEntry entry, long time, long duration,\r
- int value) {\r
- super(entry, time, duration);\r
- fType = entry.getType();\r
- fValue = value;\r
- }\r
-\r
- /**\r
- * Base constructor, with no value assigned\r
- *\r
- * @param entry\r
- * The entry that this event affects\r
- * @param time\r
- * The start time of the event\r
- * @param duration\r
- * The duration of the event\r
- */\r
- public ResourcesEvent(ResourcesEntry entry, long time, long duration) {\r
- super(entry, time, duration);\r
- fType = Type.NULL;\r
- }\r
-\r
- /**\r
- * Retrieve the value associated with this event\r
- *\r
- * @return The integer value\r
- */\r
- public int getValue() {\r
- return fValue;\r
- }\r
-\r
- /**\r
- * Retrieve the type of this entry. Uses the ResourcesEntry.Type interface.\r
- *\r
- * @return The entry type\r
- */\r
- public Type getType() {\r
- return fType;\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;
+
+import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;
+
+/**
+ * Time Event implementation specific to the Resource View
+ *
+ * @author Patrick Tasse
+ */
+public class ResourcesEvent extends TimeEvent {
+
+ private final Type fType;
+ private int fValue;
+
+ /**
+ * Standard constructor
+ *
+ * @param entry
+ * The entry that this event affects
+ * @param time
+ * The start time of the event
+ * @param duration
+ * The duration of the event
+ * @param value
+ * The value type associated to this event
+ */
+ public ResourcesEvent(ResourcesEntry entry, long time, long duration,
+ int value) {
+ super(entry, time, duration);
+ fType = entry.getType();
+ fValue = value;
+ }
+
+ /**
+ * Base constructor, with no value assigned
+ *
+ * @param entry
+ * The entry that this event affects
+ * @param time
+ * The start time of the event
+ * @param duration
+ * The duration of the event
+ */
+ public ResourcesEvent(ResourcesEntry entry, long time, long duration) {
+ super(entry, time, duration);
+ fType = Type.NULL;
+ }
+
+ /**
+ * Retrieve the value associated with this event
+ *
+ * @return The integer value
+ */
+ public int getValue() {
+ return fValue;
+ }
+
+ /**
+ * Retrieve the type of this entry. Uses the ResourcesEntry.Type interface.
+ *
+ * @return The entry type
+ */
+ public Type getType() {
+ return fType;
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.Comparator;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.core.runtime.NullProgressMonitor;\r
-import org.eclipse.jface.action.Action;\r
-import org.eclipse.jface.action.IToolBarManager;\r
-import org.eclipse.jface.action.Separator;\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;\r
-import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;\r
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;\r
-import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfStateSystemBuildCompleted;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;\r
-import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;\r
-import org.eclipse.linuxtools.tmf.ui.views.TmfView;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphViewer;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.ui.IActionBars;\r
-\r
-/**\r
- * Main implementation for the LTTng 2.0 kernel Resource view\r
- *\r
- * @author Patrick Tasse\r
- */\r
-public class ResourcesView extends TmfView {\r
-\r
- // ------------------------------------------------------------------------\r
- // Constants\r
- // ------------------------------------------------------------------------\r
-\r
- /** View ID. */\r
- public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$\r
-\r
- /** Initial time range */\r
- private static final long INITIAL_WINDOW_OFFSET = (1L * 100 * 1000 * 1000); // .1sec\r
-\r
- /**\r
- * Redraw state enum\r
- */\r
- private enum State { IDLE, BUSY, PENDING }\r
-\r
- // ------------------------------------------------------------------------\r
- // Fields\r
- // ------------------------------------------------------------------------\r
-\r
- // The time graph viewer\r
- TimeGraphViewer fTimeGraphViewer;\r
-\r
- // The selected experiment\r
- private TmfExperiment fSelectedExperiment;\r
-\r
- // The time graph entry list\r
- private ArrayList<TraceEntry> fEntryList;\r
-\r
- // The time graph entry list synchronization object\r
- final private Object fEntryListSyncObj = new Object();\r
-\r
- // The start time\r
- private long fStartTime;\r
-\r
- // The end time\r
- private long fEndTime;\r
-\r
- // The display width\r
- private final int fDisplayWidth;\r
-\r
- // The next resource action\r
- private Action fNextResourceAction;\r
-\r
- // The previous resource action\r
- private Action fPreviousResourceAction;\r
-\r
- // The zoom thread\r
- private ZoomThread fZoomThread;\r
-\r
- // The redraw state used to prevent unnecessary queuing of display runnables\r
- private State fRedrawState = State.IDLE;\r
-\r
- // The redraw synchronization object\r
- final private Object fSyncObj = new Object();\r
-\r
- // ------------------------------------------------------------------------\r
- // Classes\r
- // ------------------------------------------------------------------------\r
-\r
- private class TraceEntry implements ITimeGraphEntry {\r
- // The Trace\r
- private final CtfKernelTrace fTrace;\r
- // The start time\r
- private final long fTraceStartTime;\r
- // The end time\r
- private final long fTraceEndTime;\r
- // The children of the entry\r
- private final ArrayList<ResourcesEntry> fChildren;\r
- // The name of entry\r
- private final String fName;\r
-\r
- public TraceEntry(CtfKernelTrace trace, String name, long startTime, long endTime) {\r
- fTrace = trace;\r
- fChildren = new ArrayList<ResourcesEntry>();\r
- fName = name;\r
- fTraceStartTime = startTime;\r
- fTraceEndTime = endTime;\r
- }\r
-\r
- @Override\r
- public ITimeGraphEntry getParent() {\r
- return null;\r
- }\r
-\r
- @Override\r
- public boolean hasChildren() {\r
- return fChildren != null && fChildren.size() > 0;\r
- }\r
-\r
- @Override\r
- public ResourcesEntry[] getChildren() {\r
- return fChildren.toArray(new ResourcesEntry[0]);\r
- }\r
-\r
- @Override\r
- public String getName() {\r
- return fName;\r
- }\r
-\r
- @Override\r
- public long getStartTime() {\r
- return fTraceStartTime;\r
- }\r
-\r
- @Override\r
- public long getEndTime() {\r
- return fTraceEndTime;\r
- }\r
-\r
- @Override\r
- public boolean hasTimeEvents() {\r
- return false;\r
- }\r
-\r
- @Override\r
- public Iterator<ITimeEvent> getTimeEventsIterator() {\r
- return null;\r
- }\r
-\r
- @Override\r
- public <T extends ITimeEvent> Iterator<T> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration) {\r
- return null;\r
- }\r
-\r
- public CtfKernelTrace getTrace() {\r
- return fTrace;\r
- }\r
-\r
- public void addChild(ResourcesEntry entry) {\r
- int index;\r
- for (index = 0; index < fChildren.size(); index++) {\r
- ResourcesEntry other = fChildren.get(index);\r
- if (entry.getType().compareTo(other.getType()) < 0) {\r
- break;\r
- } else if (entry.getType().equals(other.getType())) {\r
- if (entry.getId() < other.getId()) {\r
- break;\r
- }\r
- }\r
- }\r
- entry.setParent(this);\r
- fChildren.add(index, entry);\r
- }\r
- }\r
-\r
- private static class TraceEntryComparator implements Comparator<ITimeGraphEntry> {\r
- @Override\r
- public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {\r
- int result = o1.getStartTime() < o2.getStartTime() ? -1 : o1.getStartTime() > o2.getStartTime() ? 1 : 0;\r
- if (result == 0) {\r
- result = o1.getName().compareTo(o2.getName());\r
- }\r
- return result;\r
- }\r
- }\r
-\r
- private class ZoomThread extends Thread {\r
- private final long fZoomStartTime;\r
- private final long fZoomEndTime;\r
- private final IProgressMonitor fMonitor;\r
-\r
- public ZoomThread(long startTime, long endTime) {\r
- super("ResourcesView zoom"); //$NON-NLS-1$\r
- fZoomStartTime = startTime;\r
- fZoomEndTime = endTime;\r
- fMonitor = new NullProgressMonitor();\r
- }\r
-\r
- @Override\r
- public void run() {\r
- ArrayList<TraceEntry> entryList = null;\r
- synchronized (fEntryListSyncObj) {\r
- entryList = (ArrayList<TraceEntry>) fEntryList.clone();\r
- }\r
- if (entryList == null) {\r
- return;\r
- }\r
- long resolution = Math.max(1, (fZoomEndTime - fZoomStartTime) / fDisplayWidth);\r
- for (TraceEntry traceEntry : entryList) {\r
- for (ITimeGraphEntry child : traceEntry.getChildren()) {\r
- if (fMonitor.isCanceled()) {\r
- break;\r
- }\r
- ResourcesEntry entry = (ResourcesEntry) child;\r
- if (fZoomStartTime <= fStartTime && fZoomEndTime >= fEndTime) {\r
- entry.setZoomedEventList(null);\r
- } else {\r
- List<ITimeEvent> zoomedEventList = getEventList(entry, fZoomStartTime, fZoomEndTime, resolution, true, fMonitor);\r
- if (zoomedEventList != null) {\r
- entry.setZoomedEventList(zoomedEventList);\r
- }\r
- }\r
- redraw();\r
- }\r
- }\r
- }\r
-\r
- public void cancel() {\r
- fMonitor.setCanceled(true);\r
- }\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Constructors\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Default constructor\r
- */\r
- public ResourcesView() {\r
- super(ID);\r
- fDisplayWidth = Display.getDefault().getBounds().width;\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // ViewPart\r
- // ------------------------------------------------------------------------\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite)\r
- */\r
- @Override\r
- public void createPartControl(Composite parent) {\r
- fTimeGraphViewer = new TimeGraphViewer(parent, SWT.NONE);\r
-\r
- fTimeGraphViewer.setTimeGraphProvider(new ResourcesPresentationProvider());\r
-\r
- fTimeGraphViewer.setTimeCalendarFormat(true);\r
-\r
- fTimeGraphViewer.addRangeListener(new ITimeGraphRangeListener() {\r
- @Override\r
- public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) {\r
- long startTime = event.getStartTime();\r
- long endTime = event.getEndTime();\r
- TmfTimeRange range = new TmfTimeRange(new CtfTmfTimestamp(startTime), new CtfTmfTimestamp(endTime));\r
- TmfTimestamp time = new CtfTmfTimestamp(fTimeGraphViewer.getSelectedTime());\r
- broadcast(new TmfRangeSynchSignal(ResourcesView.this, range, time));\r
- startZoomThread(startTime, endTime);\r
- }\r
- });\r
-\r
- fTimeGraphViewer.addTimeListener(new ITimeGraphTimeListener() {\r
- @Override\r
- public void timeSelected(TimeGraphTimeEvent event) {\r
- long time = event.getTime();\r
- broadcast(new TmfTimeSynchSignal(ResourcesView.this, new CtfTmfTimestamp(time)));\r
- }\r
- });\r
-\r
- final Thread thread = new Thread("ResourcesView build") { //$NON-NLS-1$\r
- @Override\r
- public void run() {\r
- if (TmfExperiment.getCurrentExperiment() != null) {\r
- selectExperiment(TmfExperiment.getCurrentExperiment());\r
- }\r
- }\r
- };\r
- thread.start();\r
-\r
- // View Action Handling\r
- makeActions();\r
- contributeToActionBars();\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.ui.part.WorkbenchPart#setFocus()\r
- */\r
- @Override\r
- public void setFocus() {\r
- refresh(INITIAL_WINDOW_OFFSET);\r
- fTimeGraphViewer.setFocus();\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Signal handlers\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Handler for the ExperimentSelected signal\r
- *\r
- * @param signal\r
- * The incoming signal\r
- */\r
- @TmfSignalHandler\r
- public void experimentSelected(final TmfExperimentSelectedSignal signal) {\r
- if (signal.getExperiment().equals(fSelectedExperiment)) {\r
- return;\r
- }\r
-\r
- final Thread thread = new Thread("ResourcesView build") { //$NON-NLS-1$\r
- @Override\r
- public void run() {\r
- selectExperiment(signal.getExperiment());\r
- }\r
- };\r
- thread.start();\r
- }\r
-\r
- /**\r
- * Experiment is disposed: clear the data structures and the view\r
- *\r
- * @param signal the signal received\r
- */\r
- @TmfSignalHandler\r
- public void experimentDisposed(final TmfExperimentDisposedSignal signal) {\r
- if (signal.getExperiment().equals(fSelectedExperiment)) {\r
- fSelectedExperiment = null;\r
- fStartTime = 0;\r
- fEndTime = 0;\r
- fZoomThread.cancel();\r
- synchronized(fEntryListSyncObj) {\r
- fEntryList.clear();\r
- }\r
- refresh(INITIAL_WINDOW_OFFSET);\r
- }\r
- }\r
-\r
- /**\r
- * Handler for the TimeSynch signal\r
- *\r
- * @param signal\r
- * The incoming signal\r
- */\r
- @TmfSignalHandler\r
- public void synchToTime(final TmfTimeSynchSignal signal) {\r
- if (signal.getSource() == this || fSelectedExperiment == null) {\r
- return;\r
- }\r
- final long time = signal.getCurrentTime().normalize(0, -9).getValue();\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- if (fTimeGraphViewer.getControl().isDisposed()) {\r
- return;\r
- }\r
- fTimeGraphViewer.setSelectedTime(time, true);\r
- startZoomThread(fTimeGraphViewer.getTime0(), fTimeGraphViewer.getTime1());\r
- }\r
- });\r
- }\r
-\r
- /**\r
- * Handler for the RangeSynch signal\r
- *\r
- * @param signal\r
- * The incoming signal\r
- */\r
- @TmfSignalHandler\r
- public void synchToRange(final TmfRangeSynchSignal signal) {\r
- if (signal.getSource() == this || fSelectedExperiment == null) {\r
- return;\r
- }\r
- final long startTime = signal.getCurrentRange().getStartTime().normalize(0, -9).getValue();\r
- final long endTime = signal.getCurrentRange().getEndTime().normalize(0, -9).getValue();\r
- final long time = signal.getCurrentTime().normalize(0, -9).getValue();\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- if (fTimeGraphViewer.getControl().isDisposed()) {\r
- return;\r
- }\r
- fTimeGraphViewer.setStartFinishTime(startTime, endTime);\r
- fTimeGraphViewer.setSelectedTime(time, false);\r
- startZoomThread(startTime, endTime);\r
- }\r
- });\r
- }\r
-\r
- /**\r
- * Handler for the StatesystemBuildCompleted signal\r
- *\r
- * @param signal\r
- * The incoming signal\r
- */\r
- @TmfSignalHandler\r
- public void stateSystemBuildCompleted (final TmfStateSystemBuildCompleted signal) {\r
- final TmfExperiment selectedExperiment = fSelectedExperiment;\r
- if (selectedExperiment == null || selectedExperiment.getTraces() == null) {\r
- return;\r
- }\r
- for (ITmfTrace trace : selectedExperiment.getTraces()) {\r
- if (trace == signal.getTrace() && trace instanceof CtfKernelTrace) {\r
- final Thread thread = new Thread("ResourcesView build") { //$NON-NLS-1$\r
- @Override\r
- public void run() {\r
- // rebuild the model\r
- selectExperiment(selectedExperiment);\r
- }\r
- };\r
- thread.start();\r
- }\r
- }\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Internal\r
- // ------------------------------------------------------------------------\r
-\r
- private void selectExperiment(TmfExperiment experiment) {\r
- fStartTime = Long.MAX_VALUE;\r
- fEndTime = Long.MIN_VALUE;\r
- fSelectedExperiment = experiment;\r
- ArrayList<TraceEntry> entryList = new ArrayList<TraceEntry>();\r
- for (ITmfTrace trace : experiment.getTraces()) {\r
- if (trace instanceof CtfKernelTrace) {\r
- CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) trace;\r
- IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();\r
- long startTime = ssq.getStartTime();\r
- long endTime = ssq.getCurrentEndTime() + 1;\r
- TraceEntry groupEntry = new TraceEntry(ctfKernelTrace, trace.getName(), startTime, endTime);\r
- entryList.add(groupEntry);\r
- fStartTime = Math.min(fStartTime, startTime);\r
- fEndTime = Math.max(fEndTime, endTime);\r
- List<Integer> cpuQuarks = ssq.getQuarks(Attributes.CPUS, "*"); //$NON-NLS-1$\r
- ResourcesEntry[] cpuEntries = new ResourcesEntry[cpuQuarks.size()];\r
- for (int i = 0; i < cpuQuarks.size(); i++) {\r
- int cpuQuark = cpuQuarks.get(i);\r
- int cpu = Integer.parseInt(ssq.getAttributeName(cpuQuark));\r
- ResourcesEntry entry = new ResourcesEntry(cpuQuark, ctfKernelTrace, Type.CPU, cpu);\r
- groupEntry.addChild(entry);\r
- cpuEntries[i] = entry;\r
- }\r
- List<Integer> irqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$\r
- ResourcesEntry[] irqEntries = new ResourcesEntry[irqQuarks.size()];\r
- for (int i = 0; i < irqQuarks.size(); i++) {\r
- int irqQuark = irqQuarks.get(i);\r
- int irq = Integer.parseInt(ssq.getAttributeName(irqQuark));\r
- ResourcesEntry entry = new ResourcesEntry(irqQuark, ctfKernelTrace, Type.IRQ, irq);\r
- groupEntry.addChild(entry);\r
- irqEntries[i] = entry;\r
- }\r
- List<Integer> softIrqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$\r
- ResourcesEntry[] softIrqEntries = new ResourcesEntry[softIrqQuarks.size()];\r
- for (int i = 0; i < softIrqQuarks.size(); i++) {\r
- int softIrqQuark = softIrqQuarks.get(i);\r
- int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark));\r
- ResourcesEntry entry = new ResourcesEntry(softIrqQuark, ctfKernelTrace, Type.SOFT_IRQ, softIrq);\r
- groupEntry.addChild(entry);\r
- softIrqEntries[i] = entry;\r
- }\r
- }\r
- }\r
- synchronized (fEntryListSyncObj) {\r
- fEntryList = (ArrayList<TraceEntry>) entryList.clone();\r
- }\r
- refresh(INITIAL_WINDOW_OFFSET);\r
- for (TraceEntry traceEntry : entryList) {\r
- CtfKernelTrace ctfKernelTrace = traceEntry.getTrace();\r
- IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();\r
- long startTime = ssq.getStartTime();\r
- long endTime = ssq.getCurrentEndTime() + 1;\r
- long resolution = (endTime - startTime) / fDisplayWidth;\r
- for (ResourcesEntry entry : traceEntry.getChildren()) {\r
- List<ITimeEvent> eventList = getEventList(entry, startTime, endTime, resolution, false, new NullProgressMonitor());\r
- entry.setEventList(eventList);\r
- redraw();\r
- }\r
- }\r
- }\r
-\r
- private static List<ITimeEvent> getEventList(ResourcesEntry entry,\r
- long startTime, long endTime, long resolution, boolean includeNull,\r
- IProgressMonitor monitor) {\r
- IStateSystemQuerier ssq = entry.getTrace().getStateSystem();\r
- startTime = Math.max(startTime, ssq.getStartTime());\r
- endTime = Math.min(endTime, ssq.getCurrentEndTime() + 1);\r
- if (endTime <= startTime) {\r
- return null;\r
- }\r
- List<ITimeEvent> eventList = null;\r
- int quark = entry.getQuark();\r
- try {\r
- if (entry.getType().equals(Type.CPU)) {\r
- int statusQuark = ssq.getQuarkRelative(quark, Attributes.STATUS);\r
- List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, startTime, endTime - 1, resolution, monitor);\r
- eventList = new ArrayList<ITimeEvent>(statusIntervals.size());\r
- long lastEndTime = -1;\r
- for (ITmfStateInterval statusInterval : statusIntervals) {\r
- if (monitor.isCanceled()) {\r
- return null;\r
- }\r
- int status = statusInterval.getStateValue().unboxInt();\r
- long time = statusInterval.getStartTime();\r
- long duration = statusInterval.getEndTime() - time + 1;\r
- if (!statusInterval.getStateValue().isNull()) {\r
- if (lastEndTime != time && lastEndTime != -1) {\r
- eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));\r
- }\r
- eventList.add(new ResourcesEvent(entry, time, duration, status));\r
- lastEndTime = time + duration;\r
- } else {\r
- if (includeNull) {\r
- eventList.add(new ResourcesEvent(entry, time, duration));\r
- }\r
- }\r
- }\r
- } else if (entry.getType().equals(Type.IRQ)) {\r
- List<ITmfStateInterval> irqIntervals = ssq.queryHistoryRange(quark, startTime, endTime - 1, resolution, monitor);\r
- eventList = new ArrayList<ITimeEvent>(irqIntervals.size());\r
- long lastEndTime = -1;\r
- boolean lastIsNull = true;\r
- for (ITmfStateInterval irqInterval : irqIntervals) {\r
- if (monitor.isCanceled()) {\r
- return null;\r
- }\r
- long time = irqInterval.getStartTime();\r
- long duration = irqInterval.getEndTime() - time + 1;\r
- if (!irqInterval.getStateValue().isNull()) {\r
- int cpu = irqInterval.getStateValue().unboxInt();\r
- eventList.add(new ResourcesEvent(entry, time, duration, cpu));\r
- lastIsNull = false;\r
- } else {\r
- if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {\r
- eventList.add(new ResourcesEvent(entry, lastEndTime, time - lastEndTime, -1));\r
- }\r
- if (includeNull) {\r
- eventList.add(new ResourcesEvent(entry, time, duration));\r
- }\r
- lastIsNull = true;\r
- }\r
- lastEndTime = time + duration;\r
- }\r
- } else if (entry.getType().equals(Type.SOFT_IRQ)) {\r
- List<ITmfStateInterval> softIrqIntervals = ssq.queryHistoryRange(quark, startTime, endTime - 1, resolution, monitor);\r
- eventList = new ArrayList<ITimeEvent>(softIrqIntervals.size());\r
- long lastEndTime = -1;\r
- boolean lastIsNull = true;\r
- for (ITmfStateInterval softIrqInterval : softIrqIntervals) {\r
- if (monitor.isCanceled()) {\r
- return null;\r
- }\r
- long time = softIrqInterval.getStartTime();\r
- long duration = softIrqInterval.getEndTime() - time + 1;\r
- if (!softIrqInterval.getStateValue().isNull()) {\r
- int cpu = softIrqInterval.getStateValue().unboxInt();\r
- eventList.add(new ResourcesEvent(entry, time, duration, cpu));\r
- } else {\r
- if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {\r
- eventList.add(new ResourcesEvent(entry, lastEndTime, time - lastEndTime, -1));\r
- }\r
- if (includeNull) {\r
- eventList.add(new ResourcesEvent(entry, time, duration));\r
- }\r
- lastIsNull = true;\r
- }\r
- lastEndTime = time + duration;\r
- }\r
- }\r
- } catch (AttributeNotFoundException e) {\r
- e.printStackTrace();\r
- } catch (TimeRangeException e) {\r
- e.printStackTrace();\r
- } catch (StateValueTypeException e) {\r
- e.printStackTrace();\r
- }\r
- return eventList;\r
- }\r
-\r
- private void refresh(final long windowRange) {\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- if (fTimeGraphViewer.getControl().isDisposed()) {\r
- return;\r
- }\r
- ITimeGraphEntry[] entries = null;\r
- synchronized (fEntryListSyncObj) {\r
- if (fEntryList != null) {\r
- entries = fEntryList.toArray(new ITimeGraphEntry[0]);\r
- }\r
- }\r
- if (entries != null) {\r
- Arrays.sort(entries, new TraceEntryComparator());\r
- fTimeGraphViewer.setInput(entries);\r
- fTimeGraphViewer.setTimeBounds(fStartTime, fEndTime);\r
-\r
- long endTime = fStartTime + windowRange;\r
-\r
- if (fEndTime < endTime) {\r
- endTime = fEndTime;\r
- }\r
- fTimeGraphViewer.setStartFinishTime(fStartTime, endTime);\r
-\r
- startZoomThread(fStartTime, endTime);\r
- }\r
- }\r
- });\r
- }\r
-\r
- private void redraw() {\r
- synchronized (fSyncObj) {\r
- if (fRedrawState == State.IDLE) {\r
- fRedrawState = State.BUSY;\r
- } else {\r
- fRedrawState = State.PENDING;\r
- return;\r
- }\r
- }\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- if (fTimeGraphViewer.getControl().isDisposed()) {\r
- return;\r
- }\r
- fTimeGraphViewer.getControl().redraw();\r
- fTimeGraphViewer.getControl().update();\r
- synchronized (fSyncObj) {\r
- if (fRedrawState == State.PENDING) {\r
- fRedrawState = State.IDLE;\r
- redraw();\r
- } else {\r
- fRedrawState = State.IDLE;\r
- }\r
- }\r
- }\r
- });\r
- }\r
-\r
- private void startZoomThread(long startTime, long endTime) {\r
- if (fZoomThread != null) {\r
- fZoomThread.cancel();\r
- }\r
- fZoomThread = new ZoomThread(startTime, endTime);\r
- fZoomThread.start();\r
- }\r
-\r
- private void makeActions() {\r
- fPreviousResourceAction = fTimeGraphViewer.getPreviousItemAction();\r
- fPreviousResourceAction.setText(Messages.ResourcesView_previousResourceActionNameText);\r
- fPreviousResourceAction.setToolTipText(Messages.ResourcesView_previousResourceActionToolTipText);\r
- fNextResourceAction = fTimeGraphViewer.getNextItemAction();\r
- fNextResourceAction.setText(Messages.ResourcesView_nextResourceActionNameText);\r
- fNextResourceAction.setToolTipText(Messages.ResourcesView_previousResourceActionToolTipText);\r
- }\r
-\r
- private void contributeToActionBars() {\r
- IActionBars bars = getViewSite().getActionBars();\r
- fillLocalToolBar(bars.getToolBarManager());\r
- }\r
-\r
- private void fillLocalToolBar(IToolBarManager manager) {\r
- manager.add(fTimeGraphViewer.getShowLegendAction());\r
- manager.add(new Separator());\r
- manager.add(fTimeGraphViewer.getResetScaleAction());\r
- manager.add(fTimeGraphViewer.getPreviousEventAction());\r
- manager.add(fTimeGraphViewer.getNextEventAction());\r
- manager.add(fPreviousResourceAction);\r
- manager.add(fNextResourceAction);\r
- manager.add(fTimeGraphViewer.getZoomInAction());\r
- manager.add(fTimeGraphViewer.getZoomOutAction());\r
- manager.add(new Separator());\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
+import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;
+import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;
+import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
+import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
+import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
+import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
+import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.linuxtools.tmf.core.signal.TmfStateSystemBuildCompleted;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
+import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
+import org.eclipse.linuxtools.tmf.ui.views.TmfView;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphViewer;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IActionBars;
+
+/**
+ * Main implementation for the LTTng 2.0 kernel Resource view
+ *
+ * @author Patrick Tasse
+ */
+public class ResourcesView extends TmfView {
+
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+
+ /** View ID. */
+ public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
+
+ /** Initial time range */
+ private static final long INITIAL_WINDOW_OFFSET = (1L * 100 * 1000 * 1000); // .1sec
+
+ /**
+ * Redraw state enum
+ */
+ private enum State { IDLE, BUSY, PENDING }
+
+ // ------------------------------------------------------------------------
+ // Fields
+ // ------------------------------------------------------------------------
+
+ // The time graph viewer
+ TimeGraphViewer fTimeGraphViewer;
+
+ // The selected experiment
+ private TmfExperiment fSelectedExperiment;
+
+ // The time graph entry list
+ private ArrayList<TraceEntry> fEntryList;
+
+ // The time graph entry list synchronization object
+ final private Object fEntryListSyncObj = new Object();
+
+ // The start time
+ private long fStartTime;
+
+ // The end time
+ private long fEndTime;
+
+ // The display width
+ private final int fDisplayWidth;
+
+ // The next resource action
+ private Action fNextResourceAction;
+
+ // The previous resource action
+ private Action fPreviousResourceAction;
+
+ // The zoom thread
+ private ZoomThread fZoomThread;
+
+ // The redraw state used to prevent unnecessary queuing of display runnables
+ private State fRedrawState = State.IDLE;
+
+ // The redraw synchronization object
+ final private Object fSyncObj = new Object();
+
+ // ------------------------------------------------------------------------
+ // Classes
+ // ------------------------------------------------------------------------
+
+ private class TraceEntry implements ITimeGraphEntry {
+ // The Trace
+ private final CtfKernelTrace fTrace;
+ // The start time
+ private final long fTraceStartTime;
+ // The end time
+ private final long fTraceEndTime;
+ // The children of the entry
+ private final ArrayList<ResourcesEntry> fChildren;
+ // The name of entry
+ private final String fName;
+
+ public TraceEntry(CtfKernelTrace trace, String name, long startTime, long endTime) {
+ fTrace = trace;
+ fChildren = new ArrayList<ResourcesEntry>();
+ fName = name;
+ fTraceStartTime = startTime;
+ fTraceEndTime = endTime;
+ }
+
+ @Override
+ public ITimeGraphEntry getParent() {
+ return null;
+ }
+
+ @Override
+ public boolean hasChildren() {
+ return fChildren != null && fChildren.size() > 0;
+ }
+
+ @Override
+ public ResourcesEntry[] getChildren() {
+ return fChildren.toArray(new ResourcesEntry[0]);
+ }
+
+ @Override
+ public String getName() {
+ return fName;
+ }
+
+ @Override
+ public long getStartTime() {
+ return fTraceStartTime;
+ }
+
+ @Override
+ public long getEndTime() {
+ return fTraceEndTime;
+ }
+
+ @Override
+ public boolean hasTimeEvents() {
+ return false;
+ }
+
+ @Override
+ public Iterator<ITimeEvent> getTimeEventsIterator() {
+ return null;
+ }
+
+ @Override
+ public <T extends ITimeEvent> Iterator<T> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration) {
+ return null;
+ }
+
+ public CtfKernelTrace getTrace() {
+ return fTrace;
+ }
+
+ public void addChild(ResourcesEntry entry) {
+ int index;
+ for (index = 0; index < fChildren.size(); index++) {
+ ResourcesEntry other = fChildren.get(index);
+ if (entry.getType().compareTo(other.getType()) < 0) {
+ break;
+ } else if (entry.getType().equals(other.getType())) {
+ if (entry.getId() < other.getId()) {
+ break;
+ }
+ }
+ }
+ entry.setParent(this);
+ fChildren.add(index, entry);
+ }
+ }
+
+ private static class TraceEntryComparator implements Comparator<ITimeGraphEntry> {
+ @Override
+ public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {
+ int result = o1.getStartTime() < o2.getStartTime() ? -1 : o1.getStartTime() > o2.getStartTime() ? 1 : 0;
+ if (result == 0) {
+ result = o1.getName().compareTo(o2.getName());
+ }
+ return result;
+ }
+ }
+
+ private class ZoomThread extends Thread {
+ private final long fZoomStartTime;
+ private final long fZoomEndTime;
+ private final IProgressMonitor fMonitor;
+
+ public ZoomThread(long startTime, long endTime) {
+ super("ResourcesView zoom"); //$NON-NLS-1$
+ fZoomStartTime = startTime;
+ fZoomEndTime = endTime;
+ fMonitor = new NullProgressMonitor();
+ }
+
+ @Override
+ public void run() {
+ ArrayList<TraceEntry> entryList = null;
+ synchronized (fEntryListSyncObj) {
+ entryList = (ArrayList<TraceEntry>) fEntryList.clone();
+ }
+ if (entryList == null) {
+ return;
+ }
+ long resolution = Math.max(1, (fZoomEndTime - fZoomStartTime) / fDisplayWidth);
+ for (TraceEntry traceEntry : entryList) {
+ for (ITimeGraphEntry child : traceEntry.getChildren()) {
+ if (fMonitor.isCanceled()) {
+ break;
+ }
+ ResourcesEntry entry = (ResourcesEntry) child;
+ if (fZoomStartTime <= fStartTime && fZoomEndTime >= fEndTime) {
+ entry.setZoomedEventList(null);
+ } else {
+ List<ITimeEvent> zoomedEventList = getEventList(entry, fZoomStartTime, fZoomEndTime, resolution, true, fMonitor);
+ if (zoomedEventList != null) {
+ entry.setZoomedEventList(zoomedEventList);
+ }
+ }
+ redraw();
+ }
+ }
+ }
+
+ public void cancel() {
+ fMonitor.setCanceled(true);
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Default constructor
+ */
+ public ResourcesView() {
+ super(ID);
+ fDisplayWidth = Display.getDefault().getBounds().width;
+ }
+
+ // ------------------------------------------------------------------------
+ // ViewPart
+ // ------------------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void createPartControl(Composite parent) {
+ fTimeGraphViewer = new TimeGraphViewer(parent, SWT.NONE);
+
+ fTimeGraphViewer.setTimeGraphProvider(new ResourcesPresentationProvider());
+
+ fTimeGraphViewer.setTimeCalendarFormat(true);
+
+ fTimeGraphViewer.addRangeListener(new ITimeGraphRangeListener() {
+ @Override
+ public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) {
+ long startTime = event.getStartTime();
+ long endTime = event.getEndTime();
+ TmfTimeRange range = new TmfTimeRange(new CtfTmfTimestamp(startTime), new CtfTmfTimestamp(endTime));
+ TmfTimestamp time = new CtfTmfTimestamp(fTimeGraphViewer.getSelectedTime());
+ broadcast(new TmfRangeSynchSignal(ResourcesView.this, range, time));
+ startZoomThread(startTime, endTime);
+ }
+ });
+
+ fTimeGraphViewer.addTimeListener(new ITimeGraphTimeListener() {
+ @Override
+ public void timeSelected(TimeGraphTimeEvent event) {
+ long time = event.getTime();
+ broadcast(new TmfTimeSynchSignal(ResourcesView.this, new CtfTmfTimestamp(time)));
+ }
+ });
+
+ final Thread thread = new Thread("ResourcesView build") { //$NON-NLS-1$
+ @Override
+ public void run() {
+ if (TmfExperiment.getCurrentExperiment() != null) {
+ selectExperiment(TmfExperiment.getCurrentExperiment());
+ }
+ }
+ };
+ thread.start();
+
+ // View Action Handling
+ makeActions();
+ contributeToActionBars();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
+ */
+ @Override
+ public void setFocus() {
+ refresh(INITIAL_WINDOW_OFFSET);
+ fTimeGraphViewer.setFocus();
+ }
+
+ // ------------------------------------------------------------------------
+ // Signal handlers
+ // ------------------------------------------------------------------------
+
+ /**
+ * Handler for the ExperimentSelected signal
+ *
+ * @param signal
+ * The incoming signal
+ */
+ @TmfSignalHandler
+ public void experimentSelected(final TmfExperimentSelectedSignal signal) {
+ if (signal.getExperiment().equals(fSelectedExperiment)) {
+ return;
+ }
+
+ final Thread thread = new Thread("ResourcesView build") { //$NON-NLS-1$
+ @Override
+ public void run() {
+ selectExperiment(signal.getExperiment());
+ }
+ };
+ thread.start();
+ }
+
+ /**
+ * Experiment is disposed: clear the data structures and the view
+ *
+ * @param signal the signal received
+ */
+ @TmfSignalHandler
+ public void experimentDisposed(final TmfExperimentDisposedSignal signal) {
+ if (signal.getExperiment().equals(fSelectedExperiment)) {
+ fSelectedExperiment = null;
+ fStartTime = 0;
+ fEndTime = 0;
+ fZoomThread.cancel();
+ synchronized(fEntryListSyncObj) {
+ fEntryList.clear();
+ }
+ refresh(INITIAL_WINDOW_OFFSET);
+ }
+ }
+
+ /**
+ * Handler for the TimeSynch signal
+ *
+ * @param signal
+ * The incoming signal
+ */
+ @TmfSignalHandler
+ public void synchToTime(final TmfTimeSynchSignal signal) {
+ if (signal.getSource() == this || fSelectedExperiment == null) {
+ return;
+ }
+ final long time = signal.getCurrentTime().normalize(0, -9).getValue();
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (fTimeGraphViewer.getControl().isDisposed()) {
+ return;
+ }
+ fTimeGraphViewer.setSelectedTime(time, true);
+ startZoomThread(fTimeGraphViewer.getTime0(), fTimeGraphViewer.getTime1());
+ }
+ });
+ }
+
+ /**
+ * Handler for the RangeSynch signal
+ *
+ * @param signal
+ * The incoming signal
+ */
+ @TmfSignalHandler
+ public void synchToRange(final TmfRangeSynchSignal signal) {
+ if (signal.getSource() == this || fSelectedExperiment == null) {
+ return;
+ }
+ final long startTime = signal.getCurrentRange().getStartTime().normalize(0, -9).getValue();
+ final long endTime = signal.getCurrentRange().getEndTime().normalize(0, -9).getValue();
+ final long time = signal.getCurrentTime().normalize(0, -9).getValue();
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (fTimeGraphViewer.getControl().isDisposed()) {
+ return;
+ }
+ fTimeGraphViewer.setStartFinishTime(startTime, endTime);
+ fTimeGraphViewer.setSelectedTime(time, false);
+ startZoomThread(startTime, endTime);
+ }
+ });
+ }
+
+ /**
+ * Handler for the StatesystemBuildCompleted signal
+ *
+ * @param signal
+ * The incoming signal
+ */
+ @TmfSignalHandler
+ public void stateSystemBuildCompleted (final TmfStateSystemBuildCompleted signal) {
+ final TmfExperiment selectedExperiment = fSelectedExperiment;
+ if (selectedExperiment == null || selectedExperiment.getTraces() == null) {
+ return;
+ }
+ for (ITmfTrace trace : selectedExperiment.getTraces()) {
+ if (trace == signal.getTrace() && trace instanceof CtfKernelTrace) {
+ final Thread thread = new Thread("ResourcesView build") { //$NON-NLS-1$
+ @Override
+ public void run() {
+ // rebuild the model
+ selectExperiment(selectedExperiment);
+ }
+ };
+ thread.start();
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Internal
+ // ------------------------------------------------------------------------
+
+ private void selectExperiment(TmfExperiment experiment) {
+ fStartTime = Long.MAX_VALUE;
+ fEndTime = Long.MIN_VALUE;
+ fSelectedExperiment = experiment;
+ ArrayList<TraceEntry> entryList = new ArrayList<TraceEntry>();
+ for (ITmfTrace trace : experiment.getTraces()) {
+ if (trace instanceof CtfKernelTrace) {
+ CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) trace;
+ IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();
+ long startTime = ssq.getStartTime();
+ long endTime = ssq.getCurrentEndTime() + 1;
+ TraceEntry groupEntry = new TraceEntry(ctfKernelTrace, trace.getName(), startTime, endTime);
+ entryList.add(groupEntry);
+ fStartTime = Math.min(fStartTime, startTime);
+ fEndTime = Math.max(fEndTime, endTime);
+ List<Integer> cpuQuarks = ssq.getQuarks(Attributes.CPUS, "*"); //$NON-NLS-1$
+ ResourcesEntry[] cpuEntries = new ResourcesEntry[cpuQuarks.size()];
+ for (int i = 0; i < cpuQuarks.size(); i++) {
+ int cpuQuark = cpuQuarks.get(i);
+ int cpu = Integer.parseInt(ssq.getAttributeName(cpuQuark));
+ ResourcesEntry entry = new ResourcesEntry(cpuQuark, ctfKernelTrace, Type.CPU, cpu);
+ groupEntry.addChild(entry);
+ cpuEntries[i] = entry;
+ }
+ List<Integer> irqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$
+ ResourcesEntry[] irqEntries = new ResourcesEntry[irqQuarks.size()];
+ for (int i = 0; i < irqQuarks.size(); i++) {
+ int irqQuark = irqQuarks.get(i);
+ int irq = Integer.parseInt(ssq.getAttributeName(irqQuark));
+ ResourcesEntry entry = new ResourcesEntry(irqQuark, ctfKernelTrace, Type.IRQ, irq);
+ groupEntry.addChild(entry);
+ irqEntries[i] = entry;
+ }
+ List<Integer> softIrqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$
+ ResourcesEntry[] softIrqEntries = new ResourcesEntry[softIrqQuarks.size()];
+ for (int i = 0; i < softIrqQuarks.size(); i++) {
+ int softIrqQuark = softIrqQuarks.get(i);
+ int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark));
+ ResourcesEntry entry = new ResourcesEntry(softIrqQuark, ctfKernelTrace, Type.SOFT_IRQ, softIrq);
+ groupEntry.addChild(entry);
+ softIrqEntries[i] = entry;
+ }
+ }
+ }
+ synchronized (fEntryListSyncObj) {
+ fEntryList = (ArrayList<TraceEntry>) entryList.clone();
+ }
+ refresh(INITIAL_WINDOW_OFFSET);
+ for (TraceEntry traceEntry : entryList) {
+ CtfKernelTrace ctfKernelTrace = traceEntry.getTrace();
+ IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();
+ long startTime = ssq.getStartTime();
+ long endTime = ssq.getCurrentEndTime() + 1;
+ long resolution = (endTime - startTime) / fDisplayWidth;
+ for (ResourcesEntry entry : traceEntry.getChildren()) {
+ List<ITimeEvent> eventList = getEventList(entry, startTime, endTime, resolution, false, new NullProgressMonitor());
+ entry.setEventList(eventList);
+ redraw();
+ }
+ }
+ }
+
+ private static List<ITimeEvent> getEventList(ResourcesEntry entry,
+ long startTime, long endTime, long resolution, boolean includeNull,
+ IProgressMonitor monitor) {
+ IStateSystemQuerier ssq = entry.getTrace().getStateSystem();
+ startTime = Math.max(startTime, ssq.getStartTime());
+ endTime = Math.min(endTime, ssq.getCurrentEndTime() + 1);
+ if (endTime <= startTime) {
+ return null;
+ }
+ List<ITimeEvent> eventList = null;
+ int quark = entry.getQuark();
+ try {
+ if (entry.getType().equals(Type.CPU)) {
+ int statusQuark = ssq.getQuarkRelative(quark, Attributes.STATUS);
+ List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, startTime, endTime - 1, resolution, monitor);
+ eventList = new ArrayList<ITimeEvent>(statusIntervals.size());
+ long lastEndTime = -1;
+ for (ITmfStateInterval statusInterval : statusIntervals) {
+ if (monitor.isCanceled()) {
+ return null;
+ }
+ int status = statusInterval.getStateValue().unboxInt();
+ long time = statusInterval.getStartTime();
+ long duration = statusInterval.getEndTime() - time + 1;
+ if (!statusInterval.getStateValue().isNull()) {
+ if (lastEndTime != time && lastEndTime != -1) {
+ eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));
+ }
+ eventList.add(new ResourcesEvent(entry, time, duration, status));
+ lastEndTime = time + duration;
+ } else {
+ if (includeNull) {
+ eventList.add(new ResourcesEvent(entry, time, duration));
+ }
+ }
+ }
+ } else if (entry.getType().equals(Type.IRQ)) {
+ List<ITmfStateInterval> irqIntervals = ssq.queryHistoryRange(quark, startTime, endTime - 1, resolution, monitor);
+ eventList = new ArrayList<ITimeEvent>(irqIntervals.size());
+ long lastEndTime = -1;
+ boolean lastIsNull = true;
+ for (ITmfStateInterval irqInterval : irqIntervals) {
+ if (monitor.isCanceled()) {
+ return null;
+ }
+ long time = irqInterval.getStartTime();
+ long duration = irqInterval.getEndTime() - time + 1;
+ if (!irqInterval.getStateValue().isNull()) {
+ int cpu = irqInterval.getStateValue().unboxInt();
+ eventList.add(new ResourcesEvent(entry, time, duration, cpu));
+ lastIsNull = false;
+ } else {
+ if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {
+ eventList.add(new ResourcesEvent(entry, lastEndTime, time - lastEndTime, -1));
+ }
+ if (includeNull) {
+ eventList.add(new ResourcesEvent(entry, time, duration));
+ }
+ lastIsNull = true;
+ }
+ lastEndTime = time + duration;
+ }
+ } else if (entry.getType().equals(Type.SOFT_IRQ)) {
+ List<ITmfStateInterval> softIrqIntervals = ssq.queryHistoryRange(quark, startTime, endTime - 1, resolution, monitor);
+ eventList = new ArrayList<ITimeEvent>(softIrqIntervals.size());
+ long lastEndTime = -1;
+ boolean lastIsNull = true;
+ for (ITmfStateInterval softIrqInterval : softIrqIntervals) {
+ if (monitor.isCanceled()) {
+ return null;
+ }
+ long time = softIrqInterval.getStartTime();
+ long duration = softIrqInterval.getEndTime() - time + 1;
+ if (!softIrqInterval.getStateValue().isNull()) {
+ int cpu = softIrqInterval.getStateValue().unboxInt();
+ eventList.add(new ResourcesEvent(entry, time, duration, cpu));
+ } else {
+ if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {
+ eventList.add(new ResourcesEvent(entry, lastEndTime, time - lastEndTime, -1));
+ }
+ if (includeNull) {
+ eventList.add(new ResourcesEvent(entry, time, duration));
+ }
+ lastIsNull = true;
+ }
+ lastEndTime = time + duration;
+ }
+ }
+ } catch (AttributeNotFoundException e) {
+ e.printStackTrace();
+ } catch (TimeRangeException e) {
+ e.printStackTrace();
+ } catch (StateValueTypeException e) {
+ e.printStackTrace();
+ }
+ return eventList;
+ }
+
+ private void refresh(final long windowRange) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (fTimeGraphViewer.getControl().isDisposed()) {
+ return;
+ }
+ ITimeGraphEntry[] entries = null;
+ synchronized (fEntryListSyncObj) {
+ if (fEntryList != null) {
+ entries = fEntryList.toArray(new ITimeGraphEntry[0]);
+ }
+ }
+ if (entries != null) {
+ Arrays.sort(entries, new TraceEntryComparator());
+ fTimeGraphViewer.setInput(entries);
+ fTimeGraphViewer.setTimeBounds(fStartTime, fEndTime);
+
+ long endTime = fStartTime + windowRange;
+
+ if (fEndTime < endTime) {
+ endTime = fEndTime;
+ }
+ fTimeGraphViewer.setStartFinishTime(fStartTime, endTime);
+
+ startZoomThread(fStartTime, endTime);
+ }
+ }
+ });
+ }
+
+ private void redraw() {
+ synchronized (fSyncObj) {
+ if (fRedrawState == State.IDLE) {
+ fRedrawState = State.BUSY;
+ } else {
+ fRedrawState = State.PENDING;
+ return;
+ }
+ }
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (fTimeGraphViewer.getControl().isDisposed()) {
+ return;
+ }
+ fTimeGraphViewer.getControl().redraw();
+ fTimeGraphViewer.getControl().update();
+ synchronized (fSyncObj) {
+ if (fRedrawState == State.PENDING) {
+ fRedrawState = State.IDLE;
+ redraw();
+ } else {
+ fRedrawState = State.IDLE;
+ }
+ }
+ }
+ });
+ }
+
+ private void startZoomThread(long startTime, long endTime) {
+ if (fZoomThread != null) {
+ fZoomThread.cancel();
+ }
+ fZoomThread = new ZoomThread(startTime, endTime);
+ fZoomThread.start();
+ }
+
+ private void makeActions() {
+ fPreviousResourceAction = fTimeGraphViewer.getPreviousItemAction();
+ fPreviousResourceAction.setText(Messages.ResourcesView_previousResourceActionNameText);
+ fPreviousResourceAction.setToolTipText(Messages.ResourcesView_previousResourceActionToolTipText);
+ fNextResourceAction = fTimeGraphViewer.getNextItemAction();
+ fNextResourceAction.setText(Messages.ResourcesView_nextResourceActionNameText);
+ fNextResourceAction.setToolTipText(Messages.ResourcesView_previousResourceActionToolTipText);
+ }
+
+ private void contributeToActionBars() {
+ IActionBars bars = getViewSite().getActionBars();
+ fillLocalToolBar(bars.getToolBarManager());
+ }
+
+ private void fillLocalToolBar(IToolBarManager manager) {
+ manager.add(fTimeGraphViewer.getShowLegendAction());
+ manager.add(new Separator());
+ manager.add(fTimeGraphViewer.getResetScaleAction());
+ manager.add(fTimeGraphViewer.getPreviousEventAction());
+ manager.add(fTimeGraphViewer.getNextEventAction());
+ manager.add(fPreviousResourceAction);
+ manager.add(fNextResourceAction);
+ manager.add(fTimeGraphViewer.getZoomInAction());
+ manager.add(fTimeGraphViewer.getZoomOutAction());
+ manager.add(new Separator());
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Francois Chouinard - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.core;\r
-\r
-import java.io.BufferedWriter;\r
-import java.io.FileWriter;\r
-import java.io.IOException;\r
-\r
-import org.eclipse.core.runtime.Platform;\r
-import org.eclipse.linuxtools.tmf.core.component.ITmfComponent;\r
-import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;\r
-\r
-/**\r
- * The TMF Core tracer, used to trace TMF internal components.\r
- * <p>\r
- * The tracing classes are independently controlled (i.e no implicit inclusion)\r
- * from the launch configuration's Tracing. The resulting trace is stored in a\r
- * distinct file (TmfTrace.log) in a format that can later be analyzed by TMF.\r
- * <p>\r
- * The tracing classes are:\r
- * <ul>\r
- * <li><strong>Component</strong>: TMF components life-cycle\r
- * <li><strong>Request</strong>: TMF requests life-cycle\r
- * <li><strong>Signal</strong>: TMF signals triggering and distribution\r
- * <li><strong>Event</strong>: TMF trace events\r
- * </ul>\r
- *\r
- * @version 1.0\r
- * @author Francois Chouinard\r
- */\r
-@SuppressWarnings("nls")\r
-public class TmfCoreTracer {\r
-\r
- // ------------------------------------------------------------------------\r
- // Constants\r
- // ------------------------------------------------------------------------\r
-\r
- private static final String PLUGIN_ID = Activator.PLUGIN_ID;\r
-\r
- // Tracing keys (in .options)\r
- private static final String COMPONENT_TRACE_KEY = PLUGIN_ID + "/component";\r
- private static final String REQUEST_TRACE_KEY = PLUGIN_ID + "/request";\r
- private static final String SIGNAL_TRACE_KEY = PLUGIN_ID + "/signal";\r
- private static final String EVENT_TRACE_KEY = PLUGIN_ID + "/event";\r
-\r
- private static final String TRACE_FILE_NAME = "TmfTrace.log";\r
-\r
- // ------------------------------------------------------------------------\r
- // Attributes\r
- // ------------------------------------------------------------------------\r
-\r
- // Classes tracing flags\r
- static Boolean COMPONENT_CLASS_ENABLED = Boolean.FALSE;\r
- static Boolean REQUEST_CLASS_ENABLED = Boolean.FALSE;\r
- static Boolean SIGNAL_CLASS_ENABLED = Boolean.FALSE;\r
- static Boolean EVENT_CLASS_ENABLED = Boolean.FALSE;\r
-\r
- // Trace log file\r
- private static BufferedWriter fTraceFile;\r
-\r
- // ------------------------------------------------------------------------\r
- // Start/stop tracing - controlled by the plug-in\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Set the tracing flags according to the launch configuration\r
- */\r
- public static void init() {\r
-\r
- String traceKey;\r
- boolean isTracing = false;\r
-\r
- traceKey = Platform.getDebugOption(COMPONENT_TRACE_KEY);\r
- if (traceKey != null) {\r
- COMPONENT_CLASS_ENABLED = (Boolean.valueOf(traceKey)).booleanValue();\r
- isTracing |= COMPONENT_CLASS_ENABLED;\r
- }\r
-\r
- traceKey = Platform.getDebugOption(REQUEST_TRACE_KEY);\r
- if (traceKey != null) {\r
- REQUEST_CLASS_ENABLED = (Boolean.valueOf(traceKey)).booleanValue();\r
- isTracing |= REQUEST_CLASS_ENABLED;\r
- }\r
-\r
- traceKey = Platform.getDebugOption(SIGNAL_TRACE_KEY);\r
- if (traceKey != null) {\r
- SIGNAL_CLASS_ENABLED = (Boolean.valueOf(traceKey)).booleanValue();\r
- isTracing |= SIGNAL_CLASS_ENABLED;\r
- }\r
-\r
- traceKey = Platform.getDebugOption(EVENT_TRACE_KEY);\r
- if (traceKey != null) {\r
- EVENT_CLASS_ENABLED = (Boolean.valueOf(traceKey)).booleanValue();\r
- isTracing |= EVENT_CLASS_ENABLED;\r
- }\r
-\r
- // Create trace log file if any of the flags was set\r
- if (isTracing) {\r
- try {\r
- fTraceFile = new BufferedWriter(new FileWriter(TRACE_FILE_NAME));\r
- } catch (IOException e) {\r
- Activator.logError("Error opening log file " + TRACE_FILE_NAME, e);\r
- fTraceFile = null;\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Close the trace log file\r
- */\r
- public static void stop() {\r
- if (fTraceFile != null) {\r
- try {\r
- fTraceFile.close();\r
- fTraceFile = null;\r
- } catch (IOException e) {\r
- Activator.logError("Error closing log file", e);\r
- }\r
- }\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Predicates\r
- // ------------------------------------------------------------------------\r
-\r
- @SuppressWarnings("javadoc")\r
- public static boolean isComponentTraced() {\r
- return COMPONENT_CLASS_ENABLED;\r
- }\r
-\r
- @SuppressWarnings("javadoc")\r
- public static boolean isRequestTraced() {\r
- return REQUEST_CLASS_ENABLED;\r
- }\r
-\r
- @SuppressWarnings("javadoc")\r
- public static boolean isSignalTraced() {\r
- return SIGNAL_CLASS_ENABLED;\r
- }\r
-\r
- @SuppressWarnings("javadoc")\r
- public static boolean isEventTraced() {\r
- return EVENT_CLASS_ENABLED;\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Tracing methods\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * The central tracing method. Prepends the timestamp and the thread id\r
- * to the trace message.\r
- *\r
- * @param msg the trace message to log\r
- */\r
- public static synchronized void trace(String msg) {\r
-\r
- // Set the timestamp (ms resolution)\r
- long currentTime = System.currentTimeMillis();\r
- StringBuilder message = new StringBuilder("[");\r
- message.append(currentTime / 1000);\r
- message.append(".");\r
- message.append(String.format("%1$03d", currentTime % 1000));\r
- message.append("] ");\r
-\r
- // Set the thread id\r
- message.append("[TID=");\r
- message.append(String.format("%1$03d", Thread.currentThread().getId()));\r
- message.append("] ");\r
-\r
- // Append the trace message\r
- message.append(msg);\r
-\r
- // Write to file\r
- if (fTraceFile != null) {\r
- try {\r
- fTraceFile.write(message.toString());\r
- fTraceFile.newLine();\r
- fTraceFile.flush();\r
- } catch (IOException e) {\r
- Activator.logError("Error writing to log file", e);\r
- }\r
- }\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // TMF Core specific trace formatters\r
- // ------------------------------------------------------------------------\r
-\r
- @SuppressWarnings("javadoc")\r
- public static void traceComponent(ITmfComponent component, String msg) {\r
- if (COMPONENT_CLASS_ENABLED) {\r
- String message = ("[CMP] Cmp=" + component.getName() + " " + msg);\r
- trace(message);\r
- }\r
- }\r
-\r
- @SuppressWarnings("javadoc")\r
- public static void traceRequest(ITmfDataRequest request, String msg) {\r
- if (REQUEST_CLASS_ENABLED) {\r
- String message = ("[REQ] Req=" + request.getRequestId() + " " + msg);\r
- trace(message);\r
- }\r
- }\r
-\r
- @SuppressWarnings("javadoc")\r
- public static void traceSignal(TmfSignal signal, String msg) {\r
- if (SIGNAL_CLASS_ENABLED) {\r
- String message = ("[SIG] Sig=" + signal.getClass().getSimpleName()\r
- + " Target=" + msg);\r
- trace(message);\r
- }\r
- }\r
-\r
- @SuppressWarnings("javadoc")\r
- public static void traceEvent(ITmfDataProvider provider, ITmfDataRequest request, ITmfEvent event) {\r
- if (EVENT_CLASS_ENABLED) {\r
- String message = ("[EVT] Provider=" + provider.toString()\r
- + ", Req=" + request.getRequestId() + ", Event=" + event.getTimestamp());\r
- trace(message);\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.tmf.core;
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.linuxtools.tmf.core.component.ITmfComponent;
+import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
+
+/**
+ * The TMF Core tracer, used to trace TMF internal components.
+ * <p>
+ * The tracing classes are independently controlled (i.e no implicit inclusion)
+ * from the launch configuration's Tracing. The resulting trace is stored in a
+ * distinct file (TmfTrace.log) in a format that can later be analyzed by TMF.
+ * <p>
+ * The tracing classes are:
+ * <ul>
+ * <li><strong>Component</strong>: TMF components life-cycle
+ * <li><strong>Request</strong>: TMF requests life-cycle
+ * <li><strong>Signal</strong>: TMF signals triggering and distribution
+ * <li><strong>Event</strong>: TMF trace events
+ * </ul>
+ *
+ * @version 1.0
+ * @author Francois Chouinard
+ */
+@SuppressWarnings("nls")
+public class TmfCoreTracer {
+
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+
+ private static final String PLUGIN_ID = Activator.PLUGIN_ID;
+
+ // Tracing keys (in .options)
+ private static final String COMPONENT_TRACE_KEY = PLUGIN_ID + "/component";
+ private static final String REQUEST_TRACE_KEY = PLUGIN_ID + "/request";
+ private static final String SIGNAL_TRACE_KEY = PLUGIN_ID + "/signal";
+ private static final String EVENT_TRACE_KEY = PLUGIN_ID + "/event";
+
+ private static final String TRACE_FILE_NAME = "TmfTrace.log";
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ // Classes tracing flags
+ static Boolean COMPONENT_CLASS_ENABLED = Boolean.FALSE;
+ static Boolean REQUEST_CLASS_ENABLED = Boolean.FALSE;
+ static Boolean SIGNAL_CLASS_ENABLED = Boolean.FALSE;
+ static Boolean EVENT_CLASS_ENABLED = Boolean.FALSE;
+
+ // Trace log file
+ private static BufferedWriter fTraceFile;
+
+ // ------------------------------------------------------------------------
+ // Start/stop tracing - controlled by the plug-in
+ // ------------------------------------------------------------------------
+
+ /**
+ * Set the tracing flags according to the launch configuration
+ */
+ public static void init() {
+
+ String traceKey;
+ boolean isTracing = false;
+
+ traceKey = Platform.getDebugOption(COMPONENT_TRACE_KEY);
+ if (traceKey != null) {
+ COMPONENT_CLASS_ENABLED = (Boolean.valueOf(traceKey)).booleanValue();
+ isTracing |= COMPONENT_CLASS_ENABLED;
+ }
+
+ traceKey = Platform.getDebugOption(REQUEST_TRACE_KEY);
+ if (traceKey != null) {
+ REQUEST_CLASS_ENABLED = (Boolean.valueOf(traceKey)).booleanValue();
+ isTracing |= REQUEST_CLASS_ENABLED;
+ }
+
+ traceKey = Platform.getDebugOption(SIGNAL_TRACE_KEY);
+ if (traceKey != null) {
+ SIGNAL_CLASS_ENABLED = (Boolean.valueOf(traceKey)).booleanValue();
+ isTracing |= SIGNAL_CLASS_ENABLED;
+ }
+
+ traceKey = Platform.getDebugOption(EVENT_TRACE_KEY);
+ if (traceKey != null) {
+ EVENT_CLASS_ENABLED = (Boolean.valueOf(traceKey)).booleanValue();
+ isTracing |= EVENT_CLASS_ENABLED;
+ }
+
+ // Create trace log file if any of the flags was set
+ if (isTracing) {
+ try {
+ fTraceFile = new BufferedWriter(new FileWriter(TRACE_FILE_NAME));
+ } catch (IOException e) {
+ Activator.logError("Error opening log file " + TRACE_FILE_NAME, e);
+ fTraceFile = null;
+ }
+ }
+ }
+
+ /**
+ * Close the trace log file
+ */
+ public static void stop() {
+ if (fTraceFile != null) {
+ try {
+ fTraceFile.close();
+ fTraceFile = null;
+ } catch (IOException e) {
+ Activator.logError("Error closing log file", e);
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Predicates
+ // ------------------------------------------------------------------------
+
+ @SuppressWarnings("javadoc")
+ public static boolean isComponentTraced() {
+ return COMPONENT_CLASS_ENABLED;
+ }
+
+ @SuppressWarnings("javadoc")
+ public static boolean isRequestTraced() {
+ return REQUEST_CLASS_ENABLED;
+ }
+
+ @SuppressWarnings("javadoc")
+ public static boolean isSignalTraced() {
+ return SIGNAL_CLASS_ENABLED;
+ }
+
+ @SuppressWarnings("javadoc")
+ public static boolean isEventTraced() {
+ return EVENT_CLASS_ENABLED;
+ }
+
+ // ------------------------------------------------------------------------
+ // Tracing methods
+ // ------------------------------------------------------------------------
+
+ /**
+ * The central tracing method. Prepends the timestamp and the thread id
+ * to the trace message.
+ *
+ * @param msg the trace message to log
+ */
+ public static synchronized void trace(String msg) {
+
+ // Set the timestamp (ms resolution)
+ long currentTime = System.currentTimeMillis();
+ StringBuilder message = new StringBuilder("[");
+ message.append(currentTime / 1000);
+ message.append(".");
+ message.append(String.format("%1$03d", currentTime % 1000));
+ message.append("] ");
+
+ // Set the thread id
+ message.append("[TID=");
+ message.append(String.format("%1$03d", Thread.currentThread().getId()));
+ message.append("] ");
+
+ // Append the trace message
+ message.append(msg);
+
+ // Write to file
+ if (fTraceFile != null) {
+ try {
+ fTraceFile.write(message.toString());
+ fTraceFile.newLine();
+ fTraceFile.flush();
+ } catch (IOException e) {
+ Activator.logError("Error writing to log file", e);
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // TMF Core specific trace formatters
+ // ------------------------------------------------------------------------
+
+ @SuppressWarnings("javadoc")
+ public static void traceComponent(ITmfComponent component, String msg) {
+ if (COMPONENT_CLASS_ENABLED) {
+ String message = ("[CMP] Cmp=" + component.getName() + " " + msg);
+ trace(message);
+ }
+ }
+
+ @SuppressWarnings("javadoc")
+ public static void traceRequest(ITmfDataRequest request, String msg) {
+ if (REQUEST_CLASS_ENABLED) {
+ String message = ("[REQ] Req=" + request.getRequestId() + " " + msg);
+ trace(message);
+ }
+ }
+
+ @SuppressWarnings("javadoc")
+ public static void traceSignal(TmfSignal signal, String msg) {
+ if (SIGNAL_CLASS_ENABLED) {
+ String message = ("[SIG] Sig=" + signal.getClass().getSimpleName()
+ + " Target=" + msg);
+ trace(message);
+ }
+ }
+
+ @SuppressWarnings("javadoc")
+ public static void traceEvent(ITmfDataProvider provider, ITmfDataRequest request, ITmfEvent event) {
+ if (EVENT_CLASS_ENABLED) {
+ String message = ("[EVT] Provider=" + provider.toString()
+ + ", Req=" + request.getRequestId() + ", Event=" + event.getTimestamp());
+ trace(message);
+ }
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- * \r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- * \r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.filter;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-\r
-/**\r
- * The TMF filter interface.\r
- * \r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public interface ITmfFilter {\r
-\r
- /**\r
- * Verify the filter conditions on an event\r
- * \r
- * @param event The event to verify.\r
- * @return True if the event matches the filter conditions.\r
- */\r
- public boolean matches(ITmfEvent event);\r
- \r
-}\r
+/*******************************************************************************
+ * 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.core.filter;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+
+/**
+ * The TMF filter interface.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+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(ITmfEvent event);
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Francois Godin (copelnug@gmail.com) - Initial API\r
- * Yuriy Vashchuk (yvashchuk@gmail.com) - Initial implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.filter.model;\r
-\r
-import java.util.List;\r
-\r
-import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;\r
-\r
-\r
-/**\r
- * <h4>This is Node Interface in the Filter Tree</h4>\r
- */\r
-public interface ITmfFilterTreeNode extends ITmfFilter {\r
-\r
- /**\r
- * <h4>Get the parent node of current node</h4>\r
- *\r
- * @return The parent node (null when the node has no parent).\r
- */\r
- public ITmfFilterTreeNode getParent();\r
-\r
- /**\r
- * <h4>Get the current node name</h4>\r
- *\r
- * @return The name of the current node.\r
- */\r
- public String getNodeName();\r
-\r
- /**\r
- * <h4>Tell if the node has children</h4>\r
- *\r
- * @return True if the node has children.\r
- */\r
- public boolean hasChildren();\r
-\r
- /**\r
- * <h4>Return the number of children</h4>\r
- *\r
- * @return The number of children.\r
- */\r
- public int getChildrenCount();\r
-\r
- /**\r
- * <h4>Get the array of children</h4>\r
- *\r
- * @return The array (possibly empty) of children nodes.\r
- */\r
- public ITmfFilterTreeNode[] getChildren();\r
-\r
- /**\r
- * <h4>Get the node by index</h4>\r
- *\r
- * @param index The index of node to return.\r
- * @return The desired node (null if the node is not exists).\r
- */\r
- public ITmfFilterTreeNode getChild(int index);\r
-\r
- /**\r
- * <h4>Remove the node from its parent</h4>\r
- *\r
- * <p>Shifts all nodes after the removed one to prevent having an empty spot.\r
- * See {@link #replaceChild(int, ITmfFilterTreeNode)} to replace a node.</p>\r
- *\r
- * @return The removed node.\r
- */\r
- public ITmfFilterTreeNode remove();\r
-\r
- /**\r
- * <h4>Remove the child from the current node</h4>\r
- *\r
- * <p>Shifts all nodes after the removed one to prevent having an empty spot.\r
- * See {@link #replaceChild(int, ITmfFilterTreeNode)} to replace a node.</p>\r
- *\r
- * @param node the parent node\r
- *\r
- * @return The removed node.\r
- */\r
- public ITmfFilterTreeNode removeChild(ITmfFilterTreeNode node);\r
-\r
- /**\r
- * <h4>Append a node to the current children</h4>\r
- *\r
- * @param node Node to append.\r
- * @return Index of added node (-1 if the node cannot be added).\r
- */\r
- public int addChild(ITmfFilterTreeNode node);\r
-\r
- /**\r
- * <h4>Replace a child node</h4>\r
- *\r
- * @param index Index of the node to replace.\r
- * @param node Node who will replace.\r
- * @return Node replaced.\r
- */\r
- public ITmfFilterTreeNode replaceChild(int index, ITmfFilterTreeNode node);\r
-\r
- /**\r
- * <h4>Sets the parent of current node</h4>\r
- *\r
- * @param parent The parent of current node.\r
- */\r
- public void setParent(ITmfFilterTreeNode parent);\r
-\r
- /**\r
- * <h4>Gets the list of valid children node names that could be added to the node</h4>\r
- *\r
- * @return The list of valid children node names.\r
- */\r
- public List<String> getValidChildren();\r
-\r
- /**\r
- * @return a clone of the node\r
- */\r
- public ITmfFilterTreeNode clone();\r
-\r
-}\r
+/*******************************************************************************
+ * 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.core.filter.model;
+
+import java.util.List;
+
+import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
+
+
+/**
+ * <h4>This is Node Interface in the Filter Tree</h4>
+ */
+public interface ITmfFilterTreeNode extends ITmfFilter {
+
+ /**
+ * <h4>Get the parent node of current node</h4>
+ *
+ * @return The parent node (null when the node has no parent).
+ */
+ public ITmfFilterTreeNode getParent();
+
+ /**
+ * <h4>Get the current node name</h4>
+ *
+ * @return The name of the current node.
+ */
+ public String getNodeName();
+
+ /**
+ * <h4>Tell if the node has children</h4>
+ *
+ * @return True if the node has children.
+ */
+ public boolean hasChildren();
+
+ /**
+ * <h4>Return the number of children</h4>
+ *
+ * @return The number of children.
+ */
+ public int getChildrenCount();
+
+ /**
+ * <h4>Get the array of children</h4>
+ *
+ * @return The array (possibly empty) of children nodes.
+ */
+ public ITmfFilterTreeNode[] getChildren();
+
+ /**
+ * <h4>Get the node by index</h4>
+ *
+ * @param index The index of node to return.
+ * @return The desired node (null if the node is not exists).
+ */
+ public ITmfFilterTreeNode getChild(int index);
+
+ /**
+ * <h4>Remove the node from its parent</h4>
+ *
+ * <p>Shifts all nodes after the removed one to prevent having an empty spot.
+ * See {@link #replaceChild(int, ITmfFilterTreeNode)} to replace a node.</p>
+ *
+ * @return The removed node.
+ */
+ public ITmfFilterTreeNode remove();
+
+ /**
+ * <h4>Remove the child from the current node</h4>
+ *
+ * <p>Shifts all nodes after the removed one to prevent having an empty spot.
+ * See {@link #replaceChild(int, ITmfFilterTreeNode)} to replace a node.</p>
+ *
+ * @param node the parent node
+ *
+ * @return The removed node.
+ */
+ public ITmfFilterTreeNode removeChild(ITmfFilterTreeNode node);
+
+ /**
+ * <h4>Append a node to the current children</h4>
+ *
+ * @param node Node to append.
+ * @return Index of added node (-1 if the node cannot be added).
+ */
+ public int addChild(ITmfFilterTreeNode node);
+
+ /**
+ * <h4>Replace a child node</h4>
+ *
+ * @param index Index of the node to replace.
+ * @param node Node who will replace.
+ * @return Node replaced.
+ */
+ public ITmfFilterTreeNode replaceChild(int index, ITmfFilterTreeNode node);
+
+ /**
+ * <h4>Sets the parent of current node</h4>
+ *
+ * @param parent The parent of current node.
+ */
+ public void setParent(ITmfFilterTreeNode parent);
+
+ /**
+ * <h4>Gets the list of valid children node names that could be added to the node</h4>
+ *
+ * @return The list of valid children node names.
+ */
+ public List<String> getValidChildren();
+
+ /**
+ * @return a clone of the node
+ */
+ public ITmfFilterTreeNode clone();
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.filter.model;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-\r
-\r
-/**\r
- * Filter node for the 'and' operation\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-@SuppressWarnings("javadoc")\r
-public class TmfFilterAndNode extends TmfFilterTreeNode {\r
-\r
- public static final String NODE_NAME = "AND"; //$NON-NLS-1$\r
- public static final String NOT_ATTR = "not"; //$NON-NLS-1$\r
-\r
- private boolean fNot = false;\r
-\r
- /**\r
- * @param parent the parent node\r
- */\r
- public TmfFilterAndNode(ITmfFilterTreeNode parent) {\r
- super(parent);\r
- }\r
-\r
- /**\r
- * @return the NOT state\r
- */\r
- public boolean isNot() {\r
- return fNot;\r
- }\r
-\r
- /**\r
- * @param not the NOT state\r
- */\r
- public void setNot(boolean not) {\r
- this.fNot = not;\r
- }\r
-\r
- @Override\r
- public String getNodeName() {\r
- return NODE_NAME;\r
- }\r
-\r
- @Override\r
- public boolean matches(ITmfEvent event) {\r
- for (ITmfFilterTreeNode node : getChildren()) {\r
- if (! node.matches(event)) {\r
- return false ^ fNot;\r
- }\r
- }\r
- return true ^ fNot;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- StringBuffer buf = new StringBuffer();\r
- if (fNot) {\r
- buf.append("not "); //$NON-NLS-1$\r
- }\r
- if (getParent() != null && !(getParent() instanceof TmfFilterRootNode) && !(getParent() instanceof TmfFilterNode)) {\r
- buf.append("( "); //$NON-NLS-1$\r
- }\r
- for (int i = 0; i < getChildrenCount(); i++) {\r
- ITmfFilterTreeNode node = getChildren()[i];\r
- buf.append(node.toString());\r
- if (i < getChildrenCount() - 1) {\r
- buf.append(" and "); //$NON-NLS-1$\r
- }\r
- }\r
- if (getParent() != null && !(getParent() instanceof TmfFilterRootNode) && !(getParent() instanceof TmfFilterNode)) {\r
- buf.append(" )"); //$NON-NLS-1$\r
- }\r
- return buf.toString();\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.core.filter.model;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+
+
+/**
+ * Filter node for the 'and' operation
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+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;
+
+ /**
+ * @param parent the parent node
+ */
+ public TmfFilterAndNode(ITmfFilterTreeNode parent) {
+ super(parent);
+ }
+
+ /**
+ * @return the NOT state
+ */
+ public boolean isNot() {
+ return fNot;
+ }
+
+ /**
+ * @param not the NOT state
+ */
+ public void setNot(boolean not) {
+ this.fNot = not;
+ }
+
+ @Override
+ public String getNodeName() {
+ return NODE_NAME;
+ }
+
+ @Override
+ public boolean matches(ITmfEvent 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();
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.filter.model;\r
-\r
-import java.text.NumberFormat;\r
-import java.text.ParseException;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r
-\r
-\r
-/**\r
- * Filter node for the comparison operation\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-@SuppressWarnings("javadoc")\r
-public class TmfFilterCompareNode extends TmfFilterTreeNode {\r
-\r
- public static final String NODE_NAME = "COMPARE"; //$NON-NLS-1$\r
- public static final String NOT_ATTR = "not"; //$NON-NLS-1$\r
- public static final String FIELD_ATTR = "field"; //$NON-NLS-1$\r
- public static final String RESULT_ATTR = "result"; //$NON-NLS-1$\r
- public static final String TYPE_ATTR = "type"; //$NON-NLS-1$\r
- public static final String VALUE_ATTR = "value"; //$NON-NLS-1$\r
-\r
- /**\r
- * Supported comparison types\r
- */\r
- public static enum Type {\r
- NUM,\r
- ALPHA,\r
- TIMESTAMP\r
- }\r
-\r
- private boolean fNot = false;\r
- private String fField;\r
- private int fResult;\r
- private Type fType = Type.NUM;\r
- private String fValue;\r
- private Number fValueNumber;\r
- private TmfTimestamp fValueTimestamp;\r
-\r
- /**\r
- * @param parent the parent node\r
- */\r
- public TmfFilterCompareNode(ITmfFilterTreeNode parent) {\r
- super(parent);\r
- }\r
-\r
- /**\r
- * @return the NOT state\r
- */\r
- public boolean isNot() {\r
- return fNot;\r
- }\r
-\r
- /**\r
- * @param not the NOT state\r
- */\r
- public void setNot(boolean not) {\r
- this.fNot = not;\r
- }\r
-\r
- /**\r
- * @return the field name\r
- */\r
- public String getField() {\r
- return fField;\r
- }\r
-\r
- /**\r
- * @param field the field name\r
- */\r
- public void setField(String field) {\r
- this.fField = field;\r
- }\r
-\r
- /**\r
- * @return the compare result\r
- */\r
- public int getResult() {\r
- return fResult;\r
- }\r
-\r
- /**\r
- * @param result the compare result\r
- */\r
- public void setResult(int result) {\r
- this.fResult = result;\r
- }\r
-\r
- /**\r
- * @return the comparison type\r
- */\r
- public Type getType() {\r
- return fType;\r
- }\r
-\r
- /**\r
- * @param type the comparison type\r
- */\r
- public void setType(Type type) {\r
- this.fType = type;\r
- setValue(fValue);\r
- }\r
-\r
- /**\r
- * @return the comparison value\r
- */\r
- public String getValue() {\r
- return fValue;\r
- }\r
-\r
- /**\r
- * @param value the comparison value\r
- */\r
- public void setValue(String value) {\r
- this.fValue = value;\r
- fValueNumber = null;\r
- fValueTimestamp = null;\r
- if (value == null) {\r
- return;\r
- }\r
- if (fType == Type.NUM) {\r
- try {\r
- fValueNumber = NumberFormat.getInstance().parse(value).doubleValue();\r
- } catch (ParseException e) {\r
- }\r
- } else if (fType == Type.TIMESTAMP) {\r
- try {\r
- fValueTimestamp = new TmfTimestamp((long) (1E9 * NumberFormat.getInstance().parse(value.toString()).doubleValue()));\r
- } catch (ParseException e) {\r
- }\r
- }\r
- }\r
-\r
- @Override\r
- public String getNodeName() {\r
- return NODE_NAME;\r
- }\r
-\r
- @Override\r
- public boolean matches(ITmfEvent event) {\r
- Object value = getFieldValue(event, fField);\r
- if (value == null) {\r
- return false ^ fNot;\r
- }\r
- if (fType == Type.NUM) {\r
- if (fValueNumber != null) {\r
- if (value instanceof Number) {\r
- Double valueDouble = ((Number) value).doubleValue();\r
- return (valueDouble.compareTo(fValueNumber.doubleValue()) == fResult) ^ fNot;\r
- }\r
- try {\r
- Double valueDouble = NumberFormat.getInstance().parse(value.toString())\r
- .doubleValue();\r
- return (valueDouble.compareTo(fValueNumber.doubleValue()) == fResult)\r
- ^ fNot;\r
- } catch (ParseException e) {\r
- }\r
- }\r
- } else if (fType == Type.ALPHA) {\r
- String valueString = value.toString();\r
- int comp = valueString.compareTo(fValue.toString());\r
- if (comp < -1) {\r
- comp = -1;\r
- } else if (comp > 1) {\r
- comp = 1;\r
- }\r
- return (comp == fResult) ^ fNot;\r
- } else if (fType == Type.TIMESTAMP) {\r
- if (fValueTimestamp != null) {\r
- if (value instanceof TmfTimestamp) {\r
- TmfTimestamp valueTimestamp = (TmfTimestamp) value;\r
- return (valueTimestamp.compareTo(fValueTimestamp, false) == fResult) ^ fNot;\r
- }\r
- try {\r
- TmfTimestamp valueTimestamp = new TmfTimestamp((long) (1E9 * NumberFormat\r
- .getInstance().parse(value.toString()).doubleValue()));\r
- return (valueTimestamp.compareTo(fValueTimestamp, false) == fResult) ^ fNot;\r
- } catch (ParseException e) {\r
- }\r
- }\r
- }\r
- return false ^ fNot;\r
- }\r
-\r
- @Override\r
- public List<String> getValidChildren() {\r
- return new ArrayList<String>(0);\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- String result = (fResult == 0 ? "= " : fResult < 0 ? "< " : "> "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- String open = (fType == Type.NUM ? "" : fType == Type.ALPHA ? "\"" : "["); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- String close = (fType == Type.NUM ? "" : fType == Type.ALPHA ? "\"" : "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- return fField + (fNot ? " not " : " ") + result + open + fValue + close; //$NON-NLS-1$ //$NON-NLS-2$\r
- }\r
-\r
- @Override\r
- public ITmfFilterTreeNode clone() {\r
- TmfFilterCompareNode clone = (TmfFilterCompareNode) super.clone();\r
- clone.fField = fField;\r
- clone.setValue(fValue);\r
- return clone;\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.core.filter.model;
+
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+
+
+/**
+ * Filter node for the comparison operation
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+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$
+
+ /**
+ * Supported comparison types
+ */
+ 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;
+
+ /**
+ * @param parent the parent node
+ */
+ public TmfFilterCompareNode(ITmfFilterTreeNode parent) {
+ super(parent);
+ }
+
+ /**
+ * @return the NOT state
+ */
+ public boolean isNot() {
+ return fNot;
+ }
+
+ /**
+ * @param not the NOT state
+ */
+ public void setNot(boolean not) {
+ this.fNot = not;
+ }
+
+ /**
+ * @return the field name
+ */
+ public String getField() {
+ return fField;
+ }
+
+ /**
+ * @param field the field name
+ */
+ public void setField(String field) {
+ this.fField = field;
+ }
+
+ /**
+ * @return the compare result
+ */
+ public int getResult() {
+ return fResult;
+ }
+
+ /**
+ * @param result the compare result
+ */
+ public void setResult(int result) {
+ this.fResult = result;
+ }
+
+ /**
+ * @return the comparison type
+ */
+ public Type getType() {
+ return fType;
+ }
+
+ /**
+ * @param type the comparison type
+ */
+ public void setType(Type type) {
+ this.fType = type;
+ setValue(fValue);
+ }
+
+ /**
+ * @return the comparison value
+ */
+ public String getValue() {
+ return fValue;
+ }
+
+ /**
+ * @param value the comparison value
+ */
+ 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(ITmfEvent event) {
+ Object value = getFieldValue(event, fField);
+ if (value == null) {
+ return false ^ fNot;
+ }
+ if (fType == Type.NUM) {
+ if (fValueNumber != null) {
+ if (value instanceof Number) {
+ Double valueDouble = ((Number) value).doubleValue();
+ return (valueDouble.compareTo(fValueNumber.doubleValue()) == fResult) ^ fNot;
+ }
+ 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();
+ int comp = valueString.compareTo(fValue.toString());
+ if (comp < -1) {
+ comp = -1;
+ } else if (comp > 1) {
+ comp = 1;
+ }
+ return (comp == fResult) ^ fNot;
+ } else if (fType == Type.TIMESTAMP) {
+ if (fValueTimestamp != null) {
+ if (value instanceof TmfTimestamp) {
+ TmfTimestamp valueTimestamp = (TmfTimestamp) value;
+ return (valueTimestamp.compareTo(fValueTimestamp, false) == fResult) ^ fNot;
+ }
+ try {
+ TmfTimestamp valueTimestamp = new TmfTimestamp((long) (1E9 * NumberFormat
+ .getInstance().parse(value.toString()).doubleValue()));
+ return (valueTimestamp.compareTo(fValueTimestamp, false) == fResult) ^ fNot;
+ } catch (ParseException e) {
+ }
+ }
+ }
+ return false ^ fNot;
+ }
+
+ @Override
+ public List<String> getValidChildren() {
+ return new ArrayList<String>(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 = fField;
+ clone.setValue(fValue);
+ return clone;
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.filter.model;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-\r
-/**\r
- * Filter node for the 'contains' operation\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-@SuppressWarnings("javadoc")\r
-public class TmfFilterContainsNode extends TmfFilterTreeNode {\r
-\r
- public static final String NODE_NAME = "CONTAINS"; //$NON-NLS-1$\r
- public static final String NOT_ATTR = "not"; //$NON-NLS-1$\r
- public static final String FIELD_ATTR = "field"; //$NON-NLS-1$\r
- public static final String VALUE_ATTR = "value"; //$NON-NLS-1$\r
- public static final String IGNORECASE_ATTR = "ignorecase"; //$NON-NLS-1$\r
-\r
- private boolean fNot = false;\r
- private String fField;\r
- private String fValue;\r
- private String fValueUpperCase;\r
- private boolean fIgnoreCase = false;\r
-\r
- /**\r
- * @param parent the parent node\r
- */\r
- public TmfFilterContainsNode(ITmfFilterTreeNode parent) {\r
- super(parent);\r
- }\r
-\r
- /**\r
- * @return the NOT state\r
- */\r
- public boolean isNot() {\r
- return fNot;\r
- }\r
-\r
- /**\r
- * @param not the NOT state\r
- */\r
- public void setNot(boolean not) {\r
- this.fNot = not;\r
- }\r
-\r
- /**\r
- * @return the field name\r
- */\r
- public String getField() {\r
- return fField;\r
- }\r
-\r
- /**\r
- * @param field the field name\r
- */\r
- public void setField(String field) {\r
- this.fField = field;\r
- }\r
-\r
- /**\r
- * @return the contains value\r
- */\r
- public String getValue() {\r
- return fValue;\r
- }\r
-\r
- /**\r
- * @param value the contains value\r
- */\r
- public void setValue(String value) {\r
- this.fValue = value;\r
- fValueUpperCase = value.toUpperCase();\r
- }\r
-\r
- /**\r
- * @return the ignoreCase state\r
- */\r
- public boolean isIgnoreCase() {\r
- return fIgnoreCase;\r
- }\r
-\r
- /**\r
- * @param ignoreCase the ignoreCase state\r
- */\r
- public void setIgnoreCase(boolean ignoreCase) {\r
- this.fIgnoreCase = ignoreCase;\r
- }\r
-\r
- @Override\r
- public String getNodeName() {\r
- return NODE_NAME;\r
- }\r
-\r
- @Override\r
- public boolean matches(ITmfEvent event) {\r
- Object value = getFieldValue(event, fField);\r
- if (value == null) {\r
- return false ^ fNot;\r
- }\r
- String valueString = value.toString();\r
- if (fIgnoreCase) {\r
- return valueString.toUpperCase().contains(fValueUpperCase) ^ fNot;\r
- }\r
- return valueString.contains(fValue) ^ fNot;\r
- }\r
-\r
- @Override\r
- public List<String> getValidChildren() {\r
- return new ArrayList<String>(0);\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return fField + (fNot ? " not" : "") + " contains \"" + fValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$\r
- }\r
-\r
- @Override\r
- public ITmfFilterTreeNode clone() {\r
- TmfFilterContainsNode clone = (TmfFilterContainsNode) super.clone();\r
- clone.fField = fField;\r
- clone.setValue(fValue);\r
- return clone;\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.core.filter.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+
+/**
+ * Filter node for the 'contains' operation
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+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;
+
+ /**
+ * @param parent the parent node
+ */
+ public TmfFilterContainsNode(ITmfFilterTreeNode parent) {
+ super(parent);
+ }
+
+ /**
+ * @return the NOT state
+ */
+ public boolean isNot() {
+ return fNot;
+ }
+
+ /**
+ * @param not the NOT state
+ */
+ public void setNot(boolean not) {
+ this.fNot = not;
+ }
+
+ /**
+ * @return the field name
+ */
+ public String getField() {
+ return fField;
+ }
+
+ /**
+ * @param field the field name
+ */
+ public void setField(String field) {
+ this.fField = field;
+ }
+
+ /**
+ * @return the contains value
+ */
+ public String getValue() {
+ return fValue;
+ }
+
+ /**
+ * @param value the contains value
+ */
+ public void setValue(String value) {
+ this.fValue = value;
+ fValueUpperCase = value.toUpperCase();
+ }
+
+ /**
+ * @return the ignoreCase state
+ */
+ public boolean isIgnoreCase() {
+ return fIgnoreCase;
+ }
+
+ /**
+ * @param ignoreCase the ignoreCase state
+ */
+ public void setIgnoreCase(boolean ignoreCase) {
+ this.fIgnoreCase = ignoreCase;
+ }
+
+ @Override
+ public String getNodeName() {
+ return NODE_NAME;
+ }
+
+ @Override
+ public boolean matches(ITmfEvent event) {
+ Object value = getFieldValue(event, fField);
+ if (value == null) {
+ return false ^ fNot;
+ }
+ String valueString = value.toString();
+ if (fIgnoreCase) {
+ return valueString.toUpperCase().contains(fValueUpperCase) ^ fNot;
+ }
+ return valueString.contains(fValue) ^ fNot;
+ }
+
+ @Override
+ public List<String> getValidChildren() {
+ return new ArrayList<String>(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 = fField;
+ clone.setValue(fValue);
+ return clone;
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.filter.model;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-\r
-\r
-/**\r
- * Filter node for the '==' operation\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-@SuppressWarnings("javadoc")\r
-public class TmfFilterEqualsNode extends TmfFilterTreeNode {\r
-\r
- public static final String NODE_NAME = "EQUALS"; //$NON-NLS-1$\r
- public static final String NOT_ATTR = "not"; //$NON-NLS-1$\r
- public static final String FIELD_ATTR = "field"; //$NON-NLS-1$\r
- public static final String VALUE_ATTR = "value"; //$NON-NLS-1$\r
- public static final String IGNORECASE_ATTR = "ignorecase"; //$NON-NLS-1$\r
-\r
- private boolean fNot = false;\r
- private String fField;\r
- private String fValue;\r
- private boolean fIgnoreCase = false;\r
-\r
- /**\r
- * @param parent the aprent node\r
- */\r
- public TmfFilterEqualsNode(ITmfFilterTreeNode parent) {\r
- super(parent);\r
- }\r
-\r
- /**\r
- * @return the NOT state\r
- */\r
- public boolean isNot() {\r
- return fNot;\r
- }\r
-\r
- /**\r
- * @param not the NOT state\r
- */\r
- public void setNot(boolean not) {\r
- this.fNot = not;\r
- }\r
-\r
- /**\r
- * @return the field name\r
- */\r
- public String getField() {\r
- return fField;\r
- }\r
-\r
- /**\r
- * @param field the field name\r
- */\r
- public void setField(String field) {\r
- this.fField = field;\r
- }\r
-\r
- /**\r
- * @return the equals value\r
- */\r
- public String getValue() {\r
- return fValue;\r
- }\r
-\r
- /**\r
- * @param value the equals value\r
- */\r
- public void setValue(String value) {\r
- this.fValue = value;\r
- }\r
-\r
- /**\r
- * @return the ignoreCase state\r
- */\r
- public boolean isIgnoreCase() {\r
- return fIgnoreCase;\r
- }\r
-\r
- /**\r
- * @param ignoreCase the ignoreCase state\r
- */\r
- public void setIgnoreCase(boolean ignoreCase) {\r
- this.fIgnoreCase = ignoreCase;\r
- }\r
-\r
- @Override\r
- public String getNodeName() {\r
- return NODE_NAME;\r
- }\r
-\r
- @Override\r
- public boolean matches(ITmfEvent event) {\r
- Object value = getFieldValue(event, fField);\r
- if (value == null) {\r
- return false ^ fNot;\r
- }\r
- String valueString = value.toString();\r
- if (valueString == null) {\r
- return false ^ fNot;\r
- }\r
- if (fIgnoreCase) {\r
- return valueString.equalsIgnoreCase(fValue) ^ fNot;\r
- }\r
- return valueString.equals(fValue) ^ fNot;\r
- }\r
-\r
- @Override\r
- public List<String> getValidChildren() {\r
- return new ArrayList<String>(0);\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return fField + (fNot ? " not" : "") + " equals \"" + fValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$\r
- }\r
-\r
- @Override\r
- public ITmfFilterTreeNode clone() {\r
- TmfFilterEqualsNode clone = (TmfFilterEqualsNode) super.clone();\r
- clone.fField = fField;\r
- clone.fValue = fValue;\r
- return clone;\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.core.filter.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+
+
+/**
+ * Filter node for the '==' operation
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+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;
+
+ /**
+ * @param parent the aprent node
+ */
+ public TmfFilterEqualsNode(ITmfFilterTreeNode parent) {
+ super(parent);
+ }
+
+ /**
+ * @return the NOT state
+ */
+ public boolean isNot() {
+ return fNot;
+ }
+
+ /**
+ * @param not the NOT state
+ */
+ public void setNot(boolean not) {
+ this.fNot = not;
+ }
+
+ /**
+ * @return the field name
+ */
+ public String getField() {
+ return fField;
+ }
+
+ /**
+ * @param field the field name
+ */
+ public void setField(String field) {
+ this.fField = field;
+ }
+
+ /**
+ * @return the equals value
+ */
+ public String getValue() {
+ return fValue;
+ }
+
+ /**
+ * @param value the equals value
+ */
+ public void setValue(String value) {
+ this.fValue = value;
+ }
+
+ /**
+ * @return the ignoreCase state
+ */
+ public boolean isIgnoreCase() {
+ return fIgnoreCase;
+ }
+
+ /**
+ * @param ignoreCase the ignoreCase state
+ */
+ public void setIgnoreCase(boolean ignoreCase) {
+ this.fIgnoreCase = ignoreCase;
+ }
+
+ @Override
+ public String getNodeName() {
+ return NODE_NAME;
+ }
+
+ @Override
+ public boolean matches(ITmfEvent event) {
+ Object value = getFieldValue(event, fField);
+ if (value == null) {
+ return false ^ fNot;
+ }
+ String valueString = value.toString();
+ if (valueString == null) {
+ return false ^ fNot;
+ }
+ if (fIgnoreCase) {
+ return valueString.equalsIgnoreCase(fValue) ^ fNot;
+ }
+ return valueString.equals(fValue) ^ fNot;
+ }
+
+ @Override
+ public List<String> getValidChildren() {
+ return new ArrayList<String>(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 = fField;
+ clone.fValue = fValue;
+ return clone;
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.filter.model;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-\r
-/**\r
- * Filter node for an event\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-@SuppressWarnings("javadoc")\r
-public class TmfFilterEventTypeNode extends TmfFilterTreeNode {\r
-\r
- public static final String NODE_NAME = "EVENTTYPE"; //$NON-NLS-1$\r
- public static final String TYPE_ATTR = "type"; //$NON-NLS-1$\r
- public static final String NAME_ATTR = "name"; //$NON-NLS-1$\r
-\r
- private String fType;\r
- private String fName;\r
-\r
- /**\r
- * @param parent the parent node\r
- */\r
- public TmfFilterEventTypeNode(ITmfFilterTreeNode parent) {\r
- super(parent);\r
- }\r
-\r
- @Override\r
- public String getNodeName() {\r
- return NODE_NAME;\r
- }\r
-\r
- /**\r
- * @return the event type\r
- */\r
- public String getEventType() {\r
- return fType;\r
- }\r
-\r
- /**\r
- * @param type the event type\r
- */\r
- public void setEventType(String type) {\r
- this.fType = type;\r
- }\r
-\r
- /**\r
- * @return TBD\r
- */\r
- public String getName() {\r
- return fName;\r
- }\r
-\r
- /**\r
- * @param name TBD\r
- */\r
- public void setName(String name) {\r
- this.fName = name;\r
- }\r
-\r
- @Override\r
- public boolean matches(ITmfEvent event) {\r
- boolean match = false;\r
- if (fType.contains(":")) { //$NON-NLS-1$\r
- // special case for custom parsers\r
- if (fType.startsWith(event.getClass().getCanonicalName())) {\r
- if (fType.endsWith(event.getType().getName())) {\r
- match = true;\r
- }\r
- }\r
- } else {\r
- if (event.getClass().getCanonicalName().equals(fType)) {\r
- match = true;\r
- }\r
- }\r
- if (match) {\r
- // There should be at most one child\r
- for (ITmfFilterTreeNode node : getChildren()) {\r
- if (! node.matches(event)) {\r
- return false;\r
- }\r
- }\r
- return true;\r
- }\r
- return false;\r
- }\r
-\r
- @Override\r
- public List<String> getValidChildren() {\r
- if (getChildrenCount() == 0) {\r
- return super.getValidChildren();\r
- }\r
- return new ArrayList<String>(0); // only one child allowed\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- StringBuffer buf = new StringBuffer();\r
- buf.append("EventType is " + fName); //$NON-NLS-1$\r
- if (getChildrenCount() > 0) {\r
- buf.append(" and "); //$NON-NLS-1$\r
- }\r
- if (getChildrenCount() > 1) {\r
- buf.append("( "); //$NON-NLS-1$\r
- }\r
- for (int i = 0; i < getChildrenCount(); i++) {\r
- ITmfFilterTreeNode node = getChildren()[i];\r
- buf.append(node.toString());\r
- if (i < getChildrenCount() - 1) {\r
- buf.append(" and "); //$NON-NLS-1$\r
- }\r
- }\r
- if (getChildrenCount() > 1) {\r
- buf.append(" )"); //$NON-NLS-1$\r
- }\r
- return buf.toString();\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.core.filter.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+
+/**
+ * Filter node for an event
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+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;
+
+ /**
+ * @param parent the parent node
+ */
+ public TmfFilterEventTypeNode(ITmfFilterTreeNode parent) {
+ super(parent);
+ }
+
+ @Override
+ public String getNodeName() {
+ return NODE_NAME;
+ }
+
+ /**
+ * @return the event type
+ */
+ public String getEventType() {
+ return fType;
+ }
+
+ /**
+ * @param type the event type
+ */
+ public void setEventType(String type) {
+ this.fType = type;
+ }
+
+ /**
+ * @return TBD
+ */
+ public String getName() {
+ return fName;
+ }
+
+ /**
+ * @param name TBD
+ */
+ public void setName(String name) {
+ this.fName = name;
+ }
+
+ @Override
+ public boolean matches(ITmfEvent event) {
+ boolean match = false;
+ if (fType.contains(":")) { //$NON-NLS-1$
+ // special case for custom parsers
+ if (fType.startsWith(event.getClass().getCanonicalName())) {
+ if (fType.endsWith(event.getType().getName())) {
+ match = true;
+ }
+ }
+ } else {
+ if (event.getClass().getCanonicalName().equals(fType)) {
+ match = true;
+ }
+ }
+ if (match) {
+ // There should be at most one child
+ for (ITmfFilterTreeNode node : getChildren()) {
+ if (! node.matches(event)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public List<String> getValidChildren() {
+ if (getChildrenCount() == 0) {
+ return super.getValidChildren();
+ }
+ return new ArrayList<String>(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();
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.filter.model;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.regex.Pattern;\r
-import java.util.regex.PatternSyntaxException;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-\r
-/**\r
- * Filter node for the regex match\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-@SuppressWarnings("javadoc")\r
-public class TmfFilterMatchesNode extends TmfFilterTreeNode {\r
-\r
- public static final String NODE_NAME = "MATCHES"; //$NON-NLS-1$\r
- public static final String NOT_ATTR = "not"; //$NON-NLS-1$\r
- public static final String FIELD_ATTR = "field"; //$NON-NLS-1$\r
- public static final String REGEX_ATTR = "regex"; //$NON-NLS-1$\r
-\r
- private boolean fNot = false;\r
- private String fField;\r
- private String fRegex;\r
- private Pattern fPattern;\r
-\r
- /**\r
- * @param parent the parent node\r
- */\r
- public TmfFilterMatchesNode(ITmfFilterTreeNode parent) {\r
- super(parent);\r
- }\r
-\r
- /**\r
- * @return the NOT state\r
- */\r
- public boolean isNot() {\r
- return fNot;\r
- }\r
-\r
- /**\r
- * @param not the NOT state\r
- */\r
- public void setNot(boolean not) {\r
- this.fNot = not;\r
- }\r
-\r
- /**\r
- * @return the field name\r
- */\r
- public String getField() {\r
- return fField;\r
- }\r
-\r
- /**\r
- * @param field the field name\r
- */\r
- public void setField(String field) {\r
- this.fField = field;\r
- }\r
-\r
- /**\r
- * @return the regular expression\r
- */\r
- public String getRegex() {\r
- return fRegex;\r
- }\r
-\r
- /**\r
- * @param regex the regular expression\r
- */\r
- public void setRegex(String regex) {\r
- this.fRegex = regex;\r
- try {\r
- this.fPattern = Pattern.compile(regex);\r
- } catch (PatternSyntaxException e) {\r
- this.fPattern = null;\r
- }\r
- }\r
-\r
- @Override\r
- public String getNodeName() {\r
- return NODE_NAME;\r
- }\r
-\r
- @Override\r
- public boolean matches(ITmfEvent event) {\r
- if (fPattern == null) {\r
- return false ^ fNot;\r
- }\r
-\r
- Object value = getFieldValue(event, fField);\r
- if (value == null) {\r
- return false ^ fNot;\r
- }\r
- String valueString = value.toString();\r
-\r
- return fPattern.matcher(valueString).matches() ^ fNot;\r
- }\r
-\r
- @Override\r
- public List<String> getValidChildren() {\r
- return new ArrayList<String>(0);\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return fField + (fNot ? " not" : "") + " matches \"" + fRegex + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$\r
- }\r
-\r
- @Override\r
- public ITmfFilterTreeNode clone() {\r
- TmfFilterMatchesNode clone = (TmfFilterMatchesNode) super.clone();\r
- clone.fField = fField;\r
- clone.setRegex(fRegex);\r
- return clone;\r
- }\r
-\r
- /**\r
- * @param pattern the rough regex pattern\r
- * @return the compliant regex\r
- */\r
- public static String regexFix(String pattern) {\r
- // if the pattern does not contain one of the expressions .* !^\r
- // (at the beginning) $ (at the end), then a .* is added at the\r
- // beginning and at the end of the pattern\r
- if (!(pattern.indexOf(".*") >= 0 || pattern.charAt(0) == '^' || pattern.charAt(pattern.length() - 1) == '$')) { //$NON-NLS-1$\r
- pattern = ".*" + pattern + ".*"; //$NON-NLS-1$ //$NON-NLS-2$\r
- }\r
- return pattern;\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.core.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.core.event.ITmfEvent;
+
+/**
+ * Filter node for the regex match
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+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;
+
+ /**
+ * @param parent the parent node
+ */
+ public TmfFilterMatchesNode(ITmfFilterTreeNode parent) {
+ super(parent);
+ }
+
+ /**
+ * @return the NOT state
+ */
+ public boolean isNot() {
+ return fNot;
+ }
+
+ /**
+ * @param not the NOT state
+ */
+ public void setNot(boolean not) {
+ this.fNot = not;
+ }
+
+ /**
+ * @return the field name
+ */
+ public String getField() {
+ return fField;
+ }
+
+ /**
+ * @param field the field name
+ */
+ public void setField(String field) {
+ this.fField = field;
+ }
+
+ /**
+ * @return the regular expression
+ */
+ public String getRegex() {
+ return fRegex;
+ }
+
+ /**
+ * @param regex the regular expression
+ */
+ 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(ITmfEvent event) {
+ if (fPattern == null) {
+ return false ^ fNot;
+ }
+
+ Object value = getFieldValue(event, fField);
+ if (value == null) {
+ return false ^ fNot;
+ }
+ String valueString = value.toString();
+
+ return fPattern.matcher(valueString).matches() ^ fNot;
+ }
+
+ @Override
+ public List<String> getValidChildren() {
+ return new ArrayList<String>(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 = fField;
+ clone.setRegex(fRegex);
+ return clone;
+ }
+
+ /**
+ * @param pattern the rough regex pattern
+ * @return the compliant regex
+ */
+ 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;
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.filter.model;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-\r
-/**\r
- * Filter node for the event match operation\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-@SuppressWarnings("javadoc")\r
-public class TmfFilterNode extends TmfFilterTreeNode {\r
-\r
- public static final String NODE_NAME = "FILTER"; //$NON-NLS-1$\r
- public static final String NAME_ATTR = "name"; //$NON-NLS-1$\r
-\r
- String fFilterName;\r
-\r
- /**\r
- * @param filterName the filter name\r
- */\r
- public TmfFilterNode(String filterName) {\r
- super(null);\r
- fFilterName = filterName;\r
- }\r
-\r
- /**\r
- * @param parent the parent node\r
- * @param filterName the filter name\r
- */\r
- public TmfFilterNode(ITmfFilterTreeNode parent, String filterName) {\r
- super(parent);\r
- fFilterName = filterName;\r
- }\r
-\r
- /**\r
- * @return the filer name\r
- */\r
- public String getFilterName() {\r
- return fFilterName;\r
- }\r
-\r
- /**\r
- * @param filterName the filer name\r
- */\r
- public void setFilterName(String filterName) {\r
- fFilterName = filterName;\r
- }\r
-\r
- @Override\r
- public String getNodeName() {\r
- return NODE_NAME;\r
- }\r
-\r
- @Override\r
- public boolean matches(ITmfEvent event) {\r
- // There should be at most one child\r
- for (ITmfFilterTreeNode node : getChildren()) {\r
- if (node.matches(event)) {\r
- return true;\r
- }\r
- }\r
- return false;\r
- }\r
-\r
- @Override\r
- public List<String> getValidChildren() {\r
- if (getChildrenCount() == 0) {\r
- return super.getValidChildren();\r
- }\r
- return new ArrayList<String>(0); // only one child allowed\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- StringBuffer buf = new StringBuffer();\r
- if (getChildrenCount() > 1) {\r
- buf.append("( "); //$NON-NLS-1$\r
- }\r
- for (int i = 0; i < getChildrenCount(); i++) {\r
- ITmfFilterTreeNode node = getChildren()[i];\r
- buf.append(node.toString());\r
- if (i < (getChildrenCount() - 1)) {\r
- buf.append(" and "); //$NON-NLS-1$\r
- }\r
- }\r
- if (getChildrenCount() > 1) {\r
- buf.append(" )"); //$NON-NLS-1$\r
- }\r
- return buf.toString();\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.core.filter.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+
+/**
+ * Filter node for the event match operation
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+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;
+
+ /**
+ * @param filterName the filter name
+ */
+ public TmfFilterNode(String filterName) {
+ super(null);
+ fFilterName = filterName;
+ }
+
+ /**
+ * @param parent the parent node
+ * @param filterName the filter name
+ */
+ public TmfFilterNode(ITmfFilterTreeNode parent, String filterName) {
+ super(parent);
+ fFilterName = filterName;
+ }
+
+ /**
+ * @return the filer name
+ */
+ public String getFilterName() {
+ return fFilterName;
+ }
+
+ /**
+ * @param filterName the filer name
+ */
+ public void setFilterName(String filterName) {
+ fFilterName = filterName;
+ }
+
+ @Override
+ public String getNodeName() {
+ return NODE_NAME;
+ }
+
+ @Override
+ public boolean matches(ITmfEvent event) {
+ // There should be at most one child
+ for (ITmfFilterTreeNode node : getChildren()) {
+ if (node.matches(event)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public List<String> getValidChildren() {
+ if (getChildrenCount() == 0) {
+ return super.getValidChildren();
+ }
+ return new ArrayList<String>(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();
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.filter.model;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-\r
-/**\r
- * Filter node for the 'or' operation\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-@SuppressWarnings("javadoc")\r
-public class TmfFilterOrNode extends TmfFilterTreeNode {\r
-\r
- public static final String NODE_NAME = "OR"; //$NON-NLS-1$\r
- public static final String NOT_ATTR = "not"; //$NON-NLS-1$\r
-\r
- private boolean fNot = false;\r
-\r
- /**\r
- * @param parent the parent node\r
- */\r
- public TmfFilterOrNode(ITmfFilterTreeNode parent) {\r
- super(parent);\r
- }\r
-\r
- @Override\r
- public String getNodeName() {\r
- return NODE_NAME;\r
- }\r
-\r
- /**\r
- * @return the NOT state\r
- */\r
- public boolean isNot() {\r
- return fNot;\r
- }\r
-\r
- /**\r
- * @param not the NOT state\r
- */\r
- public void setNot(boolean not) {\r
- this.fNot = not;\r
- }\r
-\r
- @Override\r
- public boolean matches(ITmfEvent event) {\r
- for (ITmfFilterTreeNode node : getChildren()) {\r
- if (node.matches(event)) {\r
- return true ^ fNot;\r
- }\r
- }\r
- return false & fNot;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- StringBuffer buf = new StringBuffer();\r
- if (fNot) {\r
- buf.append("not "); //$NON-NLS-1$\r
- }\r
- if (getParent() != null && !(getParent() instanceof TmfFilterRootNode) && !(getParent() instanceof TmfFilterNode)) {\r
- buf.append("( "); //$NON-NLS-1$\r
- }\r
- for (int i = 0; i < getChildrenCount(); i++) {\r
- ITmfFilterTreeNode node = getChildren()[i];\r
- buf.append(node.toString());\r
- if (i < getChildrenCount() - 1) {\r
- buf.append(" or "); //$NON-NLS-1$\r
- }\r
- }\r
- if (getParent() != null && !(getParent() instanceof TmfFilterRootNode) && !(getParent() instanceof TmfFilterNode)) {\r
- buf.append(" )"); //$NON-NLS-1$\r
- }\r
- return buf.toString();\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.core.filter.model;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+
+/**
+ * Filter node for the 'or' operation
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+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;
+
+ /**
+ * @param parent the parent node
+ */
+ public TmfFilterOrNode(ITmfFilterTreeNode parent) {
+ super(parent);
+ }
+
+ @Override
+ public String getNodeName() {
+ return NODE_NAME;
+ }
+
+ /**
+ * @return the NOT state
+ */
+ public boolean isNot() {
+ return fNot;
+ }
+
+ /**
+ * @param not the NOT state
+ */
+ public void setNot(boolean not) {
+ this.fNot = not;
+ }
+
+ @Override
+ public boolean matches(ITmfEvent 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();
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.filter.model;\r
-\r
-import java.util.Arrays;\r
-import java.util.List;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-\r
-/**\r
- * The Filter tree root node\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TmfFilterRootNode extends TmfFilterTreeNode {\r
-\r
- @SuppressWarnings("javadoc")\r
- public static final String NODE_NAME = "ROOT"; //$NON-NLS-1$\r
-\r
- private static final String[] VALID_CHILDREN = {\r
- TmfFilterNode.NODE_NAME\r
- };\r
-\r
- /**\r
- * Default constructor\r
- */\r
- public TmfFilterRootNode() {\r
- super(null);\r
- }\r
-\r
- @Override\r
- public String getNodeName() {\r
- return NODE_NAME;\r
- }\r
-\r
- @Override\r
- public boolean matches(ITmfEvent event) {\r
- for (ITmfFilterTreeNode node : getChildren()) {\r
- if (! node.matches(event)) {\r
- return false;\r
- }\r
- }\r
- return true;\r
- }\r
-\r
- @Override\r
- public List<String> getValidChildren() {\r
- return Arrays.asList(VALID_CHILDREN);\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.core.filter.model;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+
+/**
+ * The Filter tree root node
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TmfFilterRootNode extends TmfFilterTreeNode {
+
+ @SuppressWarnings("javadoc")
+ public static final String NODE_NAME = "ROOT"; //$NON-NLS-1$
+
+ private static final String[] VALID_CHILDREN = {
+ TmfFilterNode.NODE_NAME
+ };
+
+ /**
+ * Default constructor
+ */
+ public TmfFilterRootNode() {
+ super(null);
+ }
+
+ @Override
+ public String getNodeName() {
+ return NODE_NAME;
+ }
+
+ @Override
+ public boolean matches(ITmfEvent event) {
+ for (ITmfFilterTreeNode node : getChildren()) {
+ if (! node.matches(event)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public List<String> getValidChildren() {
+ return Arrays.asList(VALID_CHILDREN);
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Yuriy Vashchuk (yvashchuk@gmail.com) - Initial API and implementation\r
- * Patrick Tasse - Refactoring\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.filter.model;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.List;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;\r
-\r
-/**\r
- * The base class for the Filter tree nodes\r
- *\r
- * @version 1.0\r
- * @author Yuriy Vashchuk\r
- * @author Patrick Tasse\r
- */\r
-public abstract class TmfFilterTreeNode implements ITmfFilterTreeNode, Cloneable {\r
-\r
- private static final String[] VALID_CHILDREN = {\r
- TmfFilterEventTypeNode.NODE_NAME,\r
- TmfFilterAndNode.NODE_NAME,\r
- TmfFilterOrNode.NODE_NAME,\r
- TmfFilterContainsNode.NODE_NAME,\r
- TmfFilterEqualsNode.NODE_NAME,\r
- TmfFilterMatchesNode.NODE_NAME,\r
- TmfFilterCompareNode.NODE_NAME\r
- };\r
-\r
- private ITmfFilterTreeNode parent = null;\r
- private ArrayList<ITmfFilterTreeNode> children = new ArrayList<ITmfFilterTreeNode>();\r
-\r
- /**\r
- * @param parent the parent node\r
- */\r
- public TmfFilterTreeNode(final ITmfFilterTreeNode parent) {\r
- if (parent != null) {\r
- parent.addChild(this);\r
- }\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getParent()\r
- */\r
- @Override\r
- public ITmfFilterTreeNode getParent() {\r
- return parent;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getNodeName()\r
- */\r
- @Override\r
- public abstract String getNodeName();\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#hasChildren()\r
- */\r
- @Override\r
- public boolean hasChildren() {\r
- return (children.size() > 0);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getChildrenCount()\r
- */\r
- @Override\r
- public int getChildrenCount() {\r
- return children.size();\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getChildren()\r
- */\r
- @Override\r
- public ITmfFilterTreeNode[] getChildren() {\r
- return children.toArray(new ITmfFilterTreeNode[0]);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getChild(int)\r
- */\r
- @Override\r
- public ITmfFilterTreeNode getChild(final int index) throws IndexOutOfBoundsException {\r
- return children.get(index);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#remove()\r
- */\r
- @Override\r
- public ITmfFilterTreeNode remove() {\r
- if (getParent() != null) {\r
- getParent().removeChild(this);\r
- }\r
- return this;\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#removeChild(org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode)\r
- */\r
- @Override\r
- public ITmfFilterTreeNode removeChild(ITmfFilterTreeNode node) {\r
- children.remove(node);\r
- node.setParent(null);\r
- return node;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#addChild(org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode)\r
- */\r
- @Override\r
- public int addChild(final ITmfFilterTreeNode node) {\r
- node.setParent(this);\r
- if(children.add(node)) {\r
- return (children.size() - 1);\r
- }\r
- return -1;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#replaceChild(int, org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode)\r
- */\r
- @Override\r
- public ITmfFilterTreeNode replaceChild(final int index, final ITmfFilterTreeNode node) throws IndexOutOfBoundsException {\r
- node.setParent(this);\r
- return children.set(index, node);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#setParent(org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode)\r
- */\r
- @Override\r
- public void setParent(final ITmfFilterTreeNode parent) {\r
- this.parent = parent;\r
- }\r
-\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#matches(org.eclipse.linuxtools.tmf.event.TmfEvent)\r
- */\r
- @Override\r
- public abstract boolean matches(ITmfEvent event);\r
-\r
- /**\r
- * @param event the event\r
- * @param field the field id\r
- * @return the field value\r
- */\r
- protected Object getFieldValue(ITmfEvent event, String field) {\r
- Object value = null;\r
- if (ITmfEvent.EVENT_FIELD_CONTENT.equals(field)) {\r
- ITmfEventField content = event.getContent();\r
- value = (content.getValue() != null) ? content.getValue().toString() : content.toString();\r
- }\r
- else if (ITmfEvent.EVENT_FIELD_TYPE.equals(field)) {\r
- value = event.getType().getName();\r
- }\r
- else if (ITmfEvent.EVENT_FIELD_TIMESTAMP.equals(field)) {\r
- value = event.getTimestamp().toString();\r
- }\r
- else if (ITmfEvent.EVENT_FIELD_SOURCE.equals(field)) {\r
- value = event.getSource();\r
- }\r
- else if (ITmfEvent.EVENT_FIELD_REFERENCE.equals(field)) {\r
- value = event.getReference();\r
- }\r
- else {\r
- ITmfEventField eventField = event.getContent().getField(field);\r
- if (eventField != null) {\r
- value = eventField.getValue();\r
- }\r
- }\r
- return value;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getValidChildren()\r
- *\r
- * By default, all node types are valid children. Override if different.\r
- */\r
- @Override\r
- public List<String> getValidChildren() {\r
- return Arrays.asList(VALID_CHILDREN);\r
- }\r
-\r
- @Override\r
- public ITmfFilterTreeNode clone() {\r
- try {\r
- TmfFilterTreeNode clone = (TmfFilterTreeNode) super.clone();\r
- clone.parent = null;\r
- clone.children = new ArrayList<ITmfFilterTreeNode>(children.size());\r
- for (ITmfFilterTreeNode child : getChildren()) {\r
- clone.addChild(child.clone());\r
- }\r
- return clone;\r
- } catch (CloneNotSupportedException e) {\r
- return null;\r
- }\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.core.filter.model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
+
+/**
+ * The base class for the Filter tree nodes
+ *
+ * @version 1.0
+ * @author Yuriy Vashchuk
+ * @author Patrick Tasse
+ */
+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<ITmfFilterTreeNode> children = new ArrayList<ITmfFilterTreeNode>();
+
+ /**
+ * @param parent the parent node
+ */
+ 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(ITmfEvent event);
+
+ /**
+ * @param event the event
+ * @param field the field id
+ * @return the field value
+ */
+ protected Object getFieldValue(ITmfEvent event, String field) {
+ Object value = null;
+ if (ITmfEvent.EVENT_FIELD_CONTENT.equals(field)) {
+ ITmfEventField content = event.getContent();
+ value = (content.getValue() != null) ? content.getValue().toString() : content.toString();
+ }
+ else if (ITmfEvent.EVENT_FIELD_TYPE.equals(field)) {
+ value = event.getType().getName();
+ }
+ else if (ITmfEvent.EVENT_FIELD_TIMESTAMP.equals(field)) {
+ value = event.getTimestamp().toString();
+ }
+ else if (ITmfEvent.EVENT_FIELD_SOURCE.equals(field)) {
+ value = event.getSource();
+ }
+ else if (ITmfEvent.EVENT_FIELD_REFERENCE.equals(field)) {
+ value = event.getReference();
+ }
+ else {
+ ITmfEventField eventField = event.getContent().getField(field);
+ if (eventField != null) {
+ value = eventField.getValue();
+ }
+ }
+ return value;
+ }
+
+ /* (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<String> getValidChildren() {
+ return Arrays.asList(VALID_CHILDREN);
+ }
+
+ @Override
+ public ITmfFilterTreeNode clone() {
+ try {
+ TmfFilterTreeNode clone = (TmfFilterTreeNode) super.clone();
+ clone.parent = null;
+ clone.children = new ArrayList<ITmfFilterTreeNode>(children.size());
+ for (ITmfFilterTreeNode child : getChildren()) {
+ clone.addChild(child.clone());
+ }
+ return clone;
+ } catch (CloneNotSupportedException e) {
+ return null;
+ }
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- * \r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- * \r
- * Contributors:\r
- * Yuriy Vashchuk (yvashchuk@gmail.com) - Initial API and implementation\r
- * based on http://smeric.developpez.com/java/cours/xml/sax/\r
- * Patrick Tasse - Refactoring\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.filter.xml;\r
-\r
-import java.util.Stack;\r
-\r
-import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterAndNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterContainsNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEqualsNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEventTypeNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterMatchesNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterOrNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterTreeNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode.Type;\r
-import org.xml.sax.Attributes;\r
-import org.xml.sax.SAXException;\r
-import org.xml.sax.helpers.DefaultHandler;\r
-\r
-/**\r
- * The SAX Content Handler\r
- * \r
- * @version 1.0\r
- * @author Yuriy Vashchuk\r
- * @author Patrick Tasse\r
- */\r
-public class TmfFilterContentHandler extends DefaultHandler {\r
- \r
- private ITmfFilterTreeNode fRoot = null;\r
- private Stack<ITmfFilterTreeNode> fFilterTreeStack = null;\r
-\r
- /**\r
- * The default constructor\r
- */ \r
- public TmfFilterContentHandler() {\r
- super();\r
- fFilterTreeStack = new Stack<ITmfFilterTreeNode>();\r
- }\r
-\r
- /**\r
- * Getter of tree\r
- * \r
- * @return The builded tree\r
- */ \r
- public ITmfFilterTreeNode getTree() {\r
- return fRoot;\r
- }\r
- \r
- /*\r
- * (non-Javadoc)\r
- * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)\r
- */\r
- @Override\r
- public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {\r
- ITmfFilterTreeNode node = null;\r
- \r
- if (localName.equalsIgnoreCase(TmfFilterRootNode.NODE_NAME)) {\r
- \r
- node = new TmfFilterRootNode();\r
- \r
- } else if (localName.equals(TmfFilterNode.NODE_NAME)) {\r
- \r
- node = new TmfFilterNode(atts.getValue(TmfFilterNode.NAME_ATTR));\r
- \r
- } else if (localName.equals(TmfFilterEventTypeNode.NODE_NAME)) {\r
- \r
- node = new TmfFilterEventTypeNode(null);\r
- ((TmfFilterEventTypeNode) node).setEventType(atts.getValue(TmfFilterEventTypeNode.TYPE_ATTR));\r
- ((TmfFilterEventTypeNode) node).setName(atts.getValue(TmfFilterEventTypeNode.NAME_ATTR));\r
- \r
- } else if (localName.equals(TmfFilterAndNode.NODE_NAME)) {\r
- \r
- node = new TmfFilterAndNode(null);\r
- String value = atts.getValue(TmfFilterAndNode.NOT_ATTR);\r
- if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {\r
- ((TmfFilterAndNode) node).setNot(true);\r
- }\r
- \r
- } else if (localName.equals(TmfFilterOrNode.NODE_NAME)) {\r
- \r
- node = new TmfFilterOrNode(null);\r
- String value = atts.getValue(TmfFilterOrNode.NOT_ATTR);\r
- if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {\r
- ((TmfFilterOrNode) node).setNot(true);\r
- }\r
- \r
- } else if (localName.equals(TmfFilterContainsNode.NODE_NAME)) {\r
- \r
- node = new TmfFilterContainsNode(null);\r
- String value = atts.getValue(TmfFilterContainsNode.NOT_ATTR);\r
- if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {\r
- ((TmfFilterContainsNode) node).setNot(true);\r
- }\r
- ((TmfFilterContainsNode) node).setField(atts.getValue(TmfFilterContainsNode.FIELD_ATTR));\r
- ((TmfFilterContainsNode) node).setValue(atts.getValue(TmfFilterContainsNode.VALUE_ATTR));\r
- value = atts.getValue(TmfFilterContainsNode.IGNORECASE_ATTR);\r
- if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {\r
- ((TmfFilterContainsNode) node).setIgnoreCase(true);\r
- }\r
- \r
- } else if (localName.equals(TmfFilterEqualsNode.NODE_NAME)) {\r
- \r
- node = new TmfFilterEqualsNode(null);\r
- String value = atts.getValue(TmfFilterEqualsNode.NOT_ATTR);\r
- if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {\r
- ((TmfFilterEqualsNode) node).setNot(true);\r
- }\r
- ((TmfFilterEqualsNode) node).setField(atts.getValue(TmfFilterEqualsNode.FIELD_ATTR));\r
- ((TmfFilterEqualsNode) node).setValue(atts.getValue(TmfFilterEqualsNode.VALUE_ATTR));\r
- value = atts.getValue(TmfFilterEqualsNode.IGNORECASE_ATTR);\r
- if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {\r
- ((TmfFilterEqualsNode) node).setIgnoreCase(true);\r
- }\r
- \r
- } else if (localName.equals(TmfFilterMatchesNode.NODE_NAME)) {\r
- \r
- node = new TmfFilterMatchesNode(null);\r
- String value = atts.getValue(TmfFilterMatchesNode.NOT_ATTR);\r
- if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {\r
- ((TmfFilterMatchesNode) node).setNot(true);\r
- }\r
- ((TmfFilterMatchesNode) node).setField(atts.getValue(TmfFilterMatchesNode.FIELD_ATTR));\r
- ((TmfFilterMatchesNode) node).setRegex(atts.getValue(TmfFilterMatchesNode.REGEX_ATTR));\r
- \r
- } else if (localName.equals(TmfFilterCompareNode.NODE_NAME)) {\r
- \r
- node = new TmfFilterCompareNode(null);\r
- String value = atts.getValue(TmfFilterCompareNode.NOT_ATTR);\r
- if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {\r
- ((TmfFilterCompareNode) node).setNot(true);\r
- }\r
- ((TmfFilterCompareNode) node).setField(atts.getValue(TmfFilterCompareNode.FIELD_ATTR));\r
- value = atts.getValue(TmfFilterCompareNode.TYPE_ATTR);\r
- if (value != null) {\r
- ((TmfFilterCompareNode) node).setType(Type.valueOf(value));\r
- }\r
- value = atts.getValue(TmfFilterCompareNode.RESULT_ATTR);\r
- if (value != null) {\r
- if (value.equals(Integer.toString(-1))) {\r
- ((TmfFilterCompareNode) node).setResult(-1);\r
- } else if (value.equals(Integer.toString(1))) {\r
- ((TmfFilterCompareNode) node).setResult(1);\r
- } else {\r
- ((TmfFilterCompareNode) node).setResult(0);\r
- }\r
- }\r
- ((TmfFilterCompareNode) node).setValue(atts.getValue(TmfFilterCompareNode.VALUE_ATTR));\r
- \r
- }\r
-\r
- fFilterTreeStack.push(node);\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)\r
- */\r
- @Override\r
- public void endElement(String uri, String localName, String qName) throws SAXException {\r
- ITmfFilterTreeNode node = fFilterTreeStack.pop();\r
-\r
- if (fFilterTreeStack.isEmpty()) {\r
- fRoot = node;\r
- } else if (fFilterTreeStack.lastElement() instanceof TmfFilterTreeNode &&\r
- node instanceof TmfFilterTreeNode) {\r
- fFilterTreeStack.lastElement().addChild(node);\r
- }\r
- \r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.core.filter.xml;
+
+import java.util.Stack;
+
+import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterAndNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterContainsNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEqualsNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEventTypeNode;
+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.core.filter.model.TmfFilterCompareNode.Type;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * The SAX Content Handler
+ *
+ * @version 1.0
+ * @author Yuriy Vashchuk
+ * @author Patrick Tasse
+ */
+public class TmfFilterContentHandler extends DefaultHandler {
+
+ private ITmfFilterTreeNode fRoot = null;
+ private Stack<ITmfFilterTreeNode> fFilterTreeStack = null;
+
+ /**
+ * The default constructor
+ */
+ public TmfFilterContentHandler() {
+ super();
+ fFilterTreeStack = new Stack<ITmfFilterTreeNode>();
+ }
+
+ /**
+ * 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);
+ }
+
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Yuriy Vashchuk (yvashchuk@gmail.com) - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.filter.xml;\r
-\r
-import java.io.IOException;\r
-\r
-import javax.xml.parsers.ParserConfigurationException;\r
-import javax.xml.parsers.SAXParserFactory;\r
-\r
-import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;\r
-import org.xml.sax.SAXException;\r
-import org.xml.sax.XMLReader;\r
-\r
-/**\r
- * The SAX based XML parser\r
- *\r
- * @version 1.0\r
- * @author Yuriy Vashchuk\r
- * @author Patrick Tasse\r
- */\r
-public class TmfFilterXMLParser {\r
-\r
- private static ITmfFilterTreeNode fRoot = null;\r
-\r
- /**\r
- * The XMLParser constructor\r
- *\r
- * @param uri The XML file to parse\r
- * @throws SAXException SAX exception\r
- * @throws IOException IO exception\r
- */\r
- public TmfFilterXMLParser(final String uri) throws SAXException, IOException {\r
-\r
- SAXParserFactory m_parserFactory = null;\r
- m_parserFactory = SAXParserFactory.newInstance();\r
- m_parserFactory.setNamespaceAware(true);\r
-\r
- XMLReader saxReader = null;\r
- try {\r
-\r
- saxReader = m_parserFactory.newSAXParser().getXMLReader();\r
- saxReader.setContentHandler(new TmfFilterContentHandler());\r
- saxReader.parse(uri);\r
-\r
- fRoot = ((TmfFilterContentHandler) saxReader.getContentHandler()).getTree();\r
-\r
- } catch (ParserConfigurationException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- /**\r
- * Getter of tree\r
- *\r
- * @return The builded tree\r
- */\r
- public ITmfFilterTreeNode getTree() {\r
- return fRoot;\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.core.filter.xml;
+
+import java.io.IOException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
+/**
+ * The SAX based XML parser
+ *
+ * @version 1.0
+ * @author Yuriy Vashchuk
+ * @author Patrick Tasse
+ */
+public class TmfFilterXMLParser {
+
+ private static ITmfFilterTreeNode fRoot = null;
+
+ /**
+ * The XMLParser constructor
+ *
+ * @param uri The XML file to parse
+ * @throws SAXException SAX exception
+ * @throws IOException IO exception
+ */
+ public TmfFilterXMLParser(final String uri) throws SAXException, IOException {
+
+ SAXParserFactory 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;
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Yuriy Vashchuk (yvashchuk@gmail.com) - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.filter.xml;\r
-\r
-import java.io.File;\r
-\r
-import javax.xml.parsers.DocumentBuilder;\r
-import javax.xml.parsers.DocumentBuilderFactory;\r
-import javax.xml.parsers.ParserConfigurationException;\r
-import javax.xml.transform.Transformer;\r
-import javax.xml.transform.TransformerConfigurationException;\r
-import javax.xml.transform.TransformerException;\r
-import javax.xml.transform.TransformerFactory;\r
-import javax.xml.transform.dom.DOMSource;\r
-import javax.xml.transform.stream.StreamResult;\r
-\r
-import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterAndNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterContainsNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEqualsNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEventTypeNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterMatchesNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterOrNode;\r
-import org.w3c.dom.Document;\r
-import org.w3c.dom.Element;\r
-\r
-/**\r
- * The SAX based XML writer\r
- *\r
- * @version 1.0\r
- * @author Yuriy Vashchuk\r
- * @author Patrick Tasse\r
- */\r
-public class TmfFilterXMLWriter {\r
-\r
- private Document document = null;\r
-\r
- /**\r
- * The XMLParser constructor\r
- *\r
- * @param root The tree root\r
- * @throws ParserConfigurationException if a DocumentBuilder\r
- * cannot be created which satisfies the configuration requested.\r
- */\r
- public TmfFilterXMLWriter(final ITmfFilterTreeNode root) throws ParserConfigurationException {\r
- DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();\r
- DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();\r
- document = documentBuilder.newDocument();\r
-\r
- Element rootElement = document.createElement(root.getNodeName());\r
- document.appendChild(rootElement);\r
-\r
- for (ITmfFilterTreeNode node : root.getChildren()) {\r
- buildXMLTree(document, node, rootElement);\r
- }\r
- }\r
-\r
- /**\r
- * The Tree to XML parser\r
- *\r
- * @param document The XML document\r
- * @param treenode The node to write\r
- * @param parentElement The XML element of the parent\r
- */\r
- public static void buildXMLTree(final Document document, final ITmfFilterTreeNode treenode, Element parentElement) {\r
- Element element = document.createElement(treenode.getNodeName());\r
-\r
- if (treenode instanceof TmfFilterNode) {\r
-\r
- TmfFilterNode node = (TmfFilterNode) treenode;\r
- element.setAttribute(TmfFilterNode.NAME_ATTR, node.getFilterName());\r
-\r
- } else if (treenode instanceof TmfFilterEventTypeNode) {\r
-\r
- TmfFilterEventTypeNode node = (TmfFilterEventTypeNode) treenode;\r
- element.setAttribute(TmfFilterEventTypeNode.TYPE_ATTR, node.getEventType());\r
- element.setAttribute(TmfFilterEventTypeNode.NAME_ATTR, node.getName());\r
-\r
- } else if (treenode instanceof TmfFilterAndNode) {\r
-\r
- TmfFilterAndNode node = (TmfFilterAndNode) treenode;\r
- element.setAttribute(TmfFilterAndNode.NOT_ATTR, Boolean.toString(node.isNot()));\r
-\r
- } else if (treenode instanceof TmfFilterOrNode) {\r
-\r
- TmfFilterOrNode node = (TmfFilterOrNode) treenode;\r
- element.setAttribute(TmfFilterOrNode.NOT_ATTR, Boolean.toString(node.isNot()));\r
-\r
- } else if (treenode instanceof TmfFilterContainsNode) {\r
-\r
- TmfFilterContainsNode node = (TmfFilterContainsNode) treenode;\r
- element.setAttribute(TmfFilterContainsNode.NOT_ATTR, Boolean.toString(node.isNot()));\r
- element.setAttribute(TmfFilterContainsNode.FIELD_ATTR, node.getField());\r
- element.setAttribute(TmfFilterContainsNode.VALUE_ATTR, node.getValue());\r
- element.setAttribute(TmfFilterContainsNode.IGNORECASE_ATTR, Boolean.toString(node.isIgnoreCase()));\r
-\r
- } else if (treenode instanceof TmfFilterEqualsNode) {\r
-\r
- TmfFilterEqualsNode node = (TmfFilterEqualsNode) treenode;\r
- element.setAttribute(TmfFilterEqualsNode.NOT_ATTR, Boolean.toString(node.isNot()));\r
- element.setAttribute(TmfFilterEqualsNode.FIELD_ATTR, node.getField());\r
- element.setAttribute(TmfFilterEqualsNode.VALUE_ATTR, node.getValue());\r
- element.setAttribute(TmfFilterEqualsNode.IGNORECASE_ATTR, Boolean.toString(node.isIgnoreCase()));\r
-\r
- } else if (treenode instanceof TmfFilterMatchesNode) {\r
-\r
- TmfFilterMatchesNode node = (TmfFilterMatchesNode) treenode;\r
- element.setAttribute(TmfFilterMatchesNode.NOT_ATTR, Boolean.toString(node.isNot()));\r
- element.setAttribute(TmfFilterMatchesNode.FIELD_ATTR, node.getField());\r
- element.setAttribute(TmfFilterMatchesNode.REGEX_ATTR, node.getRegex());\r
-\r
- } else if (treenode instanceof TmfFilterCompareNode) {\r
-\r
- TmfFilterCompareNode node = (TmfFilterCompareNode) treenode;\r
- element.setAttribute(TmfFilterCompareNode.NOT_ATTR, Boolean.toString(node.isNot()));\r
- element.setAttribute(TmfFilterCompareNode.FIELD_ATTR, node.getField());\r
- element.setAttribute(TmfFilterCompareNode.RESULT_ATTR, Integer.toString(node.getResult()));\r
- element.setAttribute(TmfFilterCompareNode.TYPE_ATTR, node.getType().toString());\r
- element.setAttribute(TmfFilterCompareNode.VALUE_ATTR, node.getValue());\r
-\r
- }\r
-\r
- parentElement.appendChild(element);\r
-\r
- for (int i = 0; i < treenode.getChildrenCount(); i++) {\r
- buildXMLTree(document, treenode.getChild(i), element);\r
- }\r
- }\r
-\r
- /**\r
- * Save the tree\r
- *\r
- * @param uri The new Filter XML path\r
- */\r
- public void saveTree(final String uri) {\r
- TransformerFactory transformerFactory = TransformerFactory.newInstance();\r
-\r
- try {\r
- Transformer transformer = transformerFactory.newTransformer();\r
- DOMSource source = new DOMSource(document);\r
- StreamResult result = new StreamResult(new File(uri));\r
- transformer.transform(source, result);\r
- } catch (TransformerConfigurationException e) {\r
- e.printStackTrace();\r
- } catch (TransformerException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.core.filter.xml;
+
+import java.io.File;
+
+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.core.filter.model.ITmfFilterTreeNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterAndNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterContainsNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEqualsNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEventTypeNode;
+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.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * The SAX based XML writer
+ *
+ * @version 1.0
+ * @author Yuriy Vashchuk
+ * @author Patrick Tasse
+ */
+public class TmfFilterXMLWriter {
+
+ private Document document = null;
+
+ /**
+ * The XMLParser constructor
+ *
+ * @param root The tree root
+ * @throws ParserConfigurationException if a DocumentBuilder
+ * cannot be created which satisfies the configuration requested.
+ */
+ public TmfFilterXMLWriter(final ITmfFilterTreeNode root) throws 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();
+ }
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation, based on article by Nick Zhang\r
- * (http://www.javaworld.com/javatips/jw-javatip26.html)\r
- ******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.io;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.io.RandomAccessFile;\r
-import java.nio.charset.Charset;\r
-\r
-/**\r
- * A class to mitigate the Java I/O inefficiency of RandomAccessFile.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class BufferedRandomAccessFile extends RandomAccessFile {\r
-\r
- private static final int DEFAULT_BUF_SIZE = 8192;\r
- private static final Charset CHARSET_UTF8 = Charset.forName("UTF-8"); //$NON-NLS-1$\r
-\r
- final int BUF_SIZE;\r
- byte buffer[];\r
- int buf_end = 0;\r
- int buf_pos = 0;\r
- long real_pos = 0;\r
- StringBuilder sb = new StringBuilder();\r
-\r
- /**\r
- * Constructor using the default buffer size\r
- *\r
- * @param name\r
- * File path. This is passed as-is to the RandomeAccessFile's\r
- * constructor.\r
- * @param mode\r
- * File open mode ("r", "rw", etc.). This is passed as-is to\r
- * RandomAccessFile's constructor.\r
- * @throws IOException\r
- * If the file was not found or couldn't be opened with the\r
- * request permissions\r
- */\r
- public BufferedRandomAccessFile(String name, String mode) throws IOException {\r
- this(name, mode, DEFAULT_BUF_SIZE);\r
- }\r
-\r
- /**\r
- * Constructor using the default buffer size\r
- *\r
- * @param file\r
- * File object. This is passed as-is to the RandomeAccessFile's\r
- * constructor.\r
- * @param mode\r
- * File open mode ("r", "rw", etc.). This is passed as-is to\r
- * RandomAccessFile's constructor.\r
- * @throws IOException\r
- * If the file was not found or couldn't be opened with the\r
- * request permissions\r
- */\r
- public BufferedRandomAccessFile(File file, String mode) throws IOException {\r
- this(file, mode, DEFAULT_BUF_SIZE);\r
- }\r
-\r
- /**\r
- * Standard constructor.\r
- *\r
- * @param name\r
- * File path. This is passed as-is to the RandomeAccessFile's\r
- * constructor.\r
- * @param mode\r
- * File open mode ("r", "rw", etc.). This is passed as-is to\r
- * RandomAccessFile's constructor.\r
- * @param bufsize\r
- * Buffer size to use, in bytes\r
- * @throws IOException\r
- * If the file was not found or couldn't be opened with the\r
- * request permissions\r
- */\r
- public BufferedRandomAccessFile(String name, String mode, int bufsize) throws IOException {\r
- super(name, mode);\r
- invalidate();\r
- BUF_SIZE = bufsize;\r
- buffer = new byte[BUF_SIZE];\r
- }\r
-\r
- /**\r
- * Standard constructor.\r
- *\r
- * @param file\r
- * File object. This is passed as-is to the RandomeAccessFile's\r
- * constructor.\r
- * @param mode\r
- * File open mode ("r", "rw", etc.). This is passed as-is to\r
- * RandomAccessFile's constructor.\r
- * @param bufsize\r
- * Buffer size to use, in bytes\r
- * @throws IOException\r
- * If the file was not found or couldn't be opened with the\r
- * request permissions\r
- */\r
- public BufferedRandomAccessFile(File file, String mode, int bufsize) throws IOException {\r
- super(file, mode);\r
- invalidate();\r
- BUF_SIZE = bufsize;\r
- buffer = new byte[BUF_SIZE];\r
- }\r
-\r
- @Override\r
- public final int read() throws IOException{\r
- if (buf_pos >= buf_end) {\r
- if (fillBuffer() < 0) {\r
- return -1;\r
- }\r
- }\r
- if (buf_end == 0) {\r
- return -1;\r
- }\r
- return buffer[buf_pos++];\r
- }\r
-\r
- @Override\r
- public int read(byte b[], int off, int len) throws IOException {\r
- int leftover = buf_end - buf_pos;\r
- if (len <= leftover) {\r
- System.arraycopy(buffer, buf_pos, b, off, len);\r
- buf_pos += len;\r
- return len;\r
- }\r
- for(int i = 0; i < len; i++) {\r
- int c = this.read();\r
- if (c != -1) {\r
- b[off+i] = (byte) c;\r
- } else {\r
- return i;\r
- }\r
- }\r
- return len;\r
- }\r
-\r
- @Override\r
- public long getFilePointer() throws IOException{\r
- long l = real_pos;\r
- return (l - buf_end + buf_pos);\r
- }\r
-\r
- @Override\r
- public void seek(long pos) throws IOException {\r
- int n = (int) (real_pos - pos);\r
- if(n >= 0 && n <= buf_end) {\r
- buf_pos = buf_end - n;\r
- } else {\r
- super.seek(pos);\r
- invalidate();\r
- }\r
- }\r
-\r
- /**\r
- * Read the next line from the buffer (ie, until the next '\n'). The bytes\r
- * are interpreted as UTF-8 characters.\r
- *\r
- * @return The String that was read\r
- * @throws IOException\r
- * If we failed reading the file\r
- */\r
- public final String getNextLine() throws IOException {\r
- String str = null;\r
- if (buf_end - buf_pos <= 0) {\r
- if (fillBuffer() < 0) {\r
- return null;\r
- }\r
- }\r
- int lineend = -1;\r
- for (int i = buf_pos; i < buf_end; i++) {\r
- if (buffer[i] == '\n') {\r
- lineend = i;\r
- break;\r
- }\r
- }\r
- if (lineend < 0) {\r
- sb.delete(0, sb.length());\r
- int c;\r
- while (((c = read()) != -1) && (c != '\n')) {\r
- sb.append((char) c);\r
- }\r
- if ((c == -1) && (sb.length() == 0)) {\r
- return null;\r
- }\r
- if (sb.charAt(sb.length() - 1) == '\r') {\r
- sb.deleteCharAt(sb.length() - 1);\r
- }\r
- return sb.toString();\r
- }\r
- if (lineend > 0 && buffer[lineend - 1] == '\r' && lineend > buf_pos) {\r
- str = new String(buffer, buf_pos, lineend - buf_pos - 1, CHARSET_UTF8);\r
- } else {\r
- str = new String(buffer, buf_pos, lineend - buf_pos, CHARSET_UTF8);\r
- }\r
- buf_pos = lineend + 1;\r
- return str;\r
- }\r
-\r
- private int fillBuffer() throws IOException {\r
- int n = super.read(buffer, 0, BUF_SIZE);\r
- if (n >= 0) {\r
- real_pos += n;\r
- buf_end = n;\r
- buf_pos = 0;\r
- }\r
- return n;\r
- }\r
-\r
- private void invalidate() throws IOException {\r
- buf_end = 0;\r
- buf_pos = 0;\r
- real_pos = super.getFilePointer();\r
- }\r
-}\r
+/*******************************************************************************
+ * 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, based on article by Nick Zhang
+ * (http://www.javaworld.com/javatips/jw-javatip26.html)
+ ******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.io;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.charset.Charset;
+
+/**
+ * A class to mitigate the Java I/O inefficiency of RandomAccessFile.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class BufferedRandomAccessFile extends RandomAccessFile {
+
+ private static final int DEFAULT_BUF_SIZE = 8192;
+ private static final Charset CHARSET_UTF8 = Charset.forName("UTF-8"); //$NON-NLS-1$
+
+ final int BUF_SIZE;
+ byte buffer[];
+ int buf_end = 0;
+ int buf_pos = 0;
+ long real_pos = 0;
+ StringBuilder sb = new StringBuilder();
+
+ /**
+ * Constructor using the default buffer size
+ *
+ * @param name
+ * File path. This is passed as-is to the RandomeAccessFile's
+ * constructor.
+ * @param mode
+ * File open mode ("r", "rw", etc.). This is passed as-is to
+ * RandomAccessFile's constructor.
+ * @throws IOException
+ * If the file was not found or couldn't be opened with the
+ * request permissions
+ */
+ public BufferedRandomAccessFile(String name, String mode) throws IOException {
+ this(name, mode, DEFAULT_BUF_SIZE);
+ }
+
+ /**
+ * Constructor using the default buffer size
+ *
+ * @param file
+ * File object. This is passed as-is to the RandomeAccessFile's
+ * constructor.
+ * @param mode
+ * File open mode ("r", "rw", etc.). This is passed as-is to
+ * RandomAccessFile's constructor.
+ * @throws IOException
+ * If the file was not found or couldn't be opened with the
+ * request permissions
+ */
+ public BufferedRandomAccessFile(File file, String mode) throws IOException {
+ this(file, mode, DEFAULT_BUF_SIZE);
+ }
+
+ /**
+ * Standard constructor.
+ *
+ * @param name
+ * File path. This is passed as-is to the RandomeAccessFile's
+ * constructor.
+ * @param mode
+ * File open mode ("r", "rw", etc.). This is passed as-is to
+ * RandomAccessFile's constructor.
+ * @param bufsize
+ * Buffer size to use, in bytes
+ * @throws IOException
+ * If the file was not found or couldn't be opened with the
+ * request permissions
+ */
+ public BufferedRandomAccessFile(String name, String mode, int bufsize) throws IOException {
+ super(name, mode);
+ invalidate();
+ BUF_SIZE = bufsize;
+ buffer = new byte[BUF_SIZE];
+ }
+
+ /**
+ * Standard constructor.
+ *
+ * @param file
+ * File object. This is passed as-is to the RandomeAccessFile's
+ * constructor.
+ * @param mode
+ * File open mode ("r", "rw", etc.). This is passed as-is to
+ * RandomAccessFile's constructor.
+ * @param bufsize
+ * Buffer size to use, in bytes
+ * @throws IOException
+ * If the file was not found or couldn't be opened with the
+ * request permissions
+ */
+ public BufferedRandomAccessFile(File file, String mode, int bufsize) throws IOException {
+ super(file, mode);
+ invalidate();
+ BUF_SIZE = bufsize;
+ buffer = new byte[BUF_SIZE];
+ }
+
+ @Override
+ public final int read() throws IOException{
+ if (buf_pos >= buf_end) {
+ if (fillBuffer() < 0) {
+ return -1;
+ }
+ }
+ if (buf_end == 0) {
+ return -1;
+ }
+ return buffer[buf_pos++];
+ }
+
+ @Override
+ public int read(byte b[], int off, int len) throws IOException {
+ int leftover = buf_end - buf_pos;
+ if (len <= leftover) {
+ System.arraycopy(buffer, buf_pos, b, off, len);
+ buf_pos += len;
+ return len;
+ }
+ for(int i = 0; i < len; i++) {
+ int c = this.read();
+ if (c != -1) {
+ b[off+i] = (byte) c;
+ } else {
+ return i;
+ }
+ }
+ return len;
+ }
+
+ @Override
+ public long getFilePointer() throws IOException{
+ long l = real_pos;
+ return (l - buf_end + buf_pos);
+ }
+
+ @Override
+ public void seek(long pos) throws IOException {
+ int n = (int) (real_pos - pos);
+ if(n >= 0 && n <= buf_end) {
+ buf_pos = buf_end - n;
+ } else {
+ super.seek(pos);
+ invalidate();
+ }
+ }
+
+ /**
+ * Read the next line from the buffer (ie, until the next '\n'). The bytes
+ * are interpreted as UTF-8 characters.
+ *
+ * @return The String that was read
+ * @throws IOException
+ * If we failed reading the file
+ */
+ public final String getNextLine() throws IOException {
+ String str = null;
+ if (buf_end - buf_pos <= 0) {
+ if (fillBuffer() < 0) {
+ return null;
+ }
+ }
+ int lineend = -1;
+ for (int i = buf_pos; i < buf_end; i++) {
+ if (buffer[i] == '\n') {
+ lineend = i;
+ break;
+ }
+ }
+ if (lineend < 0) {
+ sb.delete(0, sb.length());
+ int c;
+ while (((c = read()) != -1) && (c != '\n')) {
+ sb.append((char) c);
+ }
+ if ((c == -1) && (sb.length() == 0)) {
+ return null;
+ }
+ if (sb.charAt(sb.length() - 1) == '\r') {
+ sb.deleteCharAt(sb.length() - 1);
+ }
+ return sb.toString();
+ }
+ if (lineend > 0 && buffer[lineend - 1] == '\r' && lineend > buf_pos) {
+ str = new String(buffer, buf_pos, lineend - buf_pos - 1, CHARSET_UTF8);
+ } else {
+ str = new String(buffer, buf_pos, lineend - buf_pos, CHARSET_UTF8);
+ }
+ buf_pos = lineend + 1;
+ return str;
+ }
+
+ private int fillBuffer() throws IOException {
+ int n = super.read(buffer, 0, BUF_SIZE);
+ if (n >= 0) {
+ real_pos += n;
+ buf_end = n;
+ buf_pos = 0;
+ }
+ return n;
+ }
+
+ private void invalidate() throws IOException {
+ buf_end = 0;
+ buf_pos = 0;
+ real_pos = super.getFilePointer();
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Francois Chouinard - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.signal;\r
-\r
-/**\r
- * Clear experiment signal\r
- *\r
- * @version 1.0\r
- * @author Francois Chouinard\r
- * @since 2.0\r
- */\r
-public class TmfClearExperimentSignal extends TmfSignal {\r
-\r
- /**\r
- * @param source the signal source\r
- */\r
- public TmfClearExperimentSignal(Object source) {\r
- super(source);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#toString()\r
- */\r
- @Override\r
- @SuppressWarnings("nls")\r
- public String toString() {\r
- return "[TmfClearExperimentSignal]";\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.signal;
+
+/**
+ * Clear experiment signal
+ *
+ * @version 1.0
+ * @author Francois Chouinard
+ * @since 2.0
+ */
+public class TmfClearExperimentSignal extends TmfSignal {
+
+ /**
+ * @param source the signal source
+ */
+ public TmfClearExperimentSignal(Object source) {
+ super(source);
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ @SuppressWarnings("nls")
+ public String toString() {
+ return "[TmfClearExperimentSignal]";
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.signal;\r
-\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-\r
-/**\r
- * A trace was selected\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TmfTraceSelectedSignal extends TmfSignal {\r
-\r
- private final ITmfTrace fTrace;\r
-\r
- /**\r
- * Constructor\r
- *\r
- * @param source\r
- * Object sending this signal\r
- * @param trace\r
- * The trace that was selected\r
- */\r
- public TmfTraceSelectedSignal(Object source, ITmfTrace trace) {\r
- super(source);\r
- fTrace = trace;\r
- }\r
-\r
- /**\r
- * @return The trace referred to by this signal\r
- */\r
- public ITmfTrace getTrace() {\r
- return fTrace;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return "[TmfTraceSelectedSignal (" + fTrace.getName() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.core.signal;
+
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+
+/**
+ * A trace was selected
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TmfTraceSelectedSignal extends TmfSignal {
+
+ private final ITmfTrace fTrace;
+
+ /**
+ * Constructor
+ *
+ * @param source
+ * Object sending this signal
+ * @param trace
+ * The trace that was selected
+ */
+ public TmfTraceSelectedSignal(Object source, ITmfTrace trace) {
+ super(source);
+ fTrace = trace;
+ }
+
+ /**
+ * @return The trace referred to by this signal
+ */
+ public ITmfTrace getTrace() {
+ return fTrace;
+ }
+
+ @Override
+ public String toString() {
+ return "[TmfTraceSelectedSignal (" + fTrace.getName() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2009, 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation\r
- *******************************************************************************/\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.adaption;\r
-\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model.EventImpl;\r
-\r
-/**\r
- * Time Graph Presentation Provider Stub.\r
- */\r
-@SuppressWarnings("nls")\r
-public class TsfImplProvider extends TimeGraphPresentationProvider {\r
-\r
- // ========================================================================\r
- // Methods\r
- // ========================================================================\r
- @Override\r
- public int getStateTableIndex(ITimeEvent event) {\r
- return 0;\r
- }\r
-\r
- @Override\r
- public Map<String, String> getEventHoverToolTipInfo(ITimeEvent revent) {\r
- Map<String, String> toolTipEventMsgs = new HashMap<String, String>();\r
- if (revent instanceof EventImpl) {\r
- toolTipEventMsgs.put("Test Tip1", "Test Value tip1");\r
- toolTipEventMsgs.put("Test Tip2", "Test Value tip2");\r
- }\r
-\r
- return toolTipEventMsgs;\r
- }\r
-\r
- @Override\r
- public String getEventName(ITimeEvent event) {\r
- String name = "Unknown";\r
- if (event instanceof EventImpl) {\r
- EventImpl devent = (EventImpl) event;\r
- name = devent.getType().toString();\r
- }\r
- return name;\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2009, 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:
+ * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.adaption;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model.EventImpl;
+
+/**
+ * Time Graph Presentation Provider Stub.
+ */
+@SuppressWarnings("nls")
+public class TsfImplProvider extends TimeGraphPresentationProvider {
+
+ // ========================================================================
+ // Methods
+ // ========================================================================
+ @Override
+ public int getStateTableIndex(ITimeEvent event) {
+ return 0;
+ }
+
+ @Override
+ public Map<String, String> getEventHoverToolTipInfo(ITimeEvent revent) {
+ Map<String, String> toolTipEventMsgs = new HashMap<String, String>();
+ if (revent instanceof EventImpl) {
+ toolTipEventMsgs.put("Test Tip1", "Test Value tip1");
+ toolTipEventMsgs.put("Test Tip2", "Test Value tip2");
+ }
+
+ return toolTipEventMsgs;
+ }
+
+ @Override
+ public String getEventName(ITimeEvent event) {
+ String name = "Unknown";
+ if (event instanceof EventImpl) {
+ EventImpl devent = (EventImpl) event;
+ name = devent.getType().toString();
+ }
+ return name;
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2009, 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation\r
- *******************************************************************************/\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model;\r
-\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-\r
-/**\r
- * ITimeEvent implementation for test purposes.\r
- */\r
-@SuppressWarnings("javadoc")\r
-public class EventImpl implements ITimeEvent {\r
- // ========================================================================\r
- // Data\r
- // ========================================================================\r
- public static enum Type {ERROR, WARNING, TIMEADJUSTMENT, ALARM, EVENT, INFORMATION, UNKNOWN, INFO1, INFO2, INFO3, INFO4, INFO5, INFO6, INFO7, INFO8, INFO9}\r
-\r
- private long time = 0;\r
- private ITimeGraphEntry trace = null;\r
- private Type myType = Type.UNKNOWN;\r
- private long duration;\r
-\r
- // ========================================================================\r
- // Constructor\r
- // ========================================================================\r
- public EventImpl(long time, ITimeGraphEntry trace, Type type) {\r
- this.time = time;\r
- this.trace = trace;\r
- this.myType = type;\r
- }\r
-\r
- // ========================================================================\r
- // Methods\r
- // ========================================================================\r
- public Type getType() {\r
- return myType;\r
- }\r
-\r
- public void setType(Type myType) {\r
- this.myType = myType;\r
- }\r
-\r
- public void setTime(long time) {\r
- this.time = time;\r
- }\r
-\r
- public void setTrace(ITimeGraphEntry trace) {\r
- this.trace = trace;\r
- }\r
-\r
- @Override\r
- public long getTime() {\r
- return time;\r
- }\r
-\r
- @Override\r
- public ITimeGraphEntry getEntry() {\r
- return trace;\r
- }\r
-\r
- /**\r
- * @param duration the duration to set\r
- */\r
- public void setDuration(long duration) {\r
- this.duration = duration;\r
- }\r
-\r
- /**\r
- * @return the duration\r
- */\r
- @Override\r
- public long getDuration() {\r
- return duration;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2009, 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:
+ * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model;
+
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+
+/**
+ * ITimeEvent implementation for test purposes.
+ */
+@SuppressWarnings("javadoc")
+public class EventImpl implements ITimeEvent {
+ // ========================================================================
+ // Data
+ // ========================================================================
+ public static enum Type {ERROR, WARNING, TIMEADJUSTMENT, ALARM, EVENT, INFORMATION, UNKNOWN, INFO1, INFO2, INFO3, INFO4, INFO5, INFO6, INFO7, INFO8, INFO9}
+
+ private long time = 0;
+ private ITimeGraphEntry trace = null;
+ private Type myType = Type.UNKNOWN;
+ private long duration;
+
+ // ========================================================================
+ // Constructor
+ // ========================================================================
+ public EventImpl(long time, ITimeGraphEntry trace, Type type) {
+ this.time = time;
+ this.trace = trace;
+ this.myType = type;
+ }
+
+ // ========================================================================
+ // Methods
+ // ========================================================================
+ public Type getType() {
+ return myType;
+ }
+
+ public void setType(Type myType) {
+ this.myType = myType;
+ }
+
+ public void setTime(long time) {
+ this.time = time;
+ }
+
+ public void setTrace(ITimeGraphEntry trace) {
+ this.trace = trace;
+ }
+
+ @Override
+ public long getTime() {
+ return time;
+ }
+
+ @Override
+ public ITimeGraphEntry getEntry() {
+ return trace;
+ }
+
+ /**
+ * @param duration the duration to set
+ */
+ public void setDuration(long duration) {
+ this.duration = duration;
+ }
+
+ /**
+ * @return the duration
+ */
+ @Override
+ public long getDuration() {
+ return duration;
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2009, 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation\r
- *******************************************************************************/\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model;\r
-\r
-import java.util.Iterator;\r
-import java.util.Vector;\r
-\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-\r
-@SuppressWarnings({"javadoc", "nls"})\r
-public class TraceImpl implements ITimeGraphEntry {\r
- // ========================================================================\r
- // Data\r
- // ========================================================================\r
- private String name = "traceDefaultName";\r
- private long startTime = 0;\r
- private long stopTime = 1;\r
- private String className = "defaultClassName";\r
- private Vector<ITimeEvent> traceEvents = new Vector<ITimeEvent>();\r
-\r
- // ========================================================================\r
- // Constructor\r
- // ========================================================================\r
-\r
- public TraceImpl(String name, long sTime, long stopTime, String className) {\r
- this.name = name;\r
- this.startTime = sTime;\r
- this.stopTime = stopTime;\r
- this.className = className;\r
- }\r
-\r
- // ========================================================================\r
- // Methods\r
- // ========================================================================\r
-\r
- public String getClassName() {\r
- return className;\r
- }\r
-\r
- public void setClassName(String className) {\r
- this.className = className;\r
- }\r
-\r
- public void setName(String name) {\r
- this.name = name;\r
- }\r
-\r
- public void setStartTime(long startTime) {\r
- this.startTime = startTime;\r
- }\r
-\r
- public void setStopTime(long stopTime) {\r
- this.stopTime = stopTime;\r
- }\r
-\r
- @Override\r
- public String getName() {\r
- return name;\r
- }\r
-\r
- @Override\r
- public long getStartTime() {\r
- return startTime;\r
- }\r
-\r
- @Override\r
- public long getEndTime() {\r
- return stopTime;\r
- }\r
-\r
- @Override\r
- public boolean hasTimeEvents() {\r
- return traceEvents != null;\r
- }\r
-\r
- @Override\r
- public Iterator<ITimeEvent> getTimeEventsIterator() {\r
- return traceEvents.iterator();\r
- }\r
-\r
- @Override\r
- public Iterator<ITimeEvent> getTimeEventsIterator(long aStartTime, long aStopTime, long maxDuration) {\r
- return traceEvents.iterator();\r
- }\r
-\r
- public void addTraceEvent(ITimeEvent event) {\r
- traceEvents.add(event);\r
- }\r
-\r
- @Override\r
- public ITimeGraphEntry[] getChildren() {\r
- return null;\r
- }\r
-\r
- @Override\r
- public ITimeGraphEntry getParent() {\r
- return null;\r
- }\r
-\r
- @Override\r
- public boolean hasChildren() {\r
- return false;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2009, 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:
+ * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+
+@SuppressWarnings({"javadoc", "nls"})
+public class TraceImpl implements ITimeGraphEntry {
+ // ========================================================================
+ // Data
+ // ========================================================================
+ private String name = "traceDefaultName";
+ private long startTime = 0;
+ private long stopTime = 1;
+ private String className = "defaultClassName";
+ private Vector<ITimeEvent> traceEvents = new Vector<ITimeEvent>();
+
+ // ========================================================================
+ // Constructor
+ // ========================================================================
+
+ public TraceImpl(String name, long sTime, long stopTime, String className) {
+ this.name = name;
+ this.startTime = sTime;
+ this.stopTime = stopTime;
+ this.className = className;
+ }
+
+ // ========================================================================
+ // Methods
+ // ========================================================================
+
+ public String getClassName() {
+ return className;
+ }
+
+ public void setClassName(String className) {
+ this.className = className;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setStartTime(long startTime) {
+ this.startTime = startTime;
+ }
+
+ public void setStopTime(long stopTime) {
+ this.stopTime = stopTime;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public long getStartTime() {
+ return startTime;
+ }
+
+ @Override
+ public long getEndTime() {
+ return stopTime;
+ }
+
+ @Override
+ public boolean hasTimeEvents() {
+ return traceEvents != null;
+ }
+
+ @Override
+ public Iterator<ITimeEvent> getTimeEventsIterator() {
+ return traceEvents.iterator();
+ }
+
+ @Override
+ public Iterator<ITimeEvent> getTimeEventsIterator(long aStartTime, long aStopTime, long maxDuration) {
+ return traceEvents.iterator();
+ }
+
+ public void addTraceEvent(ITimeEvent event) {
+ traceEvents.add(event);
+ }
+
+ @Override
+ public ITimeGraphEntry[] getChildren() {
+ return null;
+ }
+
+ @Override
+ public ITimeGraphEntry getParent() {
+ return null;
+ }
+
+ @Override
+ public boolean hasChildren() {
+ return false;
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2009, 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation\r
- *******************************************************************************/\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model;\r
-\r
-import java.util.Date;\r
-\r
-@SuppressWarnings({"javadoc", "nls"})\r
-public class TraceModelImplFactory {\r
-\r
- // ========================================================================\r
- // Data\r
- // ========================================================================\r
- private int count = 0;\r
- private final TraceStrings[] traceNames;\r
- private static final long msTons = 1000000;\r
- private final Long timeRef = new Date().getTime() * msTons;\r
-\r
- // ========================================================================\r
- // Constructor\r
- // ========================================================================\r
- public TraceModelImplFactory() {\r
- traceNames = new TraceStrings[17];\r
- loadTraceNameStrings();\r
- }\r
-\r
- // ========================================================================\r
- // Methods\r
- // ========================================================================\r
- public TraceImpl[] createTraces() {\r
- TraceImpl trace;\r
- TraceImpl[] traceArr = new TraceImpl[17];\r
- for (int i = 0; i < traceArr.length; i++) {\r
- trace = new TraceImpl(traceNames[i].name, timeRef, timeRef + 40,\r
- traceNames[i].classNmme);\r
- count = i;\r
- createEvents(trace);\r
- traceArr[i] = trace;\r
- }\r
- return traceArr;\r
- }\r
-\r
- /**\r
- * 5000 Events per Trace.\r
- * @param number\r
- * @return\r
- */\r
- public TraceImpl[] createLargeTraces(int number) {\r
- TraceImpl trace;\r
- TraceImpl[] traceArr = new TraceImpl[number];\r
- for (int i = 0; i < traceArr.length; i++) {\r
- int counter = i%17;\r
- long sTime = i * (long) 1E6;\r
- trace = new TraceImpl(traceNames[counter].name, sTime , sTime + 20000,\r
- traceNames[counter].classNmme);\r
- create5000Events(trace);\r
- traceArr[i] = trace;\r
- }\r
- return traceArr;\r
- }\r
-\r
- private static void create5000Events(TraceImpl trace) {\r
- EventImpl event;\r
- Long eventTime;\r
- int numEvents = 5000;\r
- long sTime = trace.getStartTime();\r
- long eTime = trace.getEndTime();\r
- long duration = (eTime - sTime)/numEvents;\r
- for (int i = 0; i < numEvents; i++) {\r
- eventTime = sTime + (i * duration);\r
- // eventTime = timeRef + (5 * (count % 4) + (5 * (int) (i/2) ));\r
- // System.out.println("Trace: " + trace.getName() + " EventTime: "\r
- // + eventTime);\r
-// duration = i * msTons + (long) ((i % 4));\r
-\r
- event = new EventImpl(eventTime, trace, getEventType(i%16));\r
- event.setDuration(duration);\r
- trace.addTraceEvent(event);\r
- }\r
- }\r
-\r
- private void createEvents(TraceImpl trace) {\r
- EventImpl event;\r
- Long eventTime;\r
- int numEvents = 17;\r
- long duration = 0;\r
- for (int i = 0; i < numEvents; i++) {\r
- eventTime = timeRef + msTons * i + (5 * msTons * count) + (5 * i);\r
- duration = msTons + i * msTons + ((i % 4));\r
-// duration = i + (long) ((i % 4));\r
- event = new EventImpl(eventTime, trace, getEventType(i));\r
- event.setDuration(duration);\r
- trace.addTraceEvent(event);\r
- }\r
- }\r
-\r
- private static EventImpl.Type getEventType(int val) {\r
- if (EventImpl.Type.ALARM.ordinal() == val) {\r
- return EventImpl.Type.ALARM;\r
- }\r
- if (EventImpl.Type.ERROR.ordinal() == val) {\r
- return EventImpl.Type.ERROR;\r
- }\r
- if (EventImpl.Type.EVENT.ordinal() == val) {\r
- return EventImpl.Type.EVENT;\r
- }\r
- if (EventImpl.Type.INFORMATION.ordinal() == val) {\r
- return EventImpl.Type.INFORMATION;\r
- }\r
- if (EventImpl.Type.TIMEADJUSTMENT.ordinal() == val) {\r
- return EventImpl.Type.TIMEADJUSTMENT;\r
- }\r
- if (EventImpl.Type.WARNING.ordinal() == val) {\r
- return EventImpl.Type.WARNING;\r
- }\r
- if (EventImpl.Type.INFO1.ordinal() == val) {\r
- return EventImpl.Type.INFO1;\r
- }\r
- if (EventImpl.Type.INFO2.ordinal() == val) {\r
- return EventImpl.Type.INFO2;\r
- }\r
- if (EventImpl.Type.INFO3.ordinal() == val) {\r
- return EventImpl.Type.INFO3;\r
- }\r
- if (EventImpl.Type.INFO4.ordinal() == val) {\r
- return EventImpl.Type.INFO4;\r
- }\r
- if (EventImpl.Type.INFO5.ordinal() == val) {\r
- return EventImpl.Type.INFO5;\r
- }\r
- if (EventImpl.Type.INFO6.ordinal() == val) {\r
- return EventImpl.Type.INFO6;\r
- }\r
- if (EventImpl.Type.INFO7.ordinal() == val) {\r
- return EventImpl.Type.INFO7;\r
- }\r
- if (EventImpl.Type.INFO8.ordinal() == val) {\r
- return EventImpl.Type.INFO8;\r
- }\r
- if (EventImpl.Type.INFO9.ordinal() == val) {\r
- return EventImpl.Type.INFO9;\r
- }\r
- return EventImpl.Type.UNKNOWN;\r
- }\r
-\r
- private void loadTraceNameStrings() {\r
- traceNames[0] = new TraceStrings();\r
- traceNames[0].name = "TE Log - TATA BSC11";\r
- traceNames[0].classNmme = "All Boards";\r
-\r
- traceNames[1] = new TraceStrings();\r
- traceNames[1].name = "System Log";\r
- traceNames[1].classNmme = "BSC11";\r
-\r
- traceNames[2] = new TraceStrings();\r
- traceNames[2].name = "Alarm Log";\r
- traceNames[2].classNmme = "BSC11";\r
-\r
- traceNames[3] = new TraceStrings();\r
- traceNames[3].name = "Events Log";\r
- traceNames[3].classNmme = "BSC 11";\r
-\r
- traceNames[4] = new TraceStrings();\r
- traceNames[4].name = "CPU Load";\r
- traceNames[4].classNmme = "All Boards";\r
-\r
- traceNames[5] = new TraceStrings();\r
- traceNames[5].name = "Performance Log";\r
- traceNames[5].classNmme = "BSC11";\r
-\r
- traceNames[6] = new TraceStrings();\r
- traceNames[6].name = "TE Log - TATA BSC14";\r
- traceNames[6].classNmme = "Board 24";\r
-\r
- traceNames[7] = new TraceStrings();\r
- traceNames[7].name = "TE Log - TATA BSC14";\r
- traceNames[7].classNmme = "Board 23";\r
-\r
- traceNames[8] = new TraceStrings();\r
- traceNames[8].name = "TE Log - TATA BSC14";\r
- traceNames[8].classNmme = "Board 11";\r
-\r
- traceNames[9] = new TraceStrings();\r
- traceNames[9].name = "TE Log - TATA BSC14";\r
- traceNames[9].classNmme = "Board 14, SPO";\r
-\r
- traceNames[10] = new TraceStrings();\r
- traceNames[10].name = "INFO 1";\r
- traceNames[10].classNmme = "All Boards";\r
-\r
- traceNames[11] = new TraceStrings();\r
- traceNames[11].name = "INFO2";\r
- traceNames[11].classNmme = "BSC11";\r
-\r
- traceNames[12] = new TraceStrings();\r
- traceNames[12].name = "INFO3";\r
- traceNames[12].classNmme = "Board 24";\r
-\r
- traceNames[13] = new TraceStrings();\r
- traceNames[13].name = "MISC1";\r
- traceNames[13].classNmme = "Board 23";\r
-\r
- traceNames[14] = new TraceStrings();\r
- traceNames[14].name = "MISC2";\r
- traceNames[14].classNmme = "Board 11";\r
-\r
- traceNames[15] = new TraceStrings();\r
- traceNames[15].name = "MISC3";\r
- traceNames[15].classNmme = "Board 23";\r
-\r
- traceNames[16] = new TraceStrings();\r
- traceNames[16].name = "MISC4";\r
- traceNames[16].classNmme = "Board 11";\r
-\r
- }\r
-\r
- // ========================================================================\r
- // Inner Class\r
- // ========================================================================\r
- private static class TraceStrings {\r
- public String name = "";\r
- public String classNmme = name + " class";\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2009, 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:
+ * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model;
+
+import java.util.Date;
+
+@SuppressWarnings({"javadoc", "nls"})
+public class TraceModelImplFactory {
+
+ // ========================================================================
+ // Data
+ // ========================================================================
+ private int count = 0;
+ private final TraceStrings[] traceNames;
+ private static final long msTons = 1000000;
+ private final Long timeRef = new Date().getTime() * msTons;
+
+ // ========================================================================
+ // Constructor
+ // ========================================================================
+ public TraceModelImplFactory() {
+ traceNames = new TraceStrings[17];
+ loadTraceNameStrings();
+ }
+
+ // ========================================================================
+ // Methods
+ // ========================================================================
+ public TraceImpl[] createTraces() {
+ TraceImpl trace;
+ TraceImpl[] traceArr = new TraceImpl[17];
+ for (int i = 0; i < traceArr.length; i++) {
+ trace = new TraceImpl(traceNames[i].name, timeRef, timeRef + 40,
+ traceNames[i].classNmme);
+ count = i;
+ createEvents(trace);
+ traceArr[i] = trace;
+ }
+ return traceArr;
+ }
+
+ /**
+ * 5000 Events per Trace.
+ * @param number
+ * @return
+ */
+ public TraceImpl[] createLargeTraces(int number) {
+ TraceImpl trace;
+ TraceImpl[] traceArr = new TraceImpl[number];
+ for (int i = 0; i < traceArr.length; i++) {
+ int counter = i%17;
+ long sTime = i * (long) 1E6;
+ trace = new TraceImpl(traceNames[counter].name, sTime , sTime + 20000,
+ traceNames[counter].classNmme);
+ create5000Events(trace);
+ traceArr[i] = trace;
+ }
+ return traceArr;
+ }
+
+ private static void create5000Events(TraceImpl trace) {
+ EventImpl event;
+ Long eventTime;
+ int numEvents = 5000;
+ long sTime = trace.getStartTime();
+ long eTime = trace.getEndTime();
+ long duration = (eTime - sTime)/numEvents;
+ for (int i = 0; i < numEvents; i++) {
+ eventTime = sTime + (i * duration);
+ // eventTime = timeRef + (5 * (count % 4) + (5 * (int) (i/2) ));
+ // System.out.println("Trace: " + trace.getName() + " EventTime: "
+ // + eventTime);
+// duration = i * msTons + (long) ((i % 4));
+
+ event = new EventImpl(eventTime, trace, getEventType(i%16));
+ event.setDuration(duration);
+ trace.addTraceEvent(event);
+ }
+ }
+
+ private void createEvents(TraceImpl trace) {
+ EventImpl event;
+ Long eventTime;
+ int numEvents = 17;
+ long duration = 0;
+ for (int i = 0; i < numEvents; i++) {
+ eventTime = timeRef + msTons * i + (5 * msTons * count) + (5 * i);
+ duration = msTons + i * msTons + ((i % 4));
+// duration = i + (long) ((i % 4));
+ event = new EventImpl(eventTime, trace, getEventType(i));
+ event.setDuration(duration);
+ trace.addTraceEvent(event);
+ }
+ }
+
+ private static EventImpl.Type getEventType(int val) {
+ if (EventImpl.Type.ALARM.ordinal() == val) {
+ return EventImpl.Type.ALARM;
+ }
+ if (EventImpl.Type.ERROR.ordinal() == val) {
+ return EventImpl.Type.ERROR;
+ }
+ if (EventImpl.Type.EVENT.ordinal() == val) {
+ return EventImpl.Type.EVENT;
+ }
+ if (EventImpl.Type.INFORMATION.ordinal() == val) {
+ return EventImpl.Type.INFORMATION;
+ }
+ if (EventImpl.Type.TIMEADJUSTMENT.ordinal() == val) {
+ return EventImpl.Type.TIMEADJUSTMENT;
+ }
+ if (EventImpl.Type.WARNING.ordinal() == val) {
+ return EventImpl.Type.WARNING;
+ }
+ if (EventImpl.Type.INFO1.ordinal() == val) {
+ return EventImpl.Type.INFO1;
+ }
+ if (EventImpl.Type.INFO2.ordinal() == val) {
+ return EventImpl.Type.INFO2;
+ }
+ if (EventImpl.Type.INFO3.ordinal() == val) {
+ return EventImpl.Type.INFO3;
+ }
+ if (EventImpl.Type.INFO4.ordinal() == val) {
+ return EventImpl.Type.INFO4;
+ }
+ if (EventImpl.Type.INFO5.ordinal() == val) {
+ return EventImpl.Type.INFO5;
+ }
+ if (EventImpl.Type.INFO6.ordinal() == val) {
+ return EventImpl.Type.INFO6;
+ }
+ if (EventImpl.Type.INFO7.ordinal() == val) {
+ return EventImpl.Type.INFO7;
+ }
+ if (EventImpl.Type.INFO8.ordinal() == val) {
+ return EventImpl.Type.INFO8;
+ }
+ if (EventImpl.Type.INFO9.ordinal() == val) {
+ return EventImpl.Type.INFO9;
+ }
+ return EventImpl.Type.UNKNOWN;
+ }
+
+ private void loadTraceNameStrings() {
+ traceNames[0] = new TraceStrings();
+ traceNames[0].name = "TE Log - TATA BSC11";
+ traceNames[0].classNmme = "All Boards";
+
+ traceNames[1] = new TraceStrings();
+ traceNames[1].name = "System Log";
+ traceNames[1].classNmme = "BSC11";
+
+ traceNames[2] = new TraceStrings();
+ traceNames[2].name = "Alarm Log";
+ traceNames[2].classNmme = "BSC11";
+
+ traceNames[3] = new TraceStrings();
+ traceNames[3].name = "Events Log";
+ traceNames[3].classNmme = "BSC 11";
+
+ traceNames[4] = new TraceStrings();
+ traceNames[4].name = "CPU Load";
+ traceNames[4].classNmme = "All Boards";
+
+ traceNames[5] = new TraceStrings();
+ traceNames[5].name = "Performance Log";
+ traceNames[5].classNmme = "BSC11";
+
+ traceNames[6] = new TraceStrings();
+ traceNames[6].name = "TE Log - TATA BSC14";
+ traceNames[6].classNmme = "Board 24";
+
+ traceNames[7] = new TraceStrings();
+ traceNames[7].name = "TE Log - TATA BSC14";
+ traceNames[7].classNmme = "Board 23";
+
+ traceNames[8] = new TraceStrings();
+ traceNames[8].name = "TE Log - TATA BSC14";
+ traceNames[8].classNmme = "Board 11";
+
+ traceNames[9] = new TraceStrings();
+ traceNames[9].name = "TE Log - TATA BSC14";
+ traceNames[9].classNmme = "Board 14, SPO";
+
+ traceNames[10] = new TraceStrings();
+ traceNames[10].name = "INFO 1";
+ traceNames[10].classNmme = "All Boards";
+
+ traceNames[11] = new TraceStrings();
+ traceNames[11].name = "INFO2";
+ traceNames[11].classNmme = "BSC11";
+
+ traceNames[12] = new TraceStrings();
+ traceNames[12].name = "INFO3";
+ traceNames[12].classNmme = "Board 24";
+
+ traceNames[13] = new TraceStrings();
+ traceNames[13].name = "MISC1";
+ traceNames[13].classNmme = "Board 23";
+
+ traceNames[14] = new TraceStrings();
+ traceNames[14].name = "MISC2";
+ traceNames[14].classNmme = "Board 11";
+
+ traceNames[15] = new TraceStrings();
+ traceNames[15].name = "MISC3";
+ traceNames[15].classNmme = "Board 23";
+
+ traceNames[16] = new TraceStrings();
+ traceNames[16].name = "MISC4";
+ traceNames[16].classNmme = "Board 11";
+
+ }
+
+ // ========================================================================
+ // Inner Class
+ // ========================================================================
+ private static class TraceStrings {
+ public String name = "";
+ public String classNmme = name + " class";
+ }
+}
-<?xml version="1.0" encoding="UTF-8"?>\r
-<?eclipse version="3.4"?>\r
-<plugin>\r
- <extension-point id="org.eclipse.linuxtools.tmf.ui.uml2SDLoader" name="TMF UML 2 Sequence Diagram Loader" schema="schema/org.eclipse.linuxtools.tmf.ui.uml2SDLoader.exsd"/>\r
- <extension-point id="org.eclipse.linuxtools.tmf.ui.tracetype" name="Tmf Trace Type" schema="schema/org.eclipse.linuxtools.tmf.ui.tracetype.exsd"/>\r
-\r
- <extension\r
- point="org.eclipse.ui.perspectives">\r
- <perspective\r
- class="org.eclipse.linuxtools.tmf.ui.views.TracingPerspectiveFactory"\r
- icon="icons/eview16/tracing_pers.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.perspective"\r
- name="%perspective.category.name">\r
- </perspective>\r
- </extension>\r
- <extension\r
- point="org.eclipse.ui.views">\r
- <category\r
- id="org.eclipse.linuxtools.tmf.ui.views.category"\r
- name="%views.category.name">\r
- </category>\r
- <view\r
- allowMultiple="false"\r
- category="org.eclipse.linuxtools.tmf.ui.views.category"\r
- class="org.eclipse.linuxtools.tmf.ui.views.events.TmfEventsView"\r
- icon="icons/eview16/events_view.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.views.events"\r
- name="%events.view.name"\r
- restorable="true">\r
- </view>\r
- <view\r
- category="org.eclipse.linuxtools.tmf.ui.views.category"\r
- class="org.eclipse.linuxtools.tmf.ui.views.timechart.TimeChartView"\r
- icon="icons/eview16/timechart_view.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.views.timechart"\r
- name="%timechart.view.name"\r
- restorable="true">\r
- </view> \r
- <view\r
- allowMultiple="false"\r
- category="org.eclipse.linuxtools.tmf.ui.views.category"\r
- class="org.eclipse.linuxtools.tmf.ui.views.environment.TmfEnvironmentView"\r
- icon="icons/eview16/events_view.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.views.environment"\r
- name="%environment.view.name"\r
- restorable="true">\r
- </view>\r
- <view\r
- allowMultiple="false"\r
- category="org.eclipse.linuxtools.tmf.ui.views.category"\r
- class="org.eclipse.linuxtools.tmf.ui.views.colors.ColorsView"\r
- icon="icons/eview16/colors_view.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.views.colors"\r
- name="%colors.view.name"\r
- restorable="true">\r
- </view> \r
- <view\r
- allowMultiple="false"\r
- category="org.eclipse.linuxtools.tmf.ui.views.category"\r
- class="org.eclipse.linuxtools.tmf.ui.views.filter.FilterView"\r
- icon="icons/eview16/filters_view.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.views.filter"\r
- name="%filters.view.name"\r
- restorable="true">\r
- </view>\r
- <view\r
- category="org.eclipse.linuxtools.tmf.ui.views.category"\r
- class="org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView"\r
- icon="icons/eview16/sequencediagram_view.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView"\r
- name="%uml2sd.view.name"\r
- restorable="true">\r
- </view>\r
- <view\r
- allowMultiple="false"\r
- category="org.eclipse.linuxtools.tmf.ui.views.category"\r
- class="org.eclipse.linuxtools.tmf.ui.views.statistics.TmfStatisticsView"\r
- icon="icons/eview16/statistics_view.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.views.statistics"\r
- name="%statistics.view.name"\r
- restorable="true">\r
- </view>\r
- <view\r
- allowMultiple="false"\r
- category="org.eclipse.linuxtools.tmf.ui.views.category"\r
- class="org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramView"\r
- icon="icons/eview16/histogram.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.views.histogram"\r
- name="%histogram.view.name"\r
- restorable="true">\r
- </view>\r
- </extension>\r
- <extension\r
- point="org.eclipse.ui.editors">\r
- <editor\r
- class="org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor"\r
- default="false"\r
- icon="icons/eview16/events_view.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.editors.events"\r
- name="%events.editor.name">\r
- <contentTypeBinding\r
- contentTypeId="org.eclipse.linuxtools.tmf.ui.content-type.trace">\r
- </contentTypeBinding>\r
- </editor>\r
- <editor\r
- class="org.eclipse.linuxtools.tmf.ui.editors.EventsViewEditor"\r
- default="false"\r
- icon="icons/eview16/events_view.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.editors.eventsView"\r
- name="%eventsview.editor.name">\r
- <contentTypeBinding\r
- contentTypeId="org.eclipse.linuxtools.tmf.ui.content-type.trace">\r
- </contentTypeBinding>\r
- </editor>\r
- </extension>\r
- <extension\r
- point="org.eclipse.ui.newWizards">\r
- <category\r
- id="org.eclipse.linuxtools.tmf.ui.wizards.new"\r
- name="%project.new.category.name">\r
- </category>\r
- <wizard\r
- category="org.eclipse.linuxtools.tmf.ui.wizards.new"\r
- class="org.eclipse.linuxtools.tmf.ui.project.wizards.NewTmfProjectWizard"\r
- icon="icons/elcl16/new_tracing_prj.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.views.ui.wizards.newProject"\r
- name="%project.new.wizard.name"\r
- project="true">\r
- <description>\r
- %project.new.wizard.description\r
- \r
- </description>\r
- </wizard>\r
- <wizard\r
- category="org.eclipse.linuxtools.tmf.ui.wizards.new"\r
- class="org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards.CustomTxtParserWizard"\r
- icon="icons/etool16/customparser_wizard.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.wizards.custom.text"\r
- name="%project.new.wizard.custom.text.parser">\r
- </wizard>\r
- <wizard\r
- category="org.eclipse.linuxtools.tmf.ui.wizards.new"\r
- class="org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards.CustomXmlParserWizard"\r
- icon="icons/etool16/customparser_wizard.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.wizards.custom.xml"\r
- name="%project.new.wizard.custom.xml.parser">\r
- </wizard>\r
- </extension>\r
- <extension\r
- point="org.eclipse.ui.importWizards">\r
- <category\r
- id="org.eclipse.linuxtools.tmf.import.category"\r
- name="%project.new.category.name">\r
- </category>\r
- <wizard\r
- category="org.eclipse.linuxtools.tmf.import.category"\r
- class="org.eclipse.linuxtools.tmf.ui.project.wizards.ImportTraceWizard"\r
- icon="icons/etool16/import.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.trace.import.wizard"\r
- name="%project.import.wizard.name">\r
- </wizard>\r
- </extension>\r
- <extension\r
- id="org.eclipse.linuxtools.tmf.project.nature"\r
- point="org.eclipse.core.resources.natures">\r
- <runtime>\r
- <run\r
- class="org.eclipse.linuxtools.tmf.core.TmfProjectNature">\r
- </run>\r
- </runtime>\r
- </extension>\r
- <extension\r
- point="org.eclipse.ui.ide.projectNatureImages">\r
- <image\r
- icon="icons/ovr16/trace_nature_ovr.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.nature.image"\r
- natureId="org.eclipse.linuxtools.tmf.project.nature">\r
- </image>\r
- </extension>\r
- <extension\r
- point="org.eclipse.ui.navigator.navigatorContent">\r
- <navigatorContent\r
- activeByDefault="true"\r
- contentProvider="org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorContentProvider"\r
- icon="icons/eview16/tracing_pers.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.navigator.content"\r
- labelProvider="org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorLabelProvider"\r
- name="%navigatorContent.name"\r
- priority="normal">\r
- <triggerPoints>\r
- <or>\r
- <and>\r
- <instanceof\r
- value="org.eclipse.core.resources.IProject">\r
- </instanceof>\r
- <test\r
- property="org.eclipse.core.resources.projectNature"\r
- value="org.eclipse.linuxtools.tmf.project.nature">\r
- </test>\r
- </and>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement">\r
- </instanceof>\r
- </or>\r
- </triggerPoints>\r
- <possibleChildren>\r
- <or>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement">\r
- </instanceof>\r
- <instanceof\r
- value="org.eclipse.core.resources.IResource">\r
- </instanceof>\r
- </or></possibleChildren>\r
- <override\r
- policy="InvokeAlwaysRegardlessOfSuppressedExt"\r
- suppressedExtensionId="org.eclipse.ui.navigator.resourceContent">\r
- </override>\r
- <actionProvider\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.TmfActionProvider"\r
- id="org.eclipse.linuxtools.tmf.ui.navigator.actions.provider">\r
- <enablement>\r
- <or>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement">\r
- </instanceof>\r
- </or>\r
- </enablement>\r
- </actionProvider>\r
- <dropAssistant\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DropAdapterAssistant"\r
- id="org.eclipse.linuxtools.tmf.ui.navigator.dropAssistant">\r
- <possibleDropTargets>\r
- <or>\r
- <and>\r
- <instanceof\r
- value="org.eclipse.core.resources.IProject">\r
- </instanceof>\r
- <test\r
- property="org.eclipse.core.resources.projectNature"\r
- value="org.eclipse.linuxtools.tmf.project.nature">\r
- </test>\r
- </and>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement">\r
- </instanceof>\r
- </or>\r
- </possibleDropTargets>\r
- </dropAssistant>\r
- <commonWizard\r
- menuGroupId="org.eclipse.linuxtools.tmf.ui.views.ui.wizards.menuGroupId"\r
- type="new"\r
- wizardId="org.eclipse.linuxtools.tmf.ui.views.ui.wizards.newProject">\r
- <enablement></enablement>\r
- </commonWizard>\r
- </navigatorContent>\r
- </extension>\r
- <extension\r
- point="org.eclipse.ui.navigator.viewer">\r
- <viewerContentBinding\r
- viewerId="org.eclipse.ui.navigator.ProjectExplorer">\r
- <includes>\r
- <contentExtension\r
- pattern="org.eclipse.linuxtools.tmf.ui.navigator.content">\r
- </contentExtension>\r
- <contentExtension\r
- pattern="org.eclipse.ui.navigator.resources.filters.*">\r
- </contentExtension>\r
- </includes>\r
- </viewerContentBinding>\r
- </extension>\r
- <extension\r
- point="org.eclipse.ui.decorators">\r
- <decorator\r
- icon="icons/ovr16/trace_folder_ovr.png"\r
- id="org.eclipse.linuxtools.tmf.ui.trace_folder.decorator"\r
- label="Trace Folder"\r
- lightweight="true"\r
- location="TOP_RIGHT"\r
- state="true">\r
- <enablement>\r
- <objectClass\r
- name="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder">\r
- </objectClass>\r
- </enablement>\r
- </decorator>\r
- <decorator\r
- icon="icons/ovr16/experiment_folder_ovr.png"\r
- id="org.eclipse.linuxtools.tmf.ui.experiment_folder.decorator"\r
- label="Trace Experiment Folder"\r
- lightweight="true"\r
- location="TOP_RIGHT"\r
- state="true">\r
- <enablement>\r
- <objectClass\r
- name="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder">\r
- </objectClass>\r
- </enablement>\r
- </decorator>\r
- <decorator\r
- icon="icons/ovr16/link_ovr.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.linked_trace.decorator"\r
- label="Linked Trace"\r
- lightweight="true"\r
- location="BOTTOM_RIGHT"\r
- state="true">\r
- <enablement>\r
- <and>\r
- <objectClass\r
- name="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">\r
- </objectClass>\r
- <objectState\r
- name="isLinked"\r
- value="true">\r
- </objectState>\r
- </and>\r
- </enablement>\r
- </decorator>\r
- </extension>\r
- <extension\r
- point="org.eclipse.ui.menus">\r
- <menuContribution\r
- locationURI="menu:org.eclipse.ui.navigator.ProjectExplorer">\r
- <command\r
- commandId="org.eclipse.linuxtools.tmf.ui.command.managecustomparsers"\r
- id="org.eclipse.linuxtools.tmf.ui.menu.managecustomparsers"\r
- style="push">\r
- </command>\r
- </menuContribution>\r
- <menuContribution\r
- allPopups="false"\r
- locationURI="toolbar:org.eclipse.ui.navigator.ProjectExplorer">\r
- <command\r
- commandId="org.eclipse.linuxtools.tmf.ui.command.clear_views"\r
- icon="icons/etool16/clear.gif"\r
- label="%command.clear_views"\r
- mnemonic="%command.clear_views.mnemonic"\r
- style="push">\r
- <visibleWhen\r
- checkEnabled="false">\r
- <with\r
- variable="selection">\r
- <count\r
- value="1">\r
- </count>\r
- <iterate\r
- ifEmpty="false"\r
- operator="and">\r
- <or>\r
- <and>\r
- <instanceof\r
- value="org.eclipse.core.resources.IProject">\r
- </instanceof>\r
- <test\r
- property="org.eclipse.core.resources.projectNature"\r
- value="org.eclipse.linuxtools.tmf.project.nature">\r
- </test>\r
- </and>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement">\r
- </instanceof>\r
- </or>\r
- </iterate>\r
- </with>\r
- </visibleWhen>\r
- </command>\r
- </menuContribution>\r
- <menuContribution\r
- locationURI="popup:org.eclipse.ui.popup.any?after=additions">\r
- <command\r
- commandId="org.eclipse.ui.file.import"\r
- label="%command.import"\r
- mnemonic="%command.import.mnemonic"\r
- style="push">\r
- <visibleWhen\r
- checkEnabled="false">\r
- <with\r
- variable="selection">\r
- <count\r
- value="1">\r
- </count>\r
- <iterate\r
- operator="and">\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder">\r
- </instanceof>\r
- </iterate>\r
- </with>\r
- </visibleWhen>\r
- </command>\r
- <separator\r
- name="org.eclipse.linuxtools.tmf.ui.separator1"\r
- visible="true">\r
- </separator>\r
- <command\r
- commandId="org.eclipse.ui.navigate.openResource"\r
- disabledIcon="/icons/dlcl16/open.gif"\r
- icon="/icons/elcl16/open.gif"\r
- label="%command.open"\r
- mnemonic="%command.open.mnemonic"\r
- style="push">\r
- <visibleWhen\r
- checkEnabled="false">\r
- <with\r
- variable="selection">\r
- <count\r
- value="1">\r
- </count>\r
- <iterate\r
- ifEmpty="false"\r
- operator="and">\r
- <or>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">\r
- </instanceof>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">\r
- </instanceof>\r
- </or>\r
- </iterate>\r
- </with>\r
- </visibleWhen>\r
- </command>\r
- <command\r
- commandId="org.eclipse.ui.edit.copy"\r
- label="%command.copy"\r
- mnemonic="%command.copy.mnemonic"\r
- style="push">\r
- <visibleWhen\r
- checkEnabled="false">\r
- <with\r
- variable="selection">\r
- <count\r
- value="1">\r
- </count>\r
- <iterate\r
- ifEmpty="false"\r
- operator="and">\r
- <or>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">\r
- </instanceof>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">\r
- </instanceof>\r
- </or>\r
- </iterate>\r
- </with>\r
- </visibleWhen>\r
- </command>\r
- <command\r
- commandId="org.eclipse.ui.edit.rename"\r
- disabledIcon="/icons/dlcl16/rename.gif"\r
- icon="/icons/elcl16/rename.gif"\r
- label="%command.rename"\r
- mnemonic="%command.rename.mnemonic"\r
- style="push">\r
- <visibleWhen\r
- checkEnabled="false">\r
- <with\r
- variable="selection">\r
- <count\r
- value="1">\r
- </count>\r
- <iterate\r
- ifEmpty="false"\r
- operator="and">\r
- <or>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">\r
- </instanceof>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">\r
- </instanceof>\r
- </or>\r
- </iterate>\r
- </with>\r
- </visibleWhen>\r
- </command>\r
- <command\r
- commandId="org.eclipse.ui.edit.delete"\r
- label="%command.delete"\r
- mnemonic="%command.delete.mnemonic"\r
- style="push">\r
- <visibleWhen\r
- checkEnabled="false">\r
- <with\r
- variable="selection">\r
- <iterate\r
- ifEmpty="false"\r
- operator="and">\r
- <or>\r
- <and>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">\r
- </instanceof>\r
- <not>\r
- <test\r
- forcePluginActivation="true"\r
- property="org.eclipse.linuxtools.tmf.ui.isExperimentTrace">\r
- </test>\r
- </not>\r
- </and>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">\r
- </instanceof>\r
- </or>\r
- </iterate>\r
- </with>\r
- </visibleWhen>\r
- </command>\r
- <command\r
- commandId="org.eclipse.ui.edit.delete"\r
- label="%command.remove"\r
- mnemonic="%command.remove.mnemonic"\r
- style="push">\r
- <visibleWhen\r
- checkEnabled="false">\r
- <with\r
- variable="selection">\r
- <iterate\r
- ifEmpty="false"\r
- operator="and">\r
- <and>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">\r
- </instanceof>\r
- <test\r
- forcePluginActivation="true"\r
- property="org.eclipse.linuxtools.tmf.ui.isExperimentTrace">\r
- </test>\r
- </and>\r
- </iterate>\r
- </with>\r
- </visibleWhen>\r
- </command>\r
- <separator\r
- name="org.eclipse.linuxtools.tmf.ui.separator2"\r
- visible="true">\r
- </separator>\r
- <command\r
- commandId="org.eclipse.linuxtools.tmf.ui.command.new_experiment"\r
- disabledIcon="icons/dtool16/new.gif"\r
- icon="icons/etool16/new.gif"\r
- label="%command.new_experiment"\r
- mnemonic="%command.new_experiment.mnemonic"\r
- style="push"\r
- tooltip="%command.new_experiment.description">\r
- <visibleWhen\r
- checkEnabled="false">\r
- <with\r
- variable="selection">\r
- <count\r
- value="1">\r
- </count>\r
- <iterate\r
- ifEmpty="false"\r
- operator="and">\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder">\r
- </instanceof>\r
- </iterate>\r
- </with>\r
- </visibleWhen>\r
- </command>\r
- <command\r
- commandId="org.eclipse.linuxtools.tmf.ui.command.delete_suppl_files"\r
- label="%command.delete_suppl_files"\r
- mnemonic="%command.delete_suppl_files.mnemonic"\r
- style="push"\r
- tooltip="%command.delete_suppl_files.description">\r
- <visibleWhen\r
- checkEnabled="false">\r
- <with\r
- variable="selection">\r
- <and>\r
- <count\r
- value="1">\r
- </count>\r
- <iterate\r
- ifEmpty="false"\r
- operator="and">\r
- <and>\r
- <or>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">\r
- </instanceof>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">\r
- </instanceof>\r
- </or>\r
- <test\r
- forcePluginActivation="true"\r
- property="org.eclipse.linuxtools.tmf.ui.hasSupplementaryFiles">\r
- </test>\r
- </and>\r
- </iterate>\r
- </and>\r
- </with>\r
- </visibleWhen>\r
- </command>\r
- <separator\r
- name="org.eclipse.linuxtools.tmf.ui.separator3"\r
- visible="true">\r
- </separator>\r
- <menu\r
- label="%command.select_trace_type"\r
- mnemonic="%command.select_trace_type.mnemonic"\r
- tooltip="%command.select_trace_type.description">\r
- <dynamic\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.SelectTraceTypeContributionItem"\r
- id="org.eclipse.linuxtools.tmf.ui.command.select_trace_type.dynamic">\r
- </dynamic>\r
- <visibleWhen\r
- checkEnabled="false">\r
- <with\r
- variable="selection">\r
- <iterate\r
- ifEmpty="false"\r
- operator="and">\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">\r
- </instanceof>\r
- </iterate>\r
- </with>\r
- </visibleWhen>\r
- </menu>\r
- <separator\r
- name="org.eclipse.linuxtools.tmf.ui.separator4"\r
- visible="true">\r
- </separator>\r
- <command\r
- commandId="org.eclipse.linuxtools.tmf.ui.command.select_traces"\r
- icon="IMG_OBJ_ADD"\r
- label="%command.select_traces"\r
- mnemonic="%command.select_traces.mnemonic"\r
- style="push"\r
- tooltip="%commands.select_traces.description">\r
- <visibleWhen\r
- checkEnabled="false">\r
- <with\r
- variable="selection">\r
- <count\r
- value="1">\r
- </count>\r
- <iterate\r
- ifEmpty="false"\r
- operator="and">\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">\r
- </instanceof>\r
- </iterate>\r
- </with>\r
- </visibleWhen>\r
- </command>\r
- <separator\r
- name="org.eclipse.linuxtools.tmf.ui.separator5"\r
- visible="true">\r
- </separator>\r
- <command\r
- commandId="org.eclipse.ui.file.refresh"\r
- label="%command.refresh"\r
- mnemonic="%command.refresh.mnemonic"\r
- style="push">\r
- <visibleWhen\r
- checkEnabled="false">\r
- <with\r
- variable="selection">\r
- <count\r
- value="1">\r
- </count>\r
- <iterate\r
- ifEmpty="false"\r
- operator="and">\r
- <or>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder">\r
- </instanceof>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder">\r
- </instanceof>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">\r
- </instanceof>\r
- </or>\r
- </iterate>\r
- </with>\r
- </visibleWhen>\r
- </command>\r
- <command\r
- commandId="org.eclipse.linuxtools.tmf.ui.command.clear_views"\r
- icon="icons/etool16/clear.gif"\r
- label="%command.clear_views"\r
- mnemonic="%command.clear_views.mnemonic"\r
- style="push">\r
- <visibleWhen\r
- checkEnabled="false">\r
- <with\r
- variable="selection">\r
- <count\r
- value="1">\r
- </count>\r
- <iterate\r
- ifEmpty="false"\r
- operator="and">\r
- <and>\r
- <instanceof\r
- value="org.eclipse.core.resources.IProject">\r
- </instanceof>\r
- <test\r
- property="org.eclipse.core.resources.projectNature"\r
- value="org.eclipse.linuxtools.tmf.project.nature">\r
- </test>\r
- </and>\r
- </iterate>\r
- </with>\r
- </visibleWhen>\r
- </command>\r
- </menuContribution>\r
- </extension>\r
- <extension\r
- point="org.eclipse.ui.commands">\r
- <category\r
- description="%commands.category.description"\r
- id="org.eclipse.linuxtools.tmf.ui.commands.category"\r
- name="%commands.category.name">\r
- </category>\r
- <command\r
- categoryId="org.eclipse.linuxtools.tmf.ui.commands.category"\r
- description="%command.new_experiment.description"\r
- id="org.eclipse.linuxtools.tmf.ui.command.new_experiment"\r
- name="%command.new_experiment">\r
- </command>\r
- <command\r
- categoryId="org.eclipse.linuxtools.tmf.ui.commands.category"\r
- description="%command.select_trace_type.description"\r
- id="org.eclipse.linuxtools.tmf.ui.command.select_trace_type"\r
- name="%command.select_trace_type">\r
- <commandParameter\r
- id="org.eclipse.linuxtools.tmf.ui.commandparameter.select_trace_type.bundle"\r
- name="%commands.trace.select_trace_type.bundle"\r
- optional="false">\r
- </commandParameter>\r
- <commandParameter\r
- id="org.eclipse.linuxtools.tmf.ui.commandparameter.select_trace_type.type"\r
- name="%commands.trace.select_trace_type.type"\r
- optional="false">\r
- </commandParameter>\r
- <commandParameter\r
- id="org.eclipse.linuxtools.tmf.ui.commandparameter.select_trace_type.icon"\r
- name="%commands.trace.select_trace_type.icon"\r
- optional="false">\r
- </commandParameter>\r
- </command>\r
- <command\r
- categoryId="org.eclipse.linuxtools.tmf.ui.commands.category"\r
- id="org.eclipse.linuxtools.tmf.ui.command.delete_suppl_files"\r
- name="%command.delete_suppl_files">\r
- </command>\r
- <command\r
- categoryId="org.eclipse.linuxtools.tmf.ui.commands.category"\r
- description="%command.select_traces.description"\r
- id="org.eclipse.linuxtools.tmf.ui.command.select_traces"\r
- name="%command.select_traces">\r
- </command>\r
- <command\r
- categoryId="org.eclipse.linuxtools.tmf.ui.commands.category"\r
- description="%command.clear_views.description"\r
- id="org.eclipse.linuxtools.tmf.ui.command.clear_views"\r
- name="%command.clear_views">\r
- </command>\r
- <category\r
- description="%commands.parser.category.description"\r
- id="org.eclipse.linuxtools.tmf.ui.commands.parser.category"\r
- name="%commands.parser.category.name">\r
- </category>\r
- <command\r
- categoryId="org.eclipse.linuxtools.tmf.ui.commands.parser.category"\r
- description="%commands.parser.manage.description"\r
- id="org.eclipse.linuxtools.tmf.ui.command.managecustomparsers"\r
- name="%commands.parser.manage">\r
- </command>\r
- <category\r
- description="%commands.uml2sd.category.name"\r
- id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.category" \r
- name="%commands.uml2sd.category.name">\r
- </category>\r
- <command\r
- categoryId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.category"\r
- description="%commands.uml2sd.goto.description"\r
- id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.GoToMessage"\r
- name="%commands.uml2sd.goto">\r
- </command>\r
- <command\r
- categoryId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.category"\r
- description="%commands.uml2sd.showend.description"\r
- id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeEnd"\r
- name="%commands.uml2sd.showend">\r
- </command>\r
- <command\r
- categoryId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.category"\r
- description="%commands.uml2sd.showstart.description"\r
- id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeStart"\r
- name="%commands.uml2sd.showstart">\r
- </command> \r
- <command\r
- categoryId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.category"\r
- description="%commands.uml2sd.scrollup.description"\r
- id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDUp"\r
- name="%commands.uml2sd.scrollup">\r
- </command>\r
- <command\r
- categoryId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.category"\r
- description="%commands.uml2sd.scrolldown.description"\r
- id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDDown"\r
- name="%commands.uml2sd.scrolldown">\r
- </command>\r
- <command\r
- categoryId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.category"\r
- description="%commands.uml2sd.scrollleft.description"\r
- id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDLeft"\r
- name="%commands.uml2sd.scrollleft">\r
- </command>\r
- <command\r
- categoryId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.category"\r
- description="%commands.uml2sd.scrollright.description"\r
- id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDRight"\r
- name="%commands.uml2sd.scrollright">\r
- </command>\r
- </extension>\r
- <extension\r
- point="org.eclipse.ui.handlers">\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.ImportTraceHandler"\r
- commandId="org.eclipse.ui.file.import">\r
- <activeWhen>\r
- <and>\r
- <count\r
- value="1">\r
- </count>\r
- <iterate>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder">\r
- </instanceof>\r
- </iterate>\r
- </and>\r
- </activeWhen>\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.RefreshHandler"\r
- commandId="org.eclipse.ui.file.refresh">\r
- <activeWhen>\r
- <and>\r
- <count\r
- value="1">\r
- </count>\r
- <iterate>\r
- <or>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder">\r
- </instanceof>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder">\r
- </instanceof>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">\r
- </instanceof>\r
- </or>\r
- </iterate>\r
- </and>\r
- </activeWhen>\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.OpenTraceHandler"\r
- commandId="org.eclipse.ui.navigate.openResource">\r
- <activeWhen>\r
- <and>\r
- <count\r
- value="1">\r
- </count>\r
- <iterate>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">\r
- </instanceof>\r
- </iterate>\r
- </and>\r
- </activeWhen>\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.OpenExperimentHandler"\r
- commandId="org.eclipse.ui.navigate.openResource">\r
- <activeWhen>\r
- <and>\r
- <count\r
- value="1">\r
- </count>\r
- <iterate>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">\r
- </instanceof>\r
- </iterate>\r
- </and>\r
- </activeWhen>\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.CopyTraceHandler"\r
- commandId="org.eclipse.ui.edit.copy">\r
- <activeWhen>\r
- <and>\r
- <count\r
- value="1">\r
- </count>\r
- <iterate>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">\r
- </instanceof>\r
- </iterate>\r
- </and>\r
- </activeWhen>\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.CopyExperimentHandler"\r
- commandId="org.eclipse.ui.edit.copy">\r
- <activeWhen>\r
- <and>\r
- <count\r
- value="1">\r
- </count>\r
- <iterate>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">\r
- </instanceof>\r
- </iterate>\r
- </and>\r
- </activeWhen>\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.RenameTraceHandler"\r
- commandId="org.eclipse.ui.edit.rename">\r
- <activeWhen>\r
- <and>\r
- <count\r
- value="1">\r
- </count>\r
- <iterate>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">\r
- </instanceof>\r
- </iterate>\r
- </and>\r
- </activeWhen>\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.RenameExperimentHandler"\r
- commandId="org.eclipse.ui.edit.rename">\r
- <activeWhen>\r
- <and>\r
- <count\r
- value="1">\r
- </count>\r
- <iterate>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">\r
- </instanceof>\r
- </iterate>\r
- </and>\r
- </activeWhen>\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteTraceHandler"\r
- commandId="org.eclipse.ui.edit.delete">\r
- <activeWhen>\r
- <and>\r
- <iterate>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">\r
- </instanceof>\r
- </iterate>\r
- </and>\r
- </activeWhen>\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteExperimentHandler"\r
- commandId="org.eclipse.ui.edit.delete">\r
- <activeWhen>\r
- <and>\r
- <iterate>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">\r
- </instanceof>\r
- </iterate>\r
- </and>\r
- </activeWhen>\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteTraceSupplementaryFilesHandler"\r
- commandId="org.eclipse.linuxtools.tmf.ui.command.delete_suppl_files">\r
- <activeWhen>\r
- <and>\r
- <count\r
- value="1">\r
- </count>\r
- <iterate>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">\r
- </instanceof>\r
- </iterate>\r
- </and>\r
- </activeWhen>\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteExperimentSupplementaryFilesHandler"\r
- commandId="org.eclipse.linuxtools.tmf.ui.command.delete_suppl_files">\r
- <activeWhen>\r
- <and>\r
- <count\r
- value="1">\r
- </count>\r
- <iterate>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">\r
- </instanceof>\r
- </iterate>\r
- </and>\r
- </activeWhen>\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.NewExperimentHandler"\r
- commandId="org.eclipse.linuxtools.tmf.ui.command.new_experiment">\r
- <activeWhen>\r
- <and>\r
- <count\r
- value="1">\r
- </count>\r
- <iterate>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder">\r
- </instanceof>\r
- </iterate>\r
- </and>\r
- </activeWhen>\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.SelectTraceTypeHandler"\r
- commandId="org.eclipse.linuxtools.tmf.ui.command.select_trace_type">\r
- <activeWhen>\r
- <and>\r
- <iterate>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">\r
- </instanceof>\r
- </iterate>\r
- </and>\r
- </activeWhen>\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.SelectTracesHandler"\r
- commandId="org.eclipse.linuxtools.tmf.ui.command.select_traces">\r
- <activeWhen>\r
- <and>\r
- <count\r
- value="1">\r
- </count>\r
- <iterate>\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">\r
- </instanceof>\r
- </iterate>\r
- </and>\r
- </activeWhen>\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.ClearViewsHandler"\r
- commandId="org.eclipse.linuxtools.tmf.ui.command.clear_views">\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.commands.ManageCustomParsersCommandHandler"\r
- commandId="org.eclipse.linuxtools.tmf.ui.command.managecustomparsers">\r
- </handler>\r
- <handler\r
- class="org.eclipse.linuxtools.internal.tmf.ui.editors.handlers.AddBookmarkHandler"\r
- commandId="org.eclipse.ui.edit.addBookmark">\r
- <activeWhen>\r
- <with\r
- variable="activeEditor">\r
- <instanceof\r
- value="org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor">\r
- </instanceof>\r
- </with>\r
- </activeWhen>\r
- </handler>\r
- </extension>\r
- <extension point="org.eclipse.ui.bindings">\r
- <key\r
- sequence="ALT+R"\r
- contextId="org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"\r
- commandId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.GoToMessage"\r
- schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">\r
- </key> \r
- <key\r
- sequence="SHIFT+ALT+END"\r
- contextId="org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"\r
- commandId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeEnd"\r
- schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">\r
- </key> \r
- <key\r
- sequence="SHIFT+ALT+HOME"\r
- contextId="org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"\r
- commandId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeStart"\r
- schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">\r
- </key> \r
- <key\r
- sequence="SHIFT+ALT+ARROW_UP"\r
- contextId="org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"\r
- commandId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDUp"\r
- schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">\r
- </key> \r
- <key\r
- sequence="SHIFT+ALT+ARROW_DOWN"\r
- contextId="org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"\r
- commandId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDDown"\r
- schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">\r
- </key>\r
- <key\r
- sequence="SHIFT+ALT+ARROW_LEFT"\r
- contextId="org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"\r
- commandId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDLeft"\r
- schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">\r
- </key>\r
- <key\r
- sequence="SHIFT+ALT+ARROW_RIGHT"\r
- contextId="org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"\r
- commandId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDRight"\r
- schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">\r
- </key>\r
- </extension>\r
- <extension\r
- point="org.eclipse.core.contenttype.contentTypes">\r
- <content-type\r
- id="org.eclipse.linuxtools.tmf.ui.content-type.trace"\r
- name="%contenttype.trace"\r
- priority="normal">\r
- </content-type>\r
- </extension>\r
- <extension\r
- point="org.eclipse.ui.contexts">\r
- <context\r
- id="org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"\r
- name="%contexts.uml2sd">\r
- </context>\r
- </extension>\r
- <extension\r
- point="org.eclipse.ui.preferencePages">\r
- <page\r
- class="org.eclipse.linuxtools.internal.tmf.ui.preferences.TmfTracingPreferencePage"\r
- id="org.eclipse.linuxtools.tmf.ui.TmfTracingPreferences"\r
- name="%preference.page.trace.name">\r
- </page>\r
- <page\r
- category="org.eclipse.linuxtools.tmf.ui.TmfTracingPreferences"\r
- class="org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewerPage"\r
- id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewerPage"\r
- name="%preference.page.uml2sd.name">\r
- </page>\r
- </extension>\r
- <extension\r
- point="org.eclipse.linuxtools.tmf.ui.uml2SDLoader">\r
- <uml2SDLoader\r
- class="org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader"\r
- default="true"\r
- id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.impl.TmfUml2SDSyncLoader"\r
- name="TMF UML2SD Loader"\r
- view="org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView">\r
- </uml2SDLoader>\r
- </extension>\r
- <!--extension\r
- point="org.eclipse.core.expressions.propertyTesters">\r
- <propertyTester\r
- class="org.eclipse.linuxtools.tmf.ui.project.handlers.PropertyTester"\r
- id="org.eclipse.linuxtools.tmf.ui.propertyTester.isInTraceFolder"\r
- namespace="org.eclipse.linuxtools.tmf.ui.propertyTester"\r
- properties="isInTraceFolder"\r
- type="org.eclipse.jface.viewers.ISelection">\r
- </propertyTester>\r
- </extension -->\r
- <extension\r
- point="org.eclipse.core.expressions.propertyTesters">\r
- <propertyTester\r
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.TracePropertyTester"\r
- id="org.eclipse.linuxtools.tmf.ui.tracePropertyTester"\r
- namespace="org.eclipse.linuxtools.tmf.ui"\r
- properties="isExperimentTrace,hasSupplementaryFiles"\r
- type="org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectModelElement">\r
- </propertyTester>\r
- </extension>\r
- <extension\r
- point="org.eclipse.linuxtools.tmf.ui.tracetype">\r
- <category\r
- id="org.eclipse.linuxtools.tmf.ui.category.ctf"\r
- name="%tracetype.category.ctf">\r
- </category>\r
- <type\r
- category="org.eclipse.linuxtools.tmf.ui.category.ctf"\r
- event_type="org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent"\r
- icon="icons/eview16/events_view.gif"\r
- id="org.eclipse.linuxtools.tmf.ui.type.ctf"\r
- name="%tracetype.type.ctf"\r
- trace_type="org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace">\r
- </type>\r
- </extension>\r
-\r
-</plugin>\r
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension-point id="org.eclipse.linuxtools.tmf.ui.uml2SDLoader" name="TMF UML 2 Sequence Diagram Loader" schema="schema/org.eclipse.linuxtools.tmf.ui.uml2SDLoader.exsd"/>
+ <extension-point id="org.eclipse.linuxtools.tmf.ui.tracetype" name="Tmf Trace Type" schema="schema/org.eclipse.linuxtools.tmf.ui.tracetype.exsd"/>
+
+ <extension
+ point="org.eclipse.ui.perspectives">
+ <perspective
+ class="org.eclipse.linuxtools.tmf.ui.views.TracingPerspectiveFactory"
+ icon="icons/eview16/tracing_pers.gif"
+ id="org.eclipse.linuxtools.tmf.ui.perspective"
+ name="%perspective.category.name">
+ </perspective>
+ </extension>
+ <extension
+ point="org.eclipse.ui.views">
+ <category
+ id="org.eclipse.linuxtools.tmf.ui.views.category"
+ name="%views.category.name">
+ </category>
+ <view
+ allowMultiple="false"
+ category="org.eclipse.linuxtools.tmf.ui.views.category"
+ class="org.eclipse.linuxtools.tmf.ui.views.events.TmfEventsView"
+ icon="icons/eview16/events_view.gif"
+ id="org.eclipse.linuxtools.tmf.ui.views.events"
+ name="%events.view.name"
+ restorable="true">
+ </view>
+ <view
+ category="org.eclipse.linuxtools.tmf.ui.views.category"
+ class="org.eclipse.linuxtools.tmf.ui.views.timechart.TimeChartView"
+ icon="icons/eview16/timechart_view.gif"
+ id="org.eclipse.linuxtools.tmf.ui.views.timechart"
+ name="%timechart.view.name"
+ restorable="true">
+ </view>
+ <view
+ allowMultiple="false"
+ category="org.eclipse.linuxtools.tmf.ui.views.category"
+ class="org.eclipse.linuxtools.tmf.ui.views.environment.TmfEnvironmentView"
+ icon="icons/eview16/events_view.gif"
+ id="org.eclipse.linuxtools.tmf.ui.views.environment"
+ name="%environment.view.name"
+ restorable="true">
+ </view>
+ <view
+ allowMultiple="false"
+ category="org.eclipse.linuxtools.tmf.ui.views.category"
+ class="org.eclipse.linuxtools.tmf.ui.views.colors.ColorsView"
+ icon="icons/eview16/colors_view.gif"
+ id="org.eclipse.linuxtools.tmf.ui.views.colors"
+ name="%colors.view.name"
+ restorable="true">
+ </view>
+ <view
+ allowMultiple="false"
+ category="org.eclipse.linuxtools.tmf.ui.views.category"
+ class="org.eclipse.linuxtools.tmf.ui.views.filter.FilterView"
+ icon="icons/eview16/filters_view.gif"
+ id="org.eclipse.linuxtools.tmf.ui.views.filter"
+ name="%filters.view.name"
+ restorable="true">
+ </view>
+ <view
+ category="org.eclipse.linuxtools.tmf.ui.views.category"
+ class="org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView"
+ icon="icons/eview16/sequencediagram_view.gif"
+ id="org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView"
+ name="%uml2sd.view.name"
+ restorable="true">
+ </view>
+ <view
+ allowMultiple="false"
+ category="org.eclipse.linuxtools.tmf.ui.views.category"
+ class="org.eclipse.linuxtools.tmf.ui.views.statistics.TmfStatisticsView"
+ icon="icons/eview16/statistics_view.gif"
+ id="org.eclipse.linuxtools.tmf.ui.views.statistics"
+ name="%statistics.view.name"
+ restorable="true">
+ </view>
+ <view
+ allowMultiple="false"
+ category="org.eclipse.linuxtools.tmf.ui.views.category"
+ class="org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramView"
+ icon="icons/eview16/histogram.gif"
+ id="org.eclipse.linuxtools.tmf.ui.views.histogram"
+ name="%histogram.view.name"
+ restorable="true">
+ </view>
+ </extension>
+ <extension
+ point="org.eclipse.ui.editors">
+ <editor
+ class="org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor"
+ default="false"
+ icon="icons/eview16/events_view.gif"
+ id="org.eclipse.linuxtools.tmf.ui.editors.events"
+ name="%events.editor.name">
+ <contentTypeBinding
+ contentTypeId="org.eclipse.linuxtools.tmf.ui.content-type.trace">
+ </contentTypeBinding>
+ </editor>
+ <editor
+ class="org.eclipse.linuxtools.tmf.ui.editors.EventsViewEditor"
+ default="false"
+ icon="icons/eview16/events_view.gif"
+ id="org.eclipse.linuxtools.tmf.ui.editors.eventsView"
+ name="%eventsview.editor.name">
+ <contentTypeBinding
+ contentTypeId="org.eclipse.linuxtools.tmf.ui.content-type.trace">
+ </contentTypeBinding>
+ </editor>
+ </extension>
+ <extension
+ point="org.eclipse.ui.newWizards">
+ <category
+ id="org.eclipse.linuxtools.tmf.ui.wizards.new"
+ name="%project.new.category.name">
+ </category>
+ <wizard
+ category="org.eclipse.linuxtools.tmf.ui.wizards.new"
+ class="org.eclipse.linuxtools.tmf.ui.project.wizards.NewTmfProjectWizard"
+ icon="icons/elcl16/new_tracing_prj.gif"
+ id="org.eclipse.linuxtools.tmf.ui.views.ui.wizards.newProject"
+ name="%project.new.wizard.name"
+ project="true">
+ <description>
+ %project.new.wizard.description
+
+ </description>
+ </wizard>
+ <wizard
+ category="org.eclipse.linuxtools.tmf.ui.wizards.new"
+ class="org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards.CustomTxtParserWizard"
+ icon="icons/etool16/customparser_wizard.gif"
+ id="org.eclipse.linuxtools.tmf.ui.wizards.custom.text"
+ name="%project.new.wizard.custom.text.parser">
+ </wizard>
+ <wizard
+ category="org.eclipse.linuxtools.tmf.ui.wizards.new"
+ class="org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards.CustomXmlParserWizard"
+ icon="icons/etool16/customparser_wizard.gif"
+ id="org.eclipse.linuxtools.tmf.ui.wizards.custom.xml"
+ name="%project.new.wizard.custom.xml.parser">
+ </wizard>
+ </extension>
+ <extension
+ point="org.eclipse.ui.importWizards">
+ <category
+ id="org.eclipse.linuxtools.tmf.import.category"
+ name="%project.new.category.name">
+ </category>
+ <wizard
+ category="org.eclipse.linuxtools.tmf.import.category"
+ class="org.eclipse.linuxtools.tmf.ui.project.wizards.ImportTraceWizard"
+ icon="icons/etool16/import.gif"
+ id="org.eclipse.linuxtools.tmf.ui.trace.import.wizard"
+ name="%project.import.wizard.name">
+ </wizard>
+ </extension>
+ <extension
+ id="org.eclipse.linuxtools.tmf.project.nature"
+ point="org.eclipse.core.resources.natures">
+ <runtime>
+ <run
+ class="org.eclipse.linuxtools.tmf.core.TmfProjectNature">
+ </run>
+ </runtime>
+ </extension>
+ <extension
+ point="org.eclipse.ui.ide.projectNatureImages">
+ <image
+ icon="icons/ovr16/trace_nature_ovr.gif"
+ id="org.eclipse.linuxtools.tmf.ui.nature.image"
+ natureId="org.eclipse.linuxtools.tmf.project.nature">
+ </image>
+ </extension>
+ <extension
+ point="org.eclipse.ui.navigator.navigatorContent">
+ <navigatorContent
+ activeByDefault="true"
+ contentProvider="org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorContentProvider"
+ icon="icons/eview16/tracing_pers.gif"
+ id="org.eclipse.linuxtools.tmf.ui.navigator.content"
+ labelProvider="org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorLabelProvider"
+ name="%navigatorContent.name"
+ priority="normal">
+ <triggerPoints>
+ <or>
+ <and>
+ <instanceof
+ value="org.eclipse.core.resources.IProject">
+ </instanceof>
+ <test
+ property="org.eclipse.core.resources.projectNature"
+ value="org.eclipse.linuxtools.tmf.project.nature">
+ </test>
+ </and>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement">
+ </instanceof>
+ </or>
+ </triggerPoints>
+ <possibleChildren>
+ <or>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement">
+ </instanceof>
+ <instanceof
+ value="org.eclipse.core.resources.IResource">
+ </instanceof>
+ </or></possibleChildren>
+ <override
+ policy="InvokeAlwaysRegardlessOfSuppressedExt"
+ suppressedExtensionId="org.eclipse.ui.navigator.resourceContent">
+ </override>
+ <actionProvider
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.TmfActionProvider"
+ id="org.eclipse.linuxtools.tmf.ui.navigator.actions.provider">
+ <enablement>
+ <or>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement">
+ </instanceof>
+ </or>
+ </enablement>
+ </actionProvider>
+ <dropAssistant
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DropAdapterAssistant"
+ id="org.eclipse.linuxtools.tmf.ui.navigator.dropAssistant">
+ <possibleDropTargets>
+ <or>
+ <and>
+ <instanceof
+ value="org.eclipse.core.resources.IProject">
+ </instanceof>
+ <test
+ property="org.eclipse.core.resources.projectNature"
+ value="org.eclipse.linuxtools.tmf.project.nature">
+ </test>
+ </and>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement">
+ </instanceof>
+ </or>
+ </possibleDropTargets>
+ </dropAssistant>
+ <commonWizard
+ menuGroupId="org.eclipse.linuxtools.tmf.ui.views.ui.wizards.menuGroupId"
+ type="new"
+ wizardId="org.eclipse.linuxtools.tmf.ui.views.ui.wizards.newProject">
+ <enablement></enablement>
+ </commonWizard>
+ </navigatorContent>
+ </extension>
+ <extension
+ point="org.eclipse.ui.navigator.viewer">
+ <viewerContentBinding
+ viewerId="org.eclipse.ui.navigator.ProjectExplorer">
+ <includes>
+ <contentExtension
+ pattern="org.eclipse.linuxtools.tmf.ui.navigator.content">
+ </contentExtension>
+ <contentExtension
+ pattern="org.eclipse.ui.navigator.resources.filters.*">
+ </contentExtension>
+ </includes>
+ </viewerContentBinding>
+ </extension>
+ <extension
+ point="org.eclipse.ui.decorators">
+ <decorator
+ icon="icons/ovr16/trace_folder_ovr.png"
+ id="org.eclipse.linuxtools.tmf.ui.trace_folder.decorator"
+ label="Trace Folder"
+ lightweight="true"
+ location="TOP_RIGHT"
+ state="true">
+ <enablement>
+ <objectClass
+ name="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder">
+ </objectClass>
+ </enablement>
+ </decorator>
+ <decorator
+ icon="icons/ovr16/experiment_folder_ovr.png"
+ id="org.eclipse.linuxtools.tmf.ui.experiment_folder.decorator"
+ label="Trace Experiment Folder"
+ lightweight="true"
+ location="TOP_RIGHT"
+ state="true">
+ <enablement>
+ <objectClass
+ name="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder">
+ </objectClass>
+ </enablement>
+ </decorator>
+ <decorator
+ icon="icons/ovr16/link_ovr.gif"
+ id="org.eclipse.linuxtools.tmf.ui.linked_trace.decorator"
+ label="Linked Trace"
+ lightweight="true"
+ location="BOTTOM_RIGHT"
+ state="true">
+ <enablement>
+ <and>
+ <objectClass
+ name="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+ </objectClass>
+ <objectState
+ name="isLinked"
+ value="true">
+ </objectState>
+ </and>
+ </enablement>
+ </decorator>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ locationURI="menu:org.eclipse.ui.navigator.ProjectExplorer">
+ <command
+ commandId="org.eclipse.linuxtools.tmf.ui.command.managecustomparsers"
+ id="org.eclipse.linuxtools.tmf.ui.menu.managecustomparsers"
+ style="push">
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="toolbar:org.eclipse.ui.navigator.ProjectExplorer">
+ <command
+ commandId="org.eclipse.linuxtools.tmf.ui.command.clear_views"
+ icon="icons/etool16/clear.gif"
+ label="%command.clear_views"
+ mnemonic="%command.clear_views.mnemonic"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <count
+ value="1">
+ </count>
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <or>
+ <and>
+ <instanceof
+ value="org.eclipse.core.resources.IProject">
+ </instanceof>
+ <test
+ property="org.eclipse.core.resources.projectNature"
+ value="org.eclipse.linuxtools.tmf.project.nature">
+ </test>
+ </and>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement">
+ </instanceof>
+ </or>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ <menuContribution
+ locationURI="popup:org.eclipse.ui.popup.any?after=additions">
+ <command
+ commandId="org.eclipse.ui.file.import"
+ label="%command.import"
+ mnemonic="%command.import.mnemonic"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <count
+ value="1">
+ </count>
+ <iterate
+ operator="and">
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder">
+ </instanceof>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ <separator
+ name="org.eclipse.linuxtools.tmf.ui.separator1"
+ visible="true">
+ </separator>
+ <command
+ commandId="org.eclipse.ui.navigate.openResource"
+ disabledIcon="/icons/dlcl16/open.gif"
+ icon="/icons/elcl16/open.gif"
+ label="%command.open"
+ mnemonic="%command.open.mnemonic"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <count
+ value="1">
+ </count>
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <or>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+ </instanceof>
+ </or>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.ui.edit.copy"
+ label="%command.copy"
+ mnemonic="%command.copy.mnemonic"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <count
+ value="1">
+ </count>
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <or>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+ </instanceof>
+ </or>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.ui.edit.rename"
+ disabledIcon="/icons/dlcl16/rename.gif"
+ icon="/icons/elcl16/rename.gif"
+ label="%command.rename"
+ mnemonic="%command.rename.mnemonic"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <count
+ value="1">
+ </count>
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <or>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+ </instanceof>
+ </or>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.ui.edit.delete"
+ label="%command.delete"
+ mnemonic="%command.delete.mnemonic"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <or>
+ <and>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ <not>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.linuxtools.tmf.ui.isExperimentTrace">
+ </test>
+ </not>
+ </and>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+ </instanceof>
+ </or>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.ui.edit.delete"
+ label="%command.remove"
+ mnemonic="%command.remove.mnemonic"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <and>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.linuxtools.tmf.ui.isExperimentTrace">
+ </test>
+ </and>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ <separator
+ name="org.eclipse.linuxtools.tmf.ui.separator2"
+ visible="true">
+ </separator>
+ <command
+ commandId="org.eclipse.linuxtools.tmf.ui.command.new_experiment"
+ disabledIcon="icons/dtool16/new.gif"
+ icon="icons/etool16/new.gif"
+ label="%command.new_experiment"
+ mnemonic="%command.new_experiment.mnemonic"
+ style="push"
+ tooltip="%command.new_experiment.description">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <count
+ value="1">
+ </count>
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder">
+ </instanceof>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.linuxtools.tmf.ui.command.delete_suppl_files"
+ label="%command.delete_suppl_files"
+ mnemonic="%command.delete_suppl_files.mnemonic"
+ style="push"
+ tooltip="%command.delete_suppl_files.description">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <and>
+ <count
+ value="1">
+ </count>
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <and>
+ <or>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+ </instanceof>
+ </or>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.linuxtools.tmf.ui.hasSupplementaryFiles">
+ </test>
+ </and>
+ </iterate>
+ </and>
+ </with>
+ </visibleWhen>
+ </command>
+ <separator
+ name="org.eclipse.linuxtools.tmf.ui.separator3"
+ visible="true">
+ </separator>
+ <menu
+ label="%command.select_trace_type"
+ mnemonic="%command.select_trace_type.mnemonic"
+ tooltip="%command.select_trace_type.description">
+ <dynamic
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.SelectTraceTypeContributionItem"
+ id="org.eclipse.linuxtools.tmf.ui.command.select_trace_type.dynamic">
+ </dynamic>
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </menu>
+ <separator
+ name="org.eclipse.linuxtools.tmf.ui.separator4"
+ visible="true">
+ </separator>
+ <command
+ commandId="org.eclipse.linuxtools.tmf.ui.command.select_traces"
+ icon="IMG_OBJ_ADD"
+ label="%command.select_traces"
+ mnemonic="%command.select_traces.mnemonic"
+ style="push"
+ tooltip="%commands.select_traces.description">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <count
+ value="1">
+ </count>
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+ </instanceof>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ <separator
+ name="org.eclipse.linuxtools.tmf.ui.separator5"
+ visible="true">
+ </separator>
+ <command
+ commandId="org.eclipse.ui.file.refresh"
+ label="%command.refresh"
+ mnemonic="%command.refresh.mnemonic"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <count
+ value="1">
+ </count>
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <or>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder">
+ </instanceof>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder">
+ </instanceof>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+ </instanceof>
+ </or>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.linuxtools.tmf.ui.command.clear_views"
+ icon="icons/etool16/clear.gif"
+ label="%command.clear_views"
+ mnemonic="%command.clear_views.mnemonic"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <count
+ value="1">
+ </count>
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <and>
+ <instanceof
+ value="org.eclipse.core.resources.IProject">
+ </instanceof>
+ <test
+ property="org.eclipse.core.resources.projectNature"
+ value="org.eclipse.linuxtools.tmf.project.nature">
+ </test>
+ </and>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ </extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <category
+ description="%commands.category.description"
+ id="org.eclipse.linuxtools.tmf.ui.commands.category"
+ name="%commands.category.name">
+ </category>
+ <command
+ categoryId="org.eclipse.linuxtools.tmf.ui.commands.category"
+ description="%command.new_experiment.description"
+ id="org.eclipse.linuxtools.tmf.ui.command.new_experiment"
+ name="%command.new_experiment">
+ </command>
+ <command
+ categoryId="org.eclipse.linuxtools.tmf.ui.commands.category"
+ description="%command.select_trace_type.description"
+ id="org.eclipse.linuxtools.tmf.ui.command.select_trace_type"
+ name="%command.select_trace_type">
+ <commandParameter
+ id="org.eclipse.linuxtools.tmf.ui.commandparameter.select_trace_type.bundle"
+ name="%commands.trace.select_trace_type.bundle"
+ optional="false">
+ </commandParameter>
+ <commandParameter
+ id="org.eclipse.linuxtools.tmf.ui.commandparameter.select_trace_type.type"
+ name="%commands.trace.select_trace_type.type"
+ optional="false">
+ </commandParameter>
+ <commandParameter
+ id="org.eclipse.linuxtools.tmf.ui.commandparameter.select_trace_type.icon"
+ name="%commands.trace.select_trace_type.icon"
+ optional="false">
+ </commandParameter>
+ </command>
+ <command
+ categoryId="org.eclipse.linuxtools.tmf.ui.commands.category"
+ id="org.eclipse.linuxtools.tmf.ui.command.delete_suppl_files"
+ name="%command.delete_suppl_files">
+ </command>
+ <command
+ categoryId="org.eclipse.linuxtools.tmf.ui.commands.category"
+ description="%command.select_traces.description"
+ id="org.eclipse.linuxtools.tmf.ui.command.select_traces"
+ name="%command.select_traces">
+ </command>
+ <command
+ categoryId="org.eclipse.linuxtools.tmf.ui.commands.category"
+ description="%command.clear_views.description"
+ id="org.eclipse.linuxtools.tmf.ui.command.clear_views"
+ name="%command.clear_views">
+ </command>
+ <category
+ description="%commands.parser.category.description"
+ id="org.eclipse.linuxtools.tmf.ui.commands.parser.category"
+ name="%commands.parser.category.name">
+ </category>
+ <command
+ categoryId="org.eclipse.linuxtools.tmf.ui.commands.parser.category"
+ description="%commands.parser.manage.description"
+ id="org.eclipse.linuxtools.tmf.ui.command.managecustomparsers"
+ name="%commands.parser.manage">
+ </command>
+ <category
+ description="%commands.uml2sd.category.name"
+ id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.category"
+ name="%commands.uml2sd.category.name">
+ </category>
+ <command
+ categoryId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.category"
+ description="%commands.uml2sd.goto.description"
+ id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.GoToMessage"
+ name="%commands.uml2sd.goto">
+ </command>
+ <command
+ categoryId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.category"
+ description="%commands.uml2sd.showend.description"
+ id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeEnd"
+ name="%commands.uml2sd.showend">
+ </command>
+ <command
+ categoryId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.category"
+ description="%commands.uml2sd.showstart.description"
+ id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeStart"
+ name="%commands.uml2sd.showstart">
+ </command>
+ <command
+ categoryId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.category"
+ description="%commands.uml2sd.scrollup.description"
+ id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDUp"
+ name="%commands.uml2sd.scrollup">
+ </command>
+ <command
+ categoryId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.category"
+ description="%commands.uml2sd.scrolldown.description"
+ id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDDown"
+ name="%commands.uml2sd.scrolldown">
+ </command>
+ <command
+ categoryId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.category"
+ description="%commands.uml2sd.scrollleft.description"
+ id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDLeft"
+ name="%commands.uml2sd.scrollleft">
+ </command>
+ <command
+ categoryId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.category"
+ description="%commands.uml2sd.scrollright.description"
+ id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDRight"
+ name="%commands.uml2sd.scrollright">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.ImportTraceHandler"
+ commandId="org.eclipse.ui.file.import">
+ <activeWhen>
+ <and>
+ <count
+ value="1">
+ </count>
+ <iterate>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder">
+ </instanceof>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.RefreshHandler"
+ commandId="org.eclipse.ui.file.refresh">
+ <activeWhen>
+ <and>
+ <count
+ value="1">
+ </count>
+ <iterate>
+ <or>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder">
+ </instanceof>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder">
+ </instanceof>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+ </instanceof>
+ </or>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.OpenTraceHandler"
+ commandId="org.eclipse.ui.navigate.openResource">
+ <activeWhen>
+ <and>
+ <count
+ value="1">
+ </count>
+ <iterate>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.OpenExperimentHandler"
+ commandId="org.eclipse.ui.navigate.openResource">
+ <activeWhen>
+ <and>
+ <count
+ value="1">
+ </count>
+ <iterate>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+ </instanceof>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.CopyTraceHandler"
+ commandId="org.eclipse.ui.edit.copy">
+ <activeWhen>
+ <and>
+ <count
+ value="1">
+ </count>
+ <iterate>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.CopyExperimentHandler"
+ commandId="org.eclipse.ui.edit.copy">
+ <activeWhen>
+ <and>
+ <count
+ value="1">
+ </count>
+ <iterate>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+ </instanceof>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.RenameTraceHandler"
+ commandId="org.eclipse.ui.edit.rename">
+ <activeWhen>
+ <and>
+ <count
+ value="1">
+ </count>
+ <iterate>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.RenameExperimentHandler"
+ commandId="org.eclipse.ui.edit.rename">
+ <activeWhen>
+ <and>
+ <count
+ value="1">
+ </count>
+ <iterate>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+ </instanceof>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteTraceHandler"
+ commandId="org.eclipse.ui.edit.delete">
+ <activeWhen>
+ <and>
+ <iterate>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteExperimentHandler"
+ commandId="org.eclipse.ui.edit.delete">
+ <activeWhen>
+ <and>
+ <iterate>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+ </instanceof>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteTraceSupplementaryFilesHandler"
+ commandId="org.eclipse.linuxtools.tmf.ui.command.delete_suppl_files">
+ <activeWhen>
+ <and>
+ <count
+ value="1">
+ </count>
+ <iterate>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteExperimentSupplementaryFilesHandler"
+ commandId="org.eclipse.linuxtools.tmf.ui.command.delete_suppl_files">
+ <activeWhen>
+ <and>
+ <count
+ value="1">
+ </count>
+ <iterate>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+ </instanceof>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.NewExperimentHandler"
+ commandId="org.eclipse.linuxtools.tmf.ui.command.new_experiment">
+ <activeWhen>
+ <and>
+ <count
+ value="1">
+ </count>
+ <iterate>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder">
+ </instanceof>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.SelectTraceTypeHandler"
+ commandId="org.eclipse.linuxtools.tmf.ui.command.select_trace_type">
+ <activeWhen>
+ <and>
+ <iterate>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.SelectTracesHandler"
+ commandId="org.eclipse.linuxtools.tmf.ui.command.select_traces">
+ <activeWhen>
+ <and>
+ <count
+ value="1">
+ </count>
+ <iterate>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+ </instanceof>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.ClearViewsHandler"
+ commandId="org.eclipse.linuxtools.tmf.ui.command.clear_views">
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.commands.ManageCustomParsersCommandHandler"
+ commandId="org.eclipse.linuxtools.tmf.ui.command.managecustomparsers">
+ </handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.editors.handlers.AddBookmarkHandler"
+ commandId="org.eclipse.ui.edit.addBookmark">
+ <activeWhen>
+ <with
+ variable="activeEditor">
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor">
+ </instanceof>
+ </with>
+ </activeWhen>
+ </handler>
+ </extension>
+ <extension point="org.eclipse.ui.bindings">
+ <key
+ sequence="ALT+R"
+ contextId="org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"
+ commandId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.GoToMessage"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
+ </key>
+ <key
+ sequence="SHIFT+ALT+END"
+ contextId="org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"
+ commandId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeEnd"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
+ </key>
+ <key
+ sequence="SHIFT+ALT+HOME"
+ contextId="org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"
+ commandId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeStart"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
+ </key>
+ <key
+ sequence="SHIFT+ALT+ARROW_UP"
+ contextId="org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"
+ commandId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDUp"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
+ </key>
+ <key
+ sequence="SHIFT+ALT+ARROW_DOWN"
+ contextId="org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"
+ commandId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDDown"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
+ </key>
+ <key
+ sequence="SHIFT+ALT+ARROW_LEFT"
+ contextId="org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"
+ commandId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDLeft"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
+ </key>
+ <key
+ sequence="SHIFT+ALT+ARROW_RIGHT"
+ contextId="org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"
+ commandId="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDRight"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
+ </key>
+ </extension>
+ <extension
+ point="org.eclipse.core.contenttype.contentTypes">
+ <content-type
+ id="org.eclipse.linuxtools.tmf.ui.content-type.trace"
+ name="%contenttype.trace"
+ priority="normal">
+ </content-type>
+ </extension>
+ <extension
+ point="org.eclipse.ui.contexts">
+ <context
+ id="org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"
+ name="%contexts.uml2sd">
+ </context>
+ </extension>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ class="org.eclipse.linuxtools.internal.tmf.ui.preferences.TmfTracingPreferencePage"
+ id="org.eclipse.linuxtools.tmf.ui.TmfTracingPreferences"
+ name="%preference.page.trace.name">
+ </page>
+ <page
+ category="org.eclipse.linuxtools.tmf.ui.TmfTracingPreferences"
+ class="org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewerPage"
+ id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewerPage"
+ name="%preference.page.uml2sd.name">
+ </page>
+ </extension>
+ <extension
+ point="org.eclipse.linuxtools.tmf.ui.uml2SDLoader">
+ <uml2SDLoader
+ class="org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader"
+ default="true"
+ id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.impl.TmfUml2SDSyncLoader"
+ name="TMF UML2SD Loader"
+ view="org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView">
+ </uml2SDLoader>
+ </extension>
+ <!--extension
+ point="org.eclipse.core.expressions.propertyTesters">
+ <propertyTester
+ class="org.eclipse.linuxtools.tmf.ui.project.handlers.PropertyTester"
+ id="org.eclipse.linuxtools.tmf.ui.propertyTester.isInTraceFolder"
+ namespace="org.eclipse.linuxtools.tmf.ui.propertyTester"
+ properties="isInTraceFolder"
+ type="org.eclipse.jface.viewers.ISelection">
+ </propertyTester>
+ </extension -->
+ <extension
+ point="org.eclipse.core.expressions.propertyTesters">
+ <propertyTester
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.TracePropertyTester"
+ id="org.eclipse.linuxtools.tmf.ui.tracePropertyTester"
+ namespace="org.eclipse.linuxtools.tmf.ui"
+ properties="isExperimentTrace,hasSupplementaryFiles"
+ type="org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectModelElement">
+ </propertyTester>
+ </extension>
+ <extension
+ point="org.eclipse.linuxtools.tmf.ui.tracetype">
+ <category
+ id="org.eclipse.linuxtools.tmf.ui.category.ctf"
+ name="%tracetype.category.ctf">
+ </category>
+ <type
+ category="org.eclipse.linuxtools.tmf.ui.category.ctf"
+ event_type="org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent"
+ icon="icons/eview16/events_view.gif"
+ id="org.eclipse.linuxtools.tmf.ui.type.ctf"
+ name="%tracetype.type.ctf"
+ trace_type="org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace">
+ </type>
+ </extension>
+
+</plugin>
-package org.eclipse.linuxtools.internal.tmf.ui;\r
-\r
-import org.eclipse.osgi.util.NLS;\r
-\r
-public class Messages extends NLS {\r
- private static final String BUNDLE_NAME = "org.eclipse.linuxtools.internal.tmf.ui.messages"; //$NON-NLS-1$\r
-\r
- public static String ManageCustomParsersDialog_DeleteButtonLabel;\r
- public static String ManageCustomParsersDialog_DeleteConfirmation;\r
- public static String ManageCustomParsersDialog_DeleteParserDialogHeader;\r
- public static String ManageCustomParsersDialog_DialogHeader;\r
- public static String ManageCustomParsersDialog_EditButtonLabel;\r
- public static String ManageCustomParsersDialog_ExportButtonLabel;\r
- public static String ManageCustomParsersDialog_ExportParserSelection;\r
- public static String ManageCustomParsersDialog_ImportButtonLabel;\r
- public static String ManageCustomParsersDialog_ImportParserSelection;\r
- public static String ManageCustomParsersDialog_NewButtonLabel;\r
- public static String ManageCustomParsersDialog_ParseButtonLabel;\r
- public static String ManageCustomParsersDialog_ParseError;\r
- public static String ManageCustomParsersDialog_TextButtonLabel;\r
- public static String ManageCustomParsersDialog_TraceSelection;\r
-\r
- public static String CustomTraceDefinition_messageTag;\r
- public static String CustomTraceDefinition_otherTag;\r
- public static String CustomTraceDefinition_timestampTag;\r
- public static String CustomTxtTraceDefinition_action;\r
- public static String CustomTxtTraceDefinition_cardinality;\r
- public static String CustomTxtTraceDefinition_definition;\r
- public static String CustomTxtTraceDefinition_definitionRootElement;\r
- public static String CustomTxtTraceDefinition_format;\r
- public static String CustomTxtTraceDefinition_inputData;\r
- public static String CustomTxtTraceDefinition_inputLine;\r
- public static String CustomTxtTraceDefinition_max;\r
- public static String CustomTxtTraceDefinition_min;\r
- public static String CustomTxtTraceDefinition_name;\r
- public static String CustomTxtTraceDefinition_outputColumn;\r
- public static String CustomTxtTraceDefinition_regEx;\r
- public static String CustomTxtTraceDefinition_timestampOutputFormat;\r
- public static String CustomXmlTraceDefinition_action;\r
- public static String CustomXmlTraceDefinition_attribute;\r
- public static String CustomXmlTraceDefinition_definition;\r
- public static String CustomXmlTraceDefinition_definitionRootElement;\r
- public static String CustomXmlTraceDefinition_format;\r
- public static String CustomXmlTraceDefinition_ignoreTag;\r
- public static String CustomXmlTraceDefinition_inputData;\r
- public static String CustomXmlTraceDefinition_inputElement;\r
- public static String CustomXmlTraceDefinition_logEntry;\r
- public static String CustomXmlTraceDefinition_name;\r
- public static String CustomXmlTraceDefinition_outputColumn;\r
- public static String CustomXmlTraceDefinition_timestampOutputFormat;\r
-\r
- public static String TmfEventsTable_AddBookmarkActionText;\r
- public static String TmfEventsTable_AddBookmarkDialogText;\r
- public static String TmfEventsTable_AddBookmarkDialogTitle;\r
- public static String TmfEventsTable_ApplyPresetFilterMenuName;\r
- public static String TmfEventsTable_ClearFiltersActionText;\r
- public static String TmfEventsTable_ContentColumnHeader;\r
- public static String TmfEventsTable_FilterHint;\r
- public static String TmfEventsTable_HideRawActionText;\r
- public static String TmfEventsTable_HideTableActionText;\r
- public static String TmfEventsTable_ReferenceColumnHeader;\r
- public static String TmfEventsTable_RemoveBookmarkActionText;\r
- public static String TmfEventsTable_SearchHint;\r
- public static String TmfEventsTable_SearchingJobName;\r
- public static String TmfEventsTable_ShowFilterBarActionText;\r
- public static String TmfEventsTable_ShowRawActionText;\r
- public static String TmfEventsTable_ShowSearchBarActionText;\r
- public static String TmfEventsTable_ShowTableActionText;\r
- public static String TmfEventsTable_SourceColumnHeader;\r
- public static String TmfEventsTable_TimestampColumnHeader;\r
- public static String TmfEventsTable_TypeColumnHeader;\r
-\r
- public static String TmfTimeFilterDialog_EDIT_PROFILING_OPTIONS;\r
- public static String TmfTimeFilterDialog_TRACE_FILTER;\r
- public static String TmfTimeFilterDialog_TRACE_FILTER_DESC;\r
- public static String TmfTimeFilterDialog_TRACE_ID;\r
- public static String TmfTimeFilterDialog_TRACE_NAME;\r
- public static String TmfTimeLegend_LEGEND;\r
- public static String TmfTimeLegend_TRACE_STATES;\r
- public static String TmfTimeLegend_TRACE_STATES_TITLE;\r
- public static String TmfTimeLegend_WINDOW_TITLE;\r
- public static String TmfTimeLegend_StateTypeName;\r
-\r
- public static String TmfTimeTipHandler_DURATION;\r
- public static String TmfTimeTipHandler_TRACE_DATE;\r
- public static String TmfTimeTipHandler_TRACE_EVENT_TIME;\r
- public static String TmfTimeTipHandler_TRACE_START_TIME;\r
- public static String TmfTimeTipHandler_TRACE_STATE;\r
- public static String TmfTimeTipHandler_TRACE_STOP_TIME;\r
-\r
- public static String TmfTimeGraphViewer_ResetScaleActionNameText;\r
- public static String TmfTimeGraphViewer_ResetScaleActionToolTipText;\r
- public static String TmfTimeGraphViewer_LegendActionNameText;\r
- public static String TmfTimeGraphViewer_LegendActionToolTipText;\r
- public static String TmfTimeGraphViewer_NextEventActionNameText;\r
- public static String TmfTimeGraphViewer_NextEventActionToolTipText;\r
- public static String TmfTimeGraphViewer_PreviousEventActionNameText;\r
- public static String TmfTimeGraphViewer_PreviousEventActionToolTipText;\r
- public static String TmfTimeGraphViewer_NextItemActionNameText;\r
- public static String TmfTimeGraphViewer_NextItemActionToolTipText;\r
- public static String TmfTimeGraphViewer_PreviousItemActionNameText;\r
- public static String TmfTimeGraphViewer_PreviousItemActionToolTipText;\r
- public static String TmfTimeGraphViewer_ZoomInActionNameText;\r
- public static String TmfTimeGraphViewer_ZoomInActionToolTipText;\r
- public static String TmfTimeGraphViewer_ZoomOutActionNameText;\r
- public static String TmfTimeGraphViewer_ZoomOutActionToolTipText;\r
-\r
- public static String ColorsView_AddActionToolTipText;\r
- public static String ColorsView_BackgroundButtonText;\r
- public static String ColorsView_BackgroundDialogText;\r
- public static String ColorsView_DeleteActionToolTipText;\r
- public static String ColorsView_ExportActionToolTipText;\r
- public static String ColorsView_FilterButtonText;\r
- public static String ColorsView_ForegroundButtonText;\r
- public static String ColorsView_ForegroundDialogText;\r
- public static String ColorsView_ImportActionToolTipText;\r
- public static String ColorsView_ImportOverwriteDialogMessage1;\r
- public static String ColorsView_ImportOverwriteDialogMessage2;\r
- public static String ColorsView_ImportOverwriteDialogTitle;\r
- public static String ColorsView_MoveDownActionToolTipText;\r
- public static String ColorsView_MoveUpActionToolTipText;\r
- public static String ColorsView_TickButtonText;\r
- public static String TickColorDialog_TickColorDialogTitle;\r
-\r
- public static String CustomTxtParserInputWizardPage_addChildLine;\r
- public static String CustomTxtParserInputWizardPage_addGroup;\r
- public static String CustomTxtParserInputWizardPage_addNextLine;\r
- public static String CustomTxtParserInputWizardPage_append;\r
- public static String CustomTxtParserInputWizardPage_appendWith;\r
- public static String CustomTxtParserInputWizardPage_capturedGroup;\r
- public static String CustomTxtParserInputWizardPage_cardinality;\r
- public static String CustomTxtParserInputWizardPage_dateFormatHelp;\r
- public static String CustomTxtParserInputWizardPage_desccriptionEdit;\r
- public static String CustomTxtParserInputWizardPage_descriptionNew;\r
- public static String CustomTxtParserInputWizardPage_format;\r
- public static String CustomTxtParserInputWizardPage_group;\r
- public static String CustomTxtParserInputWizardPage_highlightAll;\r
- public static String CustomTxtParserInputWizardPage_logType;\r
- public static String CustomTxtParserInputWizardPage_matchingLineRoot;\r
- public static String CustomTxtParserInputWizardPage_matchingOtherLine;\r
- public static String CustomTxtParserInputWizardPage_matchingRootLine;\r
- public static String CustomTxtParserInputWizardPage_max;\r
- public static String CustomTxtParserInputWizardPage_min;\r
- public static String CustomTxtParserInputWizardPage_moveDown;\r
- public static String CustomTxtParserInputWizardPage_moveUp;\r
- public static String CustomTxtParserInputWizardPage_name;\r
- public static String CustomTxtParserInputWizardPage_newGroup;\r
- public static String CustomTxtParserInputWizardPage_noMatch;\r
- public static String CustomTxtParserInputWizardPage_noMatchingGroup;\r
- public static String CustomTxtParserInputWizardPage_noMatchingLine;\r
- public static String CustomTxtParserInputWizardPage_noMatchingTimestamp;\r
- public static String CustomTxtParserInputWizardPage_noMathcingLine;\r
- public static String CustomTxtParserInputWizardPage_nonMatchingLine;\r
- public static String CustomTxtParserInputWizardPage_noTimestampGroup;\r
- public static String CustomTxtParserInputWizardPage_preview;\r
- public static String CustomTxtParserInputWizardPage_previewInput;\r
- public static String CustomTxtParserInputWizardPage_previewLegend;\r
- public static String CustomTxtParserInputWizardPage_regularExpression;\r
- public static String CustomTxtParserInputWizardPage_regularExpressionHelp;\r
- public static String CustomTxtParserInputWizardPage_removeGroup;\r
- public static String CustomTxtParserInputWizardPage_removeLine;\r
- public static String CustomTxtParserInputWizardPage_set;\r
- public static String CustomTxtParserInputWizardPage_timestampFormat;\r
- public static String CustomTxtParserInputWizardPage_uncapturedText;\r
- public static String CustomTxtParserInputWizardPage_unidentifiedCaptureGroup;\r
- public static String CustomTxtParserInputWizardPage_windowTitleEdit;\r
- public static String CustomTxtParserInputWizardPage_windowTitleNew;\r
- public static String CustomTxtParserOutputWizardPage_description;\r
- public static String CustomTxtParserOutputWizardPage_moveAfter;\r
- public static String CustomTxtParserOutputWizardPage_moveBefore;\r
- public static String CustomTxtParserOutputWizardPage_visible;\r
- public static String CustomXmlParserInputWizardPage_emptyLogTypeError;\r
- public static String CustomXmlParserInputWizardPage_duplicatelogTypeError;\r
- public static String CustomXmlParserInputWizardPage_noDocumentError;\r
- public static String CustomXmlParserInputWizardPage_missingLogEntryError;\r
- public static String CustomXmlParserInputWizardPage_missingTimestampFmtError;\r
- public static String CustomXmlParserInputWizardPage_invalidTimestampFmtError;\r
- public static String CustomXmlParserInputWizardPage_notimestamporAttributeError;\r
- public static String CustomXmlParserInputWizardPage_missingDocumentElementError;\r
- public static String CustomXmlParserInputWizardPage_timestampFormatPrompt;\r
- public static String CustomXmlParserInputWizardPage_timestampElementPrompt;\r
- public static String CustomXmlParserInputWizardPage_missingInputElementNameError;\r
- public static String CustomXmlParserInputWizardPage_attributePrompt;\r
- public static String CustomXmlParserInputWizardPage_missingAttribute;\r
- public static String CustomXmlParserInputWizardPage_duplicateAttributeError;\r
- public static String CustomXmlParserInputWizardPage_missingTimestampInFmtError;\r
- public static String CustomXmlParserInputWizardPage_invalidTimestampInFmtError;\r
- public static String CustomXmlParserInputWizardPage_missingDataGroupNameError;\r
- public static String CustomXmlParserInputWizardPage_missingElementNameError;\r
- public static String CustomXmlParserInputWizardPage_duplicateElementNameError;\r
- public static String CustomXmlParserInputWizardPage_addAttribute;\r
- public static String CustomXmlParserInputWizardPage_addChildElement;\r
- public static String CustomXmlParserInputWizardPage_addDocumentEleemnt;\r
- public static String CustomXmlParserInputWizardPage_addDocumentElement;\r
- public static String CustomXmlParserInputWizardPage_addNextElement;\r
- public static String CustomXmlParserInputWizardPage_append;\r
- public static String CustomXmlParserInputWizardPage_appendWith;\r
- public static String CustomXmlParserInputWizardPage_attibute;\r
- public static String CustomXmlParserInputWizardPage_dateFormatHelp;\r
- public static String CustomXmlParserInputWizardPage_descriptionEdit;\r
- public static String CustomXmlParserInputWizardPage_descriptionNew;\r
- public static String CustomXmlParserInputWizardPage_elementName;\r
- public static String CustomXmlParserInputWizardPage_feelingLucky;\r
- public static String CustomXmlParserInputWizardPage_format;\r
- public static String CustomXmlParserInputWizardPage_logEntry;\r
- public static String CustomXmlParserInputWizardPage_logType;\r
- public static String CustomXmlParserInputWizardPage_moveDown;\r
- public static String CustomXmlParserInputWizardPage_moveUp;\r
- public static String CustomXmlParserInputWizardPage_name;\r
- public static String CustomXmlParserInputWizardPage_newAttibute;\r
- public static String CustomXmlParserInputWizardPage_noMatchingAttribute;\r
- public static String CustomXmlParserInputWizardPage_noMatch;\r
- public static String CustomXmlParserInputWizardPage_noMatchingElement;\r
- public static String CustomXmlParserInputWizardPage_preview;\r
- public static String CustomXmlParserInputWizardPage_previewInput;\r
- public static String CustomXmlParserInputWizardPage_removeAttribute;\r
- public static String CustomXmlParserInputWizardPage_removeElement;\r
- public static String CustomXmlParserInputWizardPage_set;\r
- public static String CustomXmlParserInputWizardPage_tagName;\r
- public static String CustomXmlParserInputWizardPage_timestampFormat;\r
- public static String CustomXmlParserInputWizardPage_titleEdit;\r
- public static String CustomXmlParserInputWizardPage_titleNew;\r
- public static String CustomXmlParserOutputWizardPage_description;\r
- public static String CustomXmlParserOutputWizardPage_moveAfter;\r
- public static String CustomXmlParserOutputWizardPage_moveBefore;\r
- public static String CustomXmlParserOutputWizardPage_visible;\r
-\r
- public static String FilterDialog_FilterDialogTitle;\r
- public static String FilterView_AddActionToolTipText;\r
- public static String FilterView_DeleteActionToolTipText;\r
- public static String FilterView_ExportActionToolTipText;\r
- public static String FilterView_FileDialogFilterName;\r
- public static String FilterView_ImportActionToolTipText;\r
- public static String FilterView_SaveActionToolTipText;\r
- public static String FilterViewer_EmptyTreeHintText;\r
- public static String FilterViewer_CommonCategory;\r
- public static String FilterViewer_AlphaButtonText;\r
- public static String FilterViewer_DeleteActionText;\r
- public static String FilterViewer_FieldLabel;\r
- public static String FilterViewer_FilterNameHint;\r
- public static String FilterViewer_IgnoreCaseButtonText;\r
- public static String FilterViewer_NameLabel;\r
- public static String FilterViewer_NewPrefix;\r
- public static String FilterViewer_NotLabel;\r
- public static String FilterViewer_NumButtonText;\r
- public static String FilterViewer_RegexHint;\r
- public static String FilterViewer_RegexLabel;\r
- public static String FilterViewer_ResultLabel;\r
- public static String FilterViewer_TimestampButtonText;\r
- public static String FilterViewer_TypeLabel;\r
- public static String FilterViewer_ValueHint;\r
- public static String FilterViewer_ValueLabel;\r
-\r
- public static String TmfView_PinActionNameText;\r
- public static String TmfView_PinActionToolTipText;\r
-\r
- static {\r
- // initialize resource bundle\r
- NLS.initializeMessages(BUNDLE_NAME, Messages.class);\r
- }\r
-\r
- private Messages() {\r
- }\r
-}\r
+package org.eclipse.linuxtools.internal.tmf.ui;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.linuxtools.internal.tmf.ui.messages"; //$NON-NLS-1$
+
+ public static String ManageCustomParsersDialog_DeleteButtonLabel;
+ public static String ManageCustomParsersDialog_DeleteConfirmation;
+ public static String ManageCustomParsersDialog_DeleteParserDialogHeader;
+ public static String ManageCustomParsersDialog_DialogHeader;
+ public static String ManageCustomParsersDialog_EditButtonLabel;
+ public static String ManageCustomParsersDialog_ExportButtonLabel;
+ public static String ManageCustomParsersDialog_ExportParserSelection;
+ public static String ManageCustomParsersDialog_ImportButtonLabel;
+ public static String ManageCustomParsersDialog_ImportParserSelection;
+ public static String ManageCustomParsersDialog_NewButtonLabel;
+ public static String ManageCustomParsersDialog_ParseButtonLabel;
+ public static String ManageCustomParsersDialog_ParseError;
+ public static String ManageCustomParsersDialog_TextButtonLabel;
+ public static String ManageCustomParsersDialog_TraceSelection;
+
+ public static String CustomTraceDefinition_messageTag;
+ public static String CustomTraceDefinition_otherTag;
+ public static String CustomTraceDefinition_timestampTag;
+ public static String CustomTxtTraceDefinition_action;
+ public static String CustomTxtTraceDefinition_cardinality;
+ public static String CustomTxtTraceDefinition_definition;
+ public static String CustomTxtTraceDefinition_definitionRootElement;
+ public static String CustomTxtTraceDefinition_format;
+ public static String CustomTxtTraceDefinition_inputData;
+ public static String CustomTxtTraceDefinition_inputLine;
+ public static String CustomTxtTraceDefinition_max;
+ public static String CustomTxtTraceDefinition_min;
+ public static String CustomTxtTraceDefinition_name;
+ public static String CustomTxtTraceDefinition_outputColumn;
+ public static String CustomTxtTraceDefinition_regEx;
+ public static String CustomTxtTraceDefinition_timestampOutputFormat;
+ public static String CustomXmlTraceDefinition_action;
+ public static String CustomXmlTraceDefinition_attribute;
+ public static String CustomXmlTraceDefinition_definition;
+ public static String CustomXmlTraceDefinition_definitionRootElement;
+ public static String CustomXmlTraceDefinition_format;
+ public static String CustomXmlTraceDefinition_ignoreTag;
+ public static String CustomXmlTraceDefinition_inputData;
+ public static String CustomXmlTraceDefinition_inputElement;
+ public static String CustomXmlTraceDefinition_logEntry;
+ public static String CustomXmlTraceDefinition_name;
+ public static String CustomXmlTraceDefinition_outputColumn;
+ public static String CustomXmlTraceDefinition_timestampOutputFormat;
+
+ public static String TmfEventsTable_AddBookmarkActionText;
+ public static String TmfEventsTable_AddBookmarkDialogText;
+ public static String TmfEventsTable_AddBookmarkDialogTitle;
+ public static String TmfEventsTable_ApplyPresetFilterMenuName;
+ public static String TmfEventsTable_ClearFiltersActionText;
+ public static String TmfEventsTable_ContentColumnHeader;
+ public static String TmfEventsTable_FilterHint;
+ public static String TmfEventsTable_HideRawActionText;
+ public static String TmfEventsTable_HideTableActionText;
+ public static String TmfEventsTable_ReferenceColumnHeader;
+ public static String TmfEventsTable_RemoveBookmarkActionText;
+ public static String TmfEventsTable_SearchHint;
+ public static String TmfEventsTable_SearchingJobName;
+ public static String TmfEventsTable_ShowFilterBarActionText;
+ public static String TmfEventsTable_ShowRawActionText;
+ public static String TmfEventsTable_ShowSearchBarActionText;
+ public static String TmfEventsTable_ShowTableActionText;
+ public static String TmfEventsTable_SourceColumnHeader;
+ public static String TmfEventsTable_TimestampColumnHeader;
+ public static String TmfEventsTable_TypeColumnHeader;
+
+ public static String TmfTimeFilterDialog_EDIT_PROFILING_OPTIONS;
+ public static String TmfTimeFilterDialog_TRACE_FILTER;
+ public static String TmfTimeFilterDialog_TRACE_FILTER_DESC;
+ public static String TmfTimeFilterDialog_TRACE_ID;
+ public static String TmfTimeFilterDialog_TRACE_NAME;
+ public static String TmfTimeLegend_LEGEND;
+ public static String TmfTimeLegend_TRACE_STATES;
+ public static String TmfTimeLegend_TRACE_STATES_TITLE;
+ public static String TmfTimeLegend_WINDOW_TITLE;
+ public static String TmfTimeLegend_StateTypeName;
+
+ public static String TmfTimeTipHandler_DURATION;
+ public static String TmfTimeTipHandler_TRACE_DATE;
+ public static String TmfTimeTipHandler_TRACE_EVENT_TIME;
+ public static String TmfTimeTipHandler_TRACE_START_TIME;
+ public static String TmfTimeTipHandler_TRACE_STATE;
+ public static String TmfTimeTipHandler_TRACE_STOP_TIME;
+
+ public static String TmfTimeGraphViewer_ResetScaleActionNameText;
+ public static String TmfTimeGraphViewer_ResetScaleActionToolTipText;
+ public static String TmfTimeGraphViewer_LegendActionNameText;
+ public static String TmfTimeGraphViewer_LegendActionToolTipText;
+ public static String TmfTimeGraphViewer_NextEventActionNameText;
+ public static String TmfTimeGraphViewer_NextEventActionToolTipText;
+ public static String TmfTimeGraphViewer_PreviousEventActionNameText;
+ public static String TmfTimeGraphViewer_PreviousEventActionToolTipText;
+ public static String TmfTimeGraphViewer_NextItemActionNameText;
+ public static String TmfTimeGraphViewer_NextItemActionToolTipText;
+ public static String TmfTimeGraphViewer_PreviousItemActionNameText;
+ public static String TmfTimeGraphViewer_PreviousItemActionToolTipText;
+ public static String TmfTimeGraphViewer_ZoomInActionNameText;
+ public static String TmfTimeGraphViewer_ZoomInActionToolTipText;
+ public static String TmfTimeGraphViewer_ZoomOutActionNameText;
+ public static String TmfTimeGraphViewer_ZoomOutActionToolTipText;
+
+ public static String ColorsView_AddActionToolTipText;
+ public static String ColorsView_BackgroundButtonText;
+ public static String ColorsView_BackgroundDialogText;
+ public static String ColorsView_DeleteActionToolTipText;
+ public static String ColorsView_ExportActionToolTipText;
+ public static String ColorsView_FilterButtonText;
+ public static String ColorsView_ForegroundButtonText;
+ public static String ColorsView_ForegroundDialogText;
+ public static String ColorsView_ImportActionToolTipText;
+ public static String ColorsView_ImportOverwriteDialogMessage1;
+ public static String ColorsView_ImportOverwriteDialogMessage2;
+ public static String ColorsView_ImportOverwriteDialogTitle;
+ public static String ColorsView_MoveDownActionToolTipText;
+ public static String ColorsView_MoveUpActionToolTipText;
+ public static String ColorsView_TickButtonText;
+ public static String TickColorDialog_TickColorDialogTitle;
+
+ public static String CustomTxtParserInputWizardPage_addChildLine;
+ public static String CustomTxtParserInputWizardPage_addGroup;
+ public static String CustomTxtParserInputWizardPage_addNextLine;
+ public static String CustomTxtParserInputWizardPage_append;
+ public static String CustomTxtParserInputWizardPage_appendWith;
+ public static String CustomTxtParserInputWizardPage_capturedGroup;
+ public static String CustomTxtParserInputWizardPage_cardinality;
+ public static String CustomTxtParserInputWizardPage_dateFormatHelp;
+ public static String CustomTxtParserInputWizardPage_desccriptionEdit;
+ public static String CustomTxtParserInputWizardPage_descriptionNew;
+ public static String CustomTxtParserInputWizardPage_format;
+ public static String CustomTxtParserInputWizardPage_group;
+ public static String CustomTxtParserInputWizardPage_highlightAll;
+ public static String CustomTxtParserInputWizardPage_logType;
+ public static String CustomTxtParserInputWizardPage_matchingLineRoot;
+ public static String CustomTxtParserInputWizardPage_matchingOtherLine;
+ public static String CustomTxtParserInputWizardPage_matchingRootLine;
+ public static String CustomTxtParserInputWizardPage_max;
+ public static String CustomTxtParserInputWizardPage_min;
+ public static String CustomTxtParserInputWizardPage_moveDown;
+ public static String CustomTxtParserInputWizardPage_moveUp;
+ public static String CustomTxtParserInputWizardPage_name;
+ public static String CustomTxtParserInputWizardPage_newGroup;
+ public static String CustomTxtParserInputWizardPage_noMatch;
+ public static String CustomTxtParserInputWizardPage_noMatchingGroup;
+ public static String CustomTxtParserInputWizardPage_noMatchingLine;
+ public static String CustomTxtParserInputWizardPage_noMatchingTimestamp;
+ public static String CustomTxtParserInputWizardPage_noMathcingLine;
+ public static String CustomTxtParserInputWizardPage_nonMatchingLine;
+ public static String CustomTxtParserInputWizardPage_noTimestampGroup;
+ public static String CustomTxtParserInputWizardPage_preview;
+ public static String CustomTxtParserInputWizardPage_previewInput;
+ public static String CustomTxtParserInputWizardPage_previewLegend;
+ public static String CustomTxtParserInputWizardPage_regularExpression;
+ public static String CustomTxtParserInputWizardPage_regularExpressionHelp;
+ public static String CustomTxtParserInputWizardPage_removeGroup;
+ public static String CustomTxtParserInputWizardPage_removeLine;
+ public static String CustomTxtParserInputWizardPage_set;
+ public static String CustomTxtParserInputWizardPage_timestampFormat;
+ public static String CustomTxtParserInputWizardPage_uncapturedText;
+ public static String CustomTxtParserInputWizardPage_unidentifiedCaptureGroup;
+ public static String CustomTxtParserInputWizardPage_windowTitleEdit;
+ public static String CustomTxtParserInputWizardPage_windowTitleNew;
+ public static String CustomTxtParserOutputWizardPage_description;
+ public static String CustomTxtParserOutputWizardPage_moveAfter;
+ public static String CustomTxtParserOutputWizardPage_moveBefore;
+ public static String CustomTxtParserOutputWizardPage_visible;
+ public static String CustomXmlParserInputWizardPage_emptyLogTypeError;
+ public static String CustomXmlParserInputWizardPage_duplicatelogTypeError;
+ public static String CustomXmlParserInputWizardPage_noDocumentError;
+ public static String CustomXmlParserInputWizardPage_missingLogEntryError;
+ public static String CustomXmlParserInputWizardPage_missingTimestampFmtError;
+ public static String CustomXmlParserInputWizardPage_invalidTimestampFmtError;
+ public static String CustomXmlParserInputWizardPage_notimestamporAttributeError;
+ public static String CustomXmlParserInputWizardPage_missingDocumentElementError;
+ public static String CustomXmlParserInputWizardPage_timestampFormatPrompt;
+ public static String CustomXmlParserInputWizardPage_timestampElementPrompt;
+ public static String CustomXmlParserInputWizardPage_missingInputElementNameError;
+ public static String CustomXmlParserInputWizardPage_attributePrompt;
+ public static String CustomXmlParserInputWizardPage_missingAttribute;
+ public static String CustomXmlParserInputWizardPage_duplicateAttributeError;
+ public static String CustomXmlParserInputWizardPage_missingTimestampInFmtError;
+ public static String CustomXmlParserInputWizardPage_invalidTimestampInFmtError;
+ public static String CustomXmlParserInputWizardPage_missingDataGroupNameError;
+ public static String CustomXmlParserInputWizardPage_missingElementNameError;
+ public static String CustomXmlParserInputWizardPage_duplicateElementNameError;
+ public static String CustomXmlParserInputWizardPage_addAttribute;
+ public static String CustomXmlParserInputWizardPage_addChildElement;
+ public static String CustomXmlParserInputWizardPage_addDocumentEleemnt;
+ public static String CustomXmlParserInputWizardPage_addDocumentElement;
+ public static String CustomXmlParserInputWizardPage_addNextElement;
+ public static String CustomXmlParserInputWizardPage_append;
+ public static String CustomXmlParserInputWizardPage_appendWith;
+ public static String CustomXmlParserInputWizardPage_attibute;
+ public static String CustomXmlParserInputWizardPage_dateFormatHelp;
+ public static String CustomXmlParserInputWizardPage_descriptionEdit;
+ public static String CustomXmlParserInputWizardPage_descriptionNew;
+ public static String CustomXmlParserInputWizardPage_elementName;
+ public static String CustomXmlParserInputWizardPage_feelingLucky;
+ public static String CustomXmlParserInputWizardPage_format;
+ public static String CustomXmlParserInputWizardPage_logEntry;
+ public static String CustomXmlParserInputWizardPage_logType;
+ public static String CustomXmlParserInputWizardPage_moveDown;
+ public static String CustomXmlParserInputWizardPage_moveUp;
+ public static String CustomXmlParserInputWizardPage_name;
+ public static String CustomXmlParserInputWizardPage_newAttibute;
+ public static String CustomXmlParserInputWizardPage_noMatchingAttribute;
+ public static String CustomXmlParserInputWizardPage_noMatch;
+ public static String CustomXmlParserInputWizardPage_noMatchingElement;
+ public static String CustomXmlParserInputWizardPage_preview;
+ public static String CustomXmlParserInputWizardPage_previewInput;
+ public static String CustomXmlParserInputWizardPage_removeAttribute;
+ public static String CustomXmlParserInputWizardPage_removeElement;
+ public static String CustomXmlParserInputWizardPage_set;
+ public static String CustomXmlParserInputWizardPage_tagName;
+ public static String CustomXmlParserInputWizardPage_timestampFormat;
+ public static String CustomXmlParserInputWizardPage_titleEdit;
+ public static String CustomXmlParserInputWizardPage_titleNew;
+ public static String CustomXmlParserOutputWizardPage_description;
+ public static String CustomXmlParserOutputWizardPage_moveAfter;
+ public static String CustomXmlParserOutputWizardPage_moveBefore;
+ public static String CustomXmlParserOutputWizardPage_visible;
+
+ public static String FilterDialog_FilterDialogTitle;
+ public static String FilterView_AddActionToolTipText;
+ public static String FilterView_DeleteActionToolTipText;
+ public static String FilterView_ExportActionToolTipText;
+ 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;
+ public static String FilterViewer_FilterNameHint;
+ public static String FilterViewer_IgnoreCaseButtonText;
+ public static String FilterViewer_NameLabel;
+ public static String FilterViewer_NewPrefix;
+ public static String FilterViewer_NotLabel;
+ public static String FilterViewer_NumButtonText;
+ public static String FilterViewer_RegexHint;
+ public static String FilterViewer_RegexLabel;
+ public static String FilterViewer_ResultLabel;
+ public static String FilterViewer_TimestampButtonText;
+ public static String FilterViewer_TypeLabel;
+ public static String FilterViewer_ValueHint;
+ public static String FilterViewer_ValueLabel;
+
+ public static String TmfView_PinActionNameText;
+ public static String TmfView_PinActionToolTipText;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
-package org.eclipse.linuxtools.internal.tmf.ui;\r
-\r
-import java.io.BufferedWriter;\r
-import java.io.FileWriter;\r
-import java.io.IOException;\r
-\r
-import org.eclipse.core.runtime.Platform;\r
-\r
-@SuppressWarnings("nls")\r
-public class TmfUiTracer {\r
-\r
- private static String pluginID = Activator.PLUGIN_ID;\r
-\r
- static Boolean ERROR = Boolean.FALSE;\r
- static Boolean WARNING = Boolean.FALSE;\r
- static Boolean INFO = Boolean.FALSE;\r
-\r
- static Boolean INDEX = Boolean.FALSE;\r
- static Boolean DISPLAY = Boolean.FALSE;\r
- static Boolean SORTING = Boolean.FALSE;\r
-\r
- private static String LOGNAME = "traceUI.log";\r
- private static BufferedWriter fTraceLog = null;\r
-\r
- private static BufferedWriter openLogFile(String filename) {\r
- BufferedWriter outfile = null;\r
- try {\r
- outfile = new BufferedWriter(new FileWriter(filename));\r
- } catch (IOException e) {\r
- Activator.getDefault().logError("Error creating log file " + LOGNAME, e); //$NON-NLS-1$\r
- }\r
- return outfile;\r
- }\r
-\r
- public static void init() {\r
-\r
- String traceKey;\r
- boolean isTracing = false;\r
- \r
- traceKey = Platform.getDebugOption(pluginID + "/error");\r
- if (traceKey != null) {\r
- ERROR = (Boolean.valueOf(traceKey)).booleanValue();\r
- isTracing |= ERROR;\r
- }\r
-\r
- traceKey = Platform.getDebugOption(pluginID + "/warning");\r
- if (traceKey != null) {\r
- WARNING = (Boolean.valueOf(traceKey)).booleanValue();\r
- isTracing |= WARNING;\r
- }\r
-\r
- traceKey = Platform.getDebugOption(pluginID + "/info");\r
- if (traceKey != null) {\r
- INFO = (Boolean.valueOf(traceKey)).booleanValue();\r
- isTracing |= INFO;\r
- }\r
-\r
- traceKey = Platform.getDebugOption(pluginID + "/updateindex");\r
- if (traceKey != null) {\r
- INDEX = (Boolean.valueOf(traceKey)).booleanValue();\r
- isTracing |= INDEX;\r
- }\r
-\r
- traceKey = Platform.getDebugOption(pluginID + "/display");\r
- if (traceKey != null) {\r
- DISPLAY = (Boolean.valueOf(traceKey)).booleanValue();\r
- isTracing |= DISPLAY;\r
- }\r
-\r
- traceKey = Platform.getDebugOption(pluginID + "/sorting");\r
- if (traceKey != null) {\r
- SORTING = (Boolean.valueOf(traceKey)).booleanValue();\r
- isTracing |= SORTING;\r
- }\r
-\r
- // Create trace log file if needed\r
- if (isTracing) {\r
- fTraceLog = openLogFile(LOGNAME);\r
- }\r
- }\r
-\r
- public static void stop() {\r
- if (fTraceLog == null)\r
- return;\r
-\r
- try {\r
- fTraceLog.close();\r
- fTraceLog = null;\r
- } catch (IOException e) {\r
- Activator.getDefault().logError("Error closing log file " + LOGNAME, e); //$NON-NLS-1$\r
- }\r
- }\r
-\r
- // Predicates\r
- public static boolean isErrorTraced() {\r
- return ERROR;\r
- }\r
-\r
- public static boolean isIndexTraced() {\r
- return INDEX;\r
- }\r
- \r
- public static boolean isDisplayTraced() {\r
- return DISPLAY;\r
- }\r
- \r
- public static boolean isSortingTraced() {\r
- return SORTING;\r
- }\r
-\r
- // Tracers\r
- public static void trace(String msg) {\r
- long currentTime = System.currentTimeMillis();\r
- StringBuilder message = new StringBuilder("[");\r
- message.append(currentTime / 1000);\r
- message.append(".");\r
- message.append(String.format("%1$03d", currentTime % 1000));\r
- message.append("] ");\r
- message.append(msg);\r
-\r
- if (fTraceLog != null) {\r
- try {\r
- fTraceLog.write(message.toString());\r
- fTraceLog.newLine();\r
- fTraceLog.flush();\r
- } catch (IOException e) {\r
- Activator.getDefault().logError("Error writing to log file " + LOGNAME, e); //$NON-NLS-1$\r
- }\r
- }\r
- }\r
-\r
- public static void traceIndex(String msg) {\r
- String message = ("[INDEX] " + msg);\r
- trace(message);\r
- }\r
- \r
- public static void traceDisplay(String msg) {\r
- String message = ("[DISPLAY]" + msg);\r
- trace(message);\r
- }\r
-\r
- public static void traceSorting(String msg) {\r
- String message = ("[SORT] " + msg);\r
- trace(message);\r
- }\r
-\r
- public static void traceError(String msg) {\r
- String message = ("[ERR] Thread=" + Thread.currentThread().getId() + " " + msg);\r
- trace(message);\r
- }\r
-\r
- public static void traceWarning(String msg) {\r
- String message = ("[WARN] Thread=" + Thread.currentThread().getId() + " " + msg);\r
- trace(message);\r
- }\r
- \r
- public static void traceInfo(String msg) {\r
- String message = ("[INF] Thread=" + Thread.currentThread().getId() + " " + msg);\r
- trace(message);\r
- }\r
- \r
- \r
-\r
-}\r
+package org.eclipse.linuxtools.internal.tmf.ui;
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.eclipse.core.runtime.Platform;
+
+@SuppressWarnings("nls")
+public class TmfUiTracer {
+
+ private static String pluginID = Activator.PLUGIN_ID;
+
+ static Boolean ERROR = Boolean.FALSE;
+ static Boolean WARNING = Boolean.FALSE;
+ static Boolean INFO = Boolean.FALSE;
+
+ static Boolean INDEX = Boolean.FALSE;
+ static Boolean DISPLAY = Boolean.FALSE;
+ static Boolean SORTING = Boolean.FALSE;
+
+ private static String LOGNAME = "traceUI.log";
+ private static BufferedWriter fTraceLog = null;
+
+ private static BufferedWriter openLogFile(String filename) {
+ BufferedWriter outfile = null;
+ try {
+ outfile = new BufferedWriter(new FileWriter(filename));
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error creating log file " + LOGNAME, e); //$NON-NLS-1$
+ }
+ return outfile;
+ }
+
+ public static void init() {
+
+ String traceKey;
+ boolean isTracing = false;
+
+ traceKey = Platform.getDebugOption(pluginID + "/error");
+ if (traceKey != null) {
+ ERROR = (Boolean.valueOf(traceKey)).booleanValue();
+ isTracing |= ERROR;
+ }
+
+ traceKey = Platform.getDebugOption(pluginID + "/warning");
+ if (traceKey != null) {
+ WARNING = (Boolean.valueOf(traceKey)).booleanValue();
+ isTracing |= WARNING;
+ }
+
+ traceKey = Platform.getDebugOption(pluginID + "/info");
+ if (traceKey != null) {
+ INFO = (Boolean.valueOf(traceKey)).booleanValue();
+ isTracing |= INFO;
+ }
+
+ traceKey = Platform.getDebugOption(pluginID + "/updateindex");
+ if (traceKey != null) {
+ INDEX = (Boolean.valueOf(traceKey)).booleanValue();
+ isTracing |= INDEX;
+ }
+
+ traceKey = Platform.getDebugOption(pluginID + "/display");
+ if (traceKey != null) {
+ DISPLAY = (Boolean.valueOf(traceKey)).booleanValue();
+ isTracing |= DISPLAY;
+ }
+
+ traceKey = Platform.getDebugOption(pluginID + "/sorting");
+ if (traceKey != null) {
+ SORTING = (Boolean.valueOf(traceKey)).booleanValue();
+ isTracing |= SORTING;
+ }
+
+ // Create trace log file if needed
+ if (isTracing) {
+ fTraceLog = openLogFile(LOGNAME);
+ }
+ }
+
+ public static void stop() {
+ if (fTraceLog == null)
+ return;
+
+ try {
+ fTraceLog.close();
+ fTraceLog = null;
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error closing log file " + LOGNAME, e); //$NON-NLS-1$
+ }
+ }
+
+ // Predicates
+ public static boolean isErrorTraced() {
+ return ERROR;
+ }
+
+ public static boolean isIndexTraced() {
+ return INDEX;
+ }
+
+ public static boolean isDisplayTraced() {
+ return DISPLAY;
+ }
+
+ public static boolean isSortingTraced() {
+ return SORTING;
+ }
+
+ // Tracers
+ public static void trace(String msg) {
+ long currentTime = System.currentTimeMillis();
+ StringBuilder message = new StringBuilder("[");
+ message.append(currentTime / 1000);
+ message.append(".");
+ message.append(String.format("%1$03d", currentTime % 1000));
+ message.append("] ");
+ message.append(msg);
+
+ if (fTraceLog != null) {
+ try {
+ fTraceLog.write(message.toString());
+ fTraceLog.newLine();
+ fTraceLog.flush();
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error writing to log file " + LOGNAME, e); //$NON-NLS-1$
+ }
+ }
+ }
+
+ public static void traceIndex(String msg) {
+ String message = ("[INDEX] " + msg);
+ trace(message);
+ }
+
+ public static void traceDisplay(String msg) {
+ String message = ("[DISPLAY]" + msg);
+ trace(message);
+ }
+
+ public static void traceSorting(String msg) {
+ String message = ("[SORT] " + msg);
+ trace(message);
+ }
+
+ public static void traceError(String msg) {
+ String message = ("[ERR] Thread=" + Thread.currentThread().getId() + " " + msg);
+ trace(message);
+ }
+
+ public static void traceWarning(String msg) {
+ String message = ("[WARN] Thread=" + Thread.currentThread().getId() + " " + msg);
+ trace(message);
+ }
+
+ public static void traceInfo(String msg) {
+ String message = ("[INF] Thread=" + Thread.currentThread().getId() + " " + msg);
+ trace(message);
+ }
+
+
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- * \r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- * \r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.commands;\r
-\r
-import org.eclipse.core.commands.AbstractHandler;\r
-import org.eclipse.core.commands.ExecutionEvent;\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.linuxtools.internal.tmf.ui.dialogs.ManageCustomParsersDialog;\r
-import org.eclipse.swt.widgets.Display;\r
-\r
-public class ManageCustomParsersCommandHandler extends AbstractHandler {\r
-\r
- @Override\r
- public Object execute(ExecutionEvent event) throws ExecutionException {\r
- ManageCustomParsersDialog dialog = new ManageCustomParsersDialog(Display.getDefault().getActiveShell());\r
- dialog.open();\r
- return null;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.commands;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.linuxtools.internal.tmf.ui.dialogs.ManageCustomParsersDialog;
+import org.eclipse.swt.widgets.Display;
+
+public class ManageCustomParsersCommandHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ManageCustomParsersDialog dialog = new ManageCustomParsersDialog(Display.getDefault().getActiveShell());
+ dialog.open();
+ return null;
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.dialogs;\r
-\r
-import org.eclipse.jface.dialogs.Dialog;\r
-import org.eclipse.jface.dialogs.IDialogConstants;\r
-import org.eclipse.jface.dialogs.MessageDialog;\r
-import org.eclipse.jface.window.Window;\r
-import org.eclipse.jface.wizard.WizardDialog;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards.CustomTxtParserWizard;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards.CustomXmlParserWizard;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.events.SelectionListener;\r
-import org.eclipse.swt.graphics.Image;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Button;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.FileDialog;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.List;\r
-import org.eclipse.swt.widgets.Shell;\r
-\r
-public class ManageCustomParsersDialog extends Dialog {\r
-\r
- private static final Image image = Activator.getDefault().getImageFromPath("/icons/etool16/customparser_wizard.gif"); //$NON-NLS-1$\r
-\r
- Button txtButton;\r
- Button xmlButton;\r
- List parserList;\r
- Button newButton;\r
- Button editButton;\r
- Button deleteButton;\r
- Button importButton;\r
- Button exportButton;\r
-\r
- public ManageCustomParsersDialog(Shell parent) {\r
- super(parent);\r
- setShellStyle(SWT.RESIZE | SWT.MAX | getShellStyle());\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)\r
- */\r
- @Override\r
- protected Control createDialogArea(Composite parent) {\r
- getShell().setText(Messages.ManageCustomParsersDialog_DialogHeader);\r
- getShell().setImage(image);\r
-\r
- Composite composite = (Composite) super.createDialogArea(parent);\r
- composite.setLayout(new GridLayout(2, false));\r
-\r
- Composite listContainer = new Composite(composite, SWT.NONE);\r
- listContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- GridLayout lcgl = new GridLayout();\r
- lcgl.marginHeight = 0;\r
- lcgl.marginWidth = 0;\r
- listContainer.setLayout(lcgl);\r
-\r
- Composite radioContainer = new Composite(listContainer, SWT.NONE);\r
- GridLayout rcgl = new GridLayout(2, true);\r
- rcgl.marginHeight = 0;\r
- rcgl.marginWidth = 0;\r
- radioContainer.setLayout(rcgl);\r
-\r
- txtButton = new Button(radioContainer, SWT.RADIO);\r
- txtButton.setText(Messages.ManageCustomParsersDialog_TextButtonLabel);\r
- txtButton.setSelection(true);\r
- txtButton.addSelectionListener(new SelectionListener(){\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {}\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- fillParserList();\r
- }});\r
-\r
- xmlButton = new Button(radioContainer, SWT.RADIO);\r
- xmlButton.setText("XML"); //$NON-NLS-1$\r
- xmlButton.addSelectionListener(new SelectionListener(){\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {}\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- fillParserList();\r
- }});\r
-\r
- parserList = new List(listContainer, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);\r
- parserList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- parserList.addSelectionListener(new SelectionListener(){\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {}\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (parserList.getSelectionCount() == 0) {\r
- editButton.setEnabled(false);\r
- deleteButton.setEnabled(false);\r
- exportButton.setEnabled(false);\r
- } else {\r
- editButton.setEnabled(true);\r
- deleteButton.setEnabled(true);\r
- exportButton.setEnabled(true);\r
- }\r
- }});\r
-\r
- Composite buttonContainer = new Composite(composite, SWT.NULL);\r
- buttonContainer.setLayout(new GridLayout());\r
- buttonContainer.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, false, false));\r
-\r
- newButton = new Button(buttonContainer, SWT.PUSH);\r
- newButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));\r
- newButton.setText(Messages.ManageCustomParsersDialog_NewButtonLabel);\r
- newButton.addSelectionListener(new SelectionListener(){\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {}\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- WizardDialog dialog = null;\r
- if (txtButton.getSelection()) {\r
- dialog = new WizardDialog(getShell(), new CustomTxtParserWizard());\r
- } else if (xmlButton.getSelection()) {\r
- dialog = new WizardDialog(getShell(), new CustomXmlParserWizard());\r
- }\r
- if (dialog != null) {\r
- dialog.open();\r
- if (dialog.getReturnCode() == Window.OK) {\r
- fillParserList();\r
- }\r
- }\r
- }});\r
-\r
- editButton = new Button(buttonContainer, SWT.PUSH);\r
- editButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));\r
- editButton.setText(Messages.ManageCustomParsersDialog_EditButtonLabel);\r
- editButton.setEnabled(false);\r
- editButton.addSelectionListener(new SelectionListener(){\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {}\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- WizardDialog dialog = null;\r
- if (txtButton.getSelection()) {\r
- dialog = new WizardDialog(getShell(),\r
- new CustomTxtParserWizard(CustomTxtTraceDefinition.load(parserList.getSelection()[0])));\r
- } else if (xmlButton.getSelection()) {\r
- dialog = new WizardDialog(getShell(),\r
- new CustomXmlParserWizard(CustomXmlTraceDefinition.load(parserList.getSelection()[0])));\r
- }\r
- if (dialog != null) {\r
- dialog.open();\r
- if (dialog.getReturnCode() == Window.OK) {\r
- fillParserList();\r
- }\r
- }\r
- }});\r
-\r
- deleteButton = new Button(buttonContainer, SWT.PUSH);\r
- deleteButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));\r
- deleteButton.setText(Messages.ManageCustomParsersDialog_DeleteButtonLabel);\r
- deleteButton.setEnabled(false);\r
- deleteButton.addSelectionListener(new SelectionListener(){\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {}\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- boolean confirm = MessageDialog.openQuestion(\r
- getShell(),\r
- Messages.ManageCustomParsersDialog_DeleteParserDialogHeader,\r
- Messages.ManageCustomParsersDialog_DeleteConfirmation + parserList.getSelection()[0] + "?"); //$NON-NLS-1$\r
- if (confirm) {\r
- if (txtButton.getSelection()) {\r
- CustomTxtTraceDefinition.delete(parserList.getSelection()[0]);\r
- } else if (xmlButton.getSelection()) {\r
- CustomXmlTraceDefinition.delete(parserList.getSelection()[0]);\r
- }\r
- fillParserList();\r
- }\r
- }});\r
-\r
- new Label(buttonContainer, SWT.NONE); // filler\r
-\r
- importButton = new Button(buttonContainer, SWT.PUSH);\r
- importButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));\r
- importButton.setText(Messages.ManageCustomParsersDialog_ImportButtonLabel);\r
- importButton.addSelectionListener(new SelectionListener(){\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {}\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.OPEN);\r
- dialog.setText(Messages.ManageCustomParsersDialog_ImportParserSelection);\r
- dialog.setFilterExtensions(new String[] {"*.xml", "*"}); //$NON-NLS-1$ //$NON-NLS-2$\r
- String path = dialog.open();\r
- if (path != null) {\r
- CustomTraceDefinition[] defs = null;\r
- if (txtButton.getSelection()) {\r
- defs = CustomTxtTraceDefinition.loadAll(path);\r
- } else if (xmlButton.getSelection()) {\r
- defs = CustomXmlTraceDefinition.loadAll(path);\r
- }\r
- if (defs != null && defs.length > 0) {\r
- for (CustomTraceDefinition def : defs) {\r
- def.save();\r
- }\r
- fillParserList();\r
- }\r
- }\r
- }});\r
-\r
- exportButton = new Button(buttonContainer, SWT.PUSH);\r
- exportButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));\r
- exportButton.setText(Messages.ManageCustomParsersDialog_ExportButtonLabel);\r
- exportButton.setEnabled(false);\r
- exportButton.addSelectionListener(new SelectionListener(){\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {}\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);\r
- dialog.setText(Messages.ManageCustomParsersDialog_ExportParserSelection + parserList.getSelection()[0]);\r
- dialog.setFilterExtensions(new String[] {"*.xml", "*"}); //$NON-NLS-1$ //$NON-NLS-2$\r
- String path = dialog.open();\r
- if (path != null) {\r
- CustomTraceDefinition def = null;\r
- if (txtButton.getSelection()) {\r
- def = CustomTxtTraceDefinition.load(parserList.getSelection()[0]);\r
- } else if (xmlButton.getSelection()) {\r
- def = CustomXmlTraceDefinition.load(parserList.getSelection()[0]);\r
- }\r
- if (def != null) {\r
- def.save(path);\r
- }\r
- }\r
- }});\r
-\r
- fillParserList();\r
-\r
- getShell().setMinimumSize(300, 275);\r
- return composite;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)\r
- */\r
- @Override\r
- protected void createButtonsForButtonBar(Composite parent) {\r
- createButton(parent, IDialogConstants.OK_ID, IDialogConstants.CLOSE_LABEL, false);\r
- }\r
-\r
- private void fillParserList() {\r
- parserList.removeAll();\r
- if (txtButton.getSelection()) {\r
- for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {\r
- parserList.add(def.definitionName);\r
- }\r
- } else if (xmlButton.getSelection()) {\r
- for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {\r
- parserList.add(def.definitionName);\r
- }\r
- }\r
- editButton.setEnabled(false);\r
- deleteButton.setEnabled(false);\r
- exportButton.setEnabled(false);\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.dialogs;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards.CustomTxtParserWizard;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards.CustomXmlParserWizard;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Shell;
+
+public class ManageCustomParsersDialog extends Dialog {
+
+ private static final Image image = Activator.getDefault().getImageFromPath("/icons/etool16/customparser_wizard.gif"); //$NON-NLS-1$
+
+ Button txtButton;
+ Button xmlButton;
+ List parserList;
+ Button newButton;
+ Button editButton;
+ Button deleteButton;
+ Button importButton;
+ Button exportButton;
+
+ public ManageCustomParsersDialog(Shell parent) {
+ super(parent);
+ setShellStyle(SWT.RESIZE | SWT.MAX | getShellStyle());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ getShell().setText(Messages.ManageCustomParsersDialog_DialogHeader);
+ getShell().setImage(image);
+
+ Composite composite = (Composite) super.createDialogArea(parent);
+ composite.setLayout(new GridLayout(2, false));
+
+ Composite listContainer = new Composite(composite, SWT.NONE);
+ listContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ GridLayout lcgl = new GridLayout();
+ lcgl.marginHeight = 0;
+ lcgl.marginWidth = 0;
+ listContainer.setLayout(lcgl);
+
+ Composite radioContainer = new Composite(listContainer, SWT.NONE);
+ GridLayout rcgl = new GridLayout(2, true);
+ rcgl.marginHeight = 0;
+ rcgl.marginWidth = 0;
+ radioContainer.setLayout(rcgl);
+
+ txtButton = new Button(radioContainer, SWT.RADIO);
+ txtButton.setText(Messages.ManageCustomParsersDialog_TextButtonLabel);
+ txtButton.setSelection(true);
+ txtButton.addSelectionListener(new SelectionListener(){
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {}
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ fillParserList();
+ }});
+
+ xmlButton = new Button(radioContainer, SWT.RADIO);
+ xmlButton.setText("XML"); //$NON-NLS-1$
+ xmlButton.addSelectionListener(new SelectionListener(){
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {}
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ fillParserList();
+ }});
+
+ parserList = new List(listContainer, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
+ parserList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ parserList.addSelectionListener(new SelectionListener(){
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {}
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (parserList.getSelectionCount() == 0) {
+ editButton.setEnabled(false);
+ deleteButton.setEnabled(false);
+ exportButton.setEnabled(false);
+ } else {
+ editButton.setEnabled(true);
+ deleteButton.setEnabled(true);
+ exportButton.setEnabled(true);
+ }
+ }});
+
+ Composite buttonContainer = new Composite(composite, SWT.NULL);
+ buttonContainer.setLayout(new GridLayout());
+ buttonContainer.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, false, false));
+
+ newButton = new Button(buttonContainer, SWT.PUSH);
+ newButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
+ newButton.setText(Messages.ManageCustomParsersDialog_NewButtonLabel);
+ newButton.addSelectionListener(new SelectionListener(){
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {}
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ WizardDialog dialog = null;
+ if (txtButton.getSelection()) {
+ dialog = new WizardDialog(getShell(), new CustomTxtParserWizard());
+ } else if (xmlButton.getSelection()) {
+ dialog = new WizardDialog(getShell(), new CustomXmlParserWizard());
+ }
+ if (dialog != null) {
+ dialog.open();
+ if (dialog.getReturnCode() == Window.OK) {
+ fillParserList();
+ }
+ }
+ }});
+
+ editButton = new Button(buttonContainer, SWT.PUSH);
+ editButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
+ editButton.setText(Messages.ManageCustomParsersDialog_EditButtonLabel);
+ editButton.setEnabled(false);
+ editButton.addSelectionListener(new SelectionListener(){
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {}
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ WizardDialog dialog = null;
+ if (txtButton.getSelection()) {
+ dialog = new WizardDialog(getShell(),
+ new CustomTxtParserWizard(CustomTxtTraceDefinition.load(parserList.getSelection()[0])));
+ } else if (xmlButton.getSelection()) {
+ dialog = new WizardDialog(getShell(),
+ new CustomXmlParserWizard(CustomXmlTraceDefinition.load(parserList.getSelection()[0])));
+ }
+ if (dialog != null) {
+ dialog.open();
+ if (dialog.getReturnCode() == Window.OK) {
+ fillParserList();
+ }
+ }
+ }});
+
+ deleteButton = new Button(buttonContainer, SWT.PUSH);
+ deleteButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
+ deleteButton.setText(Messages.ManageCustomParsersDialog_DeleteButtonLabel);
+ deleteButton.setEnabled(false);
+ deleteButton.addSelectionListener(new SelectionListener(){
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {}
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ boolean confirm = MessageDialog.openQuestion(
+ getShell(),
+ Messages.ManageCustomParsersDialog_DeleteParserDialogHeader,
+ Messages.ManageCustomParsersDialog_DeleteConfirmation + parserList.getSelection()[0] + "?"); //$NON-NLS-1$
+ if (confirm) {
+ if (txtButton.getSelection()) {
+ CustomTxtTraceDefinition.delete(parserList.getSelection()[0]);
+ } else if (xmlButton.getSelection()) {
+ CustomXmlTraceDefinition.delete(parserList.getSelection()[0]);
+ }
+ fillParserList();
+ }
+ }});
+
+ new Label(buttonContainer, SWT.NONE); // filler
+
+ importButton = new Button(buttonContainer, SWT.PUSH);
+ importButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
+ importButton.setText(Messages.ManageCustomParsersDialog_ImportButtonLabel);
+ importButton.addSelectionListener(new SelectionListener(){
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {}
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.OPEN);
+ dialog.setText(Messages.ManageCustomParsersDialog_ImportParserSelection);
+ dialog.setFilterExtensions(new String[] {"*.xml", "*"}); //$NON-NLS-1$ //$NON-NLS-2$
+ String path = dialog.open();
+ if (path != null) {
+ CustomTraceDefinition[] defs = null;
+ if (txtButton.getSelection()) {
+ defs = CustomTxtTraceDefinition.loadAll(path);
+ } else if (xmlButton.getSelection()) {
+ defs = CustomXmlTraceDefinition.loadAll(path);
+ }
+ if (defs != null && defs.length > 0) {
+ for (CustomTraceDefinition def : defs) {
+ def.save();
+ }
+ fillParserList();
+ }
+ }
+ }});
+
+ exportButton = new Button(buttonContainer, SWT.PUSH);
+ exportButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
+ exportButton.setText(Messages.ManageCustomParsersDialog_ExportButtonLabel);
+ exportButton.setEnabled(false);
+ exportButton.addSelectionListener(new SelectionListener(){
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {}
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
+ dialog.setText(Messages.ManageCustomParsersDialog_ExportParserSelection + parserList.getSelection()[0]);
+ dialog.setFilterExtensions(new String[] {"*.xml", "*"}); //$NON-NLS-1$ //$NON-NLS-2$
+ String path = dialog.open();
+ if (path != null) {
+ CustomTraceDefinition def = null;
+ if (txtButton.getSelection()) {
+ def = CustomTxtTraceDefinition.load(parserList.getSelection()[0]);
+ } else if (xmlButton.getSelection()) {
+ def = CustomXmlTraceDefinition.load(parserList.getSelection()[0]);
+ }
+ if (def != null) {
+ def.save(path);
+ }
+ }
+ }});
+
+ fillParserList();
+
+ getShell().setMinimumSize(300, 275);
+ return composite;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.CLOSE_LABEL, false);
+ }
+
+ private void fillParserList() {
+ parserList.removeAll();
+ if (txtButton.getSelection()) {
+ for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
+ parserList.add(def.definitionName);
+ }
+ } else if (xmlButton.getSelection()) {
+ for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
+ parserList.add(def.definitionName);
+ }
+ }
+ editButton.setEnabled(false);
+ deleteButton.setEnabled(false);
+ exportButton.setEnabled(false);
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- * \r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- * \r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.editors.handlers;\r
-\r
-import org.eclipse.core.commands.AbstractHandler;\r
-import org.eclipse.core.commands.ExecutionEvent;\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;\r
-import org.eclipse.ui.IEditorPart;\r
-import org.eclipse.ui.IWorkbench;\r
-import org.eclipse.ui.IWorkbenchPage;\r
-import org.eclipse.ui.PlatformUI;\r
-\r
-public class AddBookmarkHandler extends AbstractHandler {\r
-\r
- @Override\r
- public boolean isEnabled() {\r
- return true;\r
- }\r
-\r
- @Override\r
- public Object execute(ExecutionEvent event) throws ExecutionException {\r
- IWorkbench wb = PlatformUI.getWorkbench();\r
- IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();\r
- IEditorPart activeEditor = activePage.getActiveEditor();\r
- if (activeEditor instanceof TmfEventsEditor) {\r
- TmfEventsEditor editor = (TmfEventsEditor) activeEditor;\r
- editor.addBookmark();\r
- }\r
- return null;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.editors.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+
+public class AddBookmarkHandler extends AbstractHandler {
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbench wb = PlatformUI.getWorkbench();
+ IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
+ IEditorPart activeEditor = activePage.getActiveEditor();
+ if (activeEditor instanceof TmfEventsEditor) {
+ TmfEventsEditor editor = (TmfEventsEditor) activeEditor;
+ editor.addBookmark();
+ }
+ return null;
+ }
+
+}
-# org.eclipse.linuxtools.tmf.ui.dialogs\r
-ManageCustomParsersDialog_DeleteButtonLabel=Delete\r
-ManageCustomParsersDialog_DeleteConfirmation=Are you sure you want to delete \r
-ManageCustomParsersDialog_DeleteParserDialogHeader=Delete Custom Parser\r
-ManageCustomParsersDialog_DialogHeader=Manage Custom Parsers\r
-ManageCustomParsersDialog_EditButtonLabel=Edit...\r
-ManageCustomParsersDialog_ExportButtonLabel=Export...\r
-ManageCustomParsersDialog_ExportParserSelection=Select file to export \r
-ManageCustomParsersDialog_ImportButtonLabel=Import...\r
-ManageCustomParsersDialog_ImportParserSelection=Select custom parser file to import\r
-ManageCustomParsersDialog_NewButtonLabel=New...\r
-ManageCustomParsersDialog_ParseButtonLabel=Parse...\r
-ManageCustomParsersDialog_ParseError=Parse Error\r
-ManageCustomParsersDialog_TextButtonLabel=Text\r
-ManageCustomParsersDialog_TraceSelection=Select log file to parse using \r
-\r
-# org.eclipse.linuxtools.tmf.ui.parsers.custom\r
-CustomTraceDefinition_messageTag=Message\r
-CustomTraceDefinition_otherTag=Other\r
-CustomTraceDefinition_timestampTag=Time Stamp\r
-CustomTxtTraceDefinition_action=action\r
-CustomTxtTraceDefinition_cardinality=Cardinality\r
-CustomTxtTraceDefinition_definition=Definition\r
-CustomTxtTraceDefinition_definitionRootElement=CustomTxtTraceDefinitionList\r
-CustomTxtTraceDefinition_format=format\r
-CustomTxtTraceDefinition_inputData=InputData\r
-CustomTxtTraceDefinition_inputLine=InputLine\r
-CustomTxtTraceDefinition_max=max\r
-CustomTxtTraceDefinition_min=min\r
-CustomTxtTraceDefinition_name=name\r
-CustomTxtTraceDefinition_outputColumn=OutputColumn\r
-CustomTxtTraceDefinition_regEx=RegEx\r
-CustomTxtTraceDefinition_timestampOutputFormat=TimeStampOutputFormat\r
-CustomXmlTraceDefinition_action=action\r
-CustomXmlTraceDefinition_attribute=Attribute\r
-CustomXmlTraceDefinition_definition=Definition\r
-CustomXmlTraceDefinition_definitionRootElement=CustomXMLTraceDefinitionList\r
-CustomXmlTraceDefinition_format=format\r
-CustomXmlTraceDefinition_ignoreTag=Ignore\r
-CustomXmlTraceDefinition_inputData=InputData\r
-CustomXmlTraceDefinition_inputElement=InputElement\r
-CustomXmlTraceDefinition_logEntry=logentry\r
-CustomXmlTraceDefinition_name=name\r
-CustomXmlTraceDefinition_outputColumn=OutputColumn\r
-CustomXmlTraceDefinition_timestampOutputFormat=TimeStampOutputFormat\r
-\r
-# org.eclipse.linuxtools.tmf.ui.viewers.events\r
-TmfEventsTable_AddBookmarkActionText=Add Bookmark...\r
-TmfEventsTable_AddBookmarkDialogText=Enter Bookmark name:\r
-TmfEventsTable_AddBookmarkDialogTitle=Add Bookmark\r
-TmfEventsTable_ApplyPresetFilterMenuName=Apply preset filter...\r
-TmfEventsTable_ClearFiltersActionText=Clear Filters\r
-TmfEventsTable_ContentColumnHeader=Content\r
-TmfEventsTable_FilterHint=<filter>\r
-TmfEventsTable_HideRawActionText=Hide Raw\r
-TmfEventsTable_HideTableActionText=Hide Table\r
-TmfEventsTable_ReferenceColumnHeader=File\r
-TmfEventsTable_RemoveBookmarkActionText=Remove Bookmark\r
-TmfEventsTable_SearchHint=<srch>\r
-TmfEventsTable_SearchingJobName=Searching...\r
-TmfEventsTable_ShowFilterBarActionText=Show Filter Bar\r
-TmfEventsTable_ShowRawActionText=Show Raw\r
-TmfEventsTable_ShowSearchBarActionText=Show Search Bar\r
-TmfEventsTable_ShowTableActionText=Show Table\r
-TmfEventsTable_SourceColumnHeader=Source\r
-TmfEventsTable_TimestampColumnHeader=Timestamp\r
-TmfEventsTable_TypeColumnHeader=Type\r
-\r
-# org.eclipse.linuxtools.tmf.ui.viewers.timegraph.dialogs\r
-TmfTimeFilterDialog_EDIT_PROFILING_OPTIONS=Edit Profiling Options\r
-TmfTimeFilterDialog_TRACE_FILTER=Trace Filter\r
-TmfTimeFilterDialog_TRACE_FILTER_DESC=Define the filter set\r
-TmfTimeFilterDialog_TRACE_ID=Trace Id\r
-TmfTimeFilterDialog_TRACE_NAME=Trace Name\r
-TmfTimeLegend_LEGEND=Legend\r
-TmfTimeLegend_TRACE_STATES=Trace\r
-TmfTimeLegend_TRACE_STATES_TITLE=States Transition Visualizer\r
-TmfTimeLegend_WINDOW_TITLE=Trace Visualizer's Legend\r
-TmfTimeLegend_StateTypeName=States\r
-\r
-# org.eclipse.linuxtools.tmf.ui.viewers.timegraph.widgets\r
-TmfTimeTipHandler_DURATION=Duration\r
-TmfTimeTipHandler_TRACE_DATE=Date\r
-TmfTimeTipHandler_TRACE_EVENT_TIME=Event Time\r
-TmfTimeTipHandler_TRACE_START_TIME=Start Time\r
-TmfTimeTipHandler_TRACE_STATE=State\r
-TmfTimeTipHandler_TRACE_STOP_TIME=Stop Time\r
-\r
-\r
-TmfTimeGraphViewer_ResetScaleActionNameText=Reset\r
-TmfTimeGraphViewer_ResetScaleActionToolTipText=Reset the Time Scale to Default\r
-TmfTimeGraphViewer_LegendActionNameText=Legend\r
-TmfTimeGraphViewer_LegendActionToolTipText=Show Legend\r
-TmfTimeGraphViewer_NextEventActionNameText=Next Event\r
-TmfTimeGraphViewer_NextEventActionToolTipText=Select Next Event\r
-TmfTimeGraphViewer_PreviousEventActionNameText=Previous Event\r
-TmfTimeGraphViewer_PreviousEventActionToolTipText=Select Previous Event\r
-TmfTimeGraphViewer_NextItemActionNameText=Next Item\r
-TmfTimeGraphViewer_NextItemActionToolTipText=Select Next Item\r
-TmfTimeGraphViewer_PreviousItemActionNameText=Previous Item\r
-TmfTimeGraphViewer_PreviousItemActionToolTipText=Select Previous Item\r
-TmfTimeGraphViewer_ZoomInActionNameText=Zoom In\r
-TmfTimeGraphViewer_ZoomInActionToolTipText=Zoom In\r
-TmfTimeGraphViewer_ZoomOutActionNameText=Zoom Out\r
-TmfTimeGraphViewer_ZoomOutActionToolTipText=Zoom Out\r
-\r
-# org.eclipse.linuxtools.tmf.ui.views.colors\r
-ColorsView_AddActionToolTipText=Insert new color setting\r
-ColorsView_BackgroundButtonText=BG\r
-ColorsView_BackgroundDialogText=Set background color\r
-ColorsView_DeleteActionToolTipText=Delete color setting\r
-ColorsView_ExportActionToolTipText=Export color settings\r
-ColorsView_FilterButtonText=Filter...\r
-ColorsView_ForegroundButtonText=FG\r
-ColorsView_ForegroundDialogText=Set foreground color\r
-ColorsView_ImportActionToolTipText=Import color settings\r
-ColorsView_ImportOverwriteDialogMessage1=Do you want to overwrite the current color settings?\n\r
-ColorsView_ImportOverwriteDialogMessage2=Answering No will insert the imported settings above the current selection.\r
-ColorsView_ImportOverwriteDialogTitle=Overwrite current settings\r
-ColorsView_MoveDownActionToolTipText=Decrease priority\r
-ColorsView_MoveUpActionToolTipText=Increase priority\r
-ColorsView_TickButtonText=Tick\r
-TickColorDialog_TickColorDialogTitle=Choose tick color\r
-\r
-# org.eclipse.linuxtools.tmf.ui.wizards\r
-CustomTxtParserInputWizardPage_addChildLine=Add child line\r
-CustomTxtParserInputWizardPage_addGroup=Add group\r
-CustomTxtParserInputWizardPage_addNextLine=Add next line\r
-CustomTxtParserInputWizardPage_append=Append\r
-CustomTxtParserInputWizardPage_appendWith=Append with |\r
-CustomTxtParserInputWizardPage_capturedGroup=Captured group\r
-CustomTxtParserInputWizardPage_cardinality=Cardinality:\r
-CustomTxtParserInputWizardPage_dateFormatHelp=Date Format Help\r
-CustomTxtParserInputWizardPage_desccriptionEdit=Edit an existing custom parser for text log files\r
-CustomTxtParserInputWizardPage_descriptionNew=Create a new custom parser for text log files\r
-CustomTxtParserInputWizardPage_format=format:\r
-CustomTxtParserInputWizardPage_group=Group \r
-CustomTxtParserInputWizardPage_highlightAll=Highlight All\r
-CustomTxtParserInputWizardPage_logType=Log type:\r
-CustomTxtParserInputWizardPage_matchingLineRoot=Matching root line : \r
-CustomTxtParserInputWizardPage_matchingOtherLine=Matching other line: \r
-CustomTxtParserInputWizardPage_matchingRootLine=matchingRootLine\r
-CustomTxtParserInputWizardPage_max=max:\r
-CustomTxtParserInputWizardPage_min=min:\r
-CustomTxtParserInputWizardPage_moveDown=Move down\r
-CustomTxtParserInputWizardPage_moveUp=Move up\r
-CustomTxtParserInputWizardPage_name=name:\r
-CustomTxtParserInputWizardPage_newGroup=New group\r
-CustomTxtParserInputWizardPage_noMatch=*no match*\r
-CustomTxtParserInputWizardPage_noMatchingGroup=*no matching group*\r
-CustomTxtParserInputWizardPage_noMatchingLine=*no matching line*\r
-CustomTxtParserInputWizardPage_noMatchingTimestamp=*no matching timestamp*\r
-CustomTxtParserInputWizardPage_noMathcingLine=*no matching line*\r
-CustomTxtParserInputWizardPage_nonMatchingLine=Non-matching line\n\r
-CustomTxtParserInputWizardPage_noTimestampGroup=*no timestamp group*\r
-CustomTxtParserInputWizardPage_preview=Preview:\r
-CustomTxtParserInputWizardPage_previewInput=Preview input\r
-CustomTxtParserInputWizardPage_previewLegend=Preview Legend\r
-CustomTxtParserInputWizardPage_regularExpression=Regular expression:\r
-CustomTxtParserInputWizardPage_regularExpressionHelp=Regular Expression Help\r
-CustomTxtParserInputWizardPage_removeGroup=Remove group\r
-CustomTxtParserInputWizardPage_removeLine=Remove line\r
-CustomTxtParserInputWizardPage_set=Set\r
-CustomTxtParserInputWizardPage_timestampFormat=Time Stamp format:\r
-CustomTxtParserInputWizardPage_uncapturedText=Uncaptured text\r
-CustomTxtParserInputWizardPage_unidentifiedCaptureGroup=Unidentified captured group\r
-CustomTxtParserInputWizardPage_windowTitleEdit=Edit Custom Text Parser\r
-CustomTxtParserInputWizardPage_windowTitleNew=New Custom Text Parser\r
-CustomTxtParserOutputWizardPage_description=Customize the output of the parser\r
-CustomTxtParserOutputWizardPage_moveAfter=Move After\r
-CustomTxtParserOutputWizardPage_moveBefore=Move Before\r
-CustomTxtParserOutputWizardPage_visible=Visible\r
-CustomXmlParserInputWizardPage_emptyLogTypeError=Enter a name for the new log type. \r
-CustomXmlParserInputWizardPage_duplicatelogTypeError=The log type name already exists. \r
-CustomXmlParserInputWizardPage_noDocumentError=Add a document element. \r
-CustomXmlParserInputWizardPage_missingLogEntryError=Identify a Log Entry element. \r
-CustomXmlParserInputWizardPage_missingTimestampFmtError=Enter the output format for the Time Stamp field. \r
-CustomXmlParserInputWizardPage_invalidTimestampFmtError=Enter a valid output format for the Time Stamp field. \r
-CustomXmlParserInputWizardPage_notimestamporAttributeError=*no time stamp element or attribute*\r
-CustomXmlParserInputWizardPage_missingDocumentElementError=Enter a name for the document element. \r
-CustomXmlParserInputWizardPage_timestampElementPrompt=Element\r
-CustomXmlParserInputWizardPage_timestampFormatPrompt=Enter the input format for the Time Stamp\r
-CustomXmlParserInputWizardPage_missingInputElementNameError=Enter a name for the input\r
-CustomXmlParserInputWizardPage_attributePrompt=Attribute\r
-CustomXmlParserInputWizardPage_missingAttribute=Enter a name for the attribute\r
-CustomXmlParserInputWizardPage_duplicateAttributeError=Duplicate attribute names\r
-CustomXmlParserInputWizardPage_missingTimestampInFmtError=Enter the input format for the Time Stamp\r
-CustomXmlParserInputWizardPage_invalidTimestampInFmtError=Enter a valid input format for the Time Stamp\r
-CustomXmlParserInputWizardPage_missingDataGroupNameError=Enter a name for the data group\r
-CustomXmlParserInputWizardPage_missingElementNameError=Enter a name for the element\r
-CustomXmlParserInputWizardPage_duplicateElementNameError=Duplicate element names \r
-CustomXmlParserInputWizardPage_addAttribute=Add attribute\r
-CustomXmlParserInputWizardPage_addChildElement=Add child element\r
-CustomXmlParserInputWizardPage_addDocumentEleemnt=Add document element\r
-CustomXmlParserInputWizardPage_addDocumentElement=Add document element\r
-CustomXmlParserInputWizardPage_addNextElement=Add next element\r
-CustomXmlParserInputWizardPage_append=Append\r
-CustomXmlParserInputWizardPage_appendWith=Append with |\r
-CustomXmlParserInputWizardPage_attibute=Attribute\r
-CustomXmlParserInputWizardPage_dateFormatHelp=Date Format Help\r
-CustomXmlParserInputWizardPage_descriptionEdit=Edit an existing custom parser for XML log files\r
-CustomXmlParserInputWizardPage_descriptionNew=Create a new custom parser for XML log files\r
-CustomXmlParserInputWizardPage_elementName=Element name:\r
-CustomXmlParserInputWizardPage_feelingLucky=Feeling lucky\r
-CustomXmlParserInputWizardPage_format=format:\r
-CustomXmlParserInputWizardPage_logEntry=Log Entry\r
-CustomXmlParserInputWizardPage_logType=Log type:\r
-CustomXmlParserInputWizardPage_moveDown=Move down\r
-CustomXmlParserInputWizardPage_moveUp=Move up\r
-CustomXmlParserInputWizardPage_name=name:\r
-CustomXmlParserInputWizardPage_newAttibute=New attribute\r
-CustomXmlParserInputWizardPage_noMatch=*no match*\r
-CustomXmlParserInputWizardPage_noMatchingAttribute=*no matching attribute*\r
-CustomXmlParserInputWizardPage_noMatchingElement=*no matching element*\r
-CustomXmlParserInputWizardPage_preview=Preview:\r
-CustomXmlParserInputWizardPage_previewInput=Preview input\r
-CustomXmlParserInputWizardPage_removeAttribute=Remove attribute\r
-CustomXmlParserInputWizardPage_removeElement=Remove element\r
-CustomXmlParserInputWizardPage_set=Set\r
-CustomXmlParserInputWizardPage_tagName=tag name:\r
-CustomXmlParserInputWizardPage_timestampFormat=Time Stamp format:\r
-CustomXmlParserInputWizardPage_titleEdit=Edit Custom XML Parser\r
-CustomXmlParserInputWizardPage_titleNew=New Custom XML Parser\r
-CustomXmlParserOutputWizardPage_description=Customize the output of the parser\r
-CustomXmlParserOutputWizardPage_moveAfter=Move After\r
-CustomXmlParserOutputWizardPage_moveBefore=Move Before\r
-CustomXmlParserOutputWizardPage_visible=Visible\r
-\r
-# org.eclipse.linuxtools.tmf.ui.views.filter\r
-FilterDialog_FilterDialogTitle=Edit filter\r
-FilterView_AddActionToolTipText=Add new filter\r
-FilterView_DeleteActionToolTipText=Delete filter node\r
-FilterView_ExportActionToolTipText=Export filters\r
-FilterView_FileDialogFilterName=TMF Filter files\r
-FilterView_ImportActionToolTipText=Import filters\r
-FilterView_SaveActionToolTipText=Save filters\r
-FilterViewer_EmptyTreeHintText=<Right-click to add filter node>\r
-FilterViewer_CommonCategory=[common]\r
-FilterViewer_AlphaButtonText=Alpha\r
-FilterViewer_DeleteActionText=Delete\r
-FilterViewer_FieldLabel=field:\r
-FilterViewer_FilterNameHint=type filter name\r
-FilterViewer_IgnoreCaseButtonText=ignore case\r
-FilterViewer_NameLabel=name:\r
-FilterViewer_NewPrefix=New\r
-FilterViewer_NotLabel=not:\r
-FilterViewer_NumButtonText=Num\r
-FilterViewer_RegexHint=type regular expression\r
-FilterViewer_RegexLabel=regex:\r
-FilterViewer_ResultLabel=result:\r
-FilterViewer_TimestampButtonText=Timestamp\r
-FilterViewer_TypeLabel=type:\r
-FilterViewer_ValueHint=type value\r
-FilterViewer_ValueLabel=value:\r
-\r
-TmfView_PinActionNameText=Pin View\r
-TmfView_PinActionToolTipText=Pin View\r
-\r
+# org.eclipse.linuxtools.tmf.ui.dialogs
+ManageCustomParsersDialog_DeleteButtonLabel=Delete
+ManageCustomParsersDialog_DeleteConfirmation=Are you sure you want to delete
+ManageCustomParsersDialog_DeleteParserDialogHeader=Delete Custom Parser
+ManageCustomParsersDialog_DialogHeader=Manage Custom Parsers
+ManageCustomParsersDialog_EditButtonLabel=Edit...
+ManageCustomParsersDialog_ExportButtonLabel=Export...
+ManageCustomParsersDialog_ExportParserSelection=Select file to export
+ManageCustomParsersDialog_ImportButtonLabel=Import...
+ManageCustomParsersDialog_ImportParserSelection=Select custom parser file to import
+ManageCustomParsersDialog_NewButtonLabel=New...
+ManageCustomParsersDialog_ParseButtonLabel=Parse...
+ManageCustomParsersDialog_ParseError=Parse Error
+ManageCustomParsersDialog_TextButtonLabel=Text
+ManageCustomParsersDialog_TraceSelection=Select log file to parse using
+
+# org.eclipse.linuxtools.tmf.ui.parsers.custom
+CustomTraceDefinition_messageTag=Message
+CustomTraceDefinition_otherTag=Other
+CustomTraceDefinition_timestampTag=Time Stamp
+CustomTxtTraceDefinition_action=action
+CustomTxtTraceDefinition_cardinality=Cardinality
+CustomTxtTraceDefinition_definition=Definition
+CustomTxtTraceDefinition_definitionRootElement=CustomTxtTraceDefinitionList
+CustomTxtTraceDefinition_format=format
+CustomTxtTraceDefinition_inputData=InputData
+CustomTxtTraceDefinition_inputLine=InputLine
+CustomTxtTraceDefinition_max=max
+CustomTxtTraceDefinition_min=min
+CustomTxtTraceDefinition_name=name
+CustomTxtTraceDefinition_outputColumn=OutputColumn
+CustomTxtTraceDefinition_regEx=RegEx
+CustomTxtTraceDefinition_timestampOutputFormat=TimeStampOutputFormat
+CustomXmlTraceDefinition_action=action
+CustomXmlTraceDefinition_attribute=Attribute
+CustomXmlTraceDefinition_definition=Definition
+CustomXmlTraceDefinition_definitionRootElement=CustomXMLTraceDefinitionList
+CustomXmlTraceDefinition_format=format
+CustomXmlTraceDefinition_ignoreTag=Ignore
+CustomXmlTraceDefinition_inputData=InputData
+CustomXmlTraceDefinition_inputElement=InputElement
+CustomXmlTraceDefinition_logEntry=logentry
+CustomXmlTraceDefinition_name=name
+CustomXmlTraceDefinition_outputColumn=OutputColumn
+CustomXmlTraceDefinition_timestampOutputFormat=TimeStampOutputFormat
+
+# org.eclipse.linuxtools.tmf.ui.viewers.events
+TmfEventsTable_AddBookmarkActionText=Add Bookmark...
+TmfEventsTable_AddBookmarkDialogText=Enter Bookmark name:
+TmfEventsTable_AddBookmarkDialogTitle=Add Bookmark
+TmfEventsTable_ApplyPresetFilterMenuName=Apply preset filter...
+TmfEventsTable_ClearFiltersActionText=Clear Filters
+TmfEventsTable_ContentColumnHeader=Content
+TmfEventsTable_FilterHint=<filter>
+TmfEventsTable_HideRawActionText=Hide Raw
+TmfEventsTable_HideTableActionText=Hide Table
+TmfEventsTable_ReferenceColumnHeader=File
+TmfEventsTable_RemoveBookmarkActionText=Remove Bookmark
+TmfEventsTable_SearchHint=<srch>
+TmfEventsTable_SearchingJobName=Searching...
+TmfEventsTable_ShowFilterBarActionText=Show Filter Bar
+TmfEventsTable_ShowRawActionText=Show Raw
+TmfEventsTable_ShowSearchBarActionText=Show Search Bar
+TmfEventsTable_ShowTableActionText=Show Table
+TmfEventsTable_SourceColumnHeader=Source
+TmfEventsTable_TimestampColumnHeader=Timestamp
+TmfEventsTable_TypeColumnHeader=Type
+
+# org.eclipse.linuxtools.tmf.ui.viewers.timegraph.dialogs
+TmfTimeFilterDialog_EDIT_PROFILING_OPTIONS=Edit Profiling Options
+TmfTimeFilterDialog_TRACE_FILTER=Trace Filter
+TmfTimeFilterDialog_TRACE_FILTER_DESC=Define the filter set
+TmfTimeFilterDialog_TRACE_ID=Trace Id
+TmfTimeFilterDialog_TRACE_NAME=Trace Name
+TmfTimeLegend_LEGEND=Legend
+TmfTimeLegend_TRACE_STATES=Trace
+TmfTimeLegend_TRACE_STATES_TITLE=States Transition Visualizer
+TmfTimeLegend_WINDOW_TITLE=Trace Visualizer's Legend
+TmfTimeLegend_StateTypeName=States
+
+# org.eclipse.linuxtools.tmf.ui.viewers.timegraph.widgets
+TmfTimeTipHandler_DURATION=Duration
+TmfTimeTipHandler_TRACE_DATE=Date
+TmfTimeTipHandler_TRACE_EVENT_TIME=Event Time
+TmfTimeTipHandler_TRACE_START_TIME=Start Time
+TmfTimeTipHandler_TRACE_STATE=State
+TmfTimeTipHandler_TRACE_STOP_TIME=Stop Time
+
+
+TmfTimeGraphViewer_ResetScaleActionNameText=Reset
+TmfTimeGraphViewer_ResetScaleActionToolTipText=Reset the Time Scale to Default
+TmfTimeGraphViewer_LegendActionNameText=Legend
+TmfTimeGraphViewer_LegendActionToolTipText=Show Legend
+TmfTimeGraphViewer_NextEventActionNameText=Next Event
+TmfTimeGraphViewer_NextEventActionToolTipText=Select Next Event
+TmfTimeGraphViewer_PreviousEventActionNameText=Previous Event
+TmfTimeGraphViewer_PreviousEventActionToolTipText=Select Previous Event
+TmfTimeGraphViewer_NextItemActionNameText=Next Item
+TmfTimeGraphViewer_NextItemActionToolTipText=Select Next Item
+TmfTimeGraphViewer_PreviousItemActionNameText=Previous Item
+TmfTimeGraphViewer_PreviousItemActionToolTipText=Select Previous Item
+TmfTimeGraphViewer_ZoomInActionNameText=Zoom In
+TmfTimeGraphViewer_ZoomInActionToolTipText=Zoom In
+TmfTimeGraphViewer_ZoomOutActionNameText=Zoom Out
+TmfTimeGraphViewer_ZoomOutActionToolTipText=Zoom Out
+
+# org.eclipse.linuxtools.tmf.ui.views.colors
+ColorsView_AddActionToolTipText=Insert new color setting
+ColorsView_BackgroundButtonText=BG
+ColorsView_BackgroundDialogText=Set background color
+ColorsView_DeleteActionToolTipText=Delete color setting
+ColorsView_ExportActionToolTipText=Export color settings
+ColorsView_FilterButtonText=Filter...
+ColorsView_ForegroundButtonText=FG
+ColorsView_ForegroundDialogText=Set foreground color
+ColorsView_ImportActionToolTipText=Import color settings
+ColorsView_ImportOverwriteDialogMessage1=Do you want to overwrite the current color settings?\n
+ColorsView_ImportOverwriteDialogMessage2=Answering No will insert the imported settings above the current selection.
+ColorsView_ImportOverwriteDialogTitle=Overwrite current settings
+ColorsView_MoveDownActionToolTipText=Decrease priority
+ColorsView_MoveUpActionToolTipText=Increase priority
+ColorsView_TickButtonText=Tick
+TickColorDialog_TickColorDialogTitle=Choose tick color
+
+# org.eclipse.linuxtools.tmf.ui.wizards
+CustomTxtParserInputWizardPage_addChildLine=Add child line
+CustomTxtParserInputWizardPage_addGroup=Add group
+CustomTxtParserInputWizardPage_addNextLine=Add next line
+CustomTxtParserInputWizardPage_append=Append
+CustomTxtParserInputWizardPage_appendWith=Append with |
+CustomTxtParserInputWizardPage_capturedGroup=Captured group
+CustomTxtParserInputWizardPage_cardinality=Cardinality:
+CustomTxtParserInputWizardPage_dateFormatHelp=Date Format Help
+CustomTxtParserInputWizardPage_desccriptionEdit=Edit an existing custom parser for text log files
+CustomTxtParserInputWizardPage_descriptionNew=Create a new custom parser for text log files
+CustomTxtParserInputWizardPage_format=format:
+CustomTxtParserInputWizardPage_group=Group
+CustomTxtParserInputWizardPage_highlightAll=Highlight All
+CustomTxtParserInputWizardPage_logType=Log type:
+CustomTxtParserInputWizardPage_matchingLineRoot=Matching root line :
+CustomTxtParserInputWizardPage_matchingOtherLine=Matching other line:
+CustomTxtParserInputWizardPage_matchingRootLine=matchingRootLine
+CustomTxtParserInputWizardPage_max=max:
+CustomTxtParserInputWizardPage_min=min:
+CustomTxtParserInputWizardPage_moveDown=Move down
+CustomTxtParserInputWizardPage_moveUp=Move up
+CustomTxtParserInputWizardPage_name=name:
+CustomTxtParserInputWizardPage_newGroup=New group
+CustomTxtParserInputWizardPage_noMatch=*no match*
+CustomTxtParserInputWizardPage_noMatchingGroup=*no matching group*
+CustomTxtParserInputWizardPage_noMatchingLine=*no matching line*
+CustomTxtParserInputWizardPage_noMatchingTimestamp=*no matching timestamp*
+CustomTxtParserInputWizardPage_noMathcingLine=*no matching line*
+CustomTxtParserInputWizardPage_nonMatchingLine=Non-matching line\n
+CustomTxtParserInputWizardPage_noTimestampGroup=*no timestamp group*
+CustomTxtParserInputWizardPage_preview=Preview:
+CustomTxtParserInputWizardPage_previewInput=Preview input
+CustomTxtParserInputWizardPage_previewLegend=Preview Legend
+CustomTxtParserInputWizardPage_regularExpression=Regular expression:
+CustomTxtParserInputWizardPage_regularExpressionHelp=Regular Expression Help
+CustomTxtParserInputWizardPage_removeGroup=Remove group
+CustomTxtParserInputWizardPage_removeLine=Remove line
+CustomTxtParserInputWizardPage_set=Set
+CustomTxtParserInputWizardPage_timestampFormat=Time Stamp format:
+CustomTxtParserInputWizardPage_uncapturedText=Uncaptured text
+CustomTxtParserInputWizardPage_unidentifiedCaptureGroup=Unidentified captured group
+CustomTxtParserInputWizardPage_windowTitleEdit=Edit Custom Text Parser
+CustomTxtParserInputWizardPage_windowTitleNew=New Custom Text Parser
+CustomTxtParserOutputWizardPage_description=Customize the output of the parser
+CustomTxtParserOutputWizardPage_moveAfter=Move After
+CustomTxtParserOutputWizardPage_moveBefore=Move Before
+CustomTxtParserOutputWizardPage_visible=Visible
+CustomXmlParserInputWizardPage_emptyLogTypeError=Enter a name for the new log type.
+CustomXmlParserInputWizardPage_duplicatelogTypeError=The log type name already exists.
+CustomXmlParserInputWizardPage_noDocumentError=Add a document element.
+CustomXmlParserInputWizardPage_missingLogEntryError=Identify a Log Entry element.
+CustomXmlParserInputWizardPage_missingTimestampFmtError=Enter the output format for the Time Stamp field.
+CustomXmlParserInputWizardPage_invalidTimestampFmtError=Enter a valid output format for the Time Stamp field.
+CustomXmlParserInputWizardPage_notimestamporAttributeError=*no time stamp element or attribute*
+CustomXmlParserInputWizardPage_missingDocumentElementError=Enter a name for the document element.
+CustomXmlParserInputWizardPage_timestampElementPrompt=Element
+CustomXmlParserInputWizardPage_timestampFormatPrompt=Enter the input format for the Time Stamp
+CustomXmlParserInputWizardPage_missingInputElementNameError=Enter a name for the input
+CustomXmlParserInputWizardPage_attributePrompt=Attribute
+CustomXmlParserInputWizardPage_missingAttribute=Enter a name for the attribute
+CustomXmlParserInputWizardPage_duplicateAttributeError=Duplicate attribute names
+CustomXmlParserInputWizardPage_missingTimestampInFmtError=Enter the input format for the Time Stamp
+CustomXmlParserInputWizardPage_invalidTimestampInFmtError=Enter a valid input format for the Time Stamp
+CustomXmlParserInputWizardPage_missingDataGroupNameError=Enter a name for the data group
+CustomXmlParserInputWizardPage_missingElementNameError=Enter a name for the element
+CustomXmlParserInputWizardPage_duplicateElementNameError=Duplicate element names
+CustomXmlParserInputWizardPage_addAttribute=Add attribute
+CustomXmlParserInputWizardPage_addChildElement=Add child element
+CustomXmlParserInputWizardPage_addDocumentEleemnt=Add document element
+CustomXmlParserInputWizardPage_addDocumentElement=Add document element
+CustomXmlParserInputWizardPage_addNextElement=Add next element
+CustomXmlParserInputWizardPage_append=Append
+CustomXmlParserInputWizardPage_appendWith=Append with |
+CustomXmlParserInputWizardPage_attibute=Attribute
+CustomXmlParserInputWizardPage_dateFormatHelp=Date Format Help
+CustomXmlParserInputWizardPage_descriptionEdit=Edit an existing custom parser for XML log files
+CustomXmlParserInputWizardPage_descriptionNew=Create a new custom parser for XML log files
+CustomXmlParserInputWizardPage_elementName=Element name:
+CustomXmlParserInputWizardPage_feelingLucky=Feeling lucky
+CustomXmlParserInputWizardPage_format=format:
+CustomXmlParserInputWizardPage_logEntry=Log Entry
+CustomXmlParserInputWizardPage_logType=Log type:
+CustomXmlParserInputWizardPage_moveDown=Move down
+CustomXmlParserInputWizardPage_moveUp=Move up
+CustomXmlParserInputWizardPage_name=name:
+CustomXmlParserInputWizardPage_newAttibute=New attribute
+CustomXmlParserInputWizardPage_noMatch=*no match*
+CustomXmlParserInputWizardPage_noMatchingAttribute=*no matching attribute*
+CustomXmlParserInputWizardPage_noMatchingElement=*no matching element*
+CustomXmlParserInputWizardPage_preview=Preview:
+CustomXmlParserInputWizardPage_previewInput=Preview input
+CustomXmlParserInputWizardPage_removeAttribute=Remove attribute
+CustomXmlParserInputWizardPage_removeElement=Remove element
+CustomXmlParserInputWizardPage_set=Set
+CustomXmlParserInputWizardPage_tagName=tag name:
+CustomXmlParserInputWizardPage_timestampFormat=Time Stamp format:
+CustomXmlParserInputWizardPage_titleEdit=Edit Custom XML Parser
+CustomXmlParserInputWizardPage_titleNew=New Custom XML Parser
+CustomXmlParserOutputWizardPage_description=Customize the output of the parser
+CustomXmlParserOutputWizardPage_moveAfter=Move After
+CustomXmlParserOutputWizardPage_moveBefore=Move Before
+CustomXmlParserOutputWizardPage_visible=Visible
+
+# org.eclipse.linuxtools.tmf.ui.views.filter
+FilterDialog_FilterDialogTitle=Edit filter
+FilterView_AddActionToolTipText=Add new filter
+FilterView_DeleteActionToolTipText=Delete filter node
+FilterView_ExportActionToolTipText=Export filters
+FilterView_FileDialogFilterName=TMF Filter files
+FilterView_ImportActionToolTipText=Import filters
+FilterView_SaveActionToolTipText=Save filters
+FilterViewer_EmptyTreeHintText=<Right-click to add filter node>
+FilterViewer_CommonCategory=[common]
+FilterViewer_AlphaButtonText=Alpha
+FilterViewer_DeleteActionText=Delete
+FilterViewer_FieldLabel=field:
+FilterViewer_FilterNameHint=type filter name
+FilterViewer_IgnoreCaseButtonText=ignore case
+FilterViewer_NameLabel=name:
+FilterViewer_NewPrefix=New
+FilterViewer_NotLabel=not:
+FilterViewer_NumButtonText=Num
+FilterViewer_RegexHint=type regular expression
+FilterViewer_RegexLabel=regex:
+FilterViewer_ResultLabel=result:
+FilterViewer_TimestampButtonText=Timestamp
+FilterViewer_TypeLabel=type:
+FilterViewer_ValueHint=type value
+FilterViewer_ValueLabel=value:
+
+TmfView_PinActionNameText=Pin View
+TmfView_PinActionToolTipText=Pin View
+
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r
-\r
-import java.text.ParseException;\r
-import java.text.SimpleDateFormat;\r
-import java.util.Arrays;\r
-import java.util.Date;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEventField;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEventType;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-\r
-public class CustomEvent extends TmfEvent {\r
-\r
- protected static final String TIMESTAMP_INPUT_FORMAT_KEY = "CE_TS_I_F"; //$NON-NLS-1$\r
- protected static final String NO_MESSAGE = ""; //$NON-NLS-1$\r
- public static final byte TIMESTAMP_SCALE = -3;\r
-\r
- protected CustomTraceDefinition fDefinition;\r
- protected Map<String, String> fData;\r
- private TmfEventField[] fColumnData;\r
-\r
- public CustomEvent(CustomTraceDefinition definition) {\r
- fDefinition = definition;\r
- fData = new HashMap<String, String>();\r
- }\r
-\r
- public CustomEvent(CustomTraceDefinition definition, TmfEvent other) {\r
- super(other);\r
- fDefinition = definition;\r
- fData = new HashMap<String, String>();\r
- }\r
-\r
- public CustomEvent(CustomTraceDefinition definition, ITmfTrace parentTrace, ITmfTimestamp timestamp, String source, TmfEventType type, String reference) {\r
- super(parentTrace, timestamp, source, type, null, reference);\r
- fDefinition = definition;\r
- fData = new HashMap<String, String>();\r
- }\r
-\r
- @Override\r
- public ITmfTimestamp getTimestamp() {\r
- if (fData != null) {\r
- processData();\r
- }\r
- return super.getTimestamp();\r
- }\r
-\r
- public TmfEventField[] extractItemFields() {\r
- if (fData != null) {\r
- processData();\r
- }\r
- return Arrays.copyOf(fColumnData, fColumnData.length);\r
- }\r
-\r
- private void processData() {\r
- String timeStampString = fData.get(CustomTraceDefinition.TAG_TIMESTAMP);\r
- String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);\r
- Date date = null;\r
- if (timeStampInputFormat != null && timeStampString != null) {\r
- SimpleDateFormat dateFormat = new SimpleDateFormat(timeStampInputFormat);\r
- try {\r
- date = dateFormat.parse(timeStampString);\r
- setTimestamp(new TmfTimestamp(date.getTime(), TIMESTAMP_SCALE));\r
- } catch (ParseException e) {\r
- setTimestamp(TmfTimestamp.ZERO);\r
- }\r
- } else {\r
- setTimestamp(TmfTimestamp.ZERO);\r
- }\r
-\r
- int i = 0;\r
- fColumnData = new TmfEventField[fDefinition.outputs.size()];\r
- for (OutputColumn outputColumn : fDefinition.outputs) {\r
- String value = fData.get(outputColumn.name);\r
- if (outputColumn.name.equals(CustomTraceDefinition.TAG_TIMESTAMP) && date != null) {\r
- SimpleDateFormat dateFormat = new SimpleDateFormat(fDefinition.timeStampOutputFormat);\r
- fColumnData[i++] = new TmfEventField(outputColumn.name, dateFormat.format(date));\r
- } else {\r
- fColumnData[i++] = new TmfEventField(outputColumn.name, (value != null ? value : "")); //$NON-NLS-1$\r
- }\r
- }\r
- CustomEventContent content = (CustomEventContent) getContent();\r
- content.setFields(fColumnData);\r
- fData = null;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#hashCode()\r
- */\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = super.hashCode();\r
- result = prime * result + ((fDefinition == null) ? 0 : fDefinition.hashCode());\r
- return result;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#equals(java.lang.Object)\r
- */\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj) {\r
- return true;\r
- }\r
- if (!super.equals(obj)) {\r
- return false;\r
- }\r
- if (!(obj instanceof CustomEvent)) {\r
- return false;\r
- }\r
- CustomEvent other = (CustomEvent) obj;\r
- if (fDefinition == null) {\r
- if (other.fDefinition != null) {\r
- return false;\r
- }\r
- } else if (!fDefinition.equals(other.fDefinition)) {\r
- return false;\r
- }\r
- return true;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.parsers.custom;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;
+import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
+import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+
+public class CustomEvent extends TmfEvent {
+
+ protected static final String TIMESTAMP_INPUT_FORMAT_KEY = "CE_TS_I_F"; //$NON-NLS-1$
+ protected static final String NO_MESSAGE = ""; //$NON-NLS-1$
+ public static final byte TIMESTAMP_SCALE = -3;
+
+ protected CustomTraceDefinition fDefinition;
+ protected Map<String, String> fData;
+ private TmfEventField[] fColumnData;
+
+ public CustomEvent(CustomTraceDefinition definition) {
+ fDefinition = definition;
+ fData = new HashMap<String, String>();
+ }
+
+ public CustomEvent(CustomTraceDefinition definition, TmfEvent other) {
+ super(other);
+ fDefinition = definition;
+ fData = new HashMap<String, String>();
+ }
+
+ public CustomEvent(CustomTraceDefinition definition, ITmfTrace parentTrace, ITmfTimestamp timestamp, String source, TmfEventType type, String reference) {
+ super(parentTrace, timestamp, source, type, null, reference);
+ fDefinition = definition;
+ fData = new HashMap<String, String>();
+ }
+
+ @Override
+ public ITmfTimestamp getTimestamp() {
+ if (fData != null) {
+ processData();
+ }
+ return super.getTimestamp();
+ }
+
+ public TmfEventField[] extractItemFields() {
+ if (fData != null) {
+ processData();
+ }
+ return Arrays.copyOf(fColumnData, fColumnData.length);
+ }
+
+ private void processData() {
+ String timeStampString = fData.get(CustomTraceDefinition.TAG_TIMESTAMP);
+ String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
+ Date date = null;
+ if (timeStampInputFormat != null && timeStampString != null) {
+ SimpleDateFormat dateFormat = new SimpleDateFormat(timeStampInputFormat);
+ try {
+ date = dateFormat.parse(timeStampString);
+ setTimestamp(new TmfTimestamp(date.getTime(), TIMESTAMP_SCALE));
+ } catch (ParseException e) {
+ setTimestamp(TmfTimestamp.ZERO);
+ }
+ } else {
+ setTimestamp(TmfTimestamp.ZERO);
+ }
+
+ int i = 0;
+ fColumnData = new TmfEventField[fDefinition.outputs.size()];
+ for (OutputColumn outputColumn : fDefinition.outputs) {
+ String value = fData.get(outputColumn.name);
+ if (outputColumn.name.equals(CustomTraceDefinition.TAG_TIMESTAMP) && date != null) {
+ SimpleDateFormat dateFormat = new SimpleDateFormat(fDefinition.timeStampOutputFormat);
+ fColumnData[i++] = new TmfEventField(outputColumn.name, dateFormat.format(date));
+ } else {
+ fColumnData[i++] = new TmfEventField(outputColumn.name, (value != null ? value : "")); //$NON-NLS-1$
+ }
+ }
+ CustomEventContent content = (CustomEventContent) getContent();
+ content.setFields(fColumnData);
+ fData = null;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((fDefinition == null) ? 0 : fDefinition.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (!(obj instanceof CustomEvent)) {
+ return false;
+ }
+ CustomEvent other = (CustomEvent) obj;
+ if (fDefinition == null) {
+ if (other.fDefinition != null) {
+ return false;
+ }
+ } else if (!fDefinition.equals(other.fDefinition)) {
+ return false;
+ }
+ return true;
+ }
+
+}
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEventField;\r
-\r
-public class CustomEventContent extends TmfEventField {\r
-\r
- public CustomEventContent(CustomEvent parent, StringBuffer content) {\r
- super(ITmfEventField.ROOT_FIELD_ID, content);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#hashCode()\r
- */\r
- @Override\r
- public int hashCode() {\r
- return super.hashCode();\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#equals(java.lang.Object)\r
- */\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj) {\r
- return true;\r
- }\r
- if (!super.equals(obj)) {\r
- return false;\r
- }\r
- if (!(obj instanceof CustomEventContent)) {\r
- return false;\r
- }\r
- return true;\r
- }\r
-\r
- public void setFields(ITmfEventField[] fields) {\r
- super.setValue(getValue(), fields);\r
- }\r
-\r
-}\r
+package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
+import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
+
+public class CustomEventContent extends TmfEventField {
+
+ public CustomEventContent(CustomEvent parent, StringBuffer content) {
+ super(ITmfEventField.ROOT_FIELD_ID, content);
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (!(obj instanceof CustomEventContent)) {
+ return false;
+ }
+ return true;
+ }
+
+ public void setFields(ITmfEventField[] fields) {
+ super.setValue(getValue(), fields);
+ }
+
+}
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEventField;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEventType;\r
-\r
-public abstract class CustomEventType extends TmfEventType {\r
- \r
- private static String CONTEXT_ID = "CustomEventType"; //$NON-NLS-1$\r
- \r
- public CustomEventType(CustomTraceDefinition definition) {\r
- super(CONTEXT_ID, definition.definitionName, getRootField(definition));\r
- }\r
-\r
- private static ITmfEventField getRootField(CustomTraceDefinition definition) {\r
- ITmfEventField[] fields = new ITmfEventField[definition.outputs.size()];\r
- for (int i = 0; i < fields.length; i++) {\r
- fields[i] = new TmfEventField(definition.outputs.get(i).name, null);\r
- }\r
- ITmfEventField rootField = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, fields);\r
- return rootField;\r
- }\r
-\r
-}\r
+package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
+import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
+import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
+
+public abstract class CustomEventType extends TmfEventType {
+
+ private static String CONTEXT_ID = "CustomEventType"; //$NON-NLS-1$
+
+ public CustomEventType(CustomTraceDefinition definition) {
+ super(CONTEXT_ID, definition.definitionName, getRootField(definition));
+ }
+
+ private static ITmfEventField getRootField(CustomTraceDefinition definition) {
+ ITmfEventField[] fields = new ITmfEventField[definition.outputs.size()];
+ for (int i = 0; i < fields.length; i++) {
+ fields[i] = new TmfEventField(definition.outputs.get(i).name, null);
+ }
+ ITmfEventField rootField = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, fields);
+ return rootField;
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r
-\r
-import java.util.LinkedList;\r
-import java.util.List;\r
-\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEventField;\r
-import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.widgets.Composite;\r
-\r
-public class CustomEventsTable extends TmfEventsTable {\r
-\r
- private final CustomTraceDefinition fDefinition;\r
-\r
- public CustomEventsTable(CustomTraceDefinition definition, Composite parent, int cacheSize) {\r
- super(parent, cacheSize, new ColumnData[0]);\r
- fDefinition = definition;\r
- createColumnHeaders();\r
- }\r
-\r
- protected void createColumnHeaders() {\r
- if (fDefinition == null) {\r
- return;\r
- }\r
- List<ColumnData> columnData = new LinkedList<ColumnData>();\r
- for (OutputColumn outputColumn : fDefinition.outputs) {\r
- ColumnData column = new ColumnData(outputColumn.name, 0, SWT.LEFT);\r
- columnData.add(column);\r
- }\r
- setColumnHeaders(columnData.toArray(new ColumnData[0]));\r
- }\r
-\r
- @Override\r
- public TmfEventField[] extractItemFields(ITmfEvent event) {\r
- if (event instanceof CustomEvent) {\r
- TmfEventField[] fields = ((CustomEvent) event).extractItemFields();\r
-// String[] labels = new String[fields.length];\r
-// for (int i = 0; i < fields.length; i++) {\r
-// labels[i] = (String) fields[i].getValue();\r
-// }\r
- return fields;\r
- }\r
- return new TmfEventField[0];\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.parsers.custom;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
+import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+
+public class CustomEventsTable extends TmfEventsTable {
+
+ private final CustomTraceDefinition fDefinition;
+
+ public CustomEventsTable(CustomTraceDefinition definition, Composite parent, int cacheSize) {
+ super(parent, cacheSize, new ColumnData[0]);
+ fDefinition = definition;
+ createColumnHeaders();
+ }
+
+ protected void createColumnHeaders() {
+ if (fDefinition == null) {
+ return;
+ }
+ List<ColumnData> columnData = new LinkedList<ColumnData>();
+ for (OutputColumn outputColumn : fDefinition.outputs) {
+ ColumnData column = new ColumnData(outputColumn.name, 0, SWT.LEFT);
+ columnData.add(column);
+ }
+ setColumnHeaders(columnData.toArray(new ColumnData[0]));
+ }
+
+ @Override
+ public TmfEventField[] extractItemFields(ITmfEvent event) {
+ if (event instanceof CustomEvent) {
+ TmfEventField[] fields = ((CustomEvent) event).extractItemFields();
+// String[] labels = new String[fields.length];
+// for (int i = 0; i < fields.length; i++) {
+// labels[i] = (String) fields[i].getValue();
+// }
+ return fields;
+ }
+ return new TmfEventField[0];
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r
-\r
-import java.text.SimpleDateFormat;\r
-import java.util.List;\r
-\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r
-\r
-\r
-public abstract class CustomTraceDefinition {\r
-\r
- public static final int ACTION_SET = 0;\r
- public static final int ACTION_APPEND = 1;\r
- public static final int ACTION_APPEND_WITH_SEPARATOR = 2;\r
-\r
- public static final String TAG_TIMESTAMP = Messages.CustomTraceDefinition_timestampTag;\r
- public static final String TAG_MESSAGE = Messages.CustomTraceDefinition_messageTag;\r
- public static final String TAG_OTHER = Messages.CustomTraceDefinition_otherTag;\r
-\r
- public String definitionName;\r
- public List<OutputColumn> outputs;\r
- public String timeStampOutputFormat;\r
-\r
- public static class OutputColumn {\r
- public String name;\r
-\r
- public OutputColumn() {}\r
-\r
- public OutputColumn(String name) {\r
- this.name = name;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return name;\r
- }\r
- }\r
-\r
- public String formatTimeStamp(TmfTimestamp timestamp) {\r
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat(timeStampOutputFormat);\r
- return simpleDateFormat.format(timestamp.getValue());\r
- }\r
-\r
- public abstract void save();\r
- public abstract void save(String path);\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.parsers.custom;
+
+import java.text.SimpleDateFormat;
+import java.util.List;
+
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+
+
+public abstract class CustomTraceDefinition {
+
+ public static final int ACTION_SET = 0;
+ public static final int ACTION_APPEND = 1;
+ public static final int ACTION_APPEND_WITH_SEPARATOR = 2;
+
+ public static final String TAG_TIMESTAMP = Messages.CustomTraceDefinition_timestampTag;
+ public static final String TAG_MESSAGE = Messages.CustomTraceDefinition_messageTag;
+ public static final String TAG_OTHER = Messages.CustomTraceDefinition_otherTag;
+
+ public String definitionName;
+ public List<OutputColumn> outputs;
+ public String timeStampOutputFormat;
+
+ public static class OutputColumn {
+ public String name;
+
+ public OutputColumn() {}
+
+ public OutputColumn(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+ }
+
+ public String formatTimeStamp(TmfTimestamp timestamp) {
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat(timeStampOutputFormat);
+ return simpleDateFormat.format(timestamp.getValue());
+ }
+
+ public abstract void save();
+ public abstract void save(String path);
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r
-\r
-import java.util.regex.Matcher;\r
-\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputData;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEventType;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-\r
-public class CustomTxtEvent extends CustomEvent {\r
-\r
- public CustomTxtEvent(CustomTxtTraceDefinition definition) {\r
- super(definition);\r
- setType(new CustomTxtEventType(definition));\r
- }\r
-\r
- public CustomTxtEvent(CustomTxtTraceDefinition definition, TmfEvent other) {\r
- super(definition, other);\r
- }\r
-\r
- public CustomTxtEvent(CustomTxtTraceDefinition definition, ITmfTrace parentTrace, ITmfTimestamp timestamp, String source, TmfEventType type, String reference) {\r
- super(definition, parentTrace, timestamp, source, type, reference);\r
- }\r
-\r
- @Override\r
- public void setContent(ITmfEventField content) {\r
- super.setContent(content);\r
- }\r
-\r
- public void processGroups(InputLine input, Matcher matcher) {\r
- if (input.columns == null) {\r
- return;\r
- }\r
- for (int i = 0; i < input.columns.size(); i++) {\r
- InputData column = input.columns.get(i);\r
- if (i < matcher.groupCount() && matcher.group(i + 1) != null) {\r
- String value = matcher.group(i + 1).trim();\r
- if (value.length() == 0) {\r
- continue;\r
- }\r
- String name = column.name;\r
- if (column.action == CustomTraceDefinition.ACTION_SET) {\r
- fData.put(name, value);\r
- if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);\r
- }\r
- } else if (column.action == CustomTraceDefinition.ACTION_APPEND) {\r
- String s = fData.get(name);\r
- if (s != null) {\r
- fData.put(name, s + value);\r
- } else {\r
- fData.put(name, value);\r
- }\r
- if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);\r
- if (timeStampInputFormat != null) {\r
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + column.format);\r
- } else {\r
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);\r
- }\r
- }\r
- } else if (column.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {\r
- String s = fData.get(name);\r
- if (s != null) {\r
- fData.put(name, s + " | " + value); //$NON-NLS-1$\r
- } else {\r
- fData.put(name, value);\r
- }\r
- if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);\r
- if (timeStampInputFormat != null) {\r
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + column.format); //$NON-NLS-1$\r
- } else {\r
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);\r
- }\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.parsers.custom;
+
+import java.util.regex.Matcher;
+
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputData;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
+import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+
+public class CustomTxtEvent extends CustomEvent {
+
+ public CustomTxtEvent(CustomTxtTraceDefinition definition) {
+ super(definition);
+ setType(new CustomTxtEventType(definition));
+ }
+
+ public CustomTxtEvent(CustomTxtTraceDefinition definition, TmfEvent other) {
+ super(definition, other);
+ }
+
+ public CustomTxtEvent(CustomTxtTraceDefinition definition, ITmfTrace parentTrace, ITmfTimestamp timestamp, String source, TmfEventType type, String reference) {
+ super(definition, parentTrace, timestamp, source, type, reference);
+ }
+
+ @Override
+ public void setContent(ITmfEventField content) {
+ super.setContent(content);
+ }
+
+ public void processGroups(InputLine input, Matcher matcher) {
+ if (input.columns == null) {
+ return;
+ }
+ for (int i = 0; i < input.columns.size(); i++) {
+ InputData column = input.columns.get(i);
+ if (i < matcher.groupCount() && matcher.group(i + 1) != null) {
+ String value = matcher.group(i + 1).trim();
+ if (value.length() == 0) {
+ continue;
+ }
+ String name = column.name;
+ if (column.action == CustomTraceDefinition.ACTION_SET) {
+ fData.put(name, value);
+ if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
+ }
+ } else if (column.action == CustomTraceDefinition.ACTION_APPEND) {
+ String s = fData.get(name);
+ if (s != null) {
+ fData.put(name, s + value);
+ } else {
+ fData.put(name, value);
+ }
+ if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
+ if (timeStampInputFormat != null) {
+ fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + column.format);
+ } else {
+ fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
+ }
+ }
+ } else if (column.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
+ String s = fData.get(name);
+ if (s != null) {
+ fData.put(name, s + " | " + value); //$NON-NLS-1$
+ } else {
+ fData.put(name, value);
+ }
+ if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
+ if (timeStampInputFormat != null) {
+ fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + column.format); //$NON-NLS-1$
+ } else {
+ fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
+ }
+ }
+ }
+ }
+ }
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- * \r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- * \r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r
-\r
-public class CustomTxtEventType extends CustomEventType {\r
-\r
- public CustomTxtEventType(CustomTxtTraceDefinition definition) {\r
- super(definition);\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.parsers.custom;
+
+public class CustomTxtEventType extends CustomEventType {
+
+ public CustomTxtEventType(CustomTxtTraceDefinition definition) {
+ super(definition);
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r
-\r
-import java.io.FileNotFoundException;\r
-import java.io.IOException;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map.Entry;\r
-import java.util.regex.Matcher;\r
-\r
-import org.eclipse.core.resources.IProject;\r
-import org.eclipse.core.resources.IResource;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;\r
-import org.eclipse.linuxtools.tmf.core.io.BufferedRandomAccessFile;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfContext;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;\r
-\r
-public class CustomTxtTrace extends TmfTrace implements ITmfEventParser {\r
-\r
- private static final TmfLongLocation NULL_LOCATION = new TmfLongLocation((Long) null);\r
- private static final int DEFAULT_CACHE_SIZE = 100;\r
-\r
- private final CustomTxtTraceDefinition fDefinition;\r
- private final CustomTxtEventType fEventType;\r
- private BufferedRandomAccessFile fFile;\r
-\r
- public CustomTxtTrace(final CustomTxtTraceDefinition definition) {\r
- fDefinition = definition;\r
- fEventType = new CustomTxtEventType(fDefinition);\r
- setCacheSize(DEFAULT_CACHE_SIZE);\r
- }\r
-\r
- public CustomTxtTrace(final IResource resource, final CustomTxtTraceDefinition definition, final String path, final int cacheSize) throws TmfTraceException {\r
- this(definition);\r
- setCacheSize((cacheSize > 0) ? cacheSize : DEFAULT_CACHE_SIZE);\r
- initTrace(resource, path, CustomTxtEvent.class);\r
- }\r
-\r
- @Override\r
- public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> eventType) throws TmfTraceException {\r
- super.initTrace(resource, path, eventType);\r
- try {\r
- fFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
- } catch (IOException e) {\r
- throw new TmfTraceException(e.getMessage(), e);\r
- }\r
- indexTrace(false);\r
- }\r
-\r
- @Override\r
- public synchronized void dispose() {\r
- super.dispose();\r
- if (fFile != null) {\r
- try {\r
- fFile.close();\r
- } catch (IOException e) {\r
- } finally {\r
- fFile = null;\r
- }\r
- }\r
- }\r
-\r
- @Override\r
- public synchronized TmfContext seekEvent(final ITmfLocation location) {\r
- final CustomTxtTraceContext context = new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);\r
- if (NULL_LOCATION.equals(location) || fFile == null) {\r
- return context;\r
- }\r
- try {\r
- if (location == null) {\r
- fFile.seek(0);\r
- } else if (location.getLocationInfo() instanceof Long) {\r
- fFile.seek((Long) location.getLocationInfo());\r
- }\r
- String line;\r
- long rawPos = fFile.getFilePointer();\r
- while ((line = fFile.getNextLine()) != null) {\r
- for (final InputLine input : getFirstLines()) {\r
- final Matcher matcher = input.getPattern().matcher(line);\r
- if (matcher.find()) {\r
- context.setLocation(new TmfLongLocation(rawPos));\r
- context.firstLineMatcher = matcher;\r
- context.firstLine = line;\r
- context.nextLineLocation = fFile.getFilePointer();\r
- context.inputLine = input;\r
- return context;\r
- }\r
- }\r
- rawPos = fFile.getFilePointer();\r
- }\r
- return context;\r
- } catch (final FileNotFoundException e) {\r
- Activator.getDefault().logError("Error seeking event. File not found: " + getPath(), e); //$NON-NLS-1$\r
- return context;\r
- } catch (final IOException e) {\r
- Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$\r
- return context;\r
- }\r
-\r
- }\r
-\r
- @Override\r
- public synchronized TmfContext seekEvent(final double ratio) {\r
- if (fFile == null) {\r
- return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);\r
- }\r
- try {\r
- long pos = (long) (ratio * fFile.length());\r
- while (pos > 0) {\r
- fFile.seek(pos - 1);\r
- if (fFile.read() == '\n') {\r
- break;\r
- }\r
- pos--;\r
- }\r
- final ITmfLocation location = new TmfLongLocation(pos);\r
- final TmfContext context = seekEvent(location);\r
- context.setRank(ITmfContext.UNKNOWN_RANK);\r
- return context;\r
- } catch (final IOException e) {\r
- Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$\r
- return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);\r
- }\r
- }\r
-\r
- @Override\r
- public synchronized double getLocationRatio(final ITmfLocation location) {\r
- if (fFile == null) {\r
- return 0;\r
- }\r
- try {\r
- if (location.getLocationInfo() instanceof Long) {\r
- return (double) ((Long) location.getLocationInfo()) / fFile.length();\r
- }\r
- } catch (final IOException e) {\r
- Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$\r
- }\r
- return 0;\r
- }\r
-\r
- @Override\r
- public ITmfLocation getCurrentLocation() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
- @Override\r
- public synchronized CustomTxtEvent parseEvent(final ITmfContext tmfContext) {\r
- ITmfContext context = seekEvent(tmfContext.getLocation());\r
- return parse(context);\r
- }\r
-\r
- @Override\r
- public synchronized CustomTxtEvent getNext(final ITmfContext context) {\r
- final ITmfContext savedContext = context.clone();\r
- final CustomTxtEvent event = parse(context);\r
- if (event != null) {\r
- updateAttributes(savedContext, event.getTimestamp());\r
- context.increaseRank();\r
- }\r
- return event;\r
- }\r
-\r
- private synchronized CustomTxtEvent parse(final ITmfContext tmfContext) {\r
- if (fFile == null) {\r
- return null;\r
- }\r
- if (!(tmfContext instanceof CustomTxtTraceContext)) {\r
- return null;\r
- }\r
-\r
- final CustomTxtTraceContext context = (CustomTxtTraceContext) tmfContext;\r
- if (!(context.getLocation().getLocationInfo() instanceof Long) || NULL_LOCATION.equals(context.getLocation())) {\r
- return null;\r
- }\r
-\r
- CustomTxtEvent event = parseFirstLine(context);\r
-\r
- final HashMap<InputLine, Integer> countMap = new HashMap<InputLine, Integer>();\r
- InputLine currentInput = null;\r
- if (context.inputLine.childrenInputs != null && context.inputLine.childrenInputs.size() > 0) {\r
- currentInput = context.inputLine.childrenInputs.get(0);\r
- countMap.put(currentInput, 0);\r
- }\r
-\r
- try {\r
- if (fFile.getFilePointer() != context.nextLineLocation) {\r
- fFile.seek(context.nextLineLocation);\r
- }\r
- String line;\r
- long rawPos = fFile.getFilePointer();\r
- while ((line = fFile.getNextLine()) != null) {\r
- boolean processed = false;\r
- if (currentInput == null) {\r
- for (final InputLine input : getFirstLines()) {\r
- final Matcher matcher = input.getPattern().matcher(line);\r
- if (matcher.find()) {\r
- context.setLocation(new TmfLongLocation(rawPos));\r
- context.firstLineMatcher = matcher;\r
- context.firstLine = line;\r
- context.nextLineLocation = fFile.getFilePointer();\r
- context.inputLine = input;\r
- return event;\r
- }\r
- }\r
- } else {\r
- if (countMap.get(currentInput) >= currentInput.getMinCount()) {\r
- final List<InputLine> nextInputs = currentInput.getNextInputs(countMap);\r
- if (nextInputs.size() == 0 || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0) {\r
- for (final InputLine input : getFirstLines()) {\r
- final Matcher matcher = input.getPattern().matcher(line);\r
- if (matcher.find()) {\r
- context.setLocation(new TmfLongLocation(rawPos));\r
- context.firstLineMatcher = matcher;\r
- context.firstLine = line;\r
- context.nextLineLocation = fFile.getFilePointer();\r
- context.inputLine = input;\r
- return event;\r
- }\r
- }\r
- }\r
- for (final InputLine input : nextInputs) {\r
- final Matcher matcher = input.getPattern().matcher(line);\r
- if (matcher.find()) {\r
- event.processGroups(input, matcher);\r
- currentInput = input;\r
- if (countMap.get(currentInput) == null) {\r
- countMap.put(currentInput, 1);\r
- } else {\r
- countMap.put(currentInput, countMap.get(currentInput) + 1);\r
- }\r
- Iterator<InputLine> iter = countMap.keySet().iterator();\r
- while (iter.hasNext()) {\r
- final InputLine inputLine = iter.next();\r
- if (inputLine.level > currentInput.level) {\r
- iter.remove();\r
- }\r
- }\r
- if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {\r
- currentInput = currentInput.childrenInputs.get(0);\r
- countMap.put(currentInput, 0);\r
- } else if (countMap.get(currentInput) >= currentInput.getMaxCount()) {\r
- if (currentInput.getNextInputs(countMap).size() > 0) {\r
- currentInput = currentInput.getNextInputs(countMap).get(0);\r
- if (countMap.get(currentInput) == null) {\r
- countMap.put(currentInput, 0);\r
- }\r
- iter = countMap.keySet().iterator();\r
- while (iter.hasNext()) {\r
- final InputLine inputLine = iter.next();\r
- if (inputLine.level > currentInput.level) {\r
- iter.remove();\r
- }\r
- }\r
- } else {\r
- currentInput = null;\r
- }\r
- }\r
- processed = true;\r
- break;\r
- }\r
- }\r
- }\r
- if (! processed) {\r
- final Matcher matcher = currentInput.getPattern().matcher(line);\r
- if (matcher.find()) {\r
- event.processGroups(currentInput, matcher);\r
- countMap.put(currentInput, countMap.get(currentInput) + 1);\r
- if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {\r
- currentInput = currentInput.childrenInputs.get(0);\r
- countMap.put(currentInput, 0);\r
- } else if (countMap.get(currentInput) >= currentInput.getMaxCount()) {\r
- if (currentInput.getNextInputs(countMap).size() > 0) {\r
- currentInput = currentInput.getNextInputs(countMap).get(0);\r
- if (countMap.get(currentInput) == null) {\r
- countMap.put(currentInput, 0);\r
- }\r
- final Iterator<InputLine> iter = countMap.keySet().iterator();\r
- while (iter.hasNext()) {\r
- final InputLine inputLine = iter.next();\r
- if (inputLine.level > currentInput.level) {\r
- iter.remove();\r
- }\r
- }\r
- } else {\r
- currentInput = null;\r
- }\r
- }\r
- }\r
- ((StringBuffer) event.getContent().getValue()).append("\n").append(line); //$NON-NLS-1$\r
- }\r
- }\r
- rawPos = fFile.getFilePointer();\r
- }\r
- } catch (final IOException e) {\r
- Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$\r
- }\r
- for (final Entry<InputLine, Integer> entry : countMap.entrySet()) {\r
- if (entry.getValue() < entry.getKey().getMinCount()) {\r
- event = null;\r
- }\r
- }\r
- context.setLocation(NULL_LOCATION);\r
- return event;\r
- }\r
-\r
- public List<InputLine> getFirstLines() {\r
- return fDefinition.inputs;\r
- }\r
-\r
- public CustomTxtEvent parseFirstLine(final CustomTxtTraceContext context) {\r
- final CustomTxtEvent event = new CustomTxtEvent(fDefinition, this, TmfTimestamp.ZERO, "", fEventType, ""); //$NON-NLS-1$ //$NON-NLS-2$\r
- event.processGroups(context.inputLine, context.firstLineMatcher);\r
- event.setContent(new CustomEventContent(event, new StringBuffer(context.firstLine)));\r
- return event;\r
- }\r
-\r
- public CustomTraceDefinition getDefinition() {\r
- return fDefinition;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String)\r
- */\r
- @Override\r
- public boolean validate(IProject project, String path) {\r
- return fileExists(path);\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.parsers.custom;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.regex.Matcher;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.io.BufferedRandomAccessFile;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
+
+public class CustomTxtTrace extends TmfTrace implements ITmfEventParser {
+
+ private static final TmfLongLocation NULL_LOCATION = new TmfLongLocation((Long) null);
+ private static final int DEFAULT_CACHE_SIZE = 100;
+
+ private final CustomTxtTraceDefinition fDefinition;
+ private final CustomTxtEventType fEventType;
+ private BufferedRandomAccessFile fFile;
+
+ public CustomTxtTrace(final CustomTxtTraceDefinition definition) {
+ fDefinition = definition;
+ fEventType = new CustomTxtEventType(fDefinition);
+ setCacheSize(DEFAULT_CACHE_SIZE);
+ }
+
+ public CustomTxtTrace(final IResource resource, final CustomTxtTraceDefinition definition, final String path, final int cacheSize) throws TmfTraceException {
+ this(definition);
+ setCacheSize((cacheSize > 0) ? cacheSize : DEFAULT_CACHE_SIZE);
+ initTrace(resource, path, CustomTxtEvent.class);
+ }
+
+ @Override
+ public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> eventType) throws TmfTraceException {
+ super.initTrace(resource, path, eventType);
+ try {
+ fFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$
+ } catch (IOException e) {
+ throw new TmfTraceException(e.getMessage(), e);
+ }
+ indexTrace(false);
+ }
+
+ @Override
+ public synchronized void dispose() {
+ super.dispose();
+ if (fFile != null) {
+ try {
+ fFile.close();
+ } catch (IOException e) {
+ } finally {
+ fFile = null;
+ }
+ }
+ }
+
+ @Override
+ public synchronized TmfContext seekEvent(final ITmfLocation location) {
+ final CustomTxtTraceContext context = new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);
+ if (NULL_LOCATION.equals(location) || fFile == null) {
+ return context;
+ }
+ try {
+ if (location == null) {
+ fFile.seek(0);
+ } else if (location.getLocationInfo() instanceof Long) {
+ fFile.seek((Long) location.getLocationInfo());
+ }
+ String line;
+ long rawPos = fFile.getFilePointer();
+ while ((line = fFile.getNextLine()) != null) {
+ for (final InputLine input : getFirstLines()) {
+ final Matcher matcher = input.getPattern().matcher(line);
+ if (matcher.find()) {
+ context.setLocation(new TmfLongLocation(rawPos));
+ context.firstLineMatcher = matcher;
+ context.firstLine = line;
+ context.nextLineLocation = fFile.getFilePointer();
+ context.inputLine = input;
+ return context;
+ }
+ }
+ rawPos = fFile.getFilePointer();
+ }
+ return context;
+ } catch (final FileNotFoundException e) {
+ Activator.getDefault().logError("Error seeking event. File not found: " + getPath(), e); //$NON-NLS-1$
+ return context;
+ } catch (final IOException e) {
+ Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$
+ return context;
+ }
+
+ }
+
+ @Override
+ public synchronized TmfContext seekEvent(final double ratio) {
+ if (fFile == null) {
+ return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);
+ }
+ try {
+ long pos = (long) (ratio * fFile.length());
+ while (pos > 0) {
+ fFile.seek(pos - 1);
+ if (fFile.read() == '\n') {
+ break;
+ }
+ pos--;
+ }
+ final ITmfLocation location = new TmfLongLocation(pos);
+ final TmfContext context = seekEvent(location);
+ context.setRank(ITmfContext.UNKNOWN_RANK);
+ return context;
+ } catch (final IOException e) {
+ Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$
+ return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);
+ }
+ }
+
+ @Override
+ public synchronized double getLocationRatio(final ITmfLocation location) {
+ if (fFile == null) {
+ return 0;
+ }
+ try {
+ if (location.getLocationInfo() instanceof Long) {
+ return (double) ((Long) location.getLocationInfo()) / fFile.length();
+ }
+ } catch (final IOException e) {
+ Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$
+ }
+ return 0;
+ }
+
+ @Override
+ public ITmfLocation getCurrentLocation() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public synchronized CustomTxtEvent parseEvent(final ITmfContext tmfContext) {
+ ITmfContext context = seekEvent(tmfContext.getLocation());
+ return parse(context);
+ }
+
+ @Override
+ public synchronized CustomTxtEvent getNext(final ITmfContext context) {
+ final ITmfContext savedContext = context.clone();
+ final CustomTxtEvent event = parse(context);
+ if (event != null) {
+ updateAttributes(savedContext, event.getTimestamp());
+ context.increaseRank();
+ }
+ return event;
+ }
+
+ private synchronized CustomTxtEvent parse(final ITmfContext tmfContext) {
+ if (fFile == null) {
+ return null;
+ }
+ if (!(tmfContext instanceof CustomTxtTraceContext)) {
+ return null;
+ }
+
+ final CustomTxtTraceContext context = (CustomTxtTraceContext) tmfContext;
+ if (!(context.getLocation().getLocationInfo() instanceof Long) || NULL_LOCATION.equals(context.getLocation())) {
+ return null;
+ }
+
+ CustomTxtEvent event = parseFirstLine(context);
+
+ final HashMap<InputLine, Integer> countMap = new HashMap<InputLine, Integer>();
+ InputLine currentInput = null;
+ if (context.inputLine.childrenInputs != null && context.inputLine.childrenInputs.size() > 0) {
+ currentInput = context.inputLine.childrenInputs.get(0);
+ countMap.put(currentInput, 0);
+ }
+
+ try {
+ if (fFile.getFilePointer() != context.nextLineLocation) {
+ fFile.seek(context.nextLineLocation);
+ }
+ String line;
+ long rawPos = fFile.getFilePointer();
+ while ((line = fFile.getNextLine()) != null) {
+ boolean processed = false;
+ if (currentInput == null) {
+ for (final InputLine input : getFirstLines()) {
+ final Matcher matcher = input.getPattern().matcher(line);
+ if (matcher.find()) {
+ context.setLocation(new TmfLongLocation(rawPos));
+ context.firstLineMatcher = matcher;
+ context.firstLine = line;
+ context.nextLineLocation = fFile.getFilePointer();
+ context.inputLine = input;
+ return event;
+ }
+ }
+ } else {
+ if (countMap.get(currentInput) >= currentInput.getMinCount()) {
+ final List<InputLine> nextInputs = currentInput.getNextInputs(countMap);
+ if (nextInputs.size() == 0 || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0) {
+ for (final InputLine input : getFirstLines()) {
+ final Matcher matcher = input.getPattern().matcher(line);
+ if (matcher.find()) {
+ context.setLocation(new TmfLongLocation(rawPos));
+ context.firstLineMatcher = matcher;
+ context.firstLine = line;
+ context.nextLineLocation = fFile.getFilePointer();
+ context.inputLine = input;
+ return event;
+ }
+ }
+ }
+ for (final InputLine input : nextInputs) {
+ final Matcher matcher = input.getPattern().matcher(line);
+ if (matcher.find()) {
+ event.processGroups(input, matcher);
+ currentInput = input;
+ if (countMap.get(currentInput) == null) {
+ countMap.put(currentInput, 1);
+ } else {
+ countMap.put(currentInput, countMap.get(currentInput) + 1);
+ }
+ Iterator<InputLine> iter = countMap.keySet().iterator();
+ while (iter.hasNext()) {
+ final InputLine inputLine = iter.next();
+ if (inputLine.level > currentInput.level) {
+ iter.remove();
+ }
+ }
+ if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {
+ currentInput = currentInput.childrenInputs.get(0);
+ countMap.put(currentInput, 0);
+ } else if (countMap.get(currentInput) >= currentInput.getMaxCount()) {
+ if (currentInput.getNextInputs(countMap).size() > 0) {
+ currentInput = currentInput.getNextInputs(countMap).get(0);
+ if (countMap.get(currentInput) == null) {
+ countMap.put(currentInput, 0);
+ }
+ iter = countMap.keySet().iterator();
+ while (iter.hasNext()) {
+ final InputLine inputLine = iter.next();
+ if (inputLine.level > currentInput.level) {
+ iter.remove();
+ }
+ }
+ } else {
+ currentInput = null;
+ }
+ }
+ processed = true;
+ break;
+ }
+ }
+ }
+ if (! processed) {
+ final Matcher matcher = currentInput.getPattern().matcher(line);
+ if (matcher.find()) {
+ event.processGroups(currentInput, matcher);
+ countMap.put(currentInput, countMap.get(currentInput) + 1);
+ if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {
+ currentInput = currentInput.childrenInputs.get(0);
+ countMap.put(currentInput, 0);
+ } else if (countMap.get(currentInput) >= currentInput.getMaxCount()) {
+ if (currentInput.getNextInputs(countMap).size() > 0) {
+ currentInput = currentInput.getNextInputs(countMap).get(0);
+ if (countMap.get(currentInput) == null) {
+ countMap.put(currentInput, 0);
+ }
+ final Iterator<InputLine> iter = countMap.keySet().iterator();
+ while (iter.hasNext()) {
+ final InputLine inputLine = iter.next();
+ if (inputLine.level > currentInput.level) {
+ iter.remove();
+ }
+ }
+ } else {
+ currentInput = null;
+ }
+ }
+ }
+ ((StringBuffer) event.getContent().getValue()).append("\n").append(line); //$NON-NLS-1$
+ }
+ }
+ rawPos = fFile.getFilePointer();
+ }
+ } catch (final IOException e) {
+ Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$
+ }
+ for (final Entry<InputLine, Integer> entry : countMap.entrySet()) {
+ if (entry.getValue() < entry.getKey().getMinCount()) {
+ event = null;
+ }
+ }
+ context.setLocation(NULL_LOCATION);
+ return event;
+ }
+
+ public List<InputLine> getFirstLines() {
+ return fDefinition.inputs;
+ }
+
+ public CustomTxtEvent parseFirstLine(final CustomTxtTraceContext context) {
+ final CustomTxtEvent event = new CustomTxtEvent(fDefinition, this, TmfTimestamp.ZERO, "", fEventType, ""); //$NON-NLS-1$ //$NON-NLS-2$
+ event.processGroups(context.inputLine, context.firstLineMatcher);
+ event.setContent(new CustomEventContent(event, new StringBuffer(context.firstLine)));
+ return event;
+ }
+
+ public CustomTraceDefinition getDefinition() {
+ return fDefinition;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String)
+ */
+ @Override
+ public boolean validate(IProject project, String path) {
+ return fileExists(path);
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r
-\r
-import java.util.regex.Matcher;\r
-\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfContext;\r
-\r
-public class CustomTxtTraceContext extends TmfContext {\r
- public Matcher firstLineMatcher;\r
- public String firstLine;\r
- public long nextLineLocation;\r
- public InputLine inputLine;\r
-\r
- public CustomTxtTraceContext(ITmfLocation location, long rank) {\r
- super(location, rank);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#hashCode()\r
- */\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = super.hashCode();\r
- result = prime * result + ((firstLine == null) ? 0 : firstLine.hashCode());\r
- result = prime * result + ((firstLineMatcher == null) ? 0 : firstLineMatcher.hashCode());\r
- result = prime * result + ((inputLine == null) ? 0 : inputLine.hashCode());\r
- result = prime * result + (int) (nextLineLocation ^ (nextLineLocation >>> 32));\r
- return result;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#equals(java.lang.Object)\r
- */\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj) {\r
- return true;\r
- }\r
- if (!super.equals(obj)) {\r
- return false;\r
- }\r
- if (!(obj instanceof CustomTxtTraceContext)) {\r
- return false;\r
- }\r
- CustomTxtTraceContext other = (CustomTxtTraceContext) obj;\r
- if (firstLine == null) {\r
- if (other.firstLine != null) {\r
- return false;\r
- }\r
- } else if (!firstLine.equals(other.firstLine)) {\r
- return false;\r
- }\r
- if (firstLineMatcher == null) {\r
- if (other.firstLineMatcher != null) {\r
- return false;\r
- }\r
- } else if (!firstLineMatcher.equals(other.firstLineMatcher)) {\r
- return false;\r
- }\r
- if (inputLine == null) {\r
- if (other.inputLine != null) {\r
- return false;\r
- }\r
- } else if (!inputLine.equals(other.inputLine)) {\r
- return false;\r
- }\r
- if (nextLineLocation != other.nextLineLocation) {\r
- return false;\r
- }\r
- return true;\r
- }\r
-\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.parsers.custom;
+
+import java.util.regex.Matcher;
+
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+
+public class CustomTxtTraceContext extends TmfContext {
+ public Matcher firstLineMatcher;
+ public String firstLine;
+ public long nextLineLocation;
+ public InputLine inputLine;
+
+ public CustomTxtTraceContext(ITmfLocation location, long rank) {
+ super(location, rank);
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((firstLine == null) ? 0 : firstLine.hashCode());
+ result = prime * result + ((firstLineMatcher == null) ? 0 : firstLineMatcher.hashCode());
+ result = prime * result + ((inputLine == null) ? 0 : inputLine.hashCode());
+ result = prime * result + (int) (nextLineLocation ^ (nextLineLocation >>> 32));
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (!(obj instanceof CustomTxtTraceContext)) {
+ return false;
+ }
+ CustomTxtTraceContext other = (CustomTxtTraceContext) obj;
+ if (firstLine == null) {
+ if (other.firstLine != null) {
+ return false;
+ }
+ } else if (!firstLine.equals(other.firstLine)) {
+ return false;
+ }
+ if (firstLineMatcher == null) {
+ if (other.firstLineMatcher != null) {
+ return false;
+ }
+ } else if (!firstLineMatcher.equals(other.firstLineMatcher)) {
+ return false;
+ }
+ if (inputLine == null) {
+ if (other.inputLine != null) {
+ return false;
+ }
+ } else if (!inputLine.equals(other.inputLine)) {
+ return false;
+ }
+ if (nextLineLocation != other.nextLineLocation) {
+ return false;
+ }
+ return true;
+ }
+
}
\ No newline at end of file
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r
-\r
-import java.io.ByteArrayInputStream;\r
-import java.io.File;\r
-import java.io.FileWriter;\r
-import java.io.IOException;\r
-import java.io.StringWriter;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.regex.Pattern;\r
-import java.util.regex.PatternSyntaxException;\r
-\r
-import javax.xml.parsers.DocumentBuilder;\r
-import javax.xml.parsers.DocumentBuilderFactory;\r
-import javax.xml.parsers.ParserConfigurationException;\r
-import javax.xml.transform.OutputKeys;\r
-import javax.xml.transform.Transformer;\r
-import javax.xml.transform.TransformerConfigurationException;\r
-import javax.xml.transform.TransformerException;\r
-import javax.xml.transform.TransformerFactory;\r
-import javax.xml.transform.TransformerFactoryConfigurationError;\r
-import javax.xml.transform.dom.DOMSource;\r
-import javax.xml.transform.stream.StreamResult;\r
-\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.w3c.dom.Document;\r
-import org.w3c.dom.Element;\r
-import org.w3c.dom.Node;\r
-import org.w3c.dom.NodeList;\r
-import org.xml.sax.EntityResolver;\r
-import org.xml.sax.ErrorHandler;\r
-import org.xml.sax.InputSource;\r
-import org.xml.sax.SAXException;\r
-import org.xml.sax.SAXParseException;\r
-\r
-public class CustomTxtTraceDefinition extends CustomTraceDefinition {\r
-\r
- protected static final String CUSTOM_TXT_TRACE_DEFINITIONS_FILE_NAME = "custom_txt_parsers.xml"; //$NON-NLS-1$\r
- protected static final String CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME =\r
- Activator.getDefault().getStateLocation().addTrailingSeparator().append(CUSTOM_TXT_TRACE_DEFINITIONS_FILE_NAME).toString();\r
-\r
- private static final String CUSTOM_TXT_TRACE_DEFINITION_ROOT_ELEMENT = Messages.CustomTxtTraceDefinition_definitionRootElement;\r
- private static final String DEFINITION_ELEMENT = Messages.CustomTxtTraceDefinition_definition;\r
- private static final String NAME_ATTRIBUTE = Messages.CustomTxtTraceDefinition_name;\r
- private static final String TIME_STAMP_OUTPUT_FORMAT_ELEMENT = Messages.CustomTxtTraceDefinition_timestampOutputFormat;\r
- private static final String INPUT_LINE_ELEMENT = Messages.CustomTxtTraceDefinition_inputLine;\r
- private static final String CARDINALITY_ELEMENT = Messages.CustomTxtTraceDefinition_cardinality;\r
- private static final String MIN_ATTRIBUTE = Messages.CustomTxtTraceDefinition_min;\r
- private static final String MAX_ATTRIBUTE = Messages.CustomTxtTraceDefinition_max;\r
- private static final String REGEX_ELEMENT = Messages.CustomTxtTraceDefinition_regEx;\r
- private static final String INPUT_DATA_ELEMENT = Messages.CustomTxtTraceDefinition_inputData;\r
- private static final String ACTION_ATTRIBUTE = Messages.CustomTxtTraceDefinition_action;\r
- private static final String FORMAT_ATTRIBUTE = Messages.CustomTxtTraceDefinition_format;\r
- private static final String OUTPUT_COLUMN_ELEMENT = Messages.CustomTxtTraceDefinition_outputColumn;\r
-\r
- public List<InputLine> inputs;\r
-\r
- public CustomTxtTraceDefinition() {\r
- this("", new ArrayList<InputLine>(0), new ArrayList<OutputColumn>(0), ""); //$NON-NLS-1$ //$NON-NLS-2$\r
- }\r
-\r
- public CustomTxtTraceDefinition(String logtype, List<InputLine> inputs, List<OutputColumn> outputs, String timeStampOutputFormat) {\r
- this.definitionName = logtype;\r
- this.inputs = inputs;\r
- this.outputs = outputs;\r
- this.timeStampOutputFormat = timeStampOutputFormat;\r
- }\r
-\r
- public static class InputLine {\r
- public List<InputData> columns;\r
- public Cardinality cardinality;\r
- private String regex;\r
- private Pattern pattern;\r
- public InputLine parentInput;\r
- public int level;\r
- public InputLine nextInput;\r
- public List<InputLine> childrenInputs;\r
-\r
- public InputLine() {}\r
-\r
- public InputLine(Cardinality cardinality, String regex, List<InputData> columns) {\r
- this.cardinality = cardinality;\r
- this.regex = regex;\r
- this.columns = columns;\r
- }\r
-\r
- public void setRegex(String regex) {\r
- this.regex = regex;\r
- this.pattern = null;\r
- }\r
-\r
- public String getRegex() {\r
- return regex;\r
- }\r
-\r
- public Pattern getPattern() throws PatternSyntaxException {\r
- if (pattern == null) {\r
- pattern = Pattern.compile(regex);\r
- }\r
- return pattern;\r
- }\r
-\r
- public void addChild(InputLine input) {\r
- if (childrenInputs == null) {\r
- childrenInputs = new ArrayList<InputLine>(1);\r
- } else if (childrenInputs.size() > 0) {\r
- InputLine last = childrenInputs.get(childrenInputs.size() - 1);\r
- last.nextInput = input;\r
- }\r
- childrenInputs.add(input);\r
- input.parentInput = this;\r
- input.level = this.level + 1;\r
- }\r
-\r
- public void addNext(InputLine input) {\r
- if (parentInput != null) {\r
- int index = parentInput.childrenInputs.indexOf(this);\r
- parentInput.childrenInputs.add(index + 1, input);\r
- InputLine next = nextInput;\r
- nextInput = input;\r
- input.nextInput = next;\r
- }\r
- input.parentInput = this.parentInput;\r
- input.level = this.level;\r
- }\r
-\r
- public void moveUp() {\r
- if (parentInput != null) {\r
- int index = parentInput.childrenInputs.indexOf(this);\r
- if (index > 0) {\r
- parentInput.childrenInputs.add(index - 1 , parentInput.childrenInputs.remove(index));\r
- parentInput.childrenInputs.get(index).nextInput = nextInput;\r
- nextInput = parentInput.childrenInputs.get(index);\r
- }\r
- }\r
- }\r
-\r
- public void moveDown() {\r
- if (parentInput != null) {\r
- int index = parentInput.childrenInputs.indexOf(this);\r
- if (index < parentInput.childrenInputs.size() - 1) {\r
- parentInput.childrenInputs.add(index + 1 , parentInput.childrenInputs.remove(index));\r
- nextInput = parentInput.childrenInputs.get(index).nextInput;\r
- parentInput.childrenInputs.get(index).nextInput = this;\r
- }\r
- }\r
- }\r
-\r
- public void addColumn(InputData column) {\r
- if (columns == null) {\r
- columns = new ArrayList<InputData>(1);\r
- }\r
- columns.add(column);\r
- }\r
-\r
- public List<InputLine> getNextInputs(Map<InputLine, Integer> countMap) {\r
- List<InputLine> nextInputs = new ArrayList<InputLine>();\r
- InputLine next = nextInput;\r
- while (next != null) {\r
- nextInputs.add(next);\r
- if (next.cardinality.min > 0) {\r
- return nextInputs;\r
- }\r
- next = next.nextInput;\r
- }\r
- if (parentInput != null && parentInput.level > 0) {\r
- int parentCount = countMap.get(parentInput);\r
- if (parentCount < parentInput.getMaxCount()) {\r
- nextInputs.add(parentInput);\r
- }\r
- if (parentCount < parentInput.getMinCount()) {\r
- return nextInputs;\r
- }\r
- nextInputs.addAll(parentInput.getNextInputs(countMap));\r
- }\r
- return nextInputs;\r
- }\r
-\r
- public int getMinCount() {\r
- return cardinality.min;\r
- }\r
-\r
- public int getMaxCount() {\r
- return cardinality.max;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return regex + " " + cardinality; //$NON-NLS-1$\r
- }\r
-\r
- }\r
-\r
- public static class InputData {\r
- public String name;\r
- public int action;\r
- public String format;\r
-\r
- public InputData() {}\r
-\r
- public InputData(String name, int action, String format) {\r
- this.name = name;\r
- this.action = action;\r
- this.format = format;\r
- }\r
-\r
- public InputData(String name, int action) {\r
- this.name = name;\r
- this.action = action;\r
- }\r
- }\r
-\r
- public static class Cardinality {\r
- public final static int INF = Integer.MAX_VALUE;\r
- public final static Cardinality ONE = new Cardinality(1, 1);\r
- public final static Cardinality ONE_OR_MORE = new Cardinality(1, INF);\r
- public final static Cardinality ZERO_OR_ONE = new Cardinality(0, 1);\r
- public final static Cardinality ZERO_OR_MORE = new Cardinality(0, INF);\r
-\r
- private final int min;\r
- private final int max;\r
-\r
- public Cardinality(int min, int max) {\r
- this.min = min;\r
- this.max = max;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return "(" + (min >= 0 ? min : "?") + "," + (max == INF ? "\u221E" : (max >= 0 ? max : "?")) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#hashCode()\r
- */\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result + max;\r
- result = prime * result + min;\r
- return result;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#equals(java.lang.Object)\r
- */\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj) {\r
- return true;\r
- }\r
- if (obj == null) {\r
- return false;\r
- }\r
- if (!(obj instanceof Cardinality)) {\r
- return false;\r
- }\r
- Cardinality other = (Cardinality) obj;\r
- return (this.min == other.min && this.max == other.max);\r
- }\r
- }\r
-\r
- @Override\r
- public void save() {\r
- save(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME);\r
- }\r
-\r
- @Override\r
- public void save(String path) {\r
- try {\r
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\r
- DocumentBuilder db = dbf.newDocumentBuilder();\r
-\r
- // The following allows xml parsing without access to the dtd\r
- EntityResolver resolver = new EntityResolver () {\r
- @Override\r
- public InputSource resolveEntity (String publicId, String systemId) {\r
- String empty = ""; //$NON-NLS-1$\r
- ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());\r
- return new InputSource(bais);\r
- }\r
- };\r
- db.setEntityResolver(resolver);\r
-\r
- // The following catches xml parsing exceptions\r
- db.setErrorHandler(new ErrorHandler(){\r
- @Override\r
- public void error(SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void warning(SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void fatalError(SAXParseException saxparseexception) throws SAXException {\r
- throw saxparseexception;\r
- }});\r
-\r
- Document doc = null;\r
- File file = new File(path);\r
- if (file.canRead()) {\r
- doc = db.parse(file);\r
- if (! doc.getDocumentElement().getNodeName().equals(CUSTOM_TXT_TRACE_DEFINITION_ROOT_ELEMENT)) {\r
- return;\r
- }\r
- } else {\r
- doc = db.newDocument();\r
- Node node = doc.createElement(CUSTOM_TXT_TRACE_DEFINITION_ROOT_ELEMENT);\r
- doc.appendChild(node);\r
- }\r
-\r
- Element root = doc.getDocumentElement();\r
-\r
- NodeList nodeList = root.getChildNodes();\r
- for (int i = 0; i < nodeList.getLength(); i++) {\r
- Node node = nodeList.item(i);\r
- if (node instanceof Element &&\r
- node.getNodeName().equals(DEFINITION_ELEMENT) &&\r
- definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {\r
- root.removeChild(node);\r
- }\r
- }\r
- Element definitionElement = doc.createElement(DEFINITION_ELEMENT);\r
- root.appendChild(definitionElement);\r
- definitionElement.setAttribute(NAME_ATTRIBUTE, definitionName);\r
-\r
- Element formatElement = doc.createElement(TIME_STAMP_OUTPUT_FORMAT_ELEMENT);\r
- definitionElement.appendChild(formatElement);\r
- formatElement.appendChild(doc.createTextNode(timeStampOutputFormat));\r
-\r
- if (inputs != null) {\r
- for (InputLine inputLine : inputs) {\r
- definitionElement.appendChild(createInputLineElement(inputLine, doc));\r
- }\r
- }\r
-\r
- if (outputs != null) {\r
- for (OutputColumn output : outputs) {\r
- Element outputColumnElement = doc.createElement(OUTPUT_COLUMN_ELEMENT);\r
- definitionElement.appendChild(outputColumnElement);\r
- outputColumnElement.setAttribute(NAME_ATTRIBUTE, output.name);\r
- }\r
- }\r
-\r
- Transformer transformer = TransformerFactory.newInstance().newTransformer();\r
- transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$\r
-\r
- //initialize StreamResult with File object to save to file\r
- StreamResult result = new StreamResult(new StringWriter());\r
- DOMSource source = new DOMSource(doc);\r
- transformer.transform(source, result);\r
- String xmlString = result.getWriter().toString();\r
-\r
- FileWriter writer = new FileWriter(file);\r
- writer.write(xmlString);\r
- writer.close();\r
- } catch (ParserConfigurationException e) {\r
- Activator.getDefault().logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- } catch (TransformerConfigurationException e) {\r
- Activator.getDefault().logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- } catch (TransformerFactoryConfigurationError e) {\r
- Activator.getDefault().logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- } catch (TransformerException e) {\r
- Activator.getDefault().logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- } catch (IOException e) {\r
- Activator.getDefault().logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- } catch (SAXException e) {\r
- Activator.getDefault().logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- }\r
- }\r
-\r
- private Element createInputLineElement(InputLine inputLine, Document doc) {\r
- Element inputLineElement = doc.createElement(INPUT_LINE_ELEMENT);\r
-\r
- Element cardinalityElement = doc.createElement(CARDINALITY_ELEMENT);\r
- inputLineElement.appendChild(cardinalityElement);\r
- cardinalityElement.setAttribute(MIN_ATTRIBUTE, Integer.toString(inputLine.cardinality.min));\r
- cardinalityElement.setAttribute(MAX_ATTRIBUTE, Integer.toString(inputLine.cardinality.max));\r
-\r
- Element regexElement = doc.createElement(REGEX_ELEMENT);\r
- inputLineElement.appendChild(regexElement);\r
- regexElement.appendChild(doc.createTextNode(inputLine.regex));\r
-\r
- if (inputLine.columns != null) {\r
- for (InputData inputData : inputLine.columns) {\r
- Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT);\r
- inputLineElement.appendChild(inputDataElement);\r
- inputDataElement.setAttribute(NAME_ATTRIBUTE, inputData.name);\r
- inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(inputData.action));\r
- if (inputData.format != null) {\r
- inputDataElement.setAttribute(FORMAT_ATTRIBUTE, inputData.format);\r
- }\r
- }\r
- }\r
-\r
- if (inputLine.childrenInputs != null) {\r
- for (InputLine childInputLine : inputLine.childrenInputs) {\r
- inputLineElement.appendChild(createInputLineElement(childInputLine, doc));\r
- }\r
- }\r
-\r
- return inputLineElement;\r
- }\r
-\r
- public static CustomTxtTraceDefinition[] loadAll() {\r
- return loadAll(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME);\r
- }\r
-\r
- public static CustomTxtTraceDefinition[] loadAll(String path) {\r
- try {\r
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\r
- DocumentBuilder db = dbf.newDocumentBuilder();\r
-\r
- // The following allows xml parsing without access to the dtd\r
- EntityResolver resolver = new EntityResolver () {\r
- @Override\r
- public InputSource resolveEntity (String publicId, String systemId) {\r
- String empty = ""; //$NON-NLS-1$\r
- ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());\r
- return new InputSource(bais);\r
- }\r
- };\r
- db.setEntityResolver(resolver);\r
-\r
- // The following catches xml parsing exceptions\r
- db.setErrorHandler(new ErrorHandler(){\r
- @Override\r
- public void error(SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void warning(SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void fatalError(SAXParseException saxparseexception) throws SAXException {\r
- throw saxparseexception;\r
- }});\r
-\r
- File file = new File(path);\r
- if (!file.canRead()) {\r
- return new CustomTxtTraceDefinition[0];\r
- }\r
- Document doc = db.parse(file);\r
-\r
- Element root = doc.getDocumentElement();\r
- if (! root.getNodeName().equals(CUSTOM_TXT_TRACE_DEFINITION_ROOT_ELEMENT)) {\r
- return new CustomTxtTraceDefinition[0];\r
- }\r
-\r
- ArrayList<CustomTxtTraceDefinition> defList = new ArrayList<CustomTxtTraceDefinition>();\r
- NodeList nodeList = root.getChildNodes();\r
- for (int i = 0; i < nodeList.getLength(); i++) {\r
- Node node = nodeList.item(i);\r
- if (node instanceof Element && node.getNodeName().equals(DEFINITION_ELEMENT)) {\r
- CustomTxtTraceDefinition def = extractDefinition((Element) node);\r
- if (def != null) {\r
- defList.add(def);\r
- }\r
- }\r
- }\r
- return defList.toArray(new CustomTxtTraceDefinition[0]);\r
- } catch (ParserConfigurationException e) {\r
- Activator.getDefault().logError("Error loading all in CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- } catch (SAXException e) {\r
- Activator.getDefault().logError("Error loading all in CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- } catch (IOException e) {\r
- Activator.getDefault().logError("Error loading all in CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- }\r
- return new CustomTxtTraceDefinition[0];\r
- }\r
-\r
- public static CustomTxtTraceDefinition load(String definitionName) {\r
- try {\r
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\r
- DocumentBuilder db = dbf.newDocumentBuilder();\r
-\r
- // The following allows xml parsing without access to the dtd\r
- EntityResolver resolver = new EntityResolver () {\r
- @Override\r
- public InputSource resolveEntity (String publicId, String systemId) {\r
- String empty = ""; //$NON-NLS-1$\r
- ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());\r
- return new InputSource(bais);\r
- }\r
- };\r
- db.setEntityResolver(resolver);\r
-\r
- // The following catches xml parsing exceptions\r
- db.setErrorHandler(new ErrorHandler(){\r
- @Override\r
- public void error(SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void warning(SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void fatalError(SAXParseException saxparseexception) throws SAXException {\r
- throw saxparseexception;\r
- }});\r
-\r
- File file = new File(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME);\r
- Document doc = db.parse(file);\r
-\r
- Element root = doc.getDocumentElement();\r
- if (! root.getNodeName().equals(CUSTOM_TXT_TRACE_DEFINITION_ROOT_ELEMENT)) {\r
- return null;\r
- }\r
-\r
- NodeList nodeList = root.getChildNodes();\r
- for (int i = 0; i < nodeList.getLength(); i++) {\r
- Node node = nodeList.item(i);\r
- if (node instanceof Element &&\r
- node.getNodeName().equals(DEFINITION_ELEMENT) &&\r
- definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {\r
- return extractDefinition((Element) node);\r
- }\r
- }\r
- } catch (ParserConfigurationException e) {\r
- Activator.getDefault().logError("Error loading CustomTxtTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$\r
- } catch (SAXException e) {\r
- Activator.getDefault().logError("Error loading CustomTxtTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$\r
- } catch (IOException e) {\r
- Activator.getDefault().logError("Error loading CustomTxtTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$\r
- }\r
- return null;\r
- }\r
-\r
- public static CustomTxtTraceDefinition extractDefinition(Element definitionElement) {\r
- CustomTxtTraceDefinition def = new CustomTxtTraceDefinition();\r
-\r
- def.definitionName = definitionElement.getAttribute(NAME_ATTRIBUTE);\r
- if (def.definitionName == null) {\r
- return null;\r
- }\r
-\r
- NodeList nodeList = definitionElement.getChildNodes();\r
- for (int i = 0; i < nodeList.getLength(); i++) {\r
- Node node = nodeList.item(i);\r
- String nodeName = node.getNodeName();\r
- if (nodeName.equals(TIME_STAMP_OUTPUT_FORMAT_ELEMENT)) {\r
- Element formatElement = (Element) node;\r
- def.timeStampOutputFormat = formatElement.getTextContent();\r
- } else if (nodeName.equals(INPUT_LINE_ELEMENT)) {\r
- InputLine inputLine = extractInputLine((Element) node);\r
- if (inputLine != null) {\r
- def.inputs.add(inputLine);\r
- }\r
- } else if (nodeName.equals(OUTPUT_COLUMN_ELEMENT)) {\r
- Element outputColumnElement = (Element) node;\r
- OutputColumn outputColumn = new OutputColumn();\r
- outputColumn.name = outputColumnElement.getAttribute(NAME_ATTRIBUTE);\r
- def.outputs.add(outputColumn);\r
- }\r
- }\r
- return def;\r
- }\r
-\r
- private static InputLine extractInputLine(Element inputLineElement) {\r
- InputLine inputLine = new InputLine();\r
- NodeList nodeList = inputLineElement.getChildNodes();\r
- for (int i = 0; i < nodeList.getLength(); i++) {\r
- Node node = nodeList.item(i);\r
- String nodeName = node.getNodeName();\r
- if (nodeName.equals(CARDINALITY_ELEMENT)) {\r
- Element cardinalityElement = (Element) node;\r
- try {\r
- int min = Integer.parseInt(cardinalityElement.getAttribute(MIN_ATTRIBUTE));\r
- int max = Integer.parseInt(cardinalityElement.getAttribute(MAX_ATTRIBUTE));\r
- inputLine.cardinality = new Cardinality(min, max);\r
- } catch (NumberFormatException e) {\r
- return null;\r
- }\r
- } else if (nodeName.equals(REGEX_ELEMENT)) {\r
- Element regexElement = (Element) node;\r
- inputLine.regex = regexElement.getTextContent();\r
- } else if (nodeName.equals(INPUT_DATA_ELEMENT)) {\r
- Element inputDataElement = (Element) node;\r
- InputData inputData = new InputData();\r
- inputData.name = inputDataElement.getAttribute(NAME_ATTRIBUTE);\r
- inputData.action = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE));\r
- inputData.format = inputDataElement.getAttribute(FORMAT_ATTRIBUTE);\r
- inputLine.addColumn(inputData);\r
- } else if (nodeName.equals(INPUT_LINE_ELEMENT)) {\r
- Element childInputLineElement = (Element) node;\r
- InputLine childInputLine = extractInputLine(childInputLineElement);\r
- if (childInputLine != null) {\r
- inputLine.addChild(childInputLine);\r
- }\r
- }\r
- }\r
- return inputLine;\r
- }\r
-\r
- public static void delete(String definitionName) {\r
- try {\r
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\r
- DocumentBuilder db = dbf.newDocumentBuilder();\r
-\r
- // The following allows xml parsing without access to the dtd\r
- EntityResolver resolver = new EntityResolver () {\r
- @Override\r
- public InputSource resolveEntity (String publicId, String systemId) {\r
- String empty = ""; //$NON-NLS-1$\r
- ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());\r
- return new InputSource(bais);\r
- }\r
- };\r
- db.setEntityResolver(resolver);\r
-\r
- // The following catches xml parsing exceptions\r
- db.setErrorHandler(new ErrorHandler(){\r
- @Override\r
- public void error(SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void warning(SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void fatalError(SAXParseException saxparseexception) throws SAXException {\r
- throw saxparseexception;\r
- }});\r
-\r
- File file = new File(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME);\r
- Document doc = db.parse(file);\r
-\r
- Element root = doc.getDocumentElement();\r
- if (! root.getNodeName().equals(CUSTOM_TXT_TRACE_DEFINITION_ROOT_ELEMENT)) {\r
- return;\r
- }\r
-\r
- NodeList nodeList = root.getChildNodes();\r
- for (int i = 0; i < nodeList.getLength(); i++) {\r
- Node node = nodeList.item(i);\r
- if (node instanceof Element &&\r
- node.getNodeName().equals(DEFINITION_ELEMENT) &&\r
- definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {\r
- root.removeChild(node);\r
- }\r
- }\r
-\r
- Transformer transformer = TransformerFactory.newInstance().newTransformer();\r
- transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$\r
-\r
- //initialize StreamResult with File object to save to file\r
- StreamResult result = new StreamResult(new StringWriter());\r
- DOMSource source = new DOMSource(doc);\r
- transformer.transform(source, result);\r
- String xmlString = result.getWriter().toString();\r
-\r
- FileWriter writer = new FileWriter(file);\r
- writer.write(xmlString);\r
- writer.close();\r
- } catch (ParserConfigurationException e) {\r
- Activator.getDefault().logError("Error deleting CustomTxtTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$\r
- } catch (SAXException e) {\r
- Activator.getDefault().logError("Error deleting CustomTxtTraceDefinition: definitionName= " + definitionName, e); //$NON-NLS-1$\r
- } catch (IOException e) {\r
- Activator.getDefault().logError("Error deleting CustomTxtTraceDefinition: definitionName= " + definitionName, e); //$NON-NLS-1$\r
- } catch (TransformerConfigurationException e) {\r
- Activator.getDefault().logError("Error deleting CustomTxtTraceDefinition: definitionName= " + definitionName, e); //$NON-NLS-1$\r
- } catch (TransformerFactoryConfigurationError e) {\r
- Activator.getDefault().logError("Error deleting CustomTxtTraceDefinition: definitionName= " + definitionName, e); //$NON-NLS-1$\r
- } catch (TransformerException e) {\r
- Activator.getDefault().logError("Error deleting CustomTxtTraceDefinition: definitionName= " + definitionName, e); //$NON-NLS-1$\r
- }\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.parsers.custom;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+public class CustomTxtTraceDefinition extends CustomTraceDefinition {
+
+ protected static final String CUSTOM_TXT_TRACE_DEFINITIONS_FILE_NAME = "custom_txt_parsers.xml"; //$NON-NLS-1$
+ protected static final String CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME =
+ Activator.getDefault().getStateLocation().addTrailingSeparator().append(CUSTOM_TXT_TRACE_DEFINITIONS_FILE_NAME).toString();
+
+ private static final String CUSTOM_TXT_TRACE_DEFINITION_ROOT_ELEMENT = Messages.CustomTxtTraceDefinition_definitionRootElement;
+ private static final String DEFINITION_ELEMENT = Messages.CustomTxtTraceDefinition_definition;
+ private static final String NAME_ATTRIBUTE = Messages.CustomTxtTraceDefinition_name;
+ private static final String TIME_STAMP_OUTPUT_FORMAT_ELEMENT = Messages.CustomTxtTraceDefinition_timestampOutputFormat;
+ private static final String INPUT_LINE_ELEMENT = Messages.CustomTxtTraceDefinition_inputLine;
+ private static final String CARDINALITY_ELEMENT = Messages.CustomTxtTraceDefinition_cardinality;
+ private static final String MIN_ATTRIBUTE = Messages.CustomTxtTraceDefinition_min;
+ private static final String MAX_ATTRIBUTE = Messages.CustomTxtTraceDefinition_max;
+ private static final String REGEX_ELEMENT = Messages.CustomTxtTraceDefinition_regEx;
+ private static final String INPUT_DATA_ELEMENT = Messages.CustomTxtTraceDefinition_inputData;
+ private static final String ACTION_ATTRIBUTE = Messages.CustomTxtTraceDefinition_action;
+ private static final String FORMAT_ATTRIBUTE = Messages.CustomTxtTraceDefinition_format;
+ private static final String OUTPUT_COLUMN_ELEMENT = Messages.CustomTxtTraceDefinition_outputColumn;
+
+ public List<InputLine> inputs;
+
+ public CustomTxtTraceDefinition() {
+ this("", new ArrayList<InputLine>(0), new ArrayList<OutputColumn>(0), ""); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public CustomTxtTraceDefinition(String logtype, List<InputLine> inputs, List<OutputColumn> outputs, String timeStampOutputFormat) {
+ this.definitionName = logtype;
+ this.inputs = inputs;
+ this.outputs = outputs;
+ this.timeStampOutputFormat = timeStampOutputFormat;
+ }
+
+ public static class InputLine {
+ public List<InputData> columns;
+ public Cardinality cardinality;
+ private String regex;
+ private Pattern pattern;
+ public InputLine parentInput;
+ public int level;
+ public InputLine nextInput;
+ public List<InputLine> childrenInputs;
+
+ public InputLine() {}
+
+ public InputLine(Cardinality cardinality, String regex, List<InputData> columns) {
+ this.cardinality = cardinality;
+ this.regex = regex;
+ this.columns = columns;
+ }
+
+ public void setRegex(String regex) {
+ this.regex = regex;
+ this.pattern = null;
+ }
+
+ public String getRegex() {
+ return regex;
+ }
+
+ public Pattern getPattern() throws PatternSyntaxException {
+ if (pattern == null) {
+ pattern = Pattern.compile(regex);
+ }
+ return pattern;
+ }
+
+ public void addChild(InputLine input) {
+ if (childrenInputs == null) {
+ childrenInputs = new ArrayList<InputLine>(1);
+ } else if (childrenInputs.size() > 0) {
+ InputLine last = childrenInputs.get(childrenInputs.size() - 1);
+ last.nextInput = input;
+ }
+ childrenInputs.add(input);
+ input.parentInput = this;
+ input.level = this.level + 1;
+ }
+
+ public void addNext(InputLine input) {
+ if (parentInput != null) {
+ int index = parentInput.childrenInputs.indexOf(this);
+ parentInput.childrenInputs.add(index + 1, input);
+ InputLine next = nextInput;
+ nextInput = input;
+ input.nextInput = next;
+ }
+ input.parentInput = this.parentInput;
+ input.level = this.level;
+ }
+
+ public void moveUp() {
+ if (parentInput != null) {
+ int index = parentInput.childrenInputs.indexOf(this);
+ if (index > 0) {
+ parentInput.childrenInputs.add(index - 1 , parentInput.childrenInputs.remove(index));
+ parentInput.childrenInputs.get(index).nextInput = nextInput;
+ nextInput = parentInput.childrenInputs.get(index);
+ }
+ }
+ }
+
+ public void moveDown() {
+ if (parentInput != null) {
+ int index = parentInput.childrenInputs.indexOf(this);
+ if (index < parentInput.childrenInputs.size() - 1) {
+ parentInput.childrenInputs.add(index + 1 , parentInput.childrenInputs.remove(index));
+ nextInput = parentInput.childrenInputs.get(index).nextInput;
+ parentInput.childrenInputs.get(index).nextInput = this;
+ }
+ }
+ }
+
+ public void addColumn(InputData column) {
+ if (columns == null) {
+ columns = new ArrayList<InputData>(1);
+ }
+ columns.add(column);
+ }
+
+ public List<InputLine> getNextInputs(Map<InputLine, Integer> countMap) {
+ List<InputLine> nextInputs = new ArrayList<InputLine>();
+ InputLine next = nextInput;
+ while (next != null) {
+ nextInputs.add(next);
+ if (next.cardinality.min > 0) {
+ return nextInputs;
+ }
+ next = next.nextInput;
+ }
+ if (parentInput != null && parentInput.level > 0) {
+ int parentCount = countMap.get(parentInput);
+ if (parentCount < parentInput.getMaxCount()) {
+ nextInputs.add(parentInput);
+ }
+ if (parentCount < parentInput.getMinCount()) {
+ return nextInputs;
+ }
+ nextInputs.addAll(parentInput.getNextInputs(countMap));
+ }
+ return nextInputs;
+ }
+
+ public int getMinCount() {
+ return cardinality.min;
+ }
+
+ public int getMaxCount() {
+ return cardinality.max;
+ }
+
+ @Override
+ public String toString() {
+ return regex + " " + cardinality; //$NON-NLS-1$
+ }
+
+ }
+
+ public static class InputData {
+ public String name;
+ public int action;
+ public String format;
+
+ public InputData() {}
+
+ public InputData(String name, int action, String format) {
+ this.name = name;
+ this.action = action;
+ this.format = format;
+ }
+
+ public InputData(String name, int action) {
+ this.name = name;
+ this.action = action;
+ }
+ }
+
+ public static class Cardinality {
+ public final static int INF = Integer.MAX_VALUE;
+ public final static Cardinality ONE = new Cardinality(1, 1);
+ public final static Cardinality ONE_OR_MORE = new Cardinality(1, INF);
+ public final static Cardinality ZERO_OR_ONE = new Cardinality(0, 1);
+ public final static Cardinality ZERO_OR_MORE = new Cardinality(0, INF);
+
+ private final int min;
+ private final int max;
+
+ public Cardinality(int min, int max) {
+ this.min = min;
+ this.max = max;
+ }
+
+ @Override
+ public String toString() {
+ return "(" + (min >= 0 ? min : "?") + "," + (max == INF ? "\u221E" : (max >= 0 ? max : "?")) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + max;
+ result = prime * result + min;
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof Cardinality)) {
+ return false;
+ }
+ Cardinality other = (Cardinality) obj;
+ return (this.min == other.min && this.max == other.max);
+ }
+ }
+
+ @Override
+ public void save() {
+ save(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME);
+ }
+
+ @Override
+ public void save(String path) {
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ // The following allows xml parsing without access to the dtd
+ EntityResolver resolver = new EntityResolver () {
+ @Override
+ public InputSource resolveEntity (String publicId, String systemId) {
+ String empty = ""; //$NON-NLS-1$
+ ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());
+ return new InputSource(bais);
+ }
+ };
+ db.setEntityResolver(resolver);
+
+ // The following catches xml parsing exceptions
+ db.setErrorHandler(new ErrorHandler(){
+ @Override
+ public void error(SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void warning(SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void fatalError(SAXParseException saxparseexception) throws SAXException {
+ throw saxparseexception;
+ }});
+
+ Document doc = null;
+ File file = new File(path);
+ if (file.canRead()) {
+ doc = db.parse(file);
+ if (! doc.getDocumentElement().getNodeName().equals(CUSTOM_TXT_TRACE_DEFINITION_ROOT_ELEMENT)) {
+ return;
+ }
+ } else {
+ doc = db.newDocument();
+ Node node = doc.createElement(CUSTOM_TXT_TRACE_DEFINITION_ROOT_ELEMENT);
+ doc.appendChild(node);
+ }
+
+ Element root = doc.getDocumentElement();
+
+ NodeList nodeList = root.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ if (node instanceof Element &&
+ node.getNodeName().equals(DEFINITION_ELEMENT) &&
+ definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {
+ root.removeChild(node);
+ }
+ }
+ Element definitionElement = doc.createElement(DEFINITION_ELEMENT);
+ root.appendChild(definitionElement);
+ definitionElement.setAttribute(NAME_ATTRIBUTE, definitionName);
+
+ Element formatElement = doc.createElement(TIME_STAMP_OUTPUT_FORMAT_ELEMENT);
+ definitionElement.appendChild(formatElement);
+ formatElement.appendChild(doc.createTextNode(timeStampOutputFormat));
+
+ if (inputs != null) {
+ for (InputLine inputLine : inputs) {
+ definitionElement.appendChild(createInputLineElement(inputLine, doc));
+ }
+ }
+
+ if (outputs != null) {
+ for (OutputColumn output : outputs) {
+ Element outputColumnElement = doc.createElement(OUTPUT_COLUMN_ELEMENT);
+ definitionElement.appendChild(outputColumnElement);
+ outputColumnElement.setAttribute(NAME_ATTRIBUTE, output.name);
+ }
+ }
+
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+
+ //initialize StreamResult with File object to save to file
+ StreamResult result = new StreamResult(new StringWriter());
+ DOMSource source = new DOMSource(doc);
+ transformer.transform(source, result);
+ String xmlString = result.getWriter().toString();
+
+ FileWriter writer = new FileWriter(file);
+ writer.write(xmlString);
+ writer.close();
+ } catch (ParserConfigurationException e) {
+ Activator.getDefault().logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ } catch (TransformerConfigurationException e) {
+ Activator.getDefault().logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ } catch (TransformerFactoryConfigurationError e) {
+ Activator.getDefault().logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ } catch (TransformerException e) {
+ Activator.getDefault().logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ } catch (SAXException e) {
+ Activator.getDefault().logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ }
+ }
+
+ private Element createInputLineElement(InputLine inputLine, Document doc) {
+ Element inputLineElement = doc.createElement(INPUT_LINE_ELEMENT);
+
+ Element cardinalityElement = doc.createElement(CARDINALITY_ELEMENT);
+ inputLineElement.appendChild(cardinalityElement);
+ cardinalityElement.setAttribute(MIN_ATTRIBUTE, Integer.toString(inputLine.cardinality.min));
+ cardinalityElement.setAttribute(MAX_ATTRIBUTE, Integer.toString(inputLine.cardinality.max));
+
+ Element regexElement = doc.createElement(REGEX_ELEMENT);
+ inputLineElement.appendChild(regexElement);
+ regexElement.appendChild(doc.createTextNode(inputLine.regex));
+
+ if (inputLine.columns != null) {
+ for (InputData inputData : inputLine.columns) {
+ Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT);
+ inputLineElement.appendChild(inputDataElement);
+ inputDataElement.setAttribute(NAME_ATTRIBUTE, inputData.name);
+ inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(inputData.action));
+ if (inputData.format != null) {
+ inputDataElement.setAttribute(FORMAT_ATTRIBUTE, inputData.format);
+ }
+ }
+ }
+
+ if (inputLine.childrenInputs != null) {
+ for (InputLine childInputLine : inputLine.childrenInputs) {
+ inputLineElement.appendChild(createInputLineElement(childInputLine, doc));
+ }
+ }
+
+ return inputLineElement;
+ }
+
+ public static CustomTxtTraceDefinition[] loadAll() {
+ return loadAll(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME);
+ }
+
+ public static CustomTxtTraceDefinition[] loadAll(String path) {
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ // The following allows xml parsing without access to the dtd
+ EntityResolver resolver = new EntityResolver () {
+ @Override
+ public InputSource resolveEntity (String publicId, String systemId) {
+ String empty = ""; //$NON-NLS-1$
+ ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());
+ return new InputSource(bais);
+ }
+ };
+ db.setEntityResolver(resolver);
+
+ // The following catches xml parsing exceptions
+ db.setErrorHandler(new ErrorHandler(){
+ @Override
+ public void error(SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void warning(SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void fatalError(SAXParseException saxparseexception) throws SAXException {
+ throw saxparseexception;
+ }});
+
+ File file = new File(path);
+ if (!file.canRead()) {
+ return new CustomTxtTraceDefinition[0];
+ }
+ Document doc = db.parse(file);
+
+ Element root = doc.getDocumentElement();
+ if (! root.getNodeName().equals(CUSTOM_TXT_TRACE_DEFINITION_ROOT_ELEMENT)) {
+ return new CustomTxtTraceDefinition[0];
+ }
+
+ ArrayList<CustomTxtTraceDefinition> defList = new ArrayList<CustomTxtTraceDefinition>();
+ NodeList nodeList = root.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ if (node instanceof Element && node.getNodeName().equals(DEFINITION_ELEMENT)) {
+ CustomTxtTraceDefinition def = extractDefinition((Element) node);
+ if (def != null) {
+ defList.add(def);
+ }
+ }
+ }
+ return defList.toArray(new CustomTxtTraceDefinition[0]);
+ } catch (ParserConfigurationException e) {
+ Activator.getDefault().logError("Error loading all in CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ } catch (SAXException e) {
+ Activator.getDefault().logError("Error loading all in CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error loading all in CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ }
+ return new CustomTxtTraceDefinition[0];
+ }
+
+ public static CustomTxtTraceDefinition load(String definitionName) {
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ // The following allows xml parsing without access to the dtd
+ EntityResolver resolver = new EntityResolver () {
+ @Override
+ public InputSource resolveEntity (String publicId, String systemId) {
+ String empty = ""; //$NON-NLS-1$
+ ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());
+ return new InputSource(bais);
+ }
+ };
+ db.setEntityResolver(resolver);
+
+ // The following catches xml parsing exceptions
+ db.setErrorHandler(new ErrorHandler(){
+ @Override
+ public void error(SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void warning(SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void fatalError(SAXParseException saxparseexception) throws SAXException {
+ throw saxparseexception;
+ }});
+
+ File file = new File(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME);
+ Document doc = db.parse(file);
+
+ Element root = doc.getDocumentElement();
+ if (! root.getNodeName().equals(CUSTOM_TXT_TRACE_DEFINITION_ROOT_ELEMENT)) {
+ return null;
+ }
+
+ NodeList nodeList = root.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ if (node instanceof Element &&
+ node.getNodeName().equals(DEFINITION_ELEMENT) &&
+ definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {
+ return extractDefinition((Element) node);
+ }
+ }
+ } catch (ParserConfigurationException e) {
+ Activator.getDefault().logError("Error loading CustomTxtTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$
+ } catch (SAXException e) {
+ Activator.getDefault().logError("Error loading CustomTxtTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error loading CustomTxtTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ public static CustomTxtTraceDefinition extractDefinition(Element definitionElement) {
+ CustomTxtTraceDefinition def = new CustomTxtTraceDefinition();
+
+ def.definitionName = definitionElement.getAttribute(NAME_ATTRIBUTE);
+ if (def.definitionName == null) {
+ return null;
+ }
+
+ NodeList nodeList = definitionElement.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ String nodeName = node.getNodeName();
+ if (nodeName.equals(TIME_STAMP_OUTPUT_FORMAT_ELEMENT)) {
+ Element formatElement = (Element) node;
+ def.timeStampOutputFormat = formatElement.getTextContent();
+ } else if (nodeName.equals(INPUT_LINE_ELEMENT)) {
+ InputLine inputLine = extractInputLine((Element) node);
+ if (inputLine != null) {
+ def.inputs.add(inputLine);
+ }
+ } else if (nodeName.equals(OUTPUT_COLUMN_ELEMENT)) {
+ Element outputColumnElement = (Element) node;
+ OutputColumn outputColumn = new OutputColumn();
+ outputColumn.name = outputColumnElement.getAttribute(NAME_ATTRIBUTE);
+ def.outputs.add(outputColumn);
+ }
+ }
+ return def;
+ }
+
+ private static InputLine extractInputLine(Element inputLineElement) {
+ InputLine inputLine = new InputLine();
+ NodeList nodeList = inputLineElement.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ String nodeName = node.getNodeName();
+ if (nodeName.equals(CARDINALITY_ELEMENT)) {
+ Element cardinalityElement = (Element) node;
+ try {
+ int min = Integer.parseInt(cardinalityElement.getAttribute(MIN_ATTRIBUTE));
+ int max = Integer.parseInt(cardinalityElement.getAttribute(MAX_ATTRIBUTE));
+ inputLine.cardinality = new Cardinality(min, max);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ } else if (nodeName.equals(REGEX_ELEMENT)) {
+ Element regexElement = (Element) node;
+ inputLine.regex = regexElement.getTextContent();
+ } else if (nodeName.equals(INPUT_DATA_ELEMENT)) {
+ Element inputDataElement = (Element) node;
+ InputData inputData = new InputData();
+ inputData.name = inputDataElement.getAttribute(NAME_ATTRIBUTE);
+ inputData.action = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE));
+ inputData.format = inputDataElement.getAttribute(FORMAT_ATTRIBUTE);
+ inputLine.addColumn(inputData);
+ } else if (nodeName.equals(INPUT_LINE_ELEMENT)) {
+ Element childInputLineElement = (Element) node;
+ InputLine childInputLine = extractInputLine(childInputLineElement);
+ if (childInputLine != null) {
+ inputLine.addChild(childInputLine);
+ }
+ }
+ }
+ return inputLine;
+ }
+
+ public static void delete(String definitionName) {
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ // The following allows xml parsing without access to the dtd
+ EntityResolver resolver = new EntityResolver () {
+ @Override
+ public InputSource resolveEntity (String publicId, String systemId) {
+ String empty = ""; //$NON-NLS-1$
+ ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());
+ return new InputSource(bais);
+ }
+ };
+ db.setEntityResolver(resolver);
+
+ // The following catches xml parsing exceptions
+ db.setErrorHandler(new ErrorHandler(){
+ @Override
+ public void error(SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void warning(SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void fatalError(SAXParseException saxparseexception) throws SAXException {
+ throw saxparseexception;
+ }});
+
+ File file = new File(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME);
+ Document doc = db.parse(file);
+
+ Element root = doc.getDocumentElement();
+ if (! root.getNodeName().equals(CUSTOM_TXT_TRACE_DEFINITION_ROOT_ELEMENT)) {
+ return;
+ }
+
+ NodeList nodeList = root.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ if (node instanceof Element &&
+ node.getNodeName().equals(DEFINITION_ELEMENT) &&
+ definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {
+ root.removeChild(node);
+ }
+ }
+
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+
+ //initialize StreamResult with File object to save to file
+ StreamResult result = new StreamResult(new StringWriter());
+ DOMSource source = new DOMSource(doc);
+ transformer.transform(source, result);
+ String xmlString = result.getWriter().toString();
+
+ FileWriter writer = new FileWriter(file);
+ writer.write(xmlString);
+ writer.close();
+ } catch (ParserConfigurationException e) {
+ Activator.getDefault().logError("Error deleting CustomTxtTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$
+ } catch (SAXException e) {
+ Activator.getDefault().logError("Error deleting CustomTxtTraceDefinition: definitionName= " + definitionName, e); //$NON-NLS-1$
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error deleting CustomTxtTraceDefinition: definitionName= " + definitionName, e); //$NON-NLS-1$
+ } catch (TransformerConfigurationException e) {
+ Activator.getDefault().logError("Error deleting CustomTxtTraceDefinition: definitionName= " + definitionName, e); //$NON-NLS-1$
+ } catch (TransformerFactoryConfigurationError e) {
+ Activator.getDefault().logError("Error deleting CustomTxtTraceDefinition: definitionName= " + definitionName, e); //$NON-NLS-1$
+ } catch (TransformerException e) {
+ Activator.getDefault().logError("Error deleting CustomTxtTraceDefinition: definitionName= " + definitionName, e); //$NON-NLS-1$
+ }
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEventType;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-\r
-public class CustomXmlEvent extends CustomEvent {\r
-\r
- public CustomXmlEvent(CustomXmlTraceDefinition definition) {\r
- super(definition);\r
- setType(new CustomXmlEventType(definition));\r
- }\r
-\r
- public CustomXmlEvent(CustomXmlTraceDefinition definition, TmfEvent other) {\r
- super(definition, other);\r
- }\r
-\r
- public CustomXmlEvent(CustomXmlTraceDefinition definition, ITmfTrace parentTrace, ITmfTimestamp timestamp, String source, TmfEventType type, String reference) {\r
- super(definition, parentTrace, timestamp, source, type, reference);\r
- }\r
-\r
- @Override\r
- public void setContent(ITmfEventField content) {\r
- super.setContent(content);\r
- }\r
-\r
- public void parseInput(String value, String name, int inputAction, String inputFormat) {\r
- if (value.length() == 0) {\r
- return;\r
- }\r
- if (inputAction == CustomTraceDefinition.ACTION_SET) {\r
- fData.put(name, value);\r
- if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat);\r
- }\r
- } else if (inputAction == CustomTraceDefinition.ACTION_APPEND) {\r
- String s = fData.get(name);\r
- if (s != null) {\r
- fData.put(name, s + value);\r
- } else {\r
- fData.put(name, value);\r
- }\r
- if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);\r
- if (timeStampInputFormat != null) {\r
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + inputFormat);\r
- } else {\r
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat);\r
- }\r
- }\r
- } else if (inputAction == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {\r
- String s = fData.get(name);\r
- if (s != null) {\r
- fData.put(name, s + " | " + value); //$NON-NLS-1$\r
- } else {\r
- fData.put(name, value);\r
- }\r
- if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);\r
- if (timeStampInputFormat != null) {\r
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + inputFormat); //$NON-NLS-1$\r
- } else {\r
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat);\r
- }\r
- }\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.parsers.custom;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
+import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+
+public class CustomXmlEvent extends CustomEvent {
+
+ public CustomXmlEvent(CustomXmlTraceDefinition definition) {
+ super(definition);
+ setType(new CustomXmlEventType(definition));
+ }
+
+ public CustomXmlEvent(CustomXmlTraceDefinition definition, TmfEvent other) {
+ super(definition, other);
+ }
+
+ public CustomXmlEvent(CustomXmlTraceDefinition definition, ITmfTrace parentTrace, ITmfTimestamp timestamp, String source, TmfEventType type, String reference) {
+ super(definition, parentTrace, timestamp, source, type, reference);
+ }
+
+ @Override
+ public void setContent(ITmfEventField content) {
+ super.setContent(content);
+ }
+
+ public void parseInput(String value, String name, int inputAction, String inputFormat) {
+ if (value.length() == 0) {
+ return;
+ }
+ if (inputAction == CustomTraceDefinition.ACTION_SET) {
+ fData.put(name, value);
+ if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat);
+ }
+ } else if (inputAction == CustomTraceDefinition.ACTION_APPEND) {
+ String s = fData.get(name);
+ if (s != null) {
+ fData.put(name, s + value);
+ } else {
+ fData.put(name, value);
+ }
+ if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
+ if (timeStampInputFormat != null) {
+ fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + inputFormat);
+ } else {
+ fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat);
+ }
+ }
+ } else if (inputAction == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
+ String s = fData.get(name);
+ if (s != null) {
+ fData.put(name, s + " | " + value); //$NON-NLS-1$
+ } else {
+ fData.put(name, value);
+ }
+ if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
+ if (timeStampInputFormat != null) {
+ fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + inputFormat); //$NON-NLS-1$
+ } else {
+ fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat);
+ }
+ }
+ }
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- * \r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- * \r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r
-\r
-public class CustomXmlEventType extends CustomEventType {\r
-\r
- public CustomXmlEventType(CustomXmlTraceDefinition definition) {\r
- super(definition);\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.parsers.custom;
+
+public class CustomXmlEventType extends CustomEventType {
+
+ public CustomXmlEventType(CustomXmlTraceDefinition definition) {
+ super(definition);
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r
-\r
-import java.io.ByteArrayInputStream;\r
-import java.io.IOException;\r
-import java.io.RandomAccessFile;\r
-\r
-import javax.xml.parsers.DocumentBuilder;\r
-import javax.xml.parsers.DocumentBuilderFactory;\r
-import javax.xml.parsers.ParserConfigurationException;\r
-\r
-import org.eclipse.core.resources.IProject;\r
-import org.eclipse.core.resources.IResource;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputAttribute;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputElement;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;\r
-import org.eclipse.linuxtools.tmf.core.io.BufferedRandomAccessFile;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfContext;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;\r
-import org.w3c.dom.Document;\r
-import org.w3c.dom.Element;\r
-import org.w3c.dom.Node;\r
-import org.w3c.dom.NodeList;\r
-import org.xml.sax.EntityResolver;\r
-import org.xml.sax.ErrorHandler;\r
-import org.xml.sax.InputSource;\r
-import org.xml.sax.SAXException;\r
-import org.xml.sax.SAXParseException;\r
-\r
-public class CustomXmlTrace extends TmfTrace implements ITmfEventParser {\r
-\r
- private static final TmfLongLocation NULL_LOCATION = new TmfLongLocation((Long) null);\r
- private static final int DEFAULT_CACHE_SIZE = 100;\r
-\r
- private final CustomXmlTraceDefinition fDefinition;\r
- private final CustomXmlEventType fEventType;\r
- private final InputElement fRecordInputElement;\r
- private BufferedRandomAccessFile fFile;\r
-\r
- public CustomXmlTrace(final CustomXmlTraceDefinition definition) {\r
- fDefinition = definition;\r
- fEventType = new CustomXmlEventType(fDefinition);\r
- fRecordInputElement = getRecordInputElement(fDefinition.rootInputElement);\r
- setCacheSize(DEFAULT_CACHE_SIZE);\r
- }\r
-\r
- public CustomXmlTrace(final IResource resource, final CustomXmlTraceDefinition definition, final String path, final int pageSize) throws TmfTraceException {\r
- this(definition);\r
- setCacheSize((pageSize > 0) ? pageSize : DEFAULT_CACHE_SIZE);\r
- initTrace(resource, path, CustomXmlEvent.class);\r
- }\r
-\r
- @Override\r
- public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> eventType) throws TmfTraceException {\r
- super.initTrace(resource, path, eventType);\r
- try {\r
- fFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
- } catch (IOException e) {\r
- throw new TmfTraceException(e.getMessage(), e);\r
- }\r
- indexTrace(false);\r
- }\r
-\r
- @Override\r
- public synchronized void dispose() {\r
- super.dispose();\r
- if (fFile != null) {\r
- try {\r
- fFile.close();\r
- } catch (IOException e) {\r
- } finally {\r
- fFile = null;\r
- }\r
- }\r
- }\r
-\r
- @Override\r
- public synchronized TmfContext seekEvent(final ITmfLocation location) {\r
- final CustomXmlTraceContext context = new CustomXmlTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);\r
- if (NULL_LOCATION.equals(location) || fFile == null) {\r
- return context;\r
- }\r
- try {\r
- if (location == null) {\r
- fFile.seek(0);\r
- } else if (location.getLocationInfo() instanceof Long) {\r
- fFile.seek((Long) location.getLocationInfo());\r
- }\r
- String line;\r
- final String recordElementStart = "<" + fRecordInputElement.elementName; //$NON-NLS-1$\r
- long rawPos = fFile.getFilePointer();\r
-\r
- while ((line = fFile.getNextLine()) != null) {\r
- final int idx = line.indexOf(recordElementStart);\r
- if (idx != -1) {\r
- context.setLocation(new TmfLongLocation(rawPos + idx));\r
- return context;\r
- }\r
- rawPos = fFile.getFilePointer();\r
- }\r
- return context;\r
- } catch (final IOException e) {\r
- Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$\r
- return context;\r
- }\r
-\r
- }\r
-\r
- @Override\r
- public synchronized TmfContext seekEvent(final double ratio) {\r
- if (fFile == null) {\r
- return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);\r
- }\r
- try {\r
- long pos = (long) (ratio * fFile.length());\r
- while (pos > 0) {\r
- fFile.seek(pos - 1);\r
- if (fFile.read() == '\n') {\r
- break;\r
- }\r
- pos--;\r
- }\r
- final ITmfLocation location = new TmfLongLocation(pos);\r
- final TmfContext context = seekEvent(location);\r
- context.setRank(ITmfContext.UNKNOWN_RANK);\r
- return context;\r
- } catch (final IOException e) {\r
- Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$\r
- return new CustomXmlTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);\r
- }\r
- }\r
-\r
- @Override\r
- public synchronized double getLocationRatio(final ITmfLocation location) {\r
- if (fFile == null) {\r
- return 0;\r
- }\r
- try {\r
- if (location.getLocationInfo() instanceof Long) {\r
- return (double) ((Long) location.getLocationInfo()) / fFile.length();\r
- }\r
- } catch (final IOException e) {\r
- Activator.getDefault().logError("Error getting location ration. File: " + getPath(), e); //$NON-NLS-1$\r
- }\r
- return 0;\r
- }\r
-\r
- @Override\r
- public ITmfLocation getCurrentLocation() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
- @Override\r
- public synchronized CustomXmlEvent parseEvent(final ITmfContext tmfContext) {\r
- ITmfContext context = seekEvent(tmfContext.getLocation());\r
- return parse(context);\r
- }\r
-\r
- @Override\r
- public synchronized CustomXmlEvent getNext(final ITmfContext context) {\r
- final ITmfContext savedContext = context.clone();\r
- final CustomXmlEvent event = parse(context);\r
- if (event != null) {\r
- updateAttributes(savedContext, event.getTimestamp());\r
- context.increaseRank();\r
- }\r
- return event;\r
- }\r
-\r
- private synchronized CustomXmlEvent parse(final ITmfContext tmfContext) {\r
- if (fFile == null) {\r
- return null;\r
- }\r
- if (!(tmfContext instanceof CustomXmlTraceContext)) {\r
- return null;\r
- }\r
-\r
- final CustomXmlTraceContext context = (CustomXmlTraceContext) tmfContext;\r
- if (!(context.getLocation().getLocationInfo() instanceof Long) || NULL_LOCATION.equals(context.getLocation())) {\r
- return null;\r
- }\r
-\r
- CustomXmlEvent event = null;\r
- try {\r
- if (fFile.getFilePointer() != (Long)context.getLocation().getLocationInfo() + 1)\r
- {\r
- fFile.seek((Long)context.getLocation().getLocationInfo() + 1); // +1 is for the <\r
- }\r
- final StringBuffer elementBuffer = new StringBuffer("<"); //$NON-NLS-1$\r
- readElement(elementBuffer, fFile);\r
- final Element element = parseElementBuffer(elementBuffer);\r
-\r
- event = extractEvent(element, fRecordInputElement);\r
- ((StringBuffer) event.getContent().getValue()).append(elementBuffer);\r
-\r
- String line;\r
- final String recordElementStart = "<" + fRecordInputElement.elementName; //$NON-NLS-1$\r
- long rawPos = fFile.getFilePointer();\r
-\r
- while ((line = fFile.getNextLine()) != null) {\r
- final int idx = line.indexOf(recordElementStart);\r
- if (idx != -1) {\r
- context.setLocation(new TmfLongLocation(rawPos + idx));\r
- return event;\r
- }\r
- rawPos = fFile.getFilePointer();\r
- }\r
- } catch (final IOException e) {\r
- Activator.getDefault().logError("Error parsing event. File: " + getPath(), e); //$NON-NLS-1$\r
-\r
- }\r
- context.setLocation(NULL_LOCATION);\r
- return event;\r
- }\r
-\r
- private Element parseElementBuffer(final StringBuffer elementBuffer) {\r
- try {\r
- final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\r
- final DocumentBuilder db = dbf.newDocumentBuilder();\r
-\r
- // The following allows xml parsing without access to the dtd\r
- final EntityResolver resolver = new EntityResolver () {\r
- @Override\r
- public InputSource resolveEntity (final String publicId, final String systemId) {\r
- final String empty = ""; //$NON-NLS-1$\r
- final ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());\r
- return new InputSource(bais);\r
- }\r
- };\r
- db.setEntityResolver(resolver);\r
-\r
- // The following catches xml parsing exceptions\r
- db.setErrorHandler(new ErrorHandler(){\r
- @Override\r
- public void error(final SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void warning(final SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void fatalError(final SAXParseException saxparseexception) throws SAXException {\r
- throw saxparseexception;\r
- }});\r
-\r
- final Document doc = db.parse(new ByteArrayInputStream(elementBuffer.toString().getBytes()));\r
- return doc.getDocumentElement();\r
- } catch (final ParserConfigurationException e) {\r
- Activator.getDefault().logError("Error parsing element buffer. File:" + getPath(), e); //$NON-NLS-1$\r
- } catch (final SAXException e) {\r
- Activator.getDefault().logError("Error parsing element buffer. File:" + getPath(), e); //$NON-NLS-1$\r
- } catch (final IOException e) {\r
- Activator.getDefault().logError("Error parsing element buffer. File: " + getPath(), e); //$NON-NLS-1$\r
- }\r
- return null;\r
- }\r
-\r
- private void readElement(final StringBuffer buffer, final RandomAccessFile raFile) {\r
- try {\r
- int numRead = 0;\r
- boolean startTagClosed = false;\r
- int i;\r
- while ((i = raFile.read()) != -1) {\r
- numRead++;\r
- final char c = (char)i;\r
- buffer.append(c);\r
- if (c == '"') {\r
- readQuote(buffer, raFile, '"');\r
- } else if (c == '\'') {\r
- readQuote(buffer, raFile, '\'');\r
- } else if (c == '<') {\r
- readElement(buffer, raFile);\r
- } else if (c == '/' && numRead == 1) {\r
- break; // found "</"\r
- } else if (c == '-' && numRead == 3 && buffer.substring(buffer.length() - 3, buffer.length() - 1).equals("!-")) { //$NON-NLS-1$\r
- readComment(buffer, raFile); // found "<!--"\r
- } else if (i == '>') {\r
- if (buffer.charAt(buffer.length() - 2) == '/') {\r
- break; // found "/>"\r
- } else if (startTagClosed) {\r
- break; // found "<...>...</...>"\r
- }\r
- else {\r
- startTagClosed = true; // found "<...>"\r
- }\r
- }\r
- }\r
- return;\r
- } catch (final IOException e) {\r
- return;\r
- }\r
- }\r
-\r
- private static void readQuote(final StringBuffer buffer,\r
- final RandomAccessFile raFile, final char eq) {\r
- try {\r
- int i;\r
- while ((i = raFile.read()) != -1) {\r
- final char c = (char)i;\r
- buffer.append(c);\r
- if (c == eq)\r
- {\r
- break; // found matching end-quote\r
- }\r
- }\r
- return;\r
- } catch (final IOException e) {\r
- return;\r
- }\r
- }\r
-\r
- private static void readComment(final StringBuffer buffer,\r
- final RandomAccessFile raFile) {\r
- try {\r
- int numRead = 0;\r
- int i;\r
- while ((i = raFile.read()) != -1) {\r
- numRead++;\r
- final char c = (char)i;\r
- buffer.append(c);\r
- if (c == '>' && numRead >= 2 && buffer.substring(buffer.length() - 3, buffer.length() - 1).equals("--")) //$NON-NLS-1$\r
- {\r
- break; // found "-->"\r
- }\r
- }\r
- return;\r
- } catch (final IOException e) {\r
- return;\r
- }\r
- }\r
-\r
- public static StringBuffer parseElement(final Element parentElement, final StringBuffer buffer) {\r
- final NodeList nodeList = parentElement.getChildNodes();\r
- String separator = null;\r
- for (int i = 0; i < nodeList.getLength(); i++) {\r
- final Node node = nodeList.item(i);\r
- if (node.getNodeType() == Node.ELEMENT_NODE) {\r
- if (separator == null) {\r
- separator = " | "; //$NON-NLS-1$\r
- } else {\r
- buffer.append(separator);\r
- }\r
- final Element element = (Element) node;\r
- if (!element.hasChildNodes()) {\r
- buffer.append(element.getNodeName());\r
- } else if (element.getChildNodes().getLength() == 1 && element.getFirstChild().getNodeType() == Node.TEXT_NODE) {\r
- buffer.append(element.getNodeName() + ":" + element.getFirstChild().getNodeValue().trim()); //$NON-NLS-1$\r
- } else {\r
- buffer.append(element.getNodeName());\r
- buffer.append(" [ "); //$NON-NLS-1$\r
- parseElement(element, buffer);\r
- buffer.append(" ]"); //$NON-NLS-1$\r
- }\r
- } else if (node.getNodeType() == Node.TEXT_NODE) {\r
- if (node.getNodeValue().trim().length() != 0) {\r
- buffer.append(node.getNodeValue().trim());\r
- }\r
- }\r
- }\r
- return buffer;\r
- }\r
-\r
- public InputElement getRecordInputElement(final InputElement inputElement) {\r
- if (inputElement.logEntry) {\r
- return inputElement;\r
- } else if (inputElement.childElements != null) {\r
- for (final InputElement childInputElement : inputElement.childElements) {\r
- final InputElement recordInputElement = getRecordInputElement(childInputElement);\r
- if (recordInputElement != null) {\r
- return recordInputElement;\r
- }\r
- }\r
- }\r
- return null;\r
- }\r
-\r
- public CustomXmlEvent extractEvent(final Element element, final InputElement inputElement) {\r
- final CustomXmlEvent event = new CustomXmlEvent(fDefinition, this, TmfTimestamp.ZERO, "", fEventType,""); //$NON-NLS-1$ //$NON-NLS-2$\r
- event.setContent(new CustomEventContent(event, new StringBuffer()));\r
- parseElement(element, event, inputElement);\r
- return event;\r
- }\r
-\r
- private void parseElement(final Element element, final CustomXmlEvent event, final InputElement inputElement) {\r
- if (inputElement.inputName != null && !inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) {\r
- event.parseInput(parseElement(element, new StringBuffer()).toString(), inputElement.inputName, inputElement.inputAction, inputElement.inputFormat);\r
- }\r
- if (inputElement.attributes != null) {\r
- for (final InputAttribute attribute : inputElement.attributes) {\r
- event.parseInput(element.getAttribute(attribute.attributeName), attribute.inputName, attribute.inputAction, attribute.inputFormat);\r
- }\r
- }\r
- final NodeList childNodes = element.getChildNodes();\r
- if (inputElement.childElements != null) {\r
- for (int i = 0; i < childNodes.getLength(); i++) {\r
- final Node node = childNodes.item(i);\r
- if (node instanceof Element) {\r
- for (final InputElement child : inputElement.childElements) {\r
- if (node.getNodeName().equals(child.elementName)) {\r
- parseElement((Element) node, event, child);\r
- break;\r
- }\r
- }\r
- }\r
- }\r
- }\r
- return;\r
- }\r
-\r
- public CustomTraceDefinition getDefinition() {\r
- return fDefinition;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String)\r
- */\r
- @Override\r
- public boolean validate(IProject project, String path) {\r
- return fileExists(path);\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.parsers.custom;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputAttribute;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputElement;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.io.BufferedRandomAccessFile;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+public class CustomXmlTrace extends TmfTrace implements ITmfEventParser {
+
+ private static final TmfLongLocation NULL_LOCATION = new TmfLongLocation((Long) null);
+ private static final int DEFAULT_CACHE_SIZE = 100;
+
+ private final CustomXmlTraceDefinition fDefinition;
+ private final CustomXmlEventType fEventType;
+ private final InputElement fRecordInputElement;
+ private BufferedRandomAccessFile fFile;
+
+ public CustomXmlTrace(final CustomXmlTraceDefinition definition) {
+ fDefinition = definition;
+ fEventType = new CustomXmlEventType(fDefinition);
+ fRecordInputElement = getRecordInputElement(fDefinition.rootInputElement);
+ setCacheSize(DEFAULT_CACHE_SIZE);
+ }
+
+ public CustomXmlTrace(final IResource resource, final CustomXmlTraceDefinition definition, final String path, final int pageSize) throws TmfTraceException {
+ this(definition);
+ setCacheSize((pageSize > 0) ? pageSize : DEFAULT_CACHE_SIZE);
+ initTrace(resource, path, CustomXmlEvent.class);
+ }
+
+ @Override
+ public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> eventType) throws TmfTraceException {
+ super.initTrace(resource, path, eventType);
+ try {
+ fFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$
+ } catch (IOException e) {
+ throw new TmfTraceException(e.getMessage(), e);
+ }
+ indexTrace(false);
+ }
+
+ @Override
+ public synchronized void dispose() {
+ super.dispose();
+ if (fFile != null) {
+ try {
+ fFile.close();
+ } catch (IOException e) {
+ } finally {
+ fFile = null;
+ }
+ }
+ }
+
+ @Override
+ public synchronized TmfContext seekEvent(final ITmfLocation location) {
+ final CustomXmlTraceContext context = new CustomXmlTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);
+ if (NULL_LOCATION.equals(location) || fFile == null) {
+ return context;
+ }
+ try {
+ if (location == null) {
+ fFile.seek(0);
+ } else if (location.getLocationInfo() instanceof Long) {
+ fFile.seek((Long) location.getLocationInfo());
+ }
+ String line;
+ final String recordElementStart = "<" + fRecordInputElement.elementName; //$NON-NLS-1$
+ long rawPos = fFile.getFilePointer();
+
+ while ((line = fFile.getNextLine()) != null) {
+ final int idx = line.indexOf(recordElementStart);
+ if (idx != -1) {
+ context.setLocation(new TmfLongLocation(rawPos + idx));
+ return context;
+ }
+ rawPos = fFile.getFilePointer();
+ }
+ return context;
+ } catch (final IOException e) {
+ Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$
+ return context;
+ }
+
+ }
+
+ @Override
+ public synchronized TmfContext seekEvent(final double ratio) {
+ if (fFile == null) {
+ return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);
+ }
+ try {
+ long pos = (long) (ratio * fFile.length());
+ while (pos > 0) {
+ fFile.seek(pos - 1);
+ if (fFile.read() == '\n') {
+ break;
+ }
+ pos--;
+ }
+ final ITmfLocation location = new TmfLongLocation(pos);
+ final TmfContext context = seekEvent(location);
+ context.setRank(ITmfContext.UNKNOWN_RANK);
+ return context;
+ } catch (final IOException e) {
+ Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$
+ return new CustomXmlTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);
+ }
+ }
+
+ @Override
+ public synchronized double getLocationRatio(final ITmfLocation location) {
+ if (fFile == null) {
+ return 0;
+ }
+ try {
+ if (location.getLocationInfo() instanceof Long) {
+ return (double) ((Long) location.getLocationInfo()) / fFile.length();
+ }
+ } catch (final IOException e) {
+ Activator.getDefault().logError("Error getting location ration. File: " + getPath(), e); //$NON-NLS-1$
+ }
+ return 0;
+ }
+
+ @Override
+ public ITmfLocation getCurrentLocation() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public synchronized CustomXmlEvent parseEvent(final ITmfContext tmfContext) {
+ ITmfContext context = seekEvent(tmfContext.getLocation());
+ return parse(context);
+ }
+
+ @Override
+ public synchronized CustomXmlEvent getNext(final ITmfContext context) {
+ final ITmfContext savedContext = context.clone();
+ final CustomXmlEvent event = parse(context);
+ if (event != null) {
+ updateAttributes(savedContext, event.getTimestamp());
+ context.increaseRank();
+ }
+ return event;
+ }
+
+ private synchronized CustomXmlEvent parse(final ITmfContext tmfContext) {
+ if (fFile == null) {
+ return null;
+ }
+ if (!(tmfContext instanceof CustomXmlTraceContext)) {
+ return null;
+ }
+
+ final CustomXmlTraceContext context = (CustomXmlTraceContext) tmfContext;
+ if (!(context.getLocation().getLocationInfo() instanceof Long) || NULL_LOCATION.equals(context.getLocation())) {
+ return null;
+ }
+
+ CustomXmlEvent event = null;
+ try {
+ if (fFile.getFilePointer() != (Long)context.getLocation().getLocationInfo() + 1)
+ {
+ fFile.seek((Long)context.getLocation().getLocationInfo() + 1); // +1 is for the <
+ }
+ final StringBuffer elementBuffer = new StringBuffer("<"); //$NON-NLS-1$
+ readElement(elementBuffer, fFile);
+ final Element element = parseElementBuffer(elementBuffer);
+
+ event = extractEvent(element, fRecordInputElement);
+ ((StringBuffer) event.getContent().getValue()).append(elementBuffer);
+
+ String line;
+ final String recordElementStart = "<" + fRecordInputElement.elementName; //$NON-NLS-1$
+ long rawPos = fFile.getFilePointer();
+
+ while ((line = fFile.getNextLine()) != null) {
+ final int idx = line.indexOf(recordElementStart);
+ if (idx != -1) {
+ context.setLocation(new TmfLongLocation(rawPos + idx));
+ return event;
+ }
+ rawPos = fFile.getFilePointer();
+ }
+ } catch (final IOException e) {
+ Activator.getDefault().logError("Error parsing event. File: " + getPath(), e); //$NON-NLS-1$
+
+ }
+ context.setLocation(NULL_LOCATION);
+ return event;
+ }
+
+ private Element parseElementBuffer(final StringBuffer elementBuffer) {
+ try {
+ final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ final DocumentBuilder db = dbf.newDocumentBuilder();
+
+ // The following allows xml parsing without access to the dtd
+ final EntityResolver resolver = new EntityResolver () {
+ @Override
+ public InputSource resolveEntity (final String publicId, final String systemId) {
+ final String empty = ""; //$NON-NLS-1$
+ final ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());
+ return new InputSource(bais);
+ }
+ };
+ db.setEntityResolver(resolver);
+
+ // The following catches xml parsing exceptions
+ db.setErrorHandler(new ErrorHandler(){
+ @Override
+ public void error(final SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void warning(final SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void fatalError(final SAXParseException saxparseexception) throws SAXException {
+ throw saxparseexception;
+ }});
+
+ final Document doc = db.parse(new ByteArrayInputStream(elementBuffer.toString().getBytes()));
+ return doc.getDocumentElement();
+ } catch (final ParserConfigurationException e) {
+ Activator.getDefault().logError("Error parsing element buffer. File:" + getPath(), e); //$NON-NLS-1$
+ } catch (final SAXException e) {
+ Activator.getDefault().logError("Error parsing element buffer. File:" + getPath(), e); //$NON-NLS-1$
+ } catch (final IOException e) {
+ Activator.getDefault().logError("Error parsing element buffer. File: " + getPath(), e); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ private void readElement(final StringBuffer buffer, final RandomAccessFile raFile) {
+ try {
+ int numRead = 0;
+ boolean startTagClosed = false;
+ int i;
+ while ((i = raFile.read()) != -1) {
+ numRead++;
+ final char c = (char)i;
+ buffer.append(c);
+ if (c == '"') {
+ readQuote(buffer, raFile, '"');
+ } else if (c == '\'') {
+ readQuote(buffer, raFile, '\'');
+ } else if (c == '<') {
+ readElement(buffer, raFile);
+ } else if (c == '/' && numRead == 1) {
+ break; // found "</"
+ } else if (c == '-' && numRead == 3 && buffer.substring(buffer.length() - 3, buffer.length() - 1).equals("!-")) { //$NON-NLS-1$
+ readComment(buffer, raFile); // found "<!--"
+ } else if (i == '>') {
+ if (buffer.charAt(buffer.length() - 2) == '/') {
+ break; // found "/>"
+ } else if (startTagClosed) {
+ break; // found "<...>...</...>"
+ }
+ else {
+ startTagClosed = true; // found "<...>"
+ }
+ }
+ }
+ return;
+ } catch (final IOException e) {
+ return;
+ }
+ }
+
+ private static void readQuote(final StringBuffer buffer,
+ final RandomAccessFile raFile, final char eq) {
+ try {
+ int i;
+ while ((i = raFile.read()) != -1) {
+ final char c = (char)i;
+ buffer.append(c);
+ if (c == eq)
+ {
+ break; // found matching end-quote
+ }
+ }
+ return;
+ } catch (final IOException e) {
+ return;
+ }
+ }
+
+ private static void readComment(final StringBuffer buffer,
+ final RandomAccessFile raFile) {
+ try {
+ int numRead = 0;
+ int i;
+ while ((i = raFile.read()) != -1) {
+ numRead++;
+ final char c = (char)i;
+ buffer.append(c);
+ if (c == '>' && numRead >= 2 && buffer.substring(buffer.length() - 3, buffer.length() - 1).equals("--")) //$NON-NLS-1$
+ {
+ break; // found "-->"
+ }
+ }
+ return;
+ } catch (final IOException e) {
+ return;
+ }
+ }
+
+ public static StringBuffer parseElement(final Element parentElement, final StringBuffer buffer) {
+ final NodeList nodeList = parentElement.getChildNodes();
+ String separator = null;
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ final Node node = nodeList.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ if (separator == null) {
+ separator = " | "; //$NON-NLS-1$
+ } else {
+ buffer.append(separator);
+ }
+ final Element element = (Element) node;
+ if (!element.hasChildNodes()) {
+ buffer.append(element.getNodeName());
+ } else if (element.getChildNodes().getLength() == 1 && element.getFirstChild().getNodeType() == Node.TEXT_NODE) {
+ buffer.append(element.getNodeName() + ":" + element.getFirstChild().getNodeValue().trim()); //$NON-NLS-1$
+ } else {
+ buffer.append(element.getNodeName());
+ buffer.append(" [ "); //$NON-NLS-1$
+ parseElement(element, buffer);
+ buffer.append(" ]"); //$NON-NLS-1$
+ }
+ } else if (node.getNodeType() == Node.TEXT_NODE) {
+ if (node.getNodeValue().trim().length() != 0) {
+ buffer.append(node.getNodeValue().trim());
+ }
+ }
+ }
+ return buffer;
+ }
+
+ public InputElement getRecordInputElement(final InputElement inputElement) {
+ if (inputElement.logEntry) {
+ return inputElement;
+ } else if (inputElement.childElements != null) {
+ for (final InputElement childInputElement : inputElement.childElements) {
+ final InputElement recordInputElement = getRecordInputElement(childInputElement);
+ if (recordInputElement != null) {
+ return recordInputElement;
+ }
+ }
+ }
+ return null;
+ }
+
+ public CustomXmlEvent extractEvent(final Element element, final InputElement inputElement) {
+ final CustomXmlEvent event = new CustomXmlEvent(fDefinition, this, TmfTimestamp.ZERO, "", fEventType,""); //$NON-NLS-1$ //$NON-NLS-2$
+ event.setContent(new CustomEventContent(event, new StringBuffer()));
+ parseElement(element, event, inputElement);
+ return event;
+ }
+
+ private void parseElement(final Element element, final CustomXmlEvent event, final InputElement inputElement) {
+ if (inputElement.inputName != null && !inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) {
+ event.parseInput(parseElement(element, new StringBuffer()).toString(), inputElement.inputName, inputElement.inputAction, inputElement.inputFormat);
+ }
+ if (inputElement.attributes != null) {
+ for (final InputAttribute attribute : inputElement.attributes) {
+ event.parseInput(element.getAttribute(attribute.attributeName), attribute.inputName, attribute.inputAction, attribute.inputFormat);
+ }
+ }
+ final NodeList childNodes = element.getChildNodes();
+ if (inputElement.childElements != null) {
+ for (int i = 0; i < childNodes.getLength(); i++) {
+ final Node node = childNodes.item(i);
+ if (node instanceof Element) {
+ for (final InputElement child : inputElement.childElements) {
+ if (node.getNodeName().equals(child.elementName)) {
+ parseElement((Element) node, event, child);
+ break;
+ }
+ }
+ }
+ }
+ }
+ return;
+ }
+
+ public CustomTraceDefinition getDefinition() {
+ return fDefinition;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String)
+ */
+ @Override
+ public boolean validate(IProject project, String path) {
+ return fileExists(path);
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r
-\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfContext;\r
-\r
-public class CustomXmlTraceContext extends TmfContext {\r
-\r
- public CustomXmlTraceContext(ITmfLocation location, long rank) {\r
- super(location, rank);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#hashCode()\r
- */\r
- @Override\r
- public int hashCode() {\r
- return super.hashCode();\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#equals(java.lang.Object)\r
- */\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj) {\r
- return true;\r
- }\r
- if (!super.equals(obj)) {\r
- return false;\r
- }\r
- if (!(obj instanceof CustomXmlTraceContext)) {\r
- return false;\r
- }\r
- return true;\r
- }\r
-\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.parsers.custom;
+
+import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+
+public class CustomXmlTraceContext extends TmfContext {
+
+ public CustomXmlTraceContext(ITmfLocation location, long rank) {
+ super(location, rank);
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (!(obj instanceof CustomXmlTraceContext)) {
+ return false;
+ }
+ return true;
+ }
+
}
\ No newline at end of file
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r
-\r
-import java.io.ByteArrayInputStream;\r
-import java.io.File;\r
-import java.io.FileWriter;\r
-import java.io.IOException;\r
-import java.io.StringWriter;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import javax.xml.parsers.DocumentBuilder;\r
-import javax.xml.parsers.DocumentBuilderFactory;\r
-import javax.xml.parsers.ParserConfigurationException;\r
-import javax.xml.transform.OutputKeys;\r
-import javax.xml.transform.Transformer;\r
-import javax.xml.transform.TransformerConfigurationException;\r
-import javax.xml.transform.TransformerException;\r
-import javax.xml.transform.TransformerFactory;\r
-import javax.xml.transform.TransformerFactoryConfigurationError;\r
-import javax.xml.transform.dom.DOMSource;\r
-import javax.xml.transform.stream.StreamResult;\r
-\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.w3c.dom.Document;\r
-import org.w3c.dom.Element;\r
-import org.w3c.dom.Node;\r
-import org.w3c.dom.NodeList;\r
-import org.xml.sax.EntityResolver;\r
-import org.xml.sax.ErrorHandler;\r
-import org.xml.sax.InputSource;\r
-import org.xml.sax.SAXException;\r
-import org.xml.sax.SAXParseException;\r
-\r
-public class CustomXmlTraceDefinition extends CustomTraceDefinition {\r
-\r
- protected static final String CUSTOM_XML_TRACE_DEFINITIONS_FILE_NAME = "custom_xml_parsers.xml"; //$NON-NLS-1$\r
- protected static final String CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME =\r
- Activator.getDefault().getStateLocation().addTrailingSeparator().append(CUSTOM_XML_TRACE_DEFINITIONS_FILE_NAME).toString();\r
-\r
- public static final String TAG_IGNORE = Messages.CustomXmlTraceDefinition_ignoreTag;\r
-\r
- private static final String CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT = Messages.CustomXmlTraceDefinition_definitionRootElement;\r
- private static final String DEFINITION_ELEMENT = Messages.CustomXmlTraceDefinition_definition;\r
- private static final String NAME_ATTRIBUTE = Messages.CustomXmlTraceDefinition_name;\r
- private static final String LOG_ENTRY_ATTRIBUTE = Messages.CustomXmlTraceDefinition_logEntry;\r
- private static final String TIME_STAMP_OUTPUT_FORMAT_ELEMENT = Messages.CustomXmlTraceDefinition_timestampOutputFormat;\r
- private static final String INPUT_ELEMENT_ELEMENT = Messages.CustomXmlTraceDefinition_inputElement;\r
- private static final String ATTRIBUTE_ELEMENT = Messages.CustomXmlTraceDefinition_attribute;\r
- private static final String INPUT_DATA_ELEMENT = Messages.CustomXmlTraceDefinition_inputData;\r
- private static final String ACTION_ATTRIBUTE = Messages.CustomXmlTraceDefinition_action;\r
- private static final String FORMAT_ATTRIBUTE = Messages.CustomXmlTraceDefinition_format;\r
- private static final String OUTPUT_COLUMN_ELEMENT = Messages.CustomXmlTraceDefinition_outputColumn;\r
-\r
- public InputElement rootInputElement;\r
-\r
- public CustomXmlTraceDefinition() {\r
- this("", null, new ArrayList<OutputColumn>(), ""); //$NON-NLS-1$ //$NON-NLS-2$\r
- }\r
-\r
- public CustomXmlTraceDefinition(String logtype, InputElement rootElement, List<OutputColumn> outputs, String timeStampOutputFormat) {\r
- this.definitionName = logtype;\r
- this.rootInputElement = rootElement;\r
- this.outputs = outputs;\r
- this.timeStampOutputFormat = timeStampOutputFormat;\r
- }\r
-\r
- public static class InputElement {\r
- public String elementName;\r
- public boolean logEntry;\r
- public String inputName;\r
- public int inputAction;\r
- public String inputFormat;\r
- public List<InputAttribute> attributes;\r
- public InputElement parentElement;\r
- public InputElement nextElement;\r
- public List<InputElement> childElements;\r
-\r
- public InputElement() {}\r
-\r
- public InputElement(String elementName, boolean logEntry, String inputName, int inputAction, String inputFormat, List<InputAttribute> attributes) {\r
- this.elementName = elementName;\r
- this.logEntry = logEntry;\r
- this.inputName = inputName;\r
- this.inputAction = inputAction;\r
- this.inputFormat = inputFormat;\r
- this.attributes = attributes;\r
- }\r
-\r
- public void addAttribute(InputAttribute attribute) {\r
- if (attributes == null) {\r
- attributes = new ArrayList<InputAttribute>(1);\r
- }\r
- attributes.add(attribute);\r
- }\r
-\r
- public void addChild(InputElement input) {\r
- if (childElements == null) {\r
- childElements = new ArrayList<InputElement>(1);\r
- } else if (childElements.size() > 0) {\r
- InputElement last = childElements.get(childElements.size() - 1);\r
- last.nextElement = input;\r
- }\r
- childElements.add(input);\r
- input.parentElement = this;\r
- }\r
-\r
- public void addNext(InputElement input) {\r
- if (parentElement != null) {\r
- int index = parentElement.childElements.indexOf(this);\r
- parentElement.childElements.add(index + 1, input);\r
- InputElement next = nextElement;\r
- nextElement = input;\r
- input.nextElement = next;\r
- }\r
- input.parentElement = this.parentElement;\r
- }\r
-\r
- public void moveUp() {\r
- if (parentElement != null) {\r
- int index = parentElement.childElements.indexOf(this);\r
- if (index > 0) {\r
- parentElement.childElements.add(index - 1 , parentElement.childElements.remove(index));\r
- parentElement.childElements.get(index).nextElement = nextElement;\r
- nextElement = parentElement.childElements.get(index);\r
- }\r
- }\r
- }\r
-\r
- public void moveDown() {\r
- if (parentElement != null) {\r
- int index = parentElement.childElements.indexOf(this);\r
- if (index < parentElement.childElements.size() - 1) {\r
- parentElement.childElements.add(index + 1 , parentElement.childElements.remove(index));\r
- nextElement = parentElement.childElements.get(index).nextElement;\r
- parentElement.childElements.get(index).nextElement = this;\r
- }\r
- }\r
- }\r
-\r
- }\r
-\r
- public static class InputAttribute {\r
- public String attributeName;\r
- public String inputName;\r
- public int inputAction;\r
- public String inputFormat;\r
-\r
- public InputAttribute() {}\r
-\r
- public InputAttribute(String attributeName, String inputName, int inputAction, String inputFormat) {\r
- this.attributeName = attributeName;\r
- this.inputName = inputName;\r
- this.inputAction = inputAction;\r
- this.inputFormat = inputFormat;\r
- }\r
- }\r
-\r
- @Override\r
- public void save() {\r
- save(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME);\r
- }\r
-\r
- @Override\r
- public void save(String path) {\r
- try {\r
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\r
- DocumentBuilder db = dbf.newDocumentBuilder();\r
-\r
- // The following allows xml parsing without access to the dtd\r
- EntityResolver resolver = new EntityResolver () {\r
- @Override\r
- public InputSource resolveEntity (String publicId, String systemId) {\r
- String empty = ""; //$NON-NLS-1$\r
- ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());\r
- return new InputSource(bais);\r
- }\r
- };\r
- db.setEntityResolver(resolver);\r
-\r
- // The following catches xml parsing exceptions\r
- db.setErrorHandler(new ErrorHandler(){\r
- @Override\r
- public void error(SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void warning(SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void fatalError(SAXParseException saxparseexception) throws SAXException {\r
- throw saxparseexception;\r
- }});\r
-\r
- Document doc = null;\r
- File file = new File(path);\r
- if (file.canRead()) {\r
- doc = db.parse(file);\r
- if (! doc.getDocumentElement().getNodeName().equals(CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT)) {\r
- return;\r
- }\r
- } else {\r
- doc = db.newDocument();\r
- Node node = doc.createElement(CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT);\r
- doc.appendChild(node);\r
- }\r
-\r
- Element root = doc.getDocumentElement();\r
-\r
- NodeList nodeList = root.getChildNodes();\r
- for (int i = 0; i < nodeList.getLength(); i++) {\r
- Node node = nodeList.item(i);\r
- if (node instanceof Element &&\r
- node.getNodeName().equals(DEFINITION_ELEMENT) &&\r
- definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {\r
- root.removeChild(node);\r
- }\r
- }\r
- Element definitionElement = doc.createElement(DEFINITION_ELEMENT);\r
- root.appendChild(definitionElement);\r
- definitionElement.setAttribute(NAME_ATTRIBUTE, definitionName);\r
-\r
- Element formatElement = doc.createElement(TIME_STAMP_OUTPUT_FORMAT_ELEMENT);\r
- definitionElement.appendChild(formatElement);\r
- formatElement.appendChild(doc.createTextNode(timeStampOutputFormat));\r
-\r
- if (rootInputElement != null) {\r
- definitionElement.appendChild(createInputElementElement(rootInputElement, doc));\r
- }\r
-\r
- if (outputs != null) {\r
- for (OutputColumn output : outputs) {\r
- Element outputColumnElement = doc.createElement(OUTPUT_COLUMN_ELEMENT);\r
- definitionElement.appendChild(outputColumnElement);\r
- outputColumnElement.setAttribute(NAME_ATTRIBUTE, output.name);\r
- }\r
- }\r
-\r
- Transformer transformer = TransformerFactory.newInstance().newTransformer();\r
- transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$\r
-\r
- //initialize StreamResult with File object to save to file\r
- StreamResult result = new StreamResult(new StringWriter());\r
- DOMSource source = new DOMSource(doc);\r
- transformer.transform(source, result);\r
- String xmlString = result.getWriter().toString();\r
-\r
- FileWriter writer = new FileWriter(file);\r
- writer.write(xmlString);\r
- writer.close();\r
- } catch (ParserConfigurationException e) {\r
- Activator.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- } catch (TransformerConfigurationException e) {\r
- Activator.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- } catch (TransformerFactoryConfigurationError e) {\r
- Activator.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- } catch (TransformerException e) {\r
- Activator.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- } catch (IOException e) {\r
- Activator.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- } catch (SAXException e) {\r
- Activator.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- }\r
- }\r
-\r
- private Element createInputElementElement(InputElement inputElement, Document doc) {\r
- Element inputElementElement = doc.createElement(INPUT_ELEMENT_ELEMENT);\r
- inputElementElement.setAttribute(NAME_ATTRIBUTE, inputElement.elementName);\r
-\r
- if (inputElement.logEntry) {\r
- inputElementElement.setAttribute(LOG_ENTRY_ATTRIBUTE, Boolean.toString(inputElement.logEntry));\r
- }\r
-\r
- if (inputElement.parentElement != null) {\r
- Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT);\r
- inputElementElement.appendChild(inputDataElement);\r
- inputDataElement.setAttribute(NAME_ATTRIBUTE, inputElement.inputName);\r
- inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(inputElement.inputAction));\r
- if (inputElement.inputFormat != null) {\r
- inputDataElement.setAttribute(FORMAT_ATTRIBUTE, inputElement.inputFormat);\r
- }\r
- }\r
-\r
- if (inputElement.attributes != null) {\r
- for (InputAttribute attribute : inputElement.attributes) {\r
- Element inputAttributeElement = doc.createElement(ATTRIBUTE_ELEMENT);\r
- inputElementElement.appendChild(inputAttributeElement);\r
- inputAttributeElement.setAttribute(NAME_ATTRIBUTE, attribute.attributeName);\r
- Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT);\r
- inputAttributeElement.appendChild(inputDataElement);\r
- inputDataElement.setAttribute(NAME_ATTRIBUTE, attribute.inputName);\r
- inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(attribute.inputAction));\r
- if (attribute.inputFormat != null) {\r
- inputDataElement.setAttribute(FORMAT_ATTRIBUTE, attribute.inputFormat);\r
- }\r
- }\r
- }\r
-\r
- if (inputElement.childElements != null) {\r
- for (InputElement childInputElement : inputElement.childElements) {\r
- inputElementElement.appendChild(createInputElementElement(childInputElement, doc));\r
- }\r
- }\r
-\r
- return inputElementElement;\r
- }\r
-\r
- public static CustomXmlTraceDefinition[] loadAll() {\r
- return loadAll(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME);\r
- }\r
-\r
- public static CustomXmlTraceDefinition[] loadAll(String path) {\r
- try {\r
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\r
- DocumentBuilder db = dbf.newDocumentBuilder();\r
-\r
- // The following allows xml parsing without access to the dtd\r
- EntityResolver resolver = new EntityResolver () {\r
- @Override\r
- public InputSource resolveEntity (String publicId, String systemId) {\r
- String empty = ""; //$NON-NLS-1$\r
- ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());\r
- return new InputSource(bais);\r
- }\r
- };\r
- db.setEntityResolver(resolver);\r
-\r
- // The following catches xml parsing exceptions\r
- db.setErrorHandler(new ErrorHandler(){\r
- @Override\r
- public void error(SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void warning(SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void fatalError(SAXParseException saxparseexception) throws SAXException {\r
- throw saxparseexception;\r
- }});\r
-\r
- File file = new File(path);\r
- if (!file.canRead()) {\r
- return new CustomXmlTraceDefinition[0];\r
- }\r
- Document doc = db.parse(file);\r
-\r
- Element root = doc.getDocumentElement();\r
- if (! root.getNodeName().equals(CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT)) {\r
- return new CustomXmlTraceDefinition[0];\r
- }\r
-\r
- ArrayList<CustomXmlTraceDefinition> defList = new ArrayList<CustomXmlTraceDefinition>();\r
- NodeList nodeList = root.getChildNodes();\r
- for (int i = 0; i < nodeList.getLength(); i++) {\r
- Node node = nodeList.item(i);\r
- if (node instanceof Element && node.getNodeName().equals(DEFINITION_ELEMENT)) {\r
- CustomXmlTraceDefinition def = extractDefinition((Element) node);\r
- if (def != null) {\r
- defList.add(def);\r
- }\r
- }\r
- }\r
- return defList.toArray(new CustomXmlTraceDefinition[0]);\r
- } catch (ParserConfigurationException e) {\r
- Activator.getDefault().logError("Error loading all in CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- } catch (SAXException e) {\r
- Activator.getDefault().logError("Error loading all in CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- } catch (IOException e) {\r
- Activator.getDefault().logError("Error loading all in CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$\r
- }\r
- return new CustomXmlTraceDefinition[0];\r
- }\r
-\r
- public static CustomXmlTraceDefinition load(String definitionName) {\r
- try {\r
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\r
- DocumentBuilder db = dbf.newDocumentBuilder();\r
-\r
- // The following allows xml parsing without access to the dtd\r
- EntityResolver resolver = new EntityResolver () {\r
- @Override\r
- public InputSource resolveEntity (String publicId, String systemId) {\r
- String empty = ""; //$NON-NLS-1$\r
- ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());\r
- return new InputSource(bais);\r
- }\r
- };\r
- db.setEntityResolver(resolver);\r
-\r
- // The following catches xml parsing exceptions\r
- db.setErrorHandler(new ErrorHandler(){\r
- @Override\r
- public void error(SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void warning(SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void fatalError(SAXParseException saxparseexception) throws SAXException {\r
- throw saxparseexception;\r
- }});\r
-\r
- File file = new File(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME);\r
- Document doc = db.parse(file);\r
-\r
- Element root = doc.getDocumentElement();\r
- if (! root.getNodeName().equals(CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT)) {\r
- return null;\r
- }\r
-\r
- NodeList nodeList = root.getChildNodes();\r
- for (int i = 0; i < nodeList.getLength(); i++) {\r
- Node node = nodeList.item(i);\r
- if (node instanceof Element &&\r
- node.getNodeName().equals(DEFINITION_ELEMENT) &&\r
- definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {\r
- return extractDefinition((Element) node);\r
- }\r
- }\r
- } catch (ParserConfigurationException e) {\r
- Activator.getDefault().logError("Error loading CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$\r
- } catch (SAXException e) {\r
- Activator.getDefault().logError("Error loading CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$\r
- } catch (IOException e) {\r
- Activator.getDefault().logError("Error loading CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$\r
- }\r
- return null;\r
- }\r
-\r
- public static CustomXmlTraceDefinition extractDefinition(Element definitionElement) {\r
- CustomXmlTraceDefinition def = new CustomXmlTraceDefinition();\r
-\r
- def.definitionName = definitionElement.getAttribute(NAME_ATTRIBUTE);\r
- if (def.definitionName == null) {\r
- return null;\r
- }\r
-\r
- NodeList nodeList = definitionElement.getChildNodes();\r
- for (int i = 0; i < nodeList.getLength(); i++) {\r
- Node node = nodeList.item(i);\r
- String nodeName = node.getNodeName();\r
- if (nodeName.equals(TIME_STAMP_OUTPUT_FORMAT_ELEMENT)) {\r
- Element formatElement = (Element) node;\r
- def.timeStampOutputFormat = formatElement.getTextContent();\r
- } else if (nodeName.equals(INPUT_ELEMENT_ELEMENT)) {\r
- InputElement inputElement = extractInputElement((Element) node);\r
- if (inputElement != null) {\r
- if (def.rootInputElement == null) {\r
- def.rootInputElement = inputElement;\r
- } else {\r
- return null;\r
- }\r
- }\r
- } else if (nodeName.equals(OUTPUT_COLUMN_ELEMENT)) {\r
- Element outputColumnElement = (Element) node;\r
- OutputColumn outputColumn = new OutputColumn();\r
- outputColumn.name = outputColumnElement.getAttribute(NAME_ATTRIBUTE);\r
- def.outputs.add(outputColumn);\r
- }\r
- }\r
- return def;\r
- }\r
-\r
- private static InputElement extractInputElement(Element inputElementElement) {\r
- InputElement inputElement = new InputElement();\r
- inputElement.elementName = inputElementElement.getAttribute(NAME_ATTRIBUTE);\r
- inputElement.logEntry = (Boolean.toString(true).equals(inputElementElement.getAttribute(LOG_ENTRY_ATTRIBUTE))) ? true : false;\r
- NodeList nodeList = inputElementElement.getChildNodes();\r
- for (int i = 0; i < nodeList.getLength(); i++) {\r
- Node node = nodeList.item(i);\r
- String nodeName = node.getNodeName();\r
- if (nodeName.equals(INPUT_DATA_ELEMENT)) {\r
- Element inputDataElement = (Element) node;\r
- inputElement.inputName = inputDataElement.getAttribute(NAME_ATTRIBUTE);\r
- inputElement.inputAction = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE));\r
- inputElement.inputFormat = inputDataElement.getAttribute(FORMAT_ATTRIBUTE);\r
- } else if (nodeName.equals(ATTRIBUTE_ELEMENT)) {\r
- Element attributeElement = (Element) node;\r
- InputAttribute attribute = new InputAttribute();\r
- attribute.attributeName = attributeElement.getAttribute(NAME_ATTRIBUTE);\r
- NodeList attributeNodeList = attributeElement.getChildNodes();\r
- for (int j = 0; j < attributeNodeList.getLength(); j++) {\r
- Node attributeNode = attributeNodeList.item(j);\r
- String attributeNodeName = attributeNode.getNodeName();\r
- if (attributeNodeName.equals(INPUT_DATA_ELEMENT)) {\r
- Element inputDataElement = (Element) attributeNode;\r
- attribute.inputName = inputDataElement.getAttribute(NAME_ATTRIBUTE);\r
- attribute.inputAction = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE));\r
- attribute.inputFormat = inputDataElement.getAttribute(FORMAT_ATTRIBUTE);\r
- }\r
- }\r
- inputElement.addAttribute(attribute);\r
- } else if (nodeName.equals(INPUT_ELEMENT_ELEMENT)) {\r
- Element childInputElementElement = (Element) node;\r
- InputElement childInputElement = extractInputElement(childInputElementElement);\r
- if (childInputElement != null) {\r
- inputElement.addChild(childInputElement);\r
- }\r
- }\r
- }\r
- return inputElement;\r
- }\r
-\r
- public static void delete(String definitionName) {\r
- try {\r
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\r
- DocumentBuilder db = dbf.newDocumentBuilder();\r
-\r
- // The following allows xml parsing without access to the dtd\r
- EntityResolver resolver = new EntityResolver () {\r
- @Override\r
- public InputSource resolveEntity (String publicId, String systemId) {\r
- String empty = ""; //$NON-NLS-1$\r
- ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());\r
- return new InputSource(bais);\r
- }\r
- };\r
- db.setEntityResolver(resolver);\r
-\r
- // The following catches xml parsing exceptions\r
- db.setErrorHandler(new ErrorHandler(){\r
- @Override\r
- public void error(SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void warning(SAXParseException saxparseexception) throws SAXException {}\r
- @Override\r
- public void fatalError(SAXParseException saxparseexception) throws SAXException {\r
- throw saxparseexception;\r
- }});\r
-\r
- File file = new File(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME);\r
- Document doc = db.parse(file);\r
-\r
- Element root = doc.getDocumentElement();\r
- if (! root.getNodeName().equals(CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT)) {\r
- return;\r
- }\r
-\r
- NodeList nodeList = root.getChildNodes();\r
- for (int i = 0; i < nodeList.getLength(); i++) {\r
- Node node = nodeList.item(i);\r
- if (node instanceof Element &&\r
- node.getNodeName().equals(DEFINITION_ELEMENT) &&\r
- definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {\r
- root.removeChild(node);\r
- }\r
- }\r
-\r
- Transformer transformer = TransformerFactory.newInstance().newTransformer();\r
- transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$\r
-\r
- //initialize StreamResult with File object to save to file\r
- StreamResult result = new StreamResult(new StringWriter());\r
- DOMSource source = new DOMSource(doc);\r
- transformer.transform(source, result);\r
- String xmlString = result.getWriter().toString();\r
-\r
- FileWriter writer = new FileWriter(file);\r
- writer.write(xmlString);\r
- writer.close();\r
- } catch (ParserConfigurationException e) {\r
- Activator.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$\r
- } catch (SAXException e) {\r
- Activator.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$\r
- } catch (IOException e) {\r
- Activator.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$\r
- } catch (TransformerConfigurationException e) {\r
- Activator.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$\r
- } catch (TransformerFactoryConfigurationError e) {\r
- Activator.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$\r
- } catch (TransformerException e) {\r
- Activator.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$\r
- }\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.parsers.custom;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+public class CustomXmlTraceDefinition extends CustomTraceDefinition {
+
+ protected static final String CUSTOM_XML_TRACE_DEFINITIONS_FILE_NAME = "custom_xml_parsers.xml"; //$NON-NLS-1$
+ protected static final String CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME =
+ Activator.getDefault().getStateLocation().addTrailingSeparator().append(CUSTOM_XML_TRACE_DEFINITIONS_FILE_NAME).toString();
+
+ public static final String TAG_IGNORE = Messages.CustomXmlTraceDefinition_ignoreTag;
+
+ private static final String CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT = Messages.CustomXmlTraceDefinition_definitionRootElement;
+ private static final String DEFINITION_ELEMENT = Messages.CustomXmlTraceDefinition_definition;
+ private static final String NAME_ATTRIBUTE = Messages.CustomXmlTraceDefinition_name;
+ private static final String LOG_ENTRY_ATTRIBUTE = Messages.CustomXmlTraceDefinition_logEntry;
+ private static final String TIME_STAMP_OUTPUT_FORMAT_ELEMENT = Messages.CustomXmlTraceDefinition_timestampOutputFormat;
+ private static final String INPUT_ELEMENT_ELEMENT = Messages.CustomXmlTraceDefinition_inputElement;
+ private static final String ATTRIBUTE_ELEMENT = Messages.CustomXmlTraceDefinition_attribute;
+ private static final String INPUT_DATA_ELEMENT = Messages.CustomXmlTraceDefinition_inputData;
+ private static final String ACTION_ATTRIBUTE = Messages.CustomXmlTraceDefinition_action;
+ private static final String FORMAT_ATTRIBUTE = Messages.CustomXmlTraceDefinition_format;
+ private static final String OUTPUT_COLUMN_ELEMENT = Messages.CustomXmlTraceDefinition_outputColumn;
+
+ public InputElement rootInputElement;
+
+ public CustomXmlTraceDefinition() {
+ this("", null, new ArrayList<OutputColumn>(), ""); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public CustomXmlTraceDefinition(String logtype, InputElement rootElement, List<OutputColumn> outputs, String timeStampOutputFormat) {
+ this.definitionName = logtype;
+ this.rootInputElement = rootElement;
+ this.outputs = outputs;
+ this.timeStampOutputFormat = timeStampOutputFormat;
+ }
+
+ public static class InputElement {
+ public String elementName;
+ public boolean logEntry;
+ public String inputName;
+ public int inputAction;
+ public String inputFormat;
+ public List<InputAttribute> attributes;
+ public InputElement parentElement;
+ public InputElement nextElement;
+ public List<InputElement> childElements;
+
+ public InputElement() {}
+
+ public InputElement(String elementName, boolean logEntry, String inputName, int inputAction, String inputFormat, List<InputAttribute> attributes) {
+ this.elementName = elementName;
+ this.logEntry = logEntry;
+ this.inputName = inputName;
+ this.inputAction = inputAction;
+ this.inputFormat = inputFormat;
+ this.attributes = attributes;
+ }
+
+ public void addAttribute(InputAttribute attribute) {
+ if (attributes == null) {
+ attributes = new ArrayList<InputAttribute>(1);
+ }
+ attributes.add(attribute);
+ }
+
+ public void addChild(InputElement input) {
+ if (childElements == null) {
+ childElements = new ArrayList<InputElement>(1);
+ } else if (childElements.size() > 0) {
+ InputElement last = childElements.get(childElements.size() - 1);
+ last.nextElement = input;
+ }
+ childElements.add(input);
+ input.parentElement = this;
+ }
+
+ public void addNext(InputElement input) {
+ if (parentElement != null) {
+ int index = parentElement.childElements.indexOf(this);
+ parentElement.childElements.add(index + 1, input);
+ InputElement next = nextElement;
+ nextElement = input;
+ input.nextElement = next;
+ }
+ input.parentElement = this.parentElement;
+ }
+
+ public void moveUp() {
+ if (parentElement != null) {
+ int index = parentElement.childElements.indexOf(this);
+ if (index > 0) {
+ parentElement.childElements.add(index - 1 , parentElement.childElements.remove(index));
+ parentElement.childElements.get(index).nextElement = nextElement;
+ nextElement = parentElement.childElements.get(index);
+ }
+ }
+ }
+
+ public void moveDown() {
+ if (parentElement != null) {
+ int index = parentElement.childElements.indexOf(this);
+ if (index < parentElement.childElements.size() - 1) {
+ parentElement.childElements.add(index + 1 , parentElement.childElements.remove(index));
+ nextElement = parentElement.childElements.get(index).nextElement;
+ parentElement.childElements.get(index).nextElement = this;
+ }
+ }
+ }
+
+ }
+
+ public static class InputAttribute {
+ public String attributeName;
+ public String inputName;
+ public int inputAction;
+ public String inputFormat;
+
+ public InputAttribute() {}
+
+ public InputAttribute(String attributeName, String inputName, int inputAction, String inputFormat) {
+ this.attributeName = attributeName;
+ this.inputName = inputName;
+ this.inputAction = inputAction;
+ this.inputFormat = inputFormat;
+ }
+ }
+
+ @Override
+ public void save() {
+ save(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME);
+ }
+
+ @Override
+ public void save(String path) {
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ // The following allows xml parsing without access to the dtd
+ EntityResolver resolver = new EntityResolver () {
+ @Override
+ public InputSource resolveEntity (String publicId, String systemId) {
+ String empty = ""; //$NON-NLS-1$
+ ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());
+ return new InputSource(bais);
+ }
+ };
+ db.setEntityResolver(resolver);
+
+ // The following catches xml parsing exceptions
+ db.setErrorHandler(new ErrorHandler(){
+ @Override
+ public void error(SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void warning(SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void fatalError(SAXParseException saxparseexception) throws SAXException {
+ throw saxparseexception;
+ }});
+
+ Document doc = null;
+ File file = new File(path);
+ if (file.canRead()) {
+ doc = db.parse(file);
+ if (! doc.getDocumentElement().getNodeName().equals(CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT)) {
+ return;
+ }
+ } else {
+ doc = db.newDocument();
+ Node node = doc.createElement(CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT);
+ doc.appendChild(node);
+ }
+
+ Element root = doc.getDocumentElement();
+
+ NodeList nodeList = root.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ if (node instanceof Element &&
+ node.getNodeName().equals(DEFINITION_ELEMENT) &&
+ definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {
+ root.removeChild(node);
+ }
+ }
+ Element definitionElement = doc.createElement(DEFINITION_ELEMENT);
+ root.appendChild(definitionElement);
+ definitionElement.setAttribute(NAME_ATTRIBUTE, definitionName);
+
+ Element formatElement = doc.createElement(TIME_STAMP_OUTPUT_FORMAT_ELEMENT);
+ definitionElement.appendChild(formatElement);
+ formatElement.appendChild(doc.createTextNode(timeStampOutputFormat));
+
+ if (rootInputElement != null) {
+ definitionElement.appendChild(createInputElementElement(rootInputElement, doc));
+ }
+
+ if (outputs != null) {
+ for (OutputColumn output : outputs) {
+ Element outputColumnElement = doc.createElement(OUTPUT_COLUMN_ELEMENT);
+ definitionElement.appendChild(outputColumnElement);
+ outputColumnElement.setAttribute(NAME_ATTRIBUTE, output.name);
+ }
+ }
+
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+
+ //initialize StreamResult with File object to save to file
+ StreamResult result = new StreamResult(new StringWriter());
+ DOMSource source = new DOMSource(doc);
+ transformer.transform(source, result);
+ String xmlString = result.getWriter().toString();
+
+ FileWriter writer = new FileWriter(file);
+ writer.write(xmlString);
+ writer.close();
+ } catch (ParserConfigurationException e) {
+ Activator.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ } catch (TransformerConfigurationException e) {
+ Activator.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ } catch (TransformerFactoryConfigurationError e) {
+ Activator.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ } catch (TransformerException e) {
+ Activator.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ } catch (SAXException e) {
+ Activator.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ }
+ }
+
+ private Element createInputElementElement(InputElement inputElement, Document doc) {
+ Element inputElementElement = doc.createElement(INPUT_ELEMENT_ELEMENT);
+ inputElementElement.setAttribute(NAME_ATTRIBUTE, inputElement.elementName);
+
+ if (inputElement.logEntry) {
+ inputElementElement.setAttribute(LOG_ENTRY_ATTRIBUTE, Boolean.toString(inputElement.logEntry));
+ }
+
+ if (inputElement.parentElement != null) {
+ Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT);
+ inputElementElement.appendChild(inputDataElement);
+ inputDataElement.setAttribute(NAME_ATTRIBUTE, inputElement.inputName);
+ inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(inputElement.inputAction));
+ if (inputElement.inputFormat != null) {
+ inputDataElement.setAttribute(FORMAT_ATTRIBUTE, inputElement.inputFormat);
+ }
+ }
+
+ if (inputElement.attributes != null) {
+ for (InputAttribute attribute : inputElement.attributes) {
+ Element inputAttributeElement = doc.createElement(ATTRIBUTE_ELEMENT);
+ inputElementElement.appendChild(inputAttributeElement);
+ inputAttributeElement.setAttribute(NAME_ATTRIBUTE, attribute.attributeName);
+ Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT);
+ inputAttributeElement.appendChild(inputDataElement);
+ inputDataElement.setAttribute(NAME_ATTRIBUTE, attribute.inputName);
+ inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(attribute.inputAction));
+ if (attribute.inputFormat != null) {
+ inputDataElement.setAttribute(FORMAT_ATTRIBUTE, attribute.inputFormat);
+ }
+ }
+ }
+
+ if (inputElement.childElements != null) {
+ for (InputElement childInputElement : inputElement.childElements) {
+ inputElementElement.appendChild(createInputElementElement(childInputElement, doc));
+ }
+ }
+
+ return inputElementElement;
+ }
+
+ public static CustomXmlTraceDefinition[] loadAll() {
+ return loadAll(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME);
+ }
+
+ public static CustomXmlTraceDefinition[] loadAll(String path) {
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ // The following allows xml parsing without access to the dtd
+ EntityResolver resolver = new EntityResolver () {
+ @Override
+ public InputSource resolveEntity (String publicId, String systemId) {
+ String empty = ""; //$NON-NLS-1$
+ ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());
+ return new InputSource(bais);
+ }
+ };
+ db.setEntityResolver(resolver);
+
+ // The following catches xml parsing exceptions
+ db.setErrorHandler(new ErrorHandler(){
+ @Override
+ public void error(SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void warning(SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void fatalError(SAXParseException saxparseexception) throws SAXException {
+ throw saxparseexception;
+ }});
+
+ File file = new File(path);
+ if (!file.canRead()) {
+ return new CustomXmlTraceDefinition[0];
+ }
+ Document doc = db.parse(file);
+
+ Element root = doc.getDocumentElement();
+ if (! root.getNodeName().equals(CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT)) {
+ return new CustomXmlTraceDefinition[0];
+ }
+
+ ArrayList<CustomXmlTraceDefinition> defList = new ArrayList<CustomXmlTraceDefinition>();
+ NodeList nodeList = root.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ if (node instanceof Element && node.getNodeName().equals(DEFINITION_ELEMENT)) {
+ CustomXmlTraceDefinition def = extractDefinition((Element) node);
+ if (def != null) {
+ defList.add(def);
+ }
+ }
+ }
+ return defList.toArray(new CustomXmlTraceDefinition[0]);
+ } catch (ParserConfigurationException e) {
+ Activator.getDefault().logError("Error loading all in CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ } catch (SAXException e) {
+ Activator.getDefault().logError("Error loading all in CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error loading all in CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$
+ }
+ return new CustomXmlTraceDefinition[0];
+ }
+
+ public static CustomXmlTraceDefinition load(String definitionName) {
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ // The following allows xml parsing without access to the dtd
+ EntityResolver resolver = new EntityResolver () {
+ @Override
+ public InputSource resolveEntity (String publicId, String systemId) {
+ String empty = ""; //$NON-NLS-1$
+ ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());
+ return new InputSource(bais);
+ }
+ };
+ db.setEntityResolver(resolver);
+
+ // The following catches xml parsing exceptions
+ db.setErrorHandler(new ErrorHandler(){
+ @Override
+ public void error(SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void warning(SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void fatalError(SAXParseException saxparseexception) throws SAXException {
+ throw saxparseexception;
+ }});
+
+ File file = new File(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME);
+ Document doc = db.parse(file);
+
+ Element root = doc.getDocumentElement();
+ if (! root.getNodeName().equals(CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT)) {
+ return null;
+ }
+
+ NodeList nodeList = root.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ if (node instanceof Element &&
+ node.getNodeName().equals(DEFINITION_ELEMENT) &&
+ definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {
+ return extractDefinition((Element) node);
+ }
+ }
+ } catch (ParserConfigurationException e) {
+ Activator.getDefault().logError("Error loading CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$
+ } catch (SAXException e) {
+ Activator.getDefault().logError("Error loading CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error loading CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ public static CustomXmlTraceDefinition extractDefinition(Element definitionElement) {
+ CustomXmlTraceDefinition def = new CustomXmlTraceDefinition();
+
+ def.definitionName = definitionElement.getAttribute(NAME_ATTRIBUTE);
+ if (def.definitionName == null) {
+ return null;
+ }
+
+ NodeList nodeList = definitionElement.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ String nodeName = node.getNodeName();
+ if (nodeName.equals(TIME_STAMP_OUTPUT_FORMAT_ELEMENT)) {
+ Element formatElement = (Element) node;
+ def.timeStampOutputFormat = formatElement.getTextContent();
+ } else if (nodeName.equals(INPUT_ELEMENT_ELEMENT)) {
+ InputElement inputElement = extractInputElement((Element) node);
+ if (inputElement != null) {
+ if (def.rootInputElement == null) {
+ def.rootInputElement = inputElement;
+ } else {
+ return null;
+ }
+ }
+ } else if (nodeName.equals(OUTPUT_COLUMN_ELEMENT)) {
+ Element outputColumnElement = (Element) node;
+ OutputColumn outputColumn = new OutputColumn();
+ outputColumn.name = outputColumnElement.getAttribute(NAME_ATTRIBUTE);
+ def.outputs.add(outputColumn);
+ }
+ }
+ return def;
+ }
+
+ private static InputElement extractInputElement(Element inputElementElement) {
+ InputElement inputElement = new InputElement();
+ inputElement.elementName = inputElementElement.getAttribute(NAME_ATTRIBUTE);
+ inputElement.logEntry = (Boolean.toString(true).equals(inputElementElement.getAttribute(LOG_ENTRY_ATTRIBUTE))) ? true : false;
+ NodeList nodeList = inputElementElement.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ String nodeName = node.getNodeName();
+ if (nodeName.equals(INPUT_DATA_ELEMENT)) {
+ Element inputDataElement = (Element) node;
+ inputElement.inputName = inputDataElement.getAttribute(NAME_ATTRIBUTE);
+ inputElement.inputAction = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE));
+ inputElement.inputFormat = inputDataElement.getAttribute(FORMAT_ATTRIBUTE);
+ } else if (nodeName.equals(ATTRIBUTE_ELEMENT)) {
+ Element attributeElement = (Element) node;
+ InputAttribute attribute = new InputAttribute();
+ attribute.attributeName = attributeElement.getAttribute(NAME_ATTRIBUTE);
+ NodeList attributeNodeList = attributeElement.getChildNodes();
+ for (int j = 0; j < attributeNodeList.getLength(); j++) {
+ Node attributeNode = attributeNodeList.item(j);
+ String attributeNodeName = attributeNode.getNodeName();
+ if (attributeNodeName.equals(INPUT_DATA_ELEMENT)) {
+ Element inputDataElement = (Element) attributeNode;
+ attribute.inputName = inputDataElement.getAttribute(NAME_ATTRIBUTE);
+ attribute.inputAction = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE));
+ attribute.inputFormat = inputDataElement.getAttribute(FORMAT_ATTRIBUTE);
+ }
+ }
+ inputElement.addAttribute(attribute);
+ } else if (nodeName.equals(INPUT_ELEMENT_ELEMENT)) {
+ Element childInputElementElement = (Element) node;
+ InputElement childInputElement = extractInputElement(childInputElementElement);
+ if (childInputElement != null) {
+ inputElement.addChild(childInputElement);
+ }
+ }
+ }
+ return inputElement;
+ }
+
+ public static void delete(String definitionName) {
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ // The following allows xml parsing without access to the dtd
+ EntityResolver resolver = new EntityResolver () {
+ @Override
+ public InputSource resolveEntity (String publicId, String systemId) {
+ String empty = ""; //$NON-NLS-1$
+ ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());
+ return new InputSource(bais);
+ }
+ };
+ db.setEntityResolver(resolver);
+
+ // The following catches xml parsing exceptions
+ db.setErrorHandler(new ErrorHandler(){
+ @Override
+ public void error(SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void warning(SAXParseException saxparseexception) throws SAXException {}
+ @Override
+ public void fatalError(SAXParseException saxparseexception) throws SAXException {
+ throw saxparseexception;
+ }});
+
+ File file = new File(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME);
+ Document doc = db.parse(file);
+
+ Element root = doc.getDocumentElement();
+ if (! root.getNodeName().equals(CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT)) {
+ return;
+ }
+
+ NodeList nodeList = root.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ if (node instanceof Element &&
+ node.getNodeName().equals(DEFINITION_ELEMENT) &&
+ definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {
+ root.removeChild(node);
+ }
+ }
+
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+
+ //initialize StreamResult with File object to save to file
+ StreamResult result = new StreamResult(new StringWriter());
+ DOMSource source = new DOMSource(doc);
+ transformer.transform(source, result);
+ String xmlString = result.getWriter().toString();
+
+ FileWriter writer = new FileWriter(file);
+ writer.write(xmlString);
+ writer.close();
+ } catch (ParserConfigurationException e) {
+ Activator.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$
+ } catch (SAXException e) {
+ Activator.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$
+ } catch (TransformerConfigurationException e) {
+ Activator.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$
+ } catch (TransformerFactoryConfigurationError e) {
+ Activator.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$
+ } catch (TransformerException e) {
+ Activator.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$
+ }
+ }
+}
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;\r
-\r
-import java.io.BufferedReader;\r
-import java.io.IOException;\r
-import java.io.InputStreamReader;\r
-import java.text.ParseException;\r
-import java.text.SimpleDateFormat;\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.Date;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Scanner;\r
-import java.util.regex.Matcher;\r
-import java.util.regex.Pattern;\r
-import java.util.regex.PatternSyntaxException;\r
-\r
-import org.eclipse.core.resources.IFile;\r
-import org.eclipse.core.runtime.CoreException;\r
-import org.eclipse.jface.viewers.ColumnLabelProvider;\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.jface.viewers.ISelectionChangedListener;\r
-import org.eclipse.jface.viewers.IStructuredSelection;\r
-import org.eclipse.jface.viewers.ITreeContentProvider;\r
-import org.eclipse.jface.viewers.SelectionChangedEvent;\r
-import org.eclipse.jface.viewers.StructuredSelection;\r
-import org.eclipse.jface.viewers.TreeViewer;\r
-import org.eclipse.jface.viewers.Viewer;\r
-import org.eclipse.jface.wizard.WizardPage;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.Cardinality;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputData;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.browser.Browser;\r
-import org.eclipse.swt.browser.TitleEvent;\r
-import org.eclipse.swt.browser.TitleListener;\r
-import org.eclipse.swt.custom.SashForm;\r
-import org.eclipse.swt.custom.ScrolledComposite;\r
-import org.eclipse.swt.custom.StyleRange;\r
-import org.eclipse.swt.custom.StyledText;\r
-import org.eclipse.swt.events.ModifyEvent;\r
-import org.eclipse.swt.events.ModifyListener;\r
-import org.eclipse.swt.events.SelectionAdapter;\r
-import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.events.SelectionListener;\r
-import org.eclipse.swt.events.VerifyEvent;\r
-import org.eclipse.swt.events.VerifyListener;\r
-import org.eclipse.swt.graphics.Color;\r
-import org.eclipse.swt.graphics.Font;\r
-import org.eclipse.swt.graphics.FontData;\r
-import org.eclipse.swt.graphics.Image;\r
-import org.eclipse.swt.layout.FillLayout;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Button;\r
-import org.eclipse.swt.widgets.Combo;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.Group;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.swt.widgets.Text;\r
-\r
-public class CustomTxtParserInputWizardPage extends WizardPage {\r
-\r
- private static final String DEFAULT_REGEX = "\\s*(.*\\S)"; //$NON-NLS-1$\r
- private static final String DEFAULT_TIMESTAMP_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$\r
- private static final String SIMPLE_DATE_FORMAT_URL = "http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html#skip-navbar_top"; //$NON-NLS-1$\r
- private static final String PATTERN_URL = "http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#sum"; //$NON-NLS-1$\r
- private static final Image lineImage = Activator.getDefault().getImageFromPath("/icons/elcl16/line_icon.gif"); //$NON-NLS-1$\r
- private static final Image addImage = Activator.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$\r
- private static final Image addNextImage = Activator.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$\r
- private static final Image addChildImage = Activator.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$\r
- private static final Image deleteImage = Activator.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$\r
- private static final Image moveUpImage = Activator.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$\r
- private static final Image moveDownImage = Activator.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$\r
- private static final Image helpImage = Activator.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$\r
- private static final Color COLOR_BLACK = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);\r
- private static final Color COLOR_LIGHT_GREEN = new Color(Display.getDefault(), 192, 255, 192);\r
- private static final Color COLOR_GREEN = Display.getCurrent().getSystemColor(SWT.COLOR_GREEN);\r
- private static final Color COLOR_LIGHT_YELLOW = new Color(Display.getDefault(), 255, 255, 192);\r
- private static final Color COLOR_YELLOW = Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW);\r
- private static final Color COLOR_LIGHT_MAGENTA = new Color(Display.getDefault(), 255, 192, 255);\r
- private static final Color COLOR_MAGENTA = Display.getCurrent().getSystemColor(SWT.COLOR_MAGENTA);\r
- private static final Color COLOR_LIGHT_RED = new Color(Display.getDefault(), 255, 192, 192);\r
- private static final Color COLOR_TEXT_BACKGROUND = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);\r
- private static final Color COLOR_WIDGET_BACKGROUND = Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);\r
-\r
- private final ISelection selection;\r
- private CustomTxtTraceDefinition definition;\r
- private String editDefinitionName;\r
- private String defaultDescription;\r
- private Line selectedLine;\r
- private Composite container;\r
- private Text logtypeText;\r
- private Text timestampOutputFormatText;\r
- private Text timestampPreviewText;\r
- private ScrolledComposite treeScrolledComposite;\r
- private ScrolledComposite lineScrolledComposite;\r
- private TreeViewer treeViewer;\r
- private Composite treeContainer;\r
- private Composite lineContainer;\r
- private StyledText inputText;\r
- private Font fixedFont;\r
- private UpdateListener updateListener;\r
- private Browser helpBrowser;\r
-\r
- // variables used recursively through line traversal\r
- private String timeStampFormat;\r
- private boolean timestampFound;\r
-\r
- protected CustomTxtParserInputWizardPage(ISelection selection, CustomTxtTraceDefinition definition) {\r
- super("CustomParserWizardPage"); //$NON-NLS-1$\r
- if (definition == null) {\r
- setTitle(Messages.CustomTxtParserInputWizardPage_windowTitleNew);\r
- defaultDescription = Messages.CustomTxtParserInputWizardPage_descriptionNew;\r
- } else {\r
- setTitle(Messages.CustomTxtParserInputWizardPage_windowTitleEdit);\r
- defaultDescription = Messages.CustomTxtParserInputWizardPage_desccriptionEdit;\r
- }\r
- setDescription(defaultDescription);\r
- this.selection = selection;\r
- this.definition = definition;\r
- if (definition != null) {\r
- this.editDefinitionName = definition.definitionName;\r
- }\r
- }\r
-\r
- @Override\r
- public void createControl(Composite parent) {\r
- container = new Composite(parent, SWT.NULL);\r
- container.setLayout(new GridLayout());\r
-\r
- updateListener = new UpdateListener();\r
-\r
- Composite headerComposite = new Composite(container, SWT.FILL);\r
- GridLayout headerLayout = new GridLayout(5, false);\r
- headerLayout.marginHeight = 0;\r
- headerLayout.marginWidth = 0;\r
- headerComposite.setLayout(headerLayout);\r
- headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
-\r
- Label logtypeLabel = new Label(headerComposite, SWT.NULL);\r
- logtypeLabel.setText(Messages.CustomTxtParserInputWizardPage_logType);\r
-\r
- logtypeText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);\r
- logtypeText.setLayoutData(new GridData(120, SWT.DEFAULT));\r
-\r
- Label timestampFormatLabel = new Label(headerComposite, SWT.NULL);\r
- timestampFormatLabel.setText(Messages.CustomTxtParserInputWizardPage_timestampFormat);\r
-\r
- timestampOutputFormatText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);\r
- timestampOutputFormatText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- timestampOutputFormatText.setText(DEFAULT_TIMESTAMP_FORMAT);\r
-\r
- Button dateFormatHelpButton = new Button(headerComposite, SWT.PUSH);\r
- dateFormatHelpButton.setImage(helpImage);\r
- dateFormatHelpButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_dateFormatHelp);\r
- dateFormatHelpButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- openHelpShell(SIMPLE_DATE_FORMAT_URL);\r
- }\r
- });\r
-\r
- Label timestampPreviewLabel = new Label(headerComposite, SWT.NULL);\r
- timestampPreviewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 3, 1));\r
- timestampPreviewLabel.setText(Messages.CustomTxtParserInputWizardPage_preview);\r
-\r
- timestampPreviewText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);\r
- timestampPreviewText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));\r
- timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingTimestamp);\r
-\r
- Composite buttonBar = new Composite(container, SWT.NONE);\r
- GridLayout buttonBarLayout = new GridLayout(5, false);\r
- buttonBarLayout.marginHeight = 0;\r
- buttonBarLayout.marginWidth = 0;\r
- buttonBar.setLayout(buttonBarLayout);\r
-\r
- Button removeButton = new Button(buttonBar, SWT.PUSH);\r
- removeButton.setImage(deleteImage);\r
- removeButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_removeLine);\r
- removeButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (treeViewer.getSelection().isEmpty() || selectedLine == null) {\r
- return;\r
- }\r
- removeLine();\r
- InputLine inputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r
- if (inputLine.parentInput == null) {\r
- definition.inputs.remove(inputLine);\r
- } else {\r
- inputLine.parentInput.childrenInputs.remove(inputLine);\r
- }\r
- treeViewer.refresh();\r
- validate();\r
- updatePreviews();\r
- }\r
- });\r
- Button addNextButton = new Button(buttonBar, SWT.PUSH);\r
- addNextButton.setImage(addNextImage);\r
- addNextButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_addNextLine);\r
- addNextButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- InputLine inputLine = new InputLine(Cardinality.ZERO_OR_MORE, "", null); //$NON-NLS-1$\r
- if (((List<?>) treeViewer.getInput()).size() == 0) {\r
- definition.inputs.add(inputLine);\r
- } else if (treeViewer.getSelection().isEmpty()) {\r
- return;\r
- } else {\r
- InputLine previousInputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r
- if (previousInputLine.parentInput == null) {\r
- for (int i = 0; i < definition.inputs.size(); i++) {\r
- if (definition.inputs.get(i).equals(previousInputLine)) {\r
- definition.inputs.add(i + 1, inputLine);\r
- }\r
- }\r
- } else {\r
- previousInputLine.addNext(inputLine);\r
- }\r
- }\r
- treeViewer.refresh();\r
- treeViewer.setSelection(new StructuredSelection(inputLine), true);\r
- }\r
- });\r
- Button addChildButton = new Button(buttonBar, SWT.PUSH);\r
- addChildButton.setImage(addChildImage);\r
- addChildButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_addChildLine);\r
- addChildButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- InputLine inputLine = new InputLine(Cardinality.ZERO_OR_MORE, "", null); //$NON-NLS-1$\r
- if (((List<?>) treeViewer.getInput()).size() == 0) {\r
- definition.inputs.add(inputLine);\r
- } else if (treeViewer.getSelection().isEmpty()) {\r
- return;\r
- } else {\r
- InputLine parentInputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r
- parentInputLine.addChild(inputLine);\r
- }\r
- treeViewer.refresh();\r
- treeViewer.setSelection(new StructuredSelection(inputLine), true);\r
- }\r
- });\r
- Button moveUpButton = new Button(buttonBar, SWT.PUSH);\r
- moveUpButton.setImage(moveUpImage);\r
- moveUpButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_moveUp);\r
- moveUpButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (treeViewer.getSelection().isEmpty()) {\r
- return;\r
- }\r
- InputLine inputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r
- if (inputLine.parentInput == null) {\r
- for (int i = 1; i < definition.inputs.size(); i++) {\r
- if (definition.inputs.get(i).equals(inputLine)) {\r
- definition.inputs.add(i - 1 , definition.inputs.remove(i));\r
- break;\r
- }\r
- }\r
- } else {\r
- inputLine.moveUp();\r
- }\r
- treeViewer.refresh();\r
- validate();\r
- updatePreviews();\r
- }\r
- });\r
- Button moveDownButton = new Button(buttonBar, SWT.PUSH);\r
- moveDownButton.setImage(moveDownImage);\r
- moveDownButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_moveDown);\r
- moveDownButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (treeViewer.getSelection().isEmpty()) {\r
- return;\r
- }\r
- InputLine inputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r
- if (inputLine.parentInput == null) {\r
- for (int i = 0; i < definition.inputs.size() - 1; i++) {\r
- if (definition.inputs.get(i).equals(inputLine)) {\r
- definition.inputs.add(i + 1 , definition.inputs.remove(i));\r
- break;\r
- }\r
- }\r
- } else {\r
- inputLine.moveDown();\r
- }\r
- treeViewer.refresh();\r
- validate();\r
- updatePreviews();\r
- }\r
- });\r
-\r
- SashForm vSash = new SashForm(container, SWT.VERTICAL);\r
- vSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- vSash.setBackground(vSash.getDisplay().getSystemColor(SWT.COLOR_GRAY));\r
-\r
- SashForm hSash = new SashForm(vSash, SWT.HORIZONTAL);\r
- hSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
-\r
- treeScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL | SWT.H_SCROLL);\r
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);\r
- gd.heightHint = 200;\r
- gd.widthHint = 200;\r
- treeScrolledComposite.setLayoutData(gd);\r
- treeContainer = new Composite(treeScrolledComposite, SWT.NONE);\r
- treeContainer.setLayout(new FillLayout());\r
- treeScrolledComposite.setContent(treeContainer);\r
- treeScrolledComposite.setExpandHorizontal(true);\r
- treeScrolledComposite.setExpandVertical(true);\r
-\r
- treeViewer = new TreeViewer(treeContainer, SWT.SINGLE | SWT.BORDER);\r
- treeViewer.setContentProvider(new InputLineTreeNodeContentProvider());\r
- treeViewer.setLabelProvider(new InputLineTreeLabelProvider());\r
- treeViewer.addSelectionChangedListener(new InputLineTreeSelectionChangedListener());\r
- treeContainer.layout();\r
-\r
- treeScrolledComposite.setMinSize(treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);\r
-\r
- lineScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL);\r
- lineScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- lineContainer = new Composite(lineScrolledComposite, SWT.NONE);\r
- GridLayout linesLayout = new GridLayout();\r
- linesLayout.marginHeight = 1;\r
- linesLayout.marginWidth = 0;\r
- lineContainer.setLayout(linesLayout);\r
- lineScrolledComposite.setContent(lineContainer);\r
- lineScrolledComposite.setExpandHorizontal(true);\r
- lineScrolledComposite.setExpandVertical(true);\r
-\r
- if (definition == null) {\r
- definition = new CustomTxtTraceDefinition();\r
- definition.inputs.add(new InputLine(Cardinality.ZERO_OR_MORE, DEFAULT_REGEX,\r
- Arrays.asList(new InputData(CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.ACTION_SET))));\r
- }\r
- loadDefinition(definition);\r
- treeViewer.expandAll();\r
- lineContainer.layout();\r
-\r
- logtypeText.addModifyListener(updateListener);\r
- timestampOutputFormatText.addModifyListener(updateListener);\r
-\r
- lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);\r
-\r
- hSash.setWeights(new int[] {1, 2});\r
-\r
- Composite sashBottom = new Composite(vSash, SWT.NONE);\r
- GridLayout sashBottomLayout = new GridLayout(3, false);\r
- sashBottomLayout.marginHeight = 0;\r
- sashBottomLayout.marginWidth = 0;\r
- sashBottom.setLayout(sashBottomLayout);\r
-\r
- Label previewLabel = new Label(sashBottom, SWT.NULL);\r
- previewLabel.setText(Messages.CustomTxtParserInputWizardPage_previewInput);\r
- previewLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
-\r
- Button highlightAllButton = new Button(sashBottom, SWT.PUSH);\r
- highlightAllButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
- highlightAllButton.setText(Messages.CustomTxtParserInputWizardPage_highlightAll);\r
- highlightAllButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- updatePreviews(true);\r
- }\r
- });\r
-\r
- Button legendButton = new Button(sashBottom, SWT.PUSH);\r
- legendButton.setImage(helpImage);\r
- legendButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_previewLegend);\r
- legendButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
- legendButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- openLegend();\r
- }\r
- });\r
-\r
- inputText = new StyledText(sashBottom, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);\r
- if (fixedFont == null) {\r
- if (System.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$\r
- fixedFont = new Font(Display.getCurrent(), new FontData("Courier New", 10, SWT.NORMAL)); //$NON-NLS-1$\r
- } else {\r
- fixedFont = new Font(Display.getCurrent(), new FontData("Monospace", 10, SWT.NORMAL)); //$NON-NLS-1$\r
- }\r
- }\r
- inputText.setFont(fixedFont);\r
- gd = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);\r
- gd.heightHint = inputText.computeSize(SWT.DEFAULT, inputText.getLineHeight() * 4).y;\r
- gd.widthHint = 800;\r
- inputText.setLayoutData(gd);\r
- inputText.setText(getSelectionText());\r
- inputText.addModifyListener(updateListener);\r
-\r
- vSash.setWeights(new int[] {hSash.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, sashBottom.computeSize(SWT.DEFAULT, SWT.DEFAULT).y});\r
-\r
- setControl(container);\r
-\r
- validate();\r
- updatePreviews();\r
- }\r
-\r
- private static class InputLineTreeNodeContentProvider implements ITreeContentProvider {\r
-\r
- @Override\r
- public Object[] getElements(Object inputElement) {\r
- return ((List<?>) inputElement).toArray();\r
- }\r
-\r
- @Override\r
- public Object[] getChildren(Object parentElement) {\r
- InputLine inputLine = (InputLine) parentElement;\r
- if (inputLine.childrenInputs == null) {\r
- return new InputLine[0];\r
- }\r
- return inputLine.childrenInputs.toArray();\r
- }\r
-\r
- @Override\r
- public boolean hasChildren(Object element) {\r
- InputLine inputLine = (InputLine) element;\r
- return (inputLine.childrenInputs != null && inputLine.childrenInputs.size() > 0);\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- }\r
-\r
- @Override\r
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {\r
- }\r
-\r
- @Override\r
- public Object getParent(Object element) {\r
- InputLine inputLine = (InputLine) element;\r
- return inputLine.parentInput;\r
- }\r
- }\r
-\r
- private class InputLineTreeLabelProvider extends ColumnLabelProvider {\r
-\r
- @Override\r
- public Image getImage(Object element) {\r
- return lineImage;\r
- }\r
-\r
- @Override\r
- public String getText(Object element) {\r
- InputLine inputLine = (InputLine) element;\r
- if (inputLine.parentInput == null) {\r
- return "Root Line " + getName(inputLine) + " " + inputLine.cardinality.toString() + " : " + inputLine.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- }\r
- return "Line " + getName(inputLine) + " " + inputLine.cardinality.toString() + " : " + inputLine.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- }\r
- }\r
-\r
- private class InputLineTreeSelectionChangedListener implements ISelectionChangedListener {\r
- @Override\r
- public void selectionChanged(SelectionChangedEvent event) {\r
- if (selectedLine != null) {\r
- selectedLine.dispose();\r
- }\r
- if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) {\r
- IStructuredSelection selection = (IStructuredSelection) event.getSelection();\r
- InputLine inputLine = (InputLine) selection.getFirstElement();\r
- selectedLine = new Line(lineContainer, getName(inputLine), inputLine);\r
- lineContainer.layout();\r
- lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);\r
- container.layout();\r
- validate();\r
- updatePreviews();\r
- }\r
- }\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.jface.dialogs.DialogPage#dispose()\r
- */\r
- @Override\r
- public void dispose() {\r
- if (fixedFont != null) {\r
- fixedFont.dispose();\r
- fixedFont = null;\r
- }\r
- super.dispose();\r
- }\r
-\r
- private void loadDefinition(CustomTxtTraceDefinition def) {\r
- logtypeText.setText(def.definitionName);\r
- timestampOutputFormatText.setText(def.timeStampOutputFormat);\r
- treeViewer.setInput(def.inputs);\r
- if (def.inputs.size() > 0) {\r
- InputLine inputLine = def.inputs.get(0);\r
- treeViewer.setSelection(new StructuredSelection(inputLine));\r
- }\r
- }\r
-\r
- private String getName(InputLine inputLine) {\r
- if (inputLine.parentInput == null) {\r
- return Integer.toString(definition.inputs.indexOf(inputLine)+1);\r
- }\r
- return getName(inputLine.parentInput) + "." + Integer.toString(inputLine.parentInput.childrenInputs.indexOf(inputLine)+1); //$NON-NLS-1$\r
- }\r
-\r
- public List<String> getInputNames() {\r
- List<String> inputs = new ArrayList<String>();\r
- for (InputLine inputLine : definition.inputs) {\r
- for (String inputName : getInputNames(inputLine)) {\r
- if (!inputs.contains(inputName)) {\r
- inputs.add(inputName);\r
- }\r
- }\r
- }\r
- return inputs;\r
- }\r
-\r
- public List<String> getInputNames(InputLine inputLine) {\r
- List<String> inputs = new ArrayList<String>();\r
- if (inputLine.columns != null) {\r
- for (InputData inputData : inputLine.columns) {\r
- String inputName = inputData.name;\r
- if (!inputs.contains(inputName)) {\r
- inputs.add(inputName);\r
- }\r
- }\r
- }\r
- if (inputLine.childrenInputs != null) {\r
- for (InputLine childInputLine : inputLine.childrenInputs) {\r
- for (String inputName : getInputNames(childInputLine)) {\r
- if (!inputs.contains(inputName)) {\r
- inputs.add(inputName);\r
- }\r
- }\r
- }\r
- }\r
- return inputs;\r
- }\r
-\r
- private void removeLine() {\r
- selectedLine.dispose();\r
- selectedLine = null;\r
- lineContainer.layout();\r
- lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);\r
- container.layout();\r
- }\r
-\r
- private String getSelectionText() {\r
- if (this.selection instanceof IStructuredSelection) {\r
- Object selection = ((IStructuredSelection)this.selection).getFirstElement();\r
- if (selection instanceof IFile) {\r
- IFile file = (IFile)selection;\r
- BufferedReader reader = null;\r
- try {\r
- reader = new BufferedReader(new InputStreamReader(file.getContents()));\r
- StringBuilder sb = new StringBuilder();\r
- String line = null;\r
- while ((line = reader.readLine()) != null) {\r
- sb.append(line + "\n"); //$NON-NLS-1$\r
- }\r
- return sb.toString();\r
- } catch (CoreException e) {\r
- return ""; //$NON-NLS-1$\r
- } catch (IOException e) {\r
- return ""; //$NON-NLS-1$\r
- } finally {\r
- if (reader != null) {\r
- try {\r
- reader.close();\r
- } catch (IOException e) {\r
- }\r
- }\r
- }\r
- }\r
- }\r
- return ""; //$NON-NLS-1$\r
- }\r
-\r
- private void updatePreviews() {\r
- updatePreviews(false);\r
- }\r
-\r
- private void updatePreviews(boolean updateAll) {\r
- if (inputText == null) {\r
- // early update during construction\r
- return;\r
- }\r
- inputText.setStyleRanges(new StyleRange[] {});\r
-\r
- Scanner scanner = new Scanner(inputText.getText());\r
- scanner.useDelimiter("\n"); //$NON-NLS-1$\r
- int rawPos = 0;\r
- String skip; // skip starting delimiters\r
- if ((skip = scanner.findWithinHorizon("\\A\n+", 0)) != null) { //$NON-NLS-1$\r
- rawPos += skip.length();\r
- }\r
-\r
- timeStampFormat = null;\r
- if (selectedLine != null) {\r
- for (InputGroup input : selectedLine.inputs) {\r
- input.previewText.setText(Messages.CustomTxtParserInputWizardPage_noMathcingLine);\r
- }\r
- }\r
-\r
- Map<String, String> data = new HashMap<String, String>();\r
- int rootLineMatches = 0;\r
- String firstEntryTimeStamp = null;\r
- String firstEntryTimeStampInputFormat = null;\r
- String log = null;\r
- event:\r
- while (scanner.hasNext()) {\r
- if (rootLineMatches > 0 && !updateAll) {\r
- break;\r
- }\r
- if (log == null) {\r
- log = scanner.next();\r
- }\r
- int length = log.length();\r
- for (InputLine rootInputLine : definition.inputs) {\r
- Pattern pattern;\r
- try {\r
- pattern = rootInputLine.getPattern();\r
- } catch (PatternSyntaxException e) {\r
- continue;\r
- }\r
- Matcher matcher = pattern.matcher(log);\r
- if (matcher.find()) {\r
- rootLineMatches++;\r
- inputText.setStyleRange(new StyleRange(rawPos, length,\r
- COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC));\r
- data = new HashMap<String, String>();\r
- timeStampFormat = null;\r
- updatePreviewLine(rootInputLine, matcher, data, rawPos, rootLineMatches);\r
- if (rootLineMatches == 1) {\r
- firstEntryTimeStamp = data.get(CustomTraceDefinition.TAG_TIMESTAMP);\r
- firstEntryTimeStampInputFormat = timeStampFormat;\r
- }\r
- HashMap<InputLine, Integer> countMap = new HashMap<InputLine, Integer>();\r
- InputLine currentInput = null;\r
- if (rootInputLine.childrenInputs != null && rootInputLine.childrenInputs.size() > 0) {\r
- currentInput = rootInputLine.childrenInputs.get(0);\r
- countMap.put(currentInput, 0);\r
- }\r
- rawPos += length + 1; // +1 for \n\r
- while (scanner.hasNext()) {\r
- log = scanner.next();\r
- length = log.length();\r
- boolean processed = false;\r
- if (currentInput == null) {\r
- for (InputLine input : definition.inputs) {\r
- matcher = input.getPattern().matcher(log);\r
- if (matcher.find()) {\r
- continue event;\r
- }\r
- }\r
- } else {\r
- if (countMap.get(currentInput) >= currentInput.getMinCount()) {\r
- List<InputLine> nextInputs = currentInput.getNextInputs(countMap);\r
- if (nextInputs.size() == 0 || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0) {\r
- for (InputLine input : definition.inputs) {\r
- matcher = input.getPattern().matcher(log);\r
- if (matcher.find()) {\r
- continue event;\r
- }\r
- }\r
- }\r
- for (InputLine input : nextInputs) {\r
- matcher = input.getPattern().matcher(log);\r
- if (matcher.find()) {\r
- inputText.setStyleRange(new StyleRange(rawPos, length,\r
- COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));\r
- currentInput = input;\r
- updatePreviewLine(currentInput, matcher, data, rawPos, rootLineMatches);\r
- if (countMap.get(currentInput) == null) {\r
- countMap.put(currentInput, 1);\r
- } else {\r
- countMap.put(currentInput, countMap.get(currentInput) + 1);\r
- }\r
- Iterator<InputLine> iter = countMap.keySet().iterator();\r
- while (iter.hasNext()) {\r
- InputLine inputLine = iter.next();\r
- if (inputLine.level > currentInput.level) {\r
- iter.remove();\r
- }\r
- }\r
- if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {\r
- currentInput = currentInput.childrenInputs.get(0);\r
- countMap.put(currentInput, 0);\r
- } else {\r
- if (countMap.get(currentInput) >= currentInput.getMaxCount()) {\r
- if (currentInput.getNextInputs(countMap).size() > 0) {\r
- currentInput = currentInput.getNextInputs(countMap).get(0);\r
- if (countMap.get(currentInput) == null) {\r
- countMap.put(currentInput, 0);\r
- }\r
- iter = countMap.keySet().iterator();\r
- while (iter.hasNext()) {\r
- InputLine inputLine = iter.next();\r
- if (inputLine.level > currentInput.level) {\r
- iter.remove();\r
- }\r
- }\r
- } else {\r
- currentInput = null;\r
- }\r
- }\r
- }\r
- processed = true;\r
- break;\r
- }\r
- }\r
- }\r
- if (! processed) {\r
- matcher = currentInput.getPattern().matcher(log);\r
- if (matcher.find()) {\r
- inputText.setStyleRange(new StyleRange(rawPos, length,\r
- COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));\r
- updatePreviewLine(currentInput, matcher, data, rawPos, rootLineMatches);\r
- countMap.put(currentInput, countMap.get(currentInput) + 1);\r
- if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {\r
- currentInput = currentInput.childrenInputs.get(0);\r
- countMap.put(currentInput, 0);\r
- } else {\r
- if (countMap.get(currentInput) >= currentInput.getMaxCount()) {\r
- if (currentInput.getNextInputs(countMap).size() > 0) {\r
- currentInput = currentInput.getNextInputs(countMap).get(0);\r
- if (countMap.get(currentInput) == null) {\r
- countMap.put(currentInput, 0);\r
- }\r
- Iterator<InputLine> iter = countMap.keySet().iterator();\r
- while (iter.hasNext()) {\r
- InputLine inputLine = iter.next();\r
- if (inputLine.level > currentInput.level) {\r
- iter.remove();\r
- }\r
- }\r
- } else {\r
- currentInput = null;\r
- }\r
- }\r
- }\r
- }\r
- }\r
- }\r
- rawPos += length + 1; // +1 for \n\r
- }\r
-\r
- break;\r
- }\r
- }\r
- rawPos += length + 1; // +1 for \n\r
- log = null;\r
- }\r
- scanner.close();\r
- if (rootLineMatches == 1) {\r
- firstEntryTimeStamp = data.get(CustomTraceDefinition.TAG_TIMESTAMP);\r
- firstEntryTimeStampInputFormat = timeStampFormat;\r
- }\r
- if (firstEntryTimeStamp == null) {\r
- timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noTimestampGroup);\r
- if (selectedLine != null) {\r
- for (InputGroup group : selectedLine.inputs) {\r
- if (group.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingTimestamp);\r
- break;\r
- }\r
- }\r
- }\r
- } else {\r
- try {\r
- SimpleDateFormat dateFormat = new SimpleDateFormat(firstEntryTimeStampInputFormat);\r
- Date date = dateFormat.parse(firstEntryTimeStamp);\r
- dateFormat = new SimpleDateFormat(timestampOutputFormatText.getText().trim());\r
- timestampPreviewText.setText(dateFormat.format(date));\r
- } catch (ParseException e) {\r
- timestampPreviewText.setText("*parse exception* [" + firstEntryTimeStamp + "] <> [" + firstEntryTimeStampInputFormat + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- } catch (IllegalArgumentException e) {\r
- timestampPreviewText.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$\r
- }\r
-\r
- }\r
- }\r
-\r
- private void updatePreviewLine(InputLine line, Matcher matcher, Map<String, String> data, int rawPos, int rootLineMatches) {\r
- for (int i = 0; i < line.columns.size(); i++) {\r
- InputData input = line.columns.get(i);\r
- if (i < matcher.groupCount() && matcher.group(i+1) != null) {\r
- if (line.parentInput == null) {\r
- inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1),\r
- COLOR_BLACK, COLOR_GREEN, SWT.BOLD));\r
- } else {\r
- inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1),\r
- COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD));\r
- }\r
- String value = matcher.group(i+1).trim();\r
- if (selectedLine != null && selectedLine.inputLine.equals(line) && rootLineMatches == 1) {\r
- if (selectedLine.inputs.get(i).previewText.getText().equals(Messages.CustomTxtParserInputWizardPage_noMatchingLine)) {\r
- selectedLine.inputs.get(i).previewText.setText(value);\r
- }\r
- }\r
- if (value.length() == 0) {\r
- continue;\r
- }\r
- if (input.action == CustomTraceDefinition.ACTION_SET) {\r
- data.put(input.name, value);\r
- if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- timeStampFormat = input.format;\r
- }\r
- } else if (input.action == CustomTraceDefinition.ACTION_APPEND) {\r
- String s = data.get(input.name);\r
- if (s != null) {\r
- data.put(input.name, s + value);\r
- } else {\r
- data.put(input.name, value);\r
- }\r
- if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- if (timeStampFormat != null) {\r
- timeStampFormat += input.format;\r
- } else {\r
- timeStampFormat = input.format;\r
- }\r
- }\r
- } else if (input.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {\r
- String s = data.get(input.name);\r
- if (s != null) {\r
- data.put(input.name, s + " | " + value); //$NON-NLS-1$\r
- } else {\r
- data.put(input.name, value);\r
- }\r
- if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- if (timeStampFormat != null) {\r
- timeStampFormat += " | " + input.format; //$NON-NLS-1$\r
- } else {\r
- timeStampFormat = input.format;\r
- }\r
- }\r
- }\r
- } else {\r
- if (selectedLine != null && selectedLine.inputLine.equals(line) && rootLineMatches == 1) {\r
- if (selectedLine.inputs.get(i).previewText.getText().equals(Messages.CustomTxtParserInputWizardPage_noMatchingLine)) {\r
- selectedLine.inputs.get(i).previewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingGroup);\r
- }\r
- }\r
- }\r
- }\r
- // highlight the matching groups that have no corresponponding input\r
- for (int i = line.columns.size(); i < matcher.groupCount(); i++) {\r
- if (matcher.group(i+1) != null) {\r
- if (line.parentInput == null) {\r
- inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1),\r
- COLOR_BLACK, COLOR_MAGENTA));\r
- } else {\r
- inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1),\r
- COLOR_BLACK, COLOR_LIGHT_MAGENTA));\r
- }\r
- }\r
- }\r
- }\r
-\r
- private void openHelpShell(String url) {\r
- if (helpBrowser != null && !helpBrowser.isDisposed()) {\r
- helpBrowser.getShell().setActive();\r
- if (!helpBrowser.getUrl().equals(url)) {\r
- helpBrowser.setUrl(url);\r
- }\r
- return;\r
- }\r
- final Shell helpShell = new Shell(getShell(), SWT.SHELL_TRIM);\r
- helpShell.setLayout(new FillLayout());\r
- helpBrowser = new Browser(helpShell, SWT.NONE);\r
- helpBrowser.addTitleListener(new TitleListener() {\r
- @Override\r
- public void changed(TitleEvent event) {\r
- helpShell.setText(event.title);\r
- }\r
- });\r
- helpBrowser.setBounds(0,0,600,400);\r
- helpShell.pack();\r
- helpShell.open();\r
- helpBrowser.setUrl(url);\r
- }\r
-\r
- private void openLegend() {\r
- final String CG = Messages.CustomTxtParserInputWizardPage_capturedGroup;\r
- final String UCG = Messages.CustomTxtParserInputWizardPage_unidentifiedCaptureGroup;\r
- final String UT = Messages.CustomTxtParserInputWizardPage_uncapturedText;\r
- int line1start = 0;\r
- String line1 = Messages.CustomTxtParserInputWizardPage_nonMatchingLine;\r
- int line2start = line1start + line1.length();\r
- String line2 = Messages.CustomTxtParserInputWizardPage_matchingLineRoot + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- int line3start = line2start + line2.length();\r
- String line3 = Messages.CustomTxtParserInputWizardPage_matchingOtherLine + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- int line4start = line3start + line3.length();\r
- String line4 = Messages.CustomTxtParserInputWizardPage_matchingOtherLine + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- int line5start = line4start + line4.length();\r
- String line5 = Messages.CustomTxtParserInputWizardPage_nonMatchingLine;\r
- int line6start = line5start + line5.length();\r
- String line6 = Messages.CustomTxtParserInputWizardPage_matchingRootLine + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
-\r
- final Shell legendShell = new Shell(getShell(), SWT.DIALOG_TRIM);\r
- legendShell.setLayout(new FillLayout());\r
- StyledText legendText = new StyledText(legendShell, SWT.MULTI);\r
- legendText.setFont(fixedFont);\r
- legendText.setText(line1 + line2 + line3 + line4 + line5 + line6);\r
- legendText.setStyleRange(new StyleRange(line2start, line2.length(), COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC));\r
- legendText.setStyleRange(new StyleRange(line3start, line3.length(), COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));\r
- legendText.setStyleRange(new StyleRange(line4start, line4.length(), COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));\r
- legendText.setStyleRange(new StyleRange(line6start, line6.length(), COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC));\r
- legendText.setStyleRange(new StyleRange(line2start + line2.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_GREEN, SWT.BOLD));\r
- legendText.setStyleRange(new StyleRange(line2start + line2.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_MAGENTA));\r
- legendText.setStyleRange(new StyleRange(line3start + line3.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD));\r
- legendText.setStyleRange(new StyleRange(line3start + line3.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_LIGHT_MAGENTA));\r
- legendText.setStyleRange(new StyleRange(line4start + line4.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD));\r
- legendText.setStyleRange(new StyleRange(line4start + line4.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_LIGHT_MAGENTA));\r
- legendText.setStyleRange(new StyleRange(line6start + line6.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_GREEN, SWT.BOLD));\r
- legendText.setStyleRange(new StyleRange(line6start + line6.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_MAGENTA));\r
- legendShell.setText(Messages.CustomTxtParserInputWizardPage_previewLegend);\r
- legendShell.pack();\r
- legendShell.open();\r
- }\r
-\r
- private class UpdateListener implements ModifyListener, SelectionListener {\r
-\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- validate();\r
- updatePreviews();\r
- }\r
-\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {\r
- validate();\r
- updatePreviews();\r
- }\r
-\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- validate();\r
- updatePreviews();\r
- }\r
-\r
- }\r
-\r
- private class Line {\r
- private static final String INFINITY_STRING = "\u221E"; //$NON-NLS-1$\r
- InputLine inputLine;\r
- Group group;\r
- Composite labelComposite;\r
- Text regexText;\r
- Composite cardinalityContainer;\r
- Combo cardinalityCombo;\r
- Label cardinalityMinLabel;\r
- Text cardinalityMinText;\r
- Label cardinalityMaxLabel;\r
- Text cardinalityMaxText;\r
- Button infiniteButton;\r
- List<InputGroup> inputs = new ArrayList<InputGroup>();\r
- Button addGroupButton;\r
- Label addGroupLabel;\r
-\r
- public Line(Composite parent, String name, InputLine inputLine) {\r
- this.inputLine = inputLine;\r
-\r
- group = new Group(parent, SWT.NONE);\r
- group.setText(name);\r
- group.setLayout(new GridLayout(2, false));\r
- group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
-\r
- labelComposite = new Composite(group, SWT.FILL);\r
- GridLayout labelLayout = new GridLayout(1, false);\r
- labelLayout.marginWidth = 0;\r
- labelLayout.marginHeight = 0;\r
- labelComposite.setLayout(labelLayout);\r
- labelComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
-\r
- Label label = new Label(labelComposite, SWT.NULL);\r
- label.setText(Messages.CustomTxtParserInputWizardPage_regularExpression);\r
-\r
- Composite regexContainer = new Composite(group, SWT.NONE);\r
- GridLayout regexLayout = new GridLayout(2, false);\r
- regexLayout.marginHeight = 0;\r
- regexLayout.marginWidth = 0;\r
- regexContainer.setLayout(regexLayout);\r
- regexContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
-\r
- regexText = new Text(regexContainer, SWT.BORDER | SWT.SINGLE);\r
- GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r
- gd.widthHint = 0;\r
- regexText.setLayoutData(gd);\r
- regexText.setText(inputLine.getRegex());\r
- regexText.addModifyListener(updateListener);\r
-\r
- Button regexHelpButton = new Button(regexContainer, SWT.PUSH);\r
- regexHelpButton.setImage(helpImage);\r
- regexHelpButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_regularExpressionHelp);\r
- regexHelpButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- openHelpShell(PATTERN_URL);\r
- }\r
- });\r
-\r
- label = new Label(group, SWT.NONE);\r
- label.setText(Messages.CustomTxtParserInputWizardPage_cardinality);\r
- label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
-\r
- cardinalityContainer = new Composite(group, SWT.NONE);\r
- GridLayout cardinalityLayout = new GridLayout(6, false);\r
- cardinalityLayout.marginHeight = 0;\r
- cardinalityLayout.marginWidth = 0;\r
- cardinalityContainer.setLayout(cardinalityLayout);\r
- cardinalityContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
-\r
- cardinalityCombo = new Combo(cardinalityContainer, SWT.DROP_DOWN | SWT.READ_ONLY);\r
- cardinalityCombo.setItems(new String[] {\r
- Cardinality.ZERO_OR_MORE.toString(),\r
- Cardinality.ONE_OR_MORE.toString(),\r
- Cardinality.ZERO_OR_ONE.toString(),\r
- Cardinality.ONE.toString(),\r
- "(?,?)"}); //$NON-NLS-1$\r
- cardinalityCombo.addSelectionListener(new SelectionListener(){\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {}\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- switch (cardinalityCombo.getSelectionIndex()) {\r
- case 4: //(?,?)\r
- cardinalityMinLabel.setVisible(true);\r
- cardinalityMinText.setVisible(true);\r
- cardinalityMaxLabel.setVisible(true);\r
- cardinalityMaxText.setVisible(true);\r
- infiniteButton.setVisible(true);\r
- break;\r
- default:\r
- cardinalityMinLabel.setVisible(false);\r
- cardinalityMinText.setVisible(false);\r
- cardinalityMaxLabel.setVisible(false);\r
- cardinalityMaxText.setVisible(false);\r
- infiniteButton.setVisible(false);\r
- break;\r
- }\r
- cardinalityContainer.layout();\r
- validate();\r
- updatePreviews();\r
- }});\r
-\r
- cardinalityMinLabel = new Label(cardinalityContainer, SWT.NONE);\r
- cardinalityMinLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
- cardinalityMinLabel.setText(Messages.CustomTxtParserInputWizardPage_min);\r
- cardinalityMinLabel.setVisible(false);\r
-\r
- cardinalityMinText = new Text(cardinalityContainer, SWT.BORDER | SWT.SINGLE);\r
- gd = new GridData(SWT.CENTER, SWT.CENTER, false, false);\r
- gd.widthHint = 20;\r
- cardinalityMinText.setLayoutData(gd);\r
- cardinalityMinText.setVisible(false);\r
-\r
- cardinalityMaxLabel = new Label(cardinalityContainer, SWT.NONE);\r
- cardinalityMaxLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
- cardinalityMaxLabel.setText(Messages.CustomTxtParserInputWizardPage_max);\r
- cardinalityMaxLabel.setVisible(false);\r
-\r
- cardinalityMaxText = new Text(cardinalityContainer, SWT.BORDER | SWT.SINGLE);\r
- gd = new GridData(SWT.CENTER, SWT.CENTER, false, false);\r
- gd.widthHint = 20;\r
- cardinalityMaxText.setLayoutData(gd);\r
- cardinalityMaxText.setVisible(false);\r
-\r
- infiniteButton = new Button(cardinalityContainer, SWT.PUSH);\r
- infiniteButton.setText(INFINITY_STRING);\r
- infiniteButton.setVisible(false);\r
- infiniteButton.addSelectionListener(new SelectionAdapter(){\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- cardinalityMaxText.setText(INFINITY_STRING);\r
- }});\r
-\r
- if (inputLine.cardinality.equals(Cardinality.ZERO_OR_MORE)) {\r
- cardinalityCombo.select(0);\r
- } else if (inputLine.cardinality.equals(Cardinality.ONE_OR_MORE)) {\r
- cardinalityCombo.select(1);\r
- } else if (inputLine.cardinality.equals(Cardinality.ZERO_OR_ONE)) {\r
- cardinalityCombo.select(2);\r
- } else if (inputLine.cardinality.equals(Cardinality.ONE)) {\r
- cardinalityCombo.select(3);\r
- } else {\r
- cardinalityCombo.select(4);\r
- cardinalityMinLabel.setVisible(true);\r
- cardinalityMinText.setVisible(true);\r
- if (inputLine.getMinCount() >= 0) {\r
- cardinalityMinText.setText(Integer.toString(inputLine.getMinCount()));\r
- }\r
- cardinalityMaxLabel.setVisible(true);\r
- cardinalityMaxText.setVisible(true);\r
- if (inputLine.getMaxCount() == Cardinality.INF) {\r
- cardinalityMaxText.setText(INFINITY_STRING);\r
- } else if (inputLine.getMaxCount() >= 0) {\r
- cardinalityMaxText.setText(Integer.toString(inputLine.getMaxCount()));\r
- }\r
- infiniteButton.setVisible(true);\r
- }\r
-\r
- VerifyListener digitsListener = new VerifyListener() {\r
- @Override\r
- public void verifyText(VerifyEvent e) {\r
- if (e.text.equals(INFINITY_STRING)) {\r
- e.doit = e.widget == cardinalityMaxText && e.start == 0 && e.end == ((Text) e.widget).getText().length();\r
- } else {\r
- if (((Text) e.widget).getText().equals(INFINITY_STRING)) {\r
- e.doit = e.start == 0 && e.end == ((Text) e.widget).getText().length();\r
- }\r
- for (int i = 0; i < e.text.length(); i++) {\r
- if (!Character.isDigit(e.text.charAt(i))) {\r
- e.doit = false;\r
- break;\r
- }\r
- }\r
- }\r
- }};\r
-\r
- cardinalityMinText.addModifyListener(updateListener);\r
- cardinalityMaxText.addModifyListener(updateListener);\r
- cardinalityMinText.addVerifyListener(digitsListener);\r
- cardinalityMaxText.addVerifyListener(digitsListener);\r
-\r
- if (inputLine.columns != null) {\r
- for (InputData inputData : inputLine.columns) {\r
- InputGroup inputGroup = new InputGroup(group, this, inputs.size()+1);\r
- if (inputData.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- inputGroup.tagCombo.select(0);\r
- inputGroup.tagText.setText(inputData.format);\r
- inputGroup.tagLabel.setText(Messages.CustomTxtParserInputWizardPage_format);\r
- inputGroup.tagLabel.setVisible(true);\r
- inputGroup.tagText.setVisible(true);\r
- inputGroup.tagText.addModifyListener(updateListener);\r
- } else if (inputData.name.equals(CustomTraceDefinition.TAG_MESSAGE)) {\r
- inputGroup.tagCombo.select(1);\r
- } else {\r
- inputGroup.tagCombo.select(2);\r
- inputGroup.tagText.setText(inputData.name);\r
- inputGroup.tagLabel.setText(Messages.CustomTxtParserInputWizardPage_name);\r
- inputGroup.tagLabel.setVisible(true);\r
- inputGroup.tagText.setVisible(true);\r
- inputGroup.tagText.addModifyListener(updateListener);\r
- }\r
- inputGroup.actionCombo.select(inputData.action);\r
- inputs.add(inputGroup);\r
- }\r
- }\r
-\r
- createAddGroupButton();\r
- }\r
-\r
- private void createAddGroupButton() {\r
- addGroupButton = new Button(group, SWT.PUSH);\r
- addGroupButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
- addGroupButton.setImage(addImage);\r
- addGroupButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_addGroup);\r
- addGroupButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- removeAddGroupButton();\r
- inputs.add(new InputGroup(group, Line.this, inputs.size()+1));\r
- createAddGroupButton();\r
- lineContainer.layout();\r
- lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);\r
- group.getParent().layout();\r
- validate();\r
- updatePreviews();\r
- }\r
- });\r
-\r
- addGroupLabel = new Label(group, SWT.NULL);\r
- addGroupLabel.setText(Messages.CustomTxtParserInputWizardPage_newGroup);\r
- }\r
-\r
- private void removeAddGroupButton() {\r
- addGroupButton.dispose();\r
- addGroupLabel.dispose();\r
- }\r
-\r
- private void removeInput(int inputNumber) {\r
- if (--inputNumber < inputs.size()) {\r
- inputs.remove(inputNumber).dispose();\r
- for (int i = inputNumber; i < inputs.size(); i++) {\r
- inputs.get(i).setInputNumber(i+1);\r
- }\r
- lineContainer.layout();\r
- lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);\r
- group.getParent().layout();\r
- }\r
- }\r
-\r
-// private void setName(String name) {\r
-// this.name = name;\r
-// group.setText("Line " + name);\r
-// }\r
-\r
- private void dispose() {\r
- group.dispose();\r
- }\r
-\r
- private void extractInputs() {\r
- inputLine.setRegex(selectedLine.regexText.getText());\r
- switch (cardinalityCombo.getSelectionIndex()) {\r
- case 0:\r
- inputLine.cardinality = Cardinality.ZERO_OR_MORE;\r
- break;\r
- case 1:\r
- inputLine.cardinality = Cardinality.ONE_OR_MORE;\r
- break;\r
- case 2:\r
- inputLine.cardinality = Cardinality.ZERO_OR_ONE;\r
- break;\r
- case 3:\r
- inputLine.cardinality = Cardinality.ONE;\r
- break;\r
- case 4: //(?,?)\r
- int min, max;\r
- try {\r
- min = Integer.parseInt(cardinalityMinText.getText());\r
- } catch (NumberFormatException e) {\r
- min = -1;\r
- }\r
- try {\r
- if (cardinalityMaxText.getText().equals(INFINITY_STRING)) {\r
- max = Cardinality.INF;\r
- } else {\r
- max = Integer.parseInt(cardinalityMaxText.getText());\r
- }\r
- } catch (NumberFormatException e) {\r
- max = -1;\r
- }\r
- inputLine.cardinality = new Cardinality(min, max);\r
- break;\r
- default:\r
- inputLine.cardinality = Cardinality.ZERO_OR_MORE;\r
- break;\r
- }\r
- inputLine.columns = new ArrayList<InputData>(inputs.size());\r
- for (int i = 0; i < inputs.size(); i++) {\r
- InputGroup group = inputs.get(i);\r
- InputData inputData = new InputData();\r
- if (group.tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {\r
- inputData.name = group.tagText.getText().trim();\r
- } else {\r
- inputData.name = group.tagCombo.getText();\r
- if (group.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- inputData.format = group.tagText.getText().trim();\r
- }\r
- }\r
- inputData.action = group.actionCombo.getSelectionIndex();\r
- inputLine.columns.add(inputData);\r
- }\r
- }\r
- }\r
-\r
- private class InputGroup {\r
- Line line;\r
- int inputNumber;\r
-\r
- // children of parent (must be disposed)\r
- Composite labelComposite;\r
- Composite tagComposite;\r
- Label previewLabel;\r
- Text previewText;\r
-\r
- // children of labelComposite\r
- Label inputLabel;\r
-\r
- // children of tagComposite\r
- Combo tagCombo;\r
- Label tagLabel;\r
- Text tagText;\r
- Combo actionCombo;\r
-\r
- public InputGroup(Composite parent, Line line, int inputNumber) {\r
- this.line = line;\r
- this.inputNumber = inputNumber;\r
-\r
- labelComposite = new Composite(parent, SWT.FILL);\r
- GridLayout labelLayout = new GridLayout(2, false);\r
- labelLayout.marginWidth = 0;\r
- labelLayout.marginHeight = 0;\r
- labelComposite.setLayout(labelLayout);\r
- labelComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
-\r
- Button deleteButton = new Button(labelComposite, SWT.PUSH);\r
- deleteButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
- deleteButton.setImage(deleteImage);\r
- deleteButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_removeGroup);\r
- deleteButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- InputGroup.this.line.removeInput(InputGroup.this.inputNumber);\r
- validate();\r
- updatePreviews();\r
- }\r
- });\r
-\r
- inputLabel = new Label(labelComposite, SWT.NULL);\r
- inputLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
- inputLabel.setText(Messages.CustomTxtParserInputWizardPage_group + inputNumber + ":"); //$NON-NLS-1$\r
-\r
- tagComposite = new Composite(parent, SWT.FILL);\r
- GridLayout tagLayout = new GridLayout(4, false);\r
- tagLayout.marginWidth = 0;\r
- tagLayout.marginHeight = 0;\r
- tagComposite.setLayout(tagLayout);\r
- tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
-\r
- tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);\r
- tagCombo.setItems(new String[] {CustomTraceDefinition.TAG_TIMESTAMP,\r
- CustomTraceDefinition.TAG_MESSAGE,\r
- CustomTraceDefinition.TAG_OTHER});\r
- tagCombo.select(1);\r
- tagCombo.addSelectionListener(new SelectionListener(){\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {}\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- tagText.removeModifyListener(updateListener);\r
- switch (tagCombo.getSelectionIndex()) {\r
- case 0: //Time Stamp\r
- tagLabel.setText(Messages.CustomTxtParserInputWizardPage_format);\r
- tagLabel.setVisible(true);\r
- tagText.setVisible(true);\r
- tagText.addModifyListener(updateListener);\r
- break;\r
- case 1: //Message\r
- tagLabel.setVisible(false);\r
- tagText.setVisible(false);\r
- break;\r
- case 2: //Other\r
- tagLabel.setText(Messages.CustomTxtParserInputWizardPage_name);\r
- tagLabel.setVisible(true);\r
- tagText.setVisible(true);\r
- tagText.addModifyListener(updateListener);\r
- break;\r
- case 3: //Continue\r
- tagLabel.setVisible(false);\r
- tagText.setVisible(false);\r
- break;\r
- default:\r
- break;\r
- }\r
- tagComposite.layout();\r
- validate();\r
- updatePreviews();\r
- }});\r
-\r
- tagLabel = new Label(tagComposite, SWT.NULL);\r
- tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
- tagLabel.setVisible(false);\r
-\r
- tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE);\r
- GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r
- gd.widthHint = 0;\r
- tagText.setLayoutData(gd);\r
- tagText.setVisible(false);\r
-\r
- actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);\r
- actionCombo.setItems(new String[] {Messages.CustomTxtParserInputWizardPage_set, Messages.CustomTxtParserInputWizardPage_append, Messages.CustomTxtParserInputWizardPage_appendWith});\r
- actionCombo.select(0);\r
- actionCombo.addSelectionListener(updateListener);\r
-\r
- previewLabel = new Label(parent, SWT.NULL);\r
- previewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
- previewLabel.setText(Messages.CustomTxtParserInputWizardPage_preview);\r
-\r
- previewText = new Text(parent, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);\r
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r
- gd.widthHint = 0;\r
- previewText.setLayoutData(gd);\r
- previewText.setText(Messages.CustomTxtParserInputWizardPage_noMatch);\r
- previewText.setBackground(COLOR_WIDGET_BACKGROUND);\r
- }\r
-\r
- private void dispose() {\r
- labelComposite.dispose();\r
- tagComposite.dispose();\r
- previewLabel.dispose();\r
- previewText.dispose();\r
- }\r
-\r
- private void setInputNumber(int inputNumber) {\r
- this.inputNumber = inputNumber;\r
- inputLabel.setText(Messages.CustomTxtParserInputWizardPage_group + inputNumber + ":"); //$NON-NLS-1$\r
- labelComposite.layout();\r
- }\r
- }\r
-\r
- private void validate() {\r
-\r
- definition.definitionName = logtypeText.getText().trim();\r
- definition.timeStampOutputFormat = timestampOutputFormatText.getText().trim();\r
-\r
- if (selectedLine != null) {\r
- selectedLine.extractInputs();\r
- treeViewer.refresh();\r
- }\r
-\r
- StringBuffer errors = new StringBuffer();\r
-\r
- if (definition.definitionName.length() == 0) {\r
- errors.append("Enter a name for the new log type. "); //$NON-NLS-1$\r
- logtypeText.setBackground(COLOR_LIGHT_RED);\r
- } else {\r
- logtypeText.setBackground(COLOR_TEXT_BACKGROUND);\r
- for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {\r
- if (definition.definitionName.equals(def.definitionName)) {\r
- if (editDefinitionName == null || ! editDefinitionName.equals(definition.definitionName)) {\r
- errors.append("The log type name already exists. "); //$NON-NLS-1$\r
- logtypeText.setBackground(COLOR_LIGHT_RED);\r
- break;\r
- }\r
- }\r
- }\r
- }\r
-\r
- timestampFound = false;\r
- for (int i = 0; i < definition.inputs.size(); i++) {\r
-\r
- InputLine inputLine = definition.inputs.get(i);\r
- String name = Integer.toString(i+1);\r
- errors.append(validateLine(inputLine, name));\r
- }\r
- if (timestampFound) {\r
- if (definition.timeStampOutputFormat.length() == 0) {\r
- errors.append("Enter the output format for the Time Stamp field. "); //$NON-NLS-1$\r
- timestampOutputFormatText.setBackground(COLOR_LIGHT_RED);\r
- } else {\r
- try {\r
- new SimpleDateFormat(definition.timeStampOutputFormat);\r
- timestampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);\r
- } catch (IllegalArgumentException e) {\r
- errors.append("Enter a valid output format for the Time Stamp field. "); //$NON-NLS-1$\r
- timestampOutputFormatText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- }\r
-\r
- } else {\r
- timestampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);\r
-// timestampPreviewText.setBackground(COLOR_WIDGET_BACKGROUND);\r
-// errors.append("Identify a Time Stamp group (Line "+name+"). ");\r
-// timestampPreviewText.setText("*no timestamp group*");\r
-// timestampPreviewText.setBackground(COLOR_LIGHT_RED);\r
- }\r
-\r
- if (errors.length() == 0) {\r
- setDescription(defaultDescription);\r
- setPageComplete(true);\r
- } else {\r
- setDescription(errors.toString());\r
- setPageComplete(false);\r
- }\r
- }\r
-\r
- public StringBuffer validateLine(InputLine inputLine, String name) {\r
- StringBuffer errors = new StringBuffer();\r
- Line line = null;\r
- if (selectedLine != null && selectedLine.inputLine.equals(inputLine)) {\r
- line = selectedLine;\r
- }\r
- try {\r
- Pattern.compile(inputLine.getRegex());\r
- if (line != null) {\r
- line.regexText.setBackground(COLOR_TEXT_BACKGROUND);\r
- }\r
- } catch (PatternSyntaxException e) {\r
- errors.append("Enter a valid regular expression (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$\r
- if (line != null) {\r
- line.regexText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- }\r
- if (inputLine.getMinCount() == -1) {\r
- errors.append("Enter a minimum value for cardinality (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$\r
- if (line != null) {\r
- line.cardinalityMinText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- } else {\r
- if (line != null) {\r
- line.cardinalityMinText.setBackground(COLOR_TEXT_BACKGROUND);\r
- }\r
- }\r
- if (inputLine.getMaxCount() == -1) {\r
- errors.append("Enter a maximum value for cardinality (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$\r
- if (line != null) {\r
- line.cardinalityMaxText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- } else if (inputLine.getMinCount() > inputLine.getMaxCount()) {\r
- errors.append("Enter correct (min <= max) values for cardinality (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$\r
- if (line != null) {\r
- line.cardinalityMinText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- if (line != null) {\r
- line.cardinalityMaxText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- } else {\r
- if (line != null) {\r
- line.cardinalityMaxText.setBackground(COLOR_TEXT_BACKGROUND);\r
- }\r
- }\r
- for (int i = 0; inputLine.columns != null && i < inputLine.columns.size(); i++) {\r
- InputData inputData = inputLine.columns.get(i);\r
- InputGroup group = null;\r
- if (line != null) {\r
- group = line.inputs.get(i);\r
- }\r
- if (inputData.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- timestampFound = true;\r
- if (inputData.format.length() == 0) {\r
- errors.append("Enter the input format for the Time Stamp (Line "+name+" Group "+(i+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- if (group != null) {\r
- group.tagText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- } else {\r
- try {\r
- new SimpleDateFormat(inputData.format);\r
- if (group != null) {\r
- group.tagText.setBackground(COLOR_TEXT_BACKGROUND);\r
- }\r
- } catch (IllegalArgumentException e) {\r
- errors.append("Enter a valid input format for the Time Stamp (Line "+name+" Group "+(i+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- if (group != null) {\r
- group.tagText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- }\r
- }\r
- } else if (inputData.name.length() == 0) {\r
- errors.append("Enter a name for the data group (Line "+name+" Group "+(i+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- if (group != null) {\r
- group.tagText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- } else {\r
- if (group != null) {\r
- group.tagText.setBackground(COLOR_TEXT_BACKGROUND);\r
- }\r
- }\r
- }\r
- for (int i = 0; inputLine.childrenInputs != null && i < inputLine.childrenInputs.size(); i++) {\r
- errors.append(validateLine(inputLine.childrenInputs.get(i), name+"."+(i+1))); //$NON-NLS-1$\r
- }\r
- return errors;\r
- }\r
-\r
- public CustomTxtTraceDefinition getDefinition() {\r
- return definition;\r
- }\r
-\r
- public char[] getInputText() {\r
- return inputText.getText().toCharArray();\r
- }\r
-}\r
+package org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Scanner;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.Cardinality;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputData;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.browser.TitleEvent;
+import org.eclipse.swt.browser.TitleListener;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
+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.events.SelectionListener;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.Image;
+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.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+public class CustomTxtParserInputWizardPage extends WizardPage {
+
+ private static final String DEFAULT_REGEX = "\\s*(.*\\S)"; //$NON-NLS-1$
+ private static final String DEFAULT_TIMESTAMP_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$
+ private static final String SIMPLE_DATE_FORMAT_URL = "http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html#skip-navbar_top"; //$NON-NLS-1$
+ private static final String PATTERN_URL = "http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#sum"; //$NON-NLS-1$
+ private static final Image lineImage = Activator.getDefault().getImageFromPath("/icons/elcl16/line_icon.gif"); //$NON-NLS-1$
+ private static final Image addImage = Activator.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
+ private static final Image addNextImage = Activator.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$
+ private static final Image addChildImage = Activator.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$
+ private static final Image deleteImage = Activator.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
+ private static final Image moveUpImage = Activator.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$
+ private static final Image moveDownImage = Activator.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$
+ private static final Image helpImage = Activator.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$
+ private static final Color COLOR_BLACK = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
+ private static final Color COLOR_LIGHT_GREEN = new Color(Display.getDefault(), 192, 255, 192);
+ private static final Color COLOR_GREEN = Display.getCurrent().getSystemColor(SWT.COLOR_GREEN);
+ private static final Color COLOR_LIGHT_YELLOW = new Color(Display.getDefault(), 255, 255, 192);
+ private static final Color COLOR_YELLOW = Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW);
+ private static final Color COLOR_LIGHT_MAGENTA = new Color(Display.getDefault(), 255, 192, 255);
+ private static final Color COLOR_MAGENTA = Display.getCurrent().getSystemColor(SWT.COLOR_MAGENTA);
+ private static final Color COLOR_LIGHT_RED = new Color(Display.getDefault(), 255, 192, 192);
+ private static final Color COLOR_TEXT_BACKGROUND = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
+ private static final Color COLOR_WIDGET_BACKGROUND = Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
+
+ private final ISelection selection;
+ private CustomTxtTraceDefinition definition;
+ private String editDefinitionName;
+ private String defaultDescription;
+ private Line selectedLine;
+ private Composite container;
+ private Text logtypeText;
+ private Text timestampOutputFormatText;
+ private Text timestampPreviewText;
+ private ScrolledComposite treeScrolledComposite;
+ private ScrolledComposite lineScrolledComposite;
+ private TreeViewer treeViewer;
+ private Composite treeContainer;
+ private Composite lineContainer;
+ private StyledText inputText;
+ private Font fixedFont;
+ private UpdateListener updateListener;
+ private Browser helpBrowser;
+
+ // variables used recursively through line traversal
+ private String timeStampFormat;
+ private boolean timestampFound;
+
+ protected CustomTxtParserInputWizardPage(ISelection selection, CustomTxtTraceDefinition definition) {
+ super("CustomParserWizardPage"); //$NON-NLS-1$
+ if (definition == null) {
+ setTitle(Messages.CustomTxtParserInputWizardPage_windowTitleNew);
+ defaultDescription = Messages.CustomTxtParserInputWizardPage_descriptionNew;
+ } else {
+ setTitle(Messages.CustomTxtParserInputWizardPage_windowTitleEdit);
+ defaultDescription = Messages.CustomTxtParserInputWizardPage_desccriptionEdit;
+ }
+ setDescription(defaultDescription);
+ this.selection = selection;
+ this.definition = definition;
+ if (definition != null) {
+ this.editDefinitionName = definition.definitionName;
+ }
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ container = new Composite(parent, SWT.NULL);
+ container.setLayout(new GridLayout());
+
+ updateListener = new UpdateListener();
+
+ Composite headerComposite = new Composite(container, SWT.FILL);
+ GridLayout headerLayout = new GridLayout(5, false);
+ headerLayout.marginHeight = 0;
+ headerLayout.marginWidth = 0;
+ headerComposite.setLayout(headerLayout);
+ headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ Label logtypeLabel = new Label(headerComposite, SWT.NULL);
+ logtypeLabel.setText(Messages.CustomTxtParserInputWizardPage_logType);
+
+ logtypeText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);
+ logtypeText.setLayoutData(new GridData(120, SWT.DEFAULT));
+
+ Label timestampFormatLabel = new Label(headerComposite, SWT.NULL);
+ timestampFormatLabel.setText(Messages.CustomTxtParserInputWizardPage_timestampFormat);
+
+ timestampOutputFormatText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);
+ timestampOutputFormatText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ timestampOutputFormatText.setText(DEFAULT_TIMESTAMP_FORMAT);
+
+ Button dateFormatHelpButton = new Button(headerComposite, SWT.PUSH);
+ dateFormatHelpButton.setImage(helpImage);
+ dateFormatHelpButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_dateFormatHelp);
+ dateFormatHelpButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ openHelpShell(SIMPLE_DATE_FORMAT_URL);
+ }
+ });
+
+ Label timestampPreviewLabel = new Label(headerComposite, SWT.NULL);
+ timestampPreviewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 3, 1));
+ timestampPreviewLabel.setText(Messages.CustomTxtParserInputWizardPage_preview);
+
+ timestampPreviewText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
+ timestampPreviewText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+ timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingTimestamp);
+
+ Composite buttonBar = new Composite(container, SWT.NONE);
+ GridLayout buttonBarLayout = new GridLayout(5, false);
+ buttonBarLayout.marginHeight = 0;
+ buttonBarLayout.marginWidth = 0;
+ buttonBar.setLayout(buttonBarLayout);
+
+ Button removeButton = new Button(buttonBar, SWT.PUSH);
+ removeButton.setImage(deleteImage);
+ removeButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_removeLine);
+ removeButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (treeViewer.getSelection().isEmpty() || selectedLine == null) {
+ return;
+ }
+ removeLine();
+ InputLine inputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
+ if (inputLine.parentInput == null) {
+ definition.inputs.remove(inputLine);
+ } else {
+ inputLine.parentInput.childrenInputs.remove(inputLine);
+ }
+ treeViewer.refresh();
+ validate();
+ updatePreviews();
+ }
+ });
+ Button addNextButton = new Button(buttonBar, SWT.PUSH);
+ addNextButton.setImage(addNextImage);
+ addNextButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_addNextLine);
+ addNextButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ InputLine inputLine = new InputLine(Cardinality.ZERO_OR_MORE, "", null); //$NON-NLS-1$
+ if (((List<?>) treeViewer.getInput()).size() == 0) {
+ definition.inputs.add(inputLine);
+ } else if (treeViewer.getSelection().isEmpty()) {
+ return;
+ } else {
+ InputLine previousInputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
+ if (previousInputLine.parentInput == null) {
+ for (int i = 0; i < definition.inputs.size(); i++) {
+ if (definition.inputs.get(i).equals(previousInputLine)) {
+ definition.inputs.add(i + 1, inputLine);
+ }
+ }
+ } else {
+ previousInputLine.addNext(inputLine);
+ }
+ }
+ treeViewer.refresh();
+ treeViewer.setSelection(new StructuredSelection(inputLine), true);
+ }
+ });
+ Button addChildButton = new Button(buttonBar, SWT.PUSH);
+ addChildButton.setImage(addChildImage);
+ addChildButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_addChildLine);
+ addChildButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ InputLine inputLine = new InputLine(Cardinality.ZERO_OR_MORE, "", null); //$NON-NLS-1$
+ if (((List<?>) treeViewer.getInput()).size() == 0) {
+ definition.inputs.add(inputLine);
+ } else if (treeViewer.getSelection().isEmpty()) {
+ return;
+ } else {
+ InputLine parentInputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
+ parentInputLine.addChild(inputLine);
+ }
+ treeViewer.refresh();
+ treeViewer.setSelection(new StructuredSelection(inputLine), true);
+ }
+ });
+ Button moveUpButton = new Button(buttonBar, SWT.PUSH);
+ moveUpButton.setImage(moveUpImage);
+ moveUpButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_moveUp);
+ moveUpButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (treeViewer.getSelection().isEmpty()) {
+ return;
+ }
+ InputLine inputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
+ if (inputLine.parentInput == null) {
+ for (int i = 1; i < definition.inputs.size(); i++) {
+ if (definition.inputs.get(i).equals(inputLine)) {
+ definition.inputs.add(i - 1 , definition.inputs.remove(i));
+ break;
+ }
+ }
+ } else {
+ inputLine.moveUp();
+ }
+ treeViewer.refresh();
+ validate();
+ updatePreviews();
+ }
+ });
+ Button moveDownButton = new Button(buttonBar, SWT.PUSH);
+ moveDownButton.setImage(moveDownImage);
+ moveDownButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_moveDown);
+ moveDownButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (treeViewer.getSelection().isEmpty()) {
+ return;
+ }
+ InputLine inputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
+ if (inputLine.parentInput == null) {
+ for (int i = 0; i < definition.inputs.size() - 1; i++) {
+ if (definition.inputs.get(i).equals(inputLine)) {
+ definition.inputs.add(i + 1 , definition.inputs.remove(i));
+ break;
+ }
+ }
+ } else {
+ inputLine.moveDown();
+ }
+ treeViewer.refresh();
+ validate();
+ updatePreviews();
+ }
+ });
+
+ SashForm vSash = new SashForm(container, SWT.VERTICAL);
+ vSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ vSash.setBackground(vSash.getDisplay().getSystemColor(SWT.COLOR_GRAY));
+
+ SashForm hSash = new SashForm(vSash, SWT.HORIZONTAL);
+ hSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ treeScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL | SWT.H_SCROLL);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gd.heightHint = 200;
+ gd.widthHint = 200;
+ treeScrolledComposite.setLayoutData(gd);
+ treeContainer = new Composite(treeScrolledComposite, SWT.NONE);
+ treeContainer.setLayout(new FillLayout());
+ treeScrolledComposite.setContent(treeContainer);
+ treeScrolledComposite.setExpandHorizontal(true);
+ treeScrolledComposite.setExpandVertical(true);
+
+ treeViewer = new TreeViewer(treeContainer, SWT.SINGLE | SWT.BORDER);
+ treeViewer.setContentProvider(new InputLineTreeNodeContentProvider());
+ treeViewer.setLabelProvider(new InputLineTreeLabelProvider());
+ treeViewer.addSelectionChangedListener(new InputLineTreeSelectionChangedListener());
+ treeContainer.layout();
+
+ treeScrolledComposite.setMinSize(treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
+
+ lineScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL);
+ lineScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ lineContainer = new Composite(lineScrolledComposite, SWT.NONE);
+ GridLayout linesLayout = new GridLayout();
+ linesLayout.marginHeight = 1;
+ linesLayout.marginWidth = 0;
+ lineContainer.setLayout(linesLayout);
+ lineScrolledComposite.setContent(lineContainer);
+ lineScrolledComposite.setExpandHorizontal(true);
+ lineScrolledComposite.setExpandVertical(true);
+
+ if (definition == null) {
+ definition = new CustomTxtTraceDefinition();
+ definition.inputs.add(new InputLine(Cardinality.ZERO_OR_MORE, DEFAULT_REGEX,
+ Arrays.asList(new InputData(CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.ACTION_SET))));
+ }
+ loadDefinition(definition);
+ treeViewer.expandAll();
+ lineContainer.layout();
+
+ logtypeText.addModifyListener(updateListener);
+ timestampOutputFormatText.addModifyListener(updateListener);
+
+ lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);
+
+ hSash.setWeights(new int[] {1, 2});
+
+ Composite sashBottom = new Composite(vSash, SWT.NONE);
+ GridLayout sashBottomLayout = new GridLayout(3, false);
+ sashBottomLayout.marginHeight = 0;
+ sashBottomLayout.marginWidth = 0;
+ sashBottom.setLayout(sashBottomLayout);
+
+ Label previewLabel = new Label(sashBottom, SWT.NULL);
+ previewLabel.setText(Messages.CustomTxtParserInputWizardPage_previewInput);
+ previewLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ Button highlightAllButton = new Button(sashBottom, SWT.PUSH);
+ highlightAllButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ highlightAllButton.setText(Messages.CustomTxtParserInputWizardPage_highlightAll);
+ highlightAllButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updatePreviews(true);
+ }
+ });
+
+ Button legendButton = new Button(sashBottom, SWT.PUSH);
+ legendButton.setImage(helpImage);
+ legendButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_previewLegend);
+ legendButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ legendButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ openLegend();
+ }
+ });
+
+ inputText = new StyledText(sashBottom, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
+ if (fixedFont == null) {
+ if (System.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
+ fixedFont = new Font(Display.getCurrent(), new FontData("Courier New", 10, SWT.NORMAL)); //$NON-NLS-1$
+ } else {
+ fixedFont = new Font(Display.getCurrent(), new FontData("Monospace", 10, SWT.NORMAL)); //$NON-NLS-1$
+ }
+ }
+ inputText.setFont(fixedFont);
+ gd = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
+ gd.heightHint = inputText.computeSize(SWT.DEFAULT, inputText.getLineHeight() * 4).y;
+ gd.widthHint = 800;
+ inputText.setLayoutData(gd);
+ inputText.setText(getSelectionText());
+ inputText.addModifyListener(updateListener);
+
+ vSash.setWeights(new int[] {hSash.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, sashBottom.computeSize(SWT.DEFAULT, SWT.DEFAULT).y});
+
+ setControl(container);
+
+ validate();
+ updatePreviews();
+ }
+
+ private static class InputLineTreeNodeContentProvider implements ITreeContentProvider {
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return ((List<?>) inputElement).toArray();
+ }
+
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ InputLine inputLine = (InputLine) parentElement;
+ if (inputLine.childrenInputs == null) {
+ return new InputLine[0];
+ }
+ return inputLine.childrenInputs.toArray();
+ }
+
+ @Override
+ public boolean hasChildren(Object element) {
+ InputLine inputLine = (InputLine) element;
+ return (inputLine.childrenInputs != null && inputLine.childrenInputs.size() > 0);
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ @Override
+ public Object getParent(Object element) {
+ InputLine inputLine = (InputLine) element;
+ return inputLine.parentInput;
+ }
+ }
+
+ private class InputLineTreeLabelProvider extends ColumnLabelProvider {
+
+ @Override
+ public Image getImage(Object element) {
+ return lineImage;
+ }
+
+ @Override
+ public String getText(Object element) {
+ InputLine inputLine = (InputLine) element;
+ if (inputLine.parentInput == null) {
+ return "Root Line " + getName(inputLine) + " " + inputLine.cardinality.toString() + " : " + inputLine.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ return "Line " + getName(inputLine) + " " + inputLine.cardinality.toString() + " : " + inputLine.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
+
+ private class InputLineTreeSelectionChangedListener implements ISelectionChangedListener {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (selectedLine != null) {
+ selectedLine.dispose();
+ }
+ if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) {
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ InputLine inputLine = (InputLine) selection.getFirstElement();
+ selectedLine = new Line(lineContainer, getName(inputLine), inputLine);
+ lineContainer.layout();
+ lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);
+ container.layout();
+ validate();
+ updatePreviews();
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.DialogPage#dispose()
+ */
+ @Override
+ public void dispose() {
+ if (fixedFont != null) {
+ fixedFont.dispose();
+ fixedFont = null;
+ }
+ super.dispose();
+ }
+
+ private void loadDefinition(CustomTxtTraceDefinition def) {
+ logtypeText.setText(def.definitionName);
+ timestampOutputFormatText.setText(def.timeStampOutputFormat);
+ treeViewer.setInput(def.inputs);
+ if (def.inputs.size() > 0) {
+ InputLine inputLine = def.inputs.get(0);
+ treeViewer.setSelection(new StructuredSelection(inputLine));
+ }
+ }
+
+ private String getName(InputLine inputLine) {
+ if (inputLine.parentInput == null) {
+ return Integer.toString(definition.inputs.indexOf(inputLine)+1);
+ }
+ return getName(inputLine.parentInput) + "." + Integer.toString(inputLine.parentInput.childrenInputs.indexOf(inputLine)+1); //$NON-NLS-1$
+ }
+
+ public List<String> getInputNames() {
+ List<String> inputs = new ArrayList<String>();
+ for (InputLine inputLine : definition.inputs) {
+ for (String inputName : getInputNames(inputLine)) {
+ if (!inputs.contains(inputName)) {
+ inputs.add(inputName);
+ }
+ }
+ }
+ return inputs;
+ }
+
+ public List<String> getInputNames(InputLine inputLine) {
+ List<String> inputs = new ArrayList<String>();
+ if (inputLine.columns != null) {
+ for (InputData inputData : inputLine.columns) {
+ String inputName = inputData.name;
+ if (!inputs.contains(inputName)) {
+ inputs.add(inputName);
+ }
+ }
+ }
+ if (inputLine.childrenInputs != null) {
+ for (InputLine childInputLine : inputLine.childrenInputs) {
+ for (String inputName : getInputNames(childInputLine)) {
+ if (!inputs.contains(inputName)) {
+ inputs.add(inputName);
+ }
+ }
+ }
+ }
+ return inputs;
+ }
+
+ private void removeLine() {
+ selectedLine.dispose();
+ selectedLine = null;
+ lineContainer.layout();
+ lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);
+ container.layout();
+ }
+
+ private String getSelectionText() {
+ if (this.selection instanceof IStructuredSelection) {
+ Object selection = ((IStructuredSelection)this.selection).getFirstElement();
+ if (selection instanceof IFile) {
+ IFile file = (IFile)selection;
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(file.getContents()));
+ StringBuilder sb = new StringBuilder();
+ String line = null;
+ while ((line = reader.readLine()) != null) {
+ sb.append(line + "\n"); //$NON-NLS-1$
+ }
+ return sb.toString();
+ } catch (CoreException e) {
+ return ""; //$NON-NLS-1$
+ } catch (IOException e) {
+ return ""; //$NON-NLS-1$
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ }
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ private void updatePreviews() {
+ updatePreviews(false);
+ }
+
+ private void updatePreviews(boolean updateAll) {
+ if (inputText == null) {
+ // early update during construction
+ return;
+ }
+ inputText.setStyleRanges(new StyleRange[] {});
+
+ Scanner scanner = new Scanner(inputText.getText());
+ scanner.useDelimiter("\n"); //$NON-NLS-1$
+ int rawPos = 0;
+ String skip; // skip starting delimiters
+ if ((skip = scanner.findWithinHorizon("\\A\n+", 0)) != null) { //$NON-NLS-1$
+ rawPos += skip.length();
+ }
+
+ timeStampFormat = null;
+ if (selectedLine != null) {
+ for (InputGroup input : selectedLine.inputs) {
+ input.previewText.setText(Messages.CustomTxtParserInputWizardPage_noMathcingLine);
+ }
+ }
+
+ Map<String, String> data = new HashMap<String, String>();
+ int rootLineMatches = 0;
+ String firstEntryTimeStamp = null;
+ String firstEntryTimeStampInputFormat = null;
+ String log = null;
+ event:
+ while (scanner.hasNext()) {
+ if (rootLineMatches > 0 && !updateAll) {
+ break;
+ }
+ if (log == null) {
+ log = scanner.next();
+ }
+ int length = log.length();
+ for (InputLine rootInputLine : definition.inputs) {
+ Pattern pattern;
+ try {
+ pattern = rootInputLine.getPattern();
+ } catch (PatternSyntaxException e) {
+ continue;
+ }
+ Matcher matcher = pattern.matcher(log);
+ if (matcher.find()) {
+ rootLineMatches++;
+ inputText.setStyleRange(new StyleRange(rawPos, length,
+ COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC));
+ data = new HashMap<String, String>();
+ timeStampFormat = null;
+ updatePreviewLine(rootInputLine, matcher, data, rawPos, rootLineMatches);
+ if (rootLineMatches == 1) {
+ firstEntryTimeStamp = data.get(CustomTraceDefinition.TAG_TIMESTAMP);
+ firstEntryTimeStampInputFormat = timeStampFormat;
+ }
+ HashMap<InputLine, Integer> countMap = new HashMap<InputLine, Integer>();
+ InputLine currentInput = null;
+ if (rootInputLine.childrenInputs != null && rootInputLine.childrenInputs.size() > 0) {
+ currentInput = rootInputLine.childrenInputs.get(0);
+ countMap.put(currentInput, 0);
+ }
+ rawPos += length + 1; // +1 for \n
+ while (scanner.hasNext()) {
+ log = scanner.next();
+ length = log.length();
+ boolean processed = false;
+ if (currentInput == null) {
+ for (InputLine input : definition.inputs) {
+ matcher = input.getPattern().matcher(log);
+ if (matcher.find()) {
+ continue event;
+ }
+ }
+ } else {
+ if (countMap.get(currentInput) >= currentInput.getMinCount()) {
+ List<InputLine> nextInputs = currentInput.getNextInputs(countMap);
+ if (nextInputs.size() == 0 || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0) {
+ for (InputLine input : definition.inputs) {
+ matcher = input.getPattern().matcher(log);
+ if (matcher.find()) {
+ continue event;
+ }
+ }
+ }
+ for (InputLine input : nextInputs) {
+ matcher = input.getPattern().matcher(log);
+ if (matcher.find()) {
+ inputText.setStyleRange(new StyleRange(rawPos, length,
+ COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));
+ currentInput = input;
+ updatePreviewLine(currentInput, matcher, data, rawPos, rootLineMatches);
+ if (countMap.get(currentInput) == null) {
+ countMap.put(currentInput, 1);
+ } else {
+ countMap.put(currentInput, countMap.get(currentInput) + 1);
+ }
+ Iterator<InputLine> iter = countMap.keySet().iterator();
+ while (iter.hasNext()) {
+ InputLine inputLine = iter.next();
+ if (inputLine.level > currentInput.level) {
+ iter.remove();
+ }
+ }
+ if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {
+ currentInput = currentInput.childrenInputs.get(0);
+ countMap.put(currentInput, 0);
+ } else {
+ if (countMap.get(currentInput) >= currentInput.getMaxCount()) {
+ if (currentInput.getNextInputs(countMap).size() > 0) {
+ currentInput = currentInput.getNextInputs(countMap).get(0);
+ if (countMap.get(currentInput) == null) {
+ countMap.put(currentInput, 0);
+ }
+ iter = countMap.keySet().iterator();
+ while (iter.hasNext()) {
+ InputLine inputLine = iter.next();
+ if (inputLine.level > currentInput.level) {
+ iter.remove();
+ }
+ }
+ } else {
+ currentInput = null;
+ }
+ }
+ }
+ processed = true;
+ break;
+ }
+ }
+ }
+ if (! processed) {
+ matcher = currentInput.getPattern().matcher(log);
+ if (matcher.find()) {
+ inputText.setStyleRange(new StyleRange(rawPos, length,
+ COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));
+ updatePreviewLine(currentInput, matcher, data, rawPos, rootLineMatches);
+ countMap.put(currentInput, countMap.get(currentInput) + 1);
+ if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {
+ currentInput = currentInput.childrenInputs.get(0);
+ countMap.put(currentInput, 0);
+ } else {
+ if (countMap.get(currentInput) >= currentInput.getMaxCount()) {
+ if (currentInput.getNextInputs(countMap).size() > 0) {
+ currentInput = currentInput.getNextInputs(countMap).get(0);
+ if (countMap.get(currentInput) == null) {
+ countMap.put(currentInput, 0);
+ }
+ Iterator<InputLine> iter = countMap.keySet().iterator();
+ while (iter.hasNext()) {
+ InputLine inputLine = iter.next();
+ if (inputLine.level > currentInput.level) {
+ iter.remove();
+ }
+ }
+ } else {
+ currentInput = null;
+ }
+ }
+ }
+ }
+ }
+ }
+ rawPos += length + 1; // +1 for \n
+ }
+
+ break;
+ }
+ }
+ rawPos += length + 1; // +1 for \n
+ log = null;
+ }
+ scanner.close();
+ if (rootLineMatches == 1) {
+ firstEntryTimeStamp = data.get(CustomTraceDefinition.TAG_TIMESTAMP);
+ firstEntryTimeStampInputFormat = timeStampFormat;
+ }
+ if (firstEntryTimeStamp == null) {
+ timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noTimestampGroup);
+ if (selectedLine != null) {
+ for (InputGroup group : selectedLine.inputs) {
+ if (group.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingTimestamp);
+ break;
+ }
+ }
+ }
+ } else {
+ try {
+ SimpleDateFormat dateFormat = new SimpleDateFormat(firstEntryTimeStampInputFormat);
+ Date date = dateFormat.parse(firstEntryTimeStamp);
+ dateFormat = new SimpleDateFormat(timestampOutputFormatText.getText().trim());
+ timestampPreviewText.setText(dateFormat.format(date));
+ } catch (ParseException e) {
+ timestampPreviewText.setText("*parse exception* [" + firstEntryTimeStamp + "] <> [" + firstEntryTimeStampInputFormat + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ } catch (IllegalArgumentException e) {
+ timestampPreviewText.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$
+ }
+
+ }
+ }
+
+ private void updatePreviewLine(InputLine line, Matcher matcher, Map<String, String> data, int rawPos, int rootLineMatches) {
+ for (int i = 0; i < line.columns.size(); i++) {
+ InputData input = line.columns.get(i);
+ if (i < matcher.groupCount() && matcher.group(i+1) != null) {
+ if (line.parentInput == null) {
+ inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1),
+ COLOR_BLACK, COLOR_GREEN, SWT.BOLD));
+ } else {
+ inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1),
+ COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD));
+ }
+ String value = matcher.group(i+1).trim();
+ if (selectedLine != null && selectedLine.inputLine.equals(line) && rootLineMatches == 1) {
+ if (selectedLine.inputs.get(i).previewText.getText().equals(Messages.CustomTxtParserInputWizardPage_noMatchingLine)) {
+ selectedLine.inputs.get(i).previewText.setText(value);
+ }
+ }
+ if (value.length() == 0) {
+ continue;
+ }
+ if (input.action == CustomTraceDefinition.ACTION_SET) {
+ data.put(input.name, value);
+ if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ timeStampFormat = input.format;
+ }
+ } else if (input.action == CustomTraceDefinition.ACTION_APPEND) {
+ String s = data.get(input.name);
+ if (s != null) {
+ data.put(input.name, s + value);
+ } else {
+ data.put(input.name, value);
+ }
+ if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ if (timeStampFormat != null) {
+ timeStampFormat += input.format;
+ } else {
+ timeStampFormat = input.format;
+ }
+ }
+ } else if (input.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
+ String s = data.get(input.name);
+ if (s != null) {
+ data.put(input.name, s + " | " + value); //$NON-NLS-1$
+ } else {
+ data.put(input.name, value);
+ }
+ if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ if (timeStampFormat != null) {
+ timeStampFormat += " | " + input.format; //$NON-NLS-1$
+ } else {
+ timeStampFormat = input.format;
+ }
+ }
+ }
+ } else {
+ if (selectedLine != null && selectedLine.inputLine.equals(line) && rootLineMatches == 1) {
+ if (selectedLine.inputs.get(i).previewText.getText().equals(Messages.CustomTxtParserInputWizardPage_noMatchingLine)) {
+ selectedLine.inputs.get(i).previewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingGroup);
+ }
+ }
+ }
+ }
+ // highlight the matching groups that have no corresponponding input
+ for (int i = line.columns.size(); i < matcher.groupCount(); i++) {
+ if (matcher.group(i+1) != null) {
+ if (line.parentInput == null) {
+ inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1),
+ COLOR_BLACK, COLOR_MAGENTA));
+ } else {
+ inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1),
+ COLOR_BLACK, COLOR_LIGHT_MAGENTA));
+ }
+ }
+ }
+ }
+
+ private void openHelpShell(String url) {
+ if (helpBrowser != null && !helpBrowser.isDisposed()) {
+ helpBrowser.getShell().setActive();
+ if (!helpBrowser.getUrl().equals(url)) {
+ helpBrowser.setUrl(url);
+ }
+ return;
+ }
+ final Shell helpShell = new Shell(getShell(), SWT.SHELL_TRIM);
+ helpShell.setLayout(new FillLayout());
+ helpBrowser = new Browser(helpShell, SWT.NONE);
+ helpBrowser.addTitleListener(new TitleListener() {
+ @Override
+ public void changed(TitleEvent event) {
+ helpShell.setText(event.title);
+ }
+ });
+ helpBrowser.setBounds(0,0,600,400);
+ helpShell.pack();
+ helpShell.open();
+ helpBrowser.setUrl(url);
+ }
+
+ private void openLegend() {
+ final String CG = Messages.CustomTxtParserInputWizardPage_capturedGroup;
+ final String UCG = Messages.CustomTxtParserInputWizardPage_unidentifiedCaptureGroup;
+ final String UT = Messages.CustomTxtParserInputWizardPage_uncapturedText;
+ int line1start = 0;
+ String line1 = Messages.CustomTxtParserInputWizardPage_nonMatchingLine;
+ int line2start = line1start + line1.length();
+ String line2 = Messages.CustomTxtParserInputWizardPage_matchingLineRoot + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ int line3start = line2start + line2.length();
+ String line3 = Messages.CustomTxtParserInputWizardPage_matchingOtherLine + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ int line4start = line3start + line3.length();
+ String line4 = Messages.CustomTxtParserInputWizardPage_matchingOtherLine + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ int line5start = line4start + line4.length();
+ String line5 = Messages.CustomTxtParserInputWizardPage_nonMatchingLine;
+ int line6start = line5start + line5.length();
+ String line6 = Messages.CustomTxtParserInputWizardPage_matchingRootLine + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ final Shell legendShell = new Shell(getShell(), SWT.DIALOG_TRIM);
+ legendShell.setLayout(new FillLayout());
+ StyledText legendText = new StyledText(legendShell, SWT.MULTI);
+ legendText.setFont(fixedFont);
+ legendText.setText(line1 + line2 + line3 + line4 + line5 + line6);
+ legendText.setStyleRange(new StyleRange(line2start, line2.length(), COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC));
+ legendText.setStyleRange(new StyleRange(line3start, line3.length(), COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));
+ legendText.setStyleRange(new StyleRange(line4start, line4.length(), COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));
+ legendText.setStyleRange(new StyleRange(line6start, line6.length(), COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC));
+ legendText.setStyleRange(new StyleRange(line2start + line2.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_GREEN, SWT.BOLD));
+ legendText.setStyleRange(new StyleRange(line2start + line2.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_MAGENTA));
+ legendText.setStyleRange(new StyleRange(line3start + line3.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD));
+ legendText.setStyleRange(new StyleRange(line3start + line3.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_LIGHT_MAGENTA));
+ legendText.setStyleRange(new StyleRange(line4start + line4.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD));
+ legendText.setStyleRange(new StyleRange(line4start + line4.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_LIGHT_MAGENTA));
+ legendText.setStyleRange(new StyleRange(line6start + line6.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_GREEN, SWT.BOLD));
+ legendText.setStyleRange(new StyleRange(line6start + line6.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_MAGENTA));
+ legendShell.setText(Messages.CustomTxtParserInputWizardPage_previewLegend);
+ legendShell.pack();
+ legendShell.open();
+ }
+
+ private class UpdateListener implements ModifyListener, SelectionListener {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ validate();
+ updatePreviews();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ validate();
+ updatePreviews();
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ validate();
+ updatePreviews();
+ }
+
+ }
+
+ private class Line {
+ private static final String INFINITY_STRING = "\u221E"; //$NON-NLS-1$
+ InputLine inputLine;
+ Group group;
+ Composite labelComposite;
+ Text regexText;
+ Composite cardinalityContainer;
+ Combo cardinalityCombo;
+ Label cardinalityMinLabel;
+ Text cardinalityMinText;
+ Label cardinalityMaxLabel;
+ Text cardinalityMaxText;
+ Button infiniteButton;
+ List<InputGroup> inputs = new ArrayList<InputGroup>();
+ Button addGroupButton;
+ Label addGroupLabel;
+
+ public Line(Composite parent, String name, InputLine inputLine) {
+ this.inputLine = inputLine;
+
+ group = new Group(parent, SWT.NONE);
+ group.setText(name);
+ group.setLayout(new GridLayout(2, false));
+ group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ labelComposite = new Composite(group, SWT.FILL);
+ GridLayout labelLayout = new GridLayout(1, false);
+ labelLayout.marginWidth = 0;
+ labelLayout.marginHeight = 0;
+ labelComposite.setLayout(labelLayout);
+ labelComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+
+ Label label = new Label(labelComposite, SWT.NULL);
+ label.setText(Messages.CustomTxtParserInputWizardPage_regularExpression);
+
+ Composite regexContainer = new Composite(group, SWT.NONE);
+ GridLayout regexLayout = new GridLayout(2, false);
+ regexLayout.marginHeight = 0;
+ regexLayout.marginWidth = 0;
+ regexContainer.setLayout(regexLayout);
+ regexContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ regexText = new Text(regexContainer, SWT.BORDER | SWT.SINGLE);
+ GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ gd.widthHint = 0;
+ regexText.setLayoutData(gd);
+ regexText.setText(inputLine.getRegex());
+ regexText.addModifyListener(updateListener);
+
+ Button regexHelpButton = new Button(regexContainer, SWT.PUSH);
+ regexHelpButton.setImage(helpImage);
+ regexHelpButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_regularExpressionHelp);
+ regexHelpButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ openHelpShell(PATTERN_URL);
+ }
+ });
+
+ label = new Label(group, SWT.NONE);
+ label.setText(Messages.CustomTxtParserInputWizardPage_cardinality);
+ label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+
+ cardinalityContainer = new Composite(group, SWT.NONE);
+ GridLayout cardinalityLayout = new GridLayout(6, false);
+ cardinalityLayout.marginHeight = 0;
+ cardinalityLayout.marginWidth = 0;
+ cardinalityContainer.setLayout(cardinalityLayout);
+ cardinalityContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ cardinalityCombo = new Combo(cardinalityContainer, SWT.DROP_DOWN | SWT.READ_ONLY);
+ cardinalityCombo.setItems(new String[] {
+ Cardinality.ZERO_OR_MORE.toString(),
+ Cardinality.ONE_OR_MORE.toString(),
+ Cardinality.ZERO_OR_ONE.toString(),
+ Cardinality.ONE.toString(),
+ "(?,?)"}); //$NON-NLS-1$
+ cardinalityCombo.addSelectionListener(new SelectionListener(){
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {}
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ switch (cardinalityCombo.getSelectionIndex()) {
+ case 4: //(?,?)
+ cardinalityMinLabel.setVisible(true);
+ cardinalityMinText.setVisible(true);
+ cardinalityMaxLabel.setVisible(true);
+ cardinalityMaxText.setVisible(true);
+ infiniteButton.setVisible(true);
+ break;
+ default:
+ cardinalityMinLabel.setVisible(false);
+ cardinalityMinText.setVisible(false);
+ cardinalityMaxLabel.setVisible(false);
+ cardinalityMaxText.setVisible(false);
+ infiniteButton.setVisible(false);
+ break;
+ }
+ cardinalityContainer.layout();
+ validate();
+ updatePreviews();
+ }});
+
+ cardinalityMinLabel = new Label(cardinalityContainer, SWT.NONE);
+ cardinalityMinLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ cardinalityMinLabel.setText(Messages.CustomTxtParserInputWizardPage_min);
+ cardinalityMinLabel.setVisible(false);
+
+ cardinalityMinText = new Text(cardinalityContainer, SWT.BORDER | SWT.SINGLE);
+ gd = new GridData(SWT.CENTER, SWT.CENTER, false, false);
+ gd.widthHint = 20;
+ cardinalityMinText.setLayoutData(gd);
+ cardinalityMinText.setVisible(false);
+
+ cardinalityMaxLabel = new Label(cardinalityContainer, SWT.NONE);
+ cardinalityMaxLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ cardinalityMaxLabel.setText(Messages.CustomTxtParserInputWizardPage_max);
+ cardinalityMaxLabel.setVisible(false);
+
+ cardinalityMaxText = new Text(cardinalityContainer, SWT.BORDER | SWT.SINGLE);
+ gd = new GridData(SWT.CENTER, SWT.CENTER, false, false);
+ gd.widthHint = 20;
+ cardinalityMaxText.setLayoutData(gd);
+ cardinalityMaxText.setVisible(false);
+
+ infiniteButton = new Button(cardinalityContainer, SWT.PUSH);
+ infiniteButton.setText(INFINITY_STRING);
+ infiniteButton.setVisible(false);
+ infiniteButton.addSelectionListener(new SelectionAdapter(){
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ cardinalityMaxText.setText(INFINITY_STRING);
+ }});
+
+ if (inputLine.cardinality.equals(Cardinality.ZERO_OR_MORE)) {
+ cardinalityCombo.select(0);
+ } else if (inputLine.cardinality.equals(Cardinality.ONE_OR_MORE)) {
+ cardinalityCombo.select(1);
+ } else if (inputLine.cardinality.equals(Cardinality.ZERO_OR_ONE)) {
+ cardinalityCombo.select(2);
+ } else if (inputLine.cardinality.equals(Cardinality.ONE)) {
+ cardinalityCombo.select(3);
+ } else {
+ cardinalityCombo.select(4);
+ cardinalityMinLabel.setVisible(true);
+ cardinalityMinText.setVisible(true);
+ if (inputLine.getMinCount() >= 0) {
+ cardinalityMinText.setText(Integer.toString(inputLine.getMinCount()));
+ }
+ cardinalityMaxLabel.setVisible(true);
+ cardinalityMaxText.setVisible(true);
+ if (inputLine.getMaxCount() == Cardinality.INF) {
+ cardinalityMaxText.setText(INFINITY_STRING);
+ } else if (inputLine.getMaxCount() >= 0) {
+ cardinalityMaxText.setText(Integer.toString(inputLine.getMaxCount()));
+ }
+ infiniteButton.setVisible(true);
+ }
+
+ VerifyListener digitsListener = new VerifyListener() {
+ @Override
+ public void verifyText(VerifyEvent e) {
+ if (e.text.equals(INFINITY_STRING)) {
+ e.doit = e.widget == cardinalityMaxText && e.start == 0 && e.end == ((Text) e.widget).getText().length();
+ } else {
+ if (((Text) e.widget).getText().equals(INFINITY_STRING)) {
+ e.doit = e.start == 0 && e.end == ((Text) e.widget).getText().length();
+ }
+ for (int i = 0; i < e.text.length(); i++) {
+ if (!Character.isDigit(e.text.charAt(i))) {
+ e.doit = false;
+ break;
+ }
+ }
+ }
+ }};
+
+ cardinalityMinText.addModifyListener(updateListener);
+ cardinalityMaxText.addModifyListener(updateListener);
+ cardinalityMinText.addVerifyListener(digitsListener);
+ cardinalityMaxText.addVerifyListener(digitsListener);
+
+ if (inputLine.columns != null) {
+ for (InputData inputData : inputLine.columns) {
+ InputGroup inputGroup = new InputGroup(group, this, inputs.size()+1);
+ if (inputData.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ inputGroup.tagCombo.select(0);
+ inputGroup.tagText.setText(inputData.format);
+ inputGroup.tagLabel.setText(Messages.CustomTxtParserInputWizardPage_format);
+ inputGroup.tagLabel.setVisible(true);
+ inputGroup.tagText.setVisible(true);
+ inputGroup.tagText.addModifyListener(updateListener);
+ } else if (inputData.name.equals(CustomTraceDefinition.TAG_MESSAGE)) {
+ inputGroup.tagCombo.select(1);
+ } else {
+ inputGroup.tagCombo.select(2);
+ inputGroup.tagText.setText(inputData.name);
+ inputGroup.tagLabel.setText(Messages.CustomTxtParserInputWizardPage_name);
+ inputGroup.tagLabel.setVisible(true);
+ inputGroup.tagText.setVisible(true);
+ inputGroup.tagText.addModifyListener(updateListener);
+ }
+ inputGroup.actionCombo.select(inputData.action);
+ inputs.add(inputGroup);
+ }
+ }
+
+ createAddGroupButton();
+ }
+
+ private void createAddGroupButton() {
+ addGroupButton = new Button(group, SWT.PUSH);
+ addGroupButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ addGroupButton.setImage(addImage);
+ addGroupButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_addGroup);
+ addGroupButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ removeAddGroupButton();
+ inputs.add(new InputGroup(group, Line.this, inputs.size()+1));
+ createAddGroupButton();
+ lineContainer.layout();
+ lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);
+ group.getParent().layout();
+ validate();
+ updatePreviews();
+ }
+ });
+
+ addGroupLabel = new Label(group, SWT.NULL);
+ addGroupLabel.setText(Messages.CustomTxtParserInputWizardPage_newGroup);
+ }
+
+ private void removeAddGroupButton() {
+ addGroupButton.dispose();
+ addGroupLabel.dispose();
+ }
+
+ private void removeInput(int inputNumber) {
+ if (--inputNumber < inputs.size()) {
+ inputs.remove(inputNumber).dispose();
+ for (int i = inputNumber; i < inputs.size(); i++) {
+ inputs.get(i).setInputNumber(i+1);
+ }
+ lineContainer.layout();
+ lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);
+ group.getParent().layout();
+ }
+ }
+
+// private void setName(String name) {
+// this.name = name;
+// group.setText("Line " + name);
+// }
+
+ private void dispose() {
+ group.dispose();
+ }
+
+ private void extractInputs() {
+ inputLine.setRegex(selectedLine.regexText.getText());
+ switch (cardinalityCombo.getSelectionIndex()) {
+ case 0:
+ inputLine.cardinality = Cardinality.ZERO_OR_MORE;
+ break;
+ case 1:
+ inputLine.cardinality = Cardinality.ONE_OR_MORE;
+ break;
+ case 2:
+ inputLine.cardinality = Cardinality.ZERO_OR_ONE;
+ break;
+ case 3:
+ inputLine.cardinality = Cardinality.ONE;
+ break;
+ case 4: //(?,?)
+ int min, max;
+ try {
+ min = Integer.parseInt(cardinalityMinText.getText());
+ } catch (NumberFormatException e) {
+ min = -1;
+ }
+ try {
+ if (cardinalityMaxText.getText().equals(INFINITY_STRING)) {
+ max = Cardinality.INF;
+ } else {
+ max = Integer.parseInt(cardinalityMaxText.getText());
+ }
+ } catch (NumberFormatException e) {
+ max = -1;
+ }
+ inputLine.cardinality = new Cardinality(min, max);
+ break;
+ default:
+ inputLine.cardinality = Cardinality.ZERO_OR_MORE;
+ break;
+ }
+ inputLine.columns = new ArrayList<InputData>(inputs.size());
+ for (int i = 0; i < inputs.size(); i++) {
+ InputGroup group = inputs.get(i);
+ InputData inputData = new InputData();
+ if (group.tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {
+ inputData.name = group.tagText.getText().trim();
+ } else {
+ inputData.name = group.tagCombo.getText();
+ if (group.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ inputData.format = group.tagText.getText().trim();
+ }
+ }
+ inputData.action = group.actionCombo.getSelectionIndex();
+ inputLine.columns.add(inputData);
+ }
+ }
+ }
+
+ private class InputGroup {
+ Line line;
+ int inputNumber;
+
+ // children of parent (must be disposed)
+ Composite labelComposite;
+ Composite tagComposite;
+ Label previewLabel;
+ Text previewText;
+
+ // children of labelComposite
+ Label inputLabel;
+
+ // children of tagComposite
+ Combo tagCombo;
+ Label tagLabel;
+ Text tagText;
+ Combo actionCombo;
+
+ public InputGroup(Composite parent, Line line, int inputNumber) {
+ this.line = line;
+ this.inputNumber = inputNumber;
+
+ labelComposite = new Composite(parent, SWT.FILL);
+ GridLayout labelLayout = new GridLayout(2, false);
+ labelLayout.marginWidth = 0;
+ labelLayout.marginHeight = 0;
+ labelComposite.setLayout(labelLayout);
+ labelComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+
+ Button deleteButton = new Button(labelComposite, SWT.PUSH);
+ deleteButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ deleteButton.setImage(deleteImage);
+ deleteButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_removeGroup);
+ deleteButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ InputGroup.this.line.removeInput(InputGroup.this.inputNumber);
+ validate();
+ updatePreviews();
+ }
+ });
+
+ inputLabel = new Label(labelComposite, SWT.NULL);
+ inputLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ inputLabel.setText(Messages.CustomTxtParserInputWizardPage_group + inputNumber + ":"); //$NON-NLS-1$
+
+ tagComposite = new Composite(parent, SWT.FILL);
+ GridLayout tagLayout = new GridLayout(4, false);
+ tagLayout.marginWidth = 0;
+ tagLayout.marginHeight = 0;
+ tagComposite.setLayout(tagLayout);
+ tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
+ tagCombo.setItems(new String[] {CustomTraceDefinition.TAG_TIMESTAMP,
+ CustomTraceDefinition.TAG_MESSAGE,
+ CustomTraceDefinition.TAG_OTHER});
+ tagCombo.select(1);
+ tagCombo.addSelectionListener(new SelectionListener(){
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {}
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ tagText.removeModifyListener(updateListener);
+ switch (tagCombo.getSelectionIndex()) {
+ case 0: //Time Stamp
+ tagLabel.setText(Messages.CustomTxtParserInputWizardPage_format);
+ tagLabel.setVisible(true);
+ tagText.setVisible(true);
+ tagText.addModifyListener(updateListener);
+ break;
+ case 1: //Message
+ tagLabel.setVisible(false);
+ tagText.setVisible(false);
+ break;
+ case 2: //Other
+ tagLabel.setText(Messages.CustomTxtParserInputWizardPage_name);
+ tagLabel.setVisible(true);
+ tagText.setVisible(true);
+ tagText.addModifyListener(updateListener);
+ break;
+ case 3: //Continue
+ tagLabel.setVisible(false);
+ tagText.setVisible(false);
+ break;
+ default:
+ break;
+ }
+ tagComposite.layout();
+ validate();
+ updatePreviews();
+ }});
+
+ tagLabel = new Label(tagComposite, SWT.NULL);
+ tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ tagLabel.setVisible(false);
+
+ tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE);
+ GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ gd.widthHint = 0;
+ tagText.setLayoutData(gd);
+ tagText.setVisible(false);
+
+ actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
+ actionCombo.setItems(new String[] {Messages.CustomTxtParserInputWizardPage_set, Messages.CustomTxtParserInputWizardPage_append, Messages.CustomTxtParserInputWizardPage_appendWith});
+ actionCombo.select(0);
+ actionCombo.addSelectionListener(updateListener);
+
+ previewLabel = new Label(parent, SWT.NULL);
+ previewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ previewLabel.setText(Messages.CustomTxtParserInputWizardPage_preview);
+
+ previewText = new Text(parent, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ gd.widthHint = 0;
+ previewText.setLayoutData(gd);
+ previewText.setText(Messages.CustomTxtParserInputWizardPage_noMatch);
+ previewText.setBackground(COLOR_WIDGET_BACKGROUND);
+ }
+
+ private void dispose() {
+ labelComposite.dispose();
+ tagComposite.dispose();
+ previewLabel.dispose();
+ previewText.dispose();
+ }
+
+ private void setInputNumber(int inputNumber) {
+ this.inputNumber = inputNumber;
+ inputLabel.setText(Messages.CustomTxtParserInputWizardPage_group + inputNumber + ":"); //$NON-NLS-1$
+ labelComposite.layout();
+ }
+ }
+
+ private void validate() {
+
+ definition.definitionName = logtypeText.getText().trim();
+ definition.timeStampOutputFormat = timestampOutputFormatText.getText().trim();
+
+ if (selectedLine != null) {
+ selectedLine.extractInputs();
+ treeViewer.refresh();
+ }
+
+ StringBuffer errors = new StringBuffer();
+
+ if (definition.definitionName.length() == 0) {
+ errors.append("Enter a name for the new log type. "); //$NON-NLS-1$
+ logtypeText.setBackground(COLOR_LIGHT_RED);
+ } else {
+ logtypeText.setBackground(COLOR_TEXT_BACKGROUND);
+ for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
+ if (definition.definitionName.equals(def.definitionName)) {
+ if (editDefinitionName == null || ! editDefinitionName.equals(definition.definitionName)) {
+ errors.append("The log type name already exists. "); //$NON-NLS-1$
+ logtypeText.setBackground(COLOR_LIGHT_RED);
+ break;
+ }
+ }
+ }
+ }
+
+ timestampFound = false;
+ for (int i = 0; i < definition.inputs.size(); i++) {
+
+ InputLine inputLine = definition.inputs.get(i);
+ String name = Integer.toString(i+1);
+ errors.append(validateLine(inputLine, name));
+ }
+ if (timestampFound) {
+ if (definition.timeStampOutputFormat.length() == 0) {
+ errors.append("Enter the output format for the Time Stamp field. "); //$NON-NLS-1$
+ timestampOutputFormatText.setBackground(COLOR_LIGHT_RED);
+ } else {
+ try {
+ new SimpleDateFormat(definition.timeStampOutputFormat);
+ timestampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);
+ } catch (IllegalArgumentException e) {
+ errors.append("Enter a valid output format for the Time Stamp field. "); //$NON-NLS-1$
+ timestampOutputFormatText.setBackground(COLOR_LIGHT_RED);
+ }
+ }
+
+ } else {
+ timestampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);
+// timestampPreviewText.setBackground(COLOR_WIDGET_BACKGROUND);
+// errors.append("Identify a Time Stamp group (Line "+name+"). ");
+// timestampPreviewText.setText("*no timestamp group*");
+// timestampPreviewText.setBackground(COLOR_LIGHT_RED);
+ }
+
+ if (errors.length() == 0) {
+ setDescription(defaultDescription);
+ setPageComplete(true);
+ } else {
+ setDescription(errors.toString());
+ setPageComplete(false);
+ }
+ }
+
+ public StringBuffer validateLine(InputLine inputLine, String name) {
+ StringBuffer errors = new StringBuffer();
+ Line line = null;
+ if (selectedLine != null && selectedLine.inputLine.equals(inputLine)) {
+ line = selectedLine;
+ }
+ try {
+ Pattern.compile(inputLine.getRegex());
+ if (line != null) {
+ line.regexText.setBackground(COLOR_TEXT_BACKGROUND);
+ }
+ } catch (PatternSyntaxException e) {
+ errors.append("Enter a valid regular expression (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$
+ if (line != null) {
+ line.regexText.setBackground(COLOR_LIGHT_RED);
+ }
+ }
+ if (inputLine.getMinCount() == -1) {
+ errors.append("Enter a minimum value for cardinality (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$
+ if (line != null) {
+ line.cardinalityMinText.setBackground(COLOR_LIGHT_RED);
+ }
+ } else {
+ if (line != null) {
+ line.cardinalityMinText.setBackground(COLOR_TEXT_BACKGROUND);
+ }
+ }
+ if (inputLine.getMaxCount() == -1) {
+ errors.append("Enter a maximum value for cardinality (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$
+ if (line != null) {
+ line.cardinalityMaxText.setBackground(COLOR_LIGHT_RED);
+ }
+ } else if (inputLine.getMinCount() > inputLine.getMaxCount()) {
+ errors.append("Enter correct (min <= max) values for cardinality (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$
+ if (line != null) {
+ line.cardinalityMinText.setBackground(COLOR_LIGHT_RED);
+ }
+ if (line != null) {
+ line.cardinalityMaxText.setBackground(COLOR_LIGHT_RED);
+ }
+ } else {
+ if (line != null) {
+ line.cardinalityMaxText.setBackground(COLOR_TEXT_BACKGROUND);
+ }
+ }
+ for (int i = 0; inputLine.columns != null && i < inputLine.columns.size(); i++) {
+ InputData inputData = inputLine.columns.get(i);
+ InputGroup group = null;
+ if (line != null) {
+ group = line.inputs.get(i);
+ }
+ if (inputData.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ timestampFound = true;
+ if (inputData.format.length() == 0) {
+ errors.append("Enter the input format for the Time Stamp (Line "+name+" Group "+(i+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (group != null) {
+ group.tagText.setBackground(COLOR_LIGHT_RED);
+ }
+ } else {
+ try {
+ new SimpleDateFormat(inputData.format);
+ if (group != null) {
+ group.tagText.setBackground(COLOR_TEXT_BACKGROUND);
+ }
+ } catch (IllegalArgumentException e) {
+ errors.append("Enter a valid input format for the Time Stamp (Line "+name+" Group "+(i+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (group != null) {
+ group.tagText.setBackground(COLOR_LIGHT_RED);
+ }
+ }
+ }
+ } else if (inputData.name.length() == 0) {
+ errors.append("Enter a name for the data group (Line "+name+" Group "+(i+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (group != null) {
+ group.tagText.setBackground(COLOR_LIGHT_RED);
+ }
+ } else {
+ if (group != null) {
+ group.tagText.setBackground(COLOR_TEXT_BACKGROUND);
+ }
+ }
+ }
+ for (int i = 0; inputLine.childrenInputs != null && i < inputLine.childrenInputs.size(); i++) {
+ errors.append(validateLine(inputLine.childrenInputs.get(i), name+"."+(i+1))); //$NON-NLS-1$
+ }
+ return errors;
+ }
+
+ public CustomTxtTraceDefinition getDefinition() {
+ return definition;
+ }
+
+ public char[] getInputText() {
+ return inputText.getText().toCharArray();
+ }
+}
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;\r
-\r
-import java.io.File;\r
-import java.io.FileWriter;\r
-import java.io.IOException;\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-\r
-import org.eclipse.jface.wizard.WizardPage;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomEventsTable;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTrace;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.SashForm;\r
-import org.eclipse.swt.custom.ScrolledComposite;\r
-import org.eclipse.swt.events.SelectionAdapter;\r
-import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.graphics.Image;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Button;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Text;\r
-\r
-public class CustomTxtParserOutputWizardPage extends WizardPage {\r
-\r
- private static final Image upImage = Activator.getDefault().getImageFromPath("/icons/elcl16/up_button.gif"); //$NON-NLS-1$\r
- private static final Image downImage = Activator.getDefault().getImageFromPath("/icons/elcl16/down_button.gif"); //$NON-NLS-1$\r
- private final CustomTxtParserWizard wizard;\r
- private CustomTxtTraceDefinition definition;\r
- List<Output> outputs = new ArrayList<Output>();\r
- // Output messageOutput;\r
- Composite container;\r
- SashForm sash;\r
- // Text timestampFormatText;\r
- // Text timestampPreviewText;\r
- ScrolledComposite outputsScrolledComposite;\r
- Composite outputsContainer;\r
- // ScrolledComposite inputScrolledComposite;\r
- Composite tableContainer;\r
- CustomEventsTable previewTable;\r
- File tmpFile;\r
-\r
- protected CustomTxtParserOutputWizardPage(final CustomTxtParserWizard wizard) {\r
- super("CustomParserOutputWizardPage"); //$NON-NLS-1$\r
- setTitle(wizard.inputPage.getTitle());\r
- setDescription(Messages.CustomTxtParserOutputWizardPage_description);\r
- this.wizard = wizard;\r
- setPageComplete(false);\r
- }\r
-\r
- @Override\r
- public void createControl(final Composite parent) {\r
- container = new Composite(parent, SWT.NULL);\r
- container.setLayout(new GridLayout());\r
-\r
- sash = new SashForm(container, SWT.VERTICAL);\r
- sash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- sash.setBackground(sash.getDisplay().getSystemColor(SWT.COLOR_GRAY));\r
-\r
- outputsScrolledComposite = new ScrolledComposite(sash, SWT.V_SCROLL);\r
- outputsScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- outputsContainer = new Composite(outputsScrolledComposite, SWT.NONE);\r
- final GridLayout outputsLayout = new GridLayout(4, false);\r
- outputsLayout.marginHeight = 10;\r
- outputsLayout.marginWidth = 0;\r
- outputsContainer.setLayout(outputsLayout);\r
- outputsScrolledComposite.setContent(outputsContainer);\r
- outputsScrolledComposite.setExpandHorizontal(true);\r
- outputsScrolledComposite.setExpandVertical(true);\r
-\r
- outputsContainer.layout();\r
-\r
- outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);\r
-\r
- tableContainer = new Composite(sash, SWT.NONE);\r
- final GridLayout tableLayout = new GridLayout();\r
- tableLayout.marginHeight = 0;\r
- tableLayout.marginWidth = 0;\r
- tableContainer.setLayout(tableLayout);\r
- previewTable = new CustomEventsTable(new CustomTxtTraceDefinition(), tableContainer, 0);\r
- previewTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
-\r
- if (wizard.definition != null) {\r
- loadDefinition(wizard.definition);\r
- }\r
- setControl(container);\r
-\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- previewTable.dispose();\r
- super.dispose();\r
- }\r
-\r
- private void loadDefinition(final CustomTxtTraceDefinition definition) {\r
- for (final OutputColumn outputColumn : definition.outputs) {\r
- final Output output = new Output(outputsContainer, outputColumn.name);\r
- outputs.add(output);\r
- }\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)\r
- */\r
- @Override\r
- public void setVisible(final boolean visible) {\r
- if (visible) {\r
- this.definition = wizard.inputPage.getDefinition();\r
- final List<String> outputNames = wizard.inputPage.getInputNames();\r
-\r
- // dispose outputs that have been removed in the input page\r
- final Iterator<Output> iter = outputs.iterator();\r
- while (iter.hasNext()) {\r
- final Output output = iter.next();\r
- boolean found = false;\r
- for (final String name : outputNames) {\r
- if (output.name.equals(name)) {\r
- found = true;\r
- break;\r
- }\r
- }\r
- if (!found) {\r
- output.dispose();\r
- iter.remove();\r
- }\r
- }\r
-\r
- // create outputs that have been added in the input page\r
- for (final String name : outputNames) {\r
- boolean found = false;\r
- for (final Output output : outputs) {\r
- if (output.name.equals(name)) {\r
- found = true;\r
- break;\r
- }\r
- }\r
- if (!found) {\r
- outputs.add(new Output(outputsContainer, name));\r
- }\r
- }\r
-\r
- outputsContainer.layout();\r
- outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);\r
- updatePreviewTable();\r
- if (sash.getSize().y > outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y + previewTable.getTable().getItemHeight()) {\r
- sash.setWeights(new int[] {outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, sash.getSize().y - outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y});\r
- } else {\r
- sash.setWeights(new int[] {outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, previewTable.getTable().getItemHeight()});\r
- }\r
- setPageComplete(true);\r
- } else {\r
- setPageComplete(false);\r
- }\r
- super.setVisible(visible);\r
- }\r
-\r
- private void moveBefore(final Output moved) {\r
- final int i = outputs.indexOf(moved);\r
- if (i > 0) {\r
- final Output previous = outputs.get(i-1);\r
- moved.enabledButton.moveAbove(previous.enabledButton);\r
- moved.nameLabel.moveBelow(moved.enabledButton);\r
- moved.upButton.moveBelow(moved.nameLabel);\r
- moved.downButton.moveBelow(moved.upButton);\r
- outputs.add(i-1, outputs.remove(i));\r
- outputsContainer.layout();\r
- outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);\r
- container.layout();\r
- updatePreviewTable();\r
- }\r
- }\r
-\r
- private void moveAfter(final Output moved) {\r
- final int i = outputs.indexOf(moved);\r
- if (i+1 < outputs.size()) {\r
- final Output next = outputs.get(i+1);\r
- moved.enabledButton.moveBelow(next.downButton);\r
- moved.nameLabel.moveBelow(moved.enabledButton);\r
- moved.upButton.moveBelow(moved.nameLabel);\r
- moved.downButton.moveBelow(moved.upButton);\r
- outputs.add(i+1, outputs.remove(i));\r
- outputsContainer.layout();\r
- outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);\r
- container.layout();\r
- updatePreviewTable();\r
- }\r
- }\r
-\r
- private void updatePreviewTable() {\r
- final int CACHE_SIZE = 50;\r
- definition.outputs = extractOutputs();\r
-\r
- try {\r
- tmpFile = Activator.getDefault().getStateLocation().addTrailingSeparator().append("customwizard.tmp").toFile(); //$NON-NLS-1$\r
- final FileWriter writer = new FileWriter(tmpFile);\r
- writer.write(wizard.inputPage.getInputText());\r
- writer.close();\r
-\r
- final ITmfTrace trace = new CustomTxtTrace(null, definition, tmpFile.getAbsolutePath(), CACHE_SIZE);\r
- previewTable.dispose();\r
- previewTable = new CustomEventsTable(definition, tableContainer, CACHE_SIZE);\r
- previewTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- previewTable.setTrace(trace, true);\r
- } catch (final TmfTraceException e) {\r
- Activator.getDefault().logError("Error creating CustomTxtTrace. File:" + tmpFile.getAbsolutePath(), e); //$NON-NLS-1$\r
- } catch (final IOException e) {\r
- Activator.getDefault().logError("Error creating CustomTxtTrace. File:" + tmpFile.getAbsolutePath(), e); //$NON-NLS-1$\r
- }\r
-\r
- tableContainer.layout();\r
- container.layout();\r
- }\r
-\r
- public List<OutputColumn> extractOutputs() {\r
- int numColumns = 0;\r
- for (int i = 0; i < outputs.size(); i++) {\r
- if (outputs.get(i).enabledButton.getSelection()) {\r
- numColumns++;\r
- }\r
- }\r
- final List<OutputColumn> outputColumns = new ArrayList<OutputColumn>(numColumns);\r
- numColumns = 0;\r
- for (int i = 0; i < outputs.size(); i++) {\r
- final Output output = outputs.get(i);\r
- if (output.enabledButton.getSelection()) {\r
- final OutputColumn column = new OutputColumn();\r
- column.name = output.nameLabel.getText();\r
- outputColumns.add(column);\r
- }\r
- }\r
- return outputColumns;\r
- }\r
-\r
- private class Output {\r
- String name;\r
- Button enabledButton;\r
- Text nameLabel;\r
- Button upButton;\r
- Button downButton;\r
-\r
- public Output(final Composite parent, final String name) {\r
- this.name = name;\r
-\r
- enabledButton = new Button(parent, SWT.CHECK);\r
- enabledButton.setToolTipText(Messages.CustomTxtParserOutputWizardPage_visible);\r
- enabledButton.setSelection(true);\r
- enabledButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(final SelectionEvent e) {\r
- updatePreviewTable();\r
- }\r
- });\r
- // if (messageOutput != null) {\r
- // enabledButton.moveAbove(messageOutput.enabledButton);\r
- // }\r
-\r
- nameLabel = new Text(parent, SWT.BORDER | SWT.READ_ONLY | SWT.SINGLE);\r
- nameLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));\r
- nameLabel.setText(name);\r
- nameLabel.moveBelow(enabledButton);\r
-\r
- upButton = new Button(parent, SWT.PUSH);\r
- upButton.setImage(upImage);\r
- upButton.setToolTipText(Messages.CustomTxtParserOutputWizardPage_moveBefore);\r
- upButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(final SelectionEvent e) {\r
- moveBefore(Output.this);\r
- }\r
- });\r
- upButton.moveBelow(nameLabel);\r
-\r
- downButton = new Button(parent, SWT.PUSH);\r
- downButton.setImage(downImage);\r
- downButton.setToolTipText(Messages.CustomTxtParserOutputWizardPage_moveAfter);\r
- downButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(final SelectionEvent e) {\r
- moveAfter(Output.this);\r
- }\r
- });\r
- downButton.moveBelow(upButton);\r
- }\r
-\r
- private void dispose() {\r
- enabledButton.dispose();\r
- nameLabel.dispose();\r
- upButton.dispose();\r
- downButton.dispose();\r
- }\r
- }\r
-\r
- public CustomTxtTraceDefinition getDefinition() {\r
- return definition;\r
- }\r
-\r
-}\r
+package org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomEventsTable;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTrace;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+
+public class CustomTxtParserOutputWizardPage extends WizardPage {
+
+ private static final Image upImage = Activator.getDefault().getImageFromPath("/icons/elcl16/up_button.gif"); //$NON-NLS-1$
+ private static final Image downImage = Activator.getDefault().getImageFromPath("/icons/elcl16/down_button.gif"); //$NON-NLS-1$
+ private final CustomTxtParserWizard wizard;
+ private CustomTxtTraceDefinition definition;
+ List<Output> outputs = new ArrayList<Output>();
+ // Output messageOutput;
+ Composite container;
+ SashForm sash;
+ // Text timestampFormatText;
+ // Text timestampPreviewText;
+ ScrolledComposite outputsScrolledComposite;
+ Composite outputsContainer;
+ // ScrolledComposite inputScrolledComposite;
+ Composite tableContainer;
+ CustomEventsTable previewTable;
+ File tmpFile;
+
+ protected CustomTxtParserOutputWizardPage(final CustomTxtParserWizard wizard) {
+ super("CustomParserOutputWizardPage"); //$NON-NLS-1$
+ setTitle(wizard.inputPage.getTitle());
+ setDescription(Messages.CustomTxtParserOutputWizardPage_description);
+ this.wizard = wizard;
+ setPageComplete(false);
+ }
+
+ @Override
+ public void createControl(final Composite parent) {
+ container = new Composite(parent, SWT.NULL);
+ container.setLayout(new GridLayout());
+
+ sash = new SashForm(container, SWT.VERTICAL);
+ sash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ sash.setBackground(sash.getDisplay().getSystemColor(SWT.COLOR_GRAY));
+
+ outputsScrolledComposite = new ScrolledComposite(sash, SWT.V_SCROLL);
+ outputsScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ outputsContainer = new Composite(outputsScrolledComposite, SWT.NONE);
+ final GridLayout outputsLayout = new GridLayout(4, false);
+ outputsLayout.marginHeight = 10;
+ outputsLayout.marginWidth = 0;
+ outputsContainer.setLayout(outputsLayout);
+ outputsScrolledComposite.setContent(outputsContainer);
+ outputsScrolledComposite.setExpandHorizontal(true);
+ outputsScrolledComposite.setExpandVertical(true);
+
+ outputsContainer.layout();
+
+ outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);
+
+ tableContainer = new Composite(sash, SWT.NONE);
+ final GridLayout tableLayout = new GridLayout();
+ tableLayout.marginHeight = 0;
+ tableLayout.marginWidth = 0;
+ tableContainer.setLayout(tableLayout);
+ previewTable = new CustomEventsTable(new CustomTxtTraceDefinition(), tableContainer, 0);
+ previewTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ if (wizard.definition != null) {
+ loadDefinition(wizard.definition);
+ }
+ setControl(container);
+
+ }
+
+ @Override
+ public void dispose() {
+ previewTable.dispose();
+ super.dispose();
+ }
+
+ private void loadDefinition(final CustomTxtTraceDefinition definition) {
+ for (final OutputColumn outputColumn : definition.outputs) {
+ final Output output = new Output(outputsContainer, outputColumn.name);
+ outputs.add(output);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
+ */
+ @Override
+ public void setVisible(final boolean visible) {
+ if (visible) {
+ this.definition = wizard.inputPage.getDefinition();
+ final List<String> outputNames = wizard.inputPage.getInputNames();
+
+ // dispose outputs that have been removed in the input page
+ final Iterator<Output> iter = outputs.iterator();
+ while (iter.hasNext()) {
+ final Output output = iter.next();
+ boolean found = false;
+ for (final String name : outputNames) {
+ if (output.name.equals(name)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ output.dispose();
+ iter.remove();
+ }
+ }
+
+ // create outputs that have been added in the input page
+ for (final String name : outputNames) {
+ boolean found = false;
+ for (final Output output : outputs) {
+ if (output.name.equals(name)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ outputs.add(new Output(outputsContainer, name));
+ }
+ }
+
+ outputsContainer.layout();
+ outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);
+ updatePreviewTable();
+ if (sash.getSize().y > outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y + previewTable.getTable().getItemHeight()) {
+ sash.setWeights(new int[] {outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, sash.getSize().y - outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y});
+ } else {
+ sash.setWeights(new int[] {outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, previewTable.getTable().getItemHeight()});
+ }
+ setPageComplete(true);
+ } else {
+ setPageComplete(false);
+ }
+ super.setVisible(visible);
+ }
+
+ private void moveBefore(final Output moved) {
+ final int i = outputs.indexOf(moved);
+ if (i > 0) {
+ final Output previous = outputs.get(i-1);
+ moved.enabledButton.moveAbove(previous.enabledButton);
+ moved.nameLabel.moveBelow(moved.enabledButton);
+ moved.upButton.moveBelow(moved.nameLabel);
+ moved.downButton.moveBelow(moved.upButton);
+ outputs.add(i-1, outputs.remove(i));
+ outputsContainer.layout();
+ outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);
+ container.layout();
+ updatePreviewTable();
+ }
+ }
+
+ private void moveAfter(final Output moved) {
+ final int i = outputs.indexOf(moved);
+ if (i+1 < outputs.size()) {
+ final Output next = outputs.get(i+1);
+ moved.enabledButton.moveBelow(next.downButton);
+ moved.nameLabel.moveBelow(moved.enabledButton);
+ moved.upButton.moveBelow(moved.nameLabel);
+ moved.downButton.moveBelow(moved.upButton);
+ outputs.add(i+1, outputs.remove(i));
+ outputsContainer.layout();
+ outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);
+ container.layout();
+ updatePreviewTable();
+ }
+ }
+
+ private void updatePreviewTable() {
+ final int CACHE_SIZE = 50;
+ definition.outputs = extractOutputs();
+
+ try {
+ tmpFile = Activator.getDefault().getStateLocation().addTrailingSeparator().append("customwizard.tmp").toFile(); //$NON-NLS-1$
+ final FileWriter writer = new FileWriter(tmpFile);
+ writer.write(wizard.inputPage.getInputText());
+ writer.close();
+
+ final ITmfTrace trace = new CustomTxtTrace(null, definition, tmpFile.getAbsolutePath(), CACHE_SIZE);
+ previewTable.dispose();
+ previewTable = new CustomEventsTable(definition, tableContainer, CACHE_SIZE);
+ previewTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ previewTable.setTrace(trace, true);
+ } catch (final TmfTraceException e) {
+ Activator.getDefault().logError("Error creating CustomTxtTrace. File:" + tmpFile.getAbsolutePath(), e); //$NON-NLS-1$
+ } catch (final IOException e) {
+ Activator.getDefault().logError("Error creating CustomTxtTrace. File:" + tmpFile.getAbsolutePath(), e); //$NON-NLS-1$
+ }
+
+ tableContainer.layout();
+ container.layout();
+ }
+
+ public List<OutputColumn> extractOutputs() {
+ int numColumns = 0;
+ for (int i = 0; i < outputs.size(); i++) {
+ if (outputs.get(i).enabledButton.getSelection()) {
+ numColumns++;
+ }
+ }
+ final List<OutputColumn> outputColumns = new ArrayList<OutputColumn>(numColumns);
+ numColumns = 0;
+ for (int i = 0; i < outputs.size(); i++) {
+ final Output output = outputs.get(i);
+ if (output.enabledButton.getSelection()) {
+ final OutputColumn column = new OutputColumn();
+ column.name = output.nameLabel.getText();
+ outputColumns.add(column);
+ }
+ }
+ return outputColumns;
+ }
+
+ private class Output {
+ String name;
+ Button enabledButton;
+ Text nameLabel;
+ Button upButton;
+ Button downButton;
+
+ public Output(final Composite parent, final String name) {
+ this.name = name;
+
+ enabledButton = new Button(parent, SWT.CHECK);
+ enabledButton.setToolTipText(Messages.CustomTxtParserOutputWizardPage_visible);
+ enabledButton.setSelection(true);
+ enabledButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ updatePreviewTable();
+ }
+ });
+ // if (messageOutput != null) {
+ // enabledButton.moveAbove(messageOutput.enabledButton);
+ // }
+
+ nameLabel = new Text(parent, SWT.BORDER | SWT.READ_ONLY | SWT.SINGLE);
+ nameLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
+ nameLabel.setText(name);
+ nameLabel.moveBelow(enabledButton);
+
+ upButton = new Button(parent, SWT.PUSH);
+ upButton.setImage(upImage);
+ upButton.setToolTipText(Messages.CustomTxtParserOutputWizardPage_moveBefore);
+ upButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ moveBefore(Output.this);
+ }
+ });
+ upButton.moveBelow(nameLabel);
+
+ downButton = new Button(parent, SWT.PUSH);
+ downButton.setImage(downImage);
+ downButton.setToolTipText(Messages.CustomTxtParserOutputWizardPage_moveAfter);
+ downButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ moveAfter(Output.this);
+ }
+ });
+ downButton.moveBelow(upButton);
+ }
+
+ private void dispose() {
+ enabledButton.dispose();
+ nameLabel.dispose();
+ upButton.dispose();
+ downButton.dispose();
+ }
+ }
+
+ public CustomTxtTraceDefinition getDefinition() {
+ return definition;
+ }
+
+}
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;\r
-\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.jface.viewers.IStructuredSelection;\r
-import org.eclipse.jface.wizard.Wizard;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition;\r
-import org.eclipse.ui.INewWizard;\r
-import org.eclipse.ui.IWorkbench;\r
-\r
-public class CustomTxtParserWizard extends Wizard implements INewWizard {\r
-\r
- CustomTxtParserInputWizardPage inputPage;\r
- CustomTxtParserOutputWizardPage outputPage;\r
- private ISelection selection;\r
- CustomTxtTraceDefinition definition;\r
-\r
- public CustomTxtParserWizard() {\r
- super();\r
- }\r
-\r
- public CustomTxtParserWizard(CustomTxtTraceDefinition definition) {\r
- super();\r
- this.definition = definition;\r
- }\r
-\r
- @Override\r
- public boolean performFinish() {\r
- CustomTxtTraceDefinition def = outputPage.getDefinition();\r
- if (definition != null && !definition.definitionName.equals(def.definitionName)) {\r
- CustomTxtTraceDefinition.delete(definition.definitionName);\r
- }\r
- def.save();\r
- return true;\r
- }\r
-\r
- /**\r
- * Adding the page to the wizard.\r
- */\r
-\r
- @Override\r
- public void addPages() {\r
- inputPage = new CustomTxtParserInputWizardPage(selection, definition);\r
- addPage(inputPage);\r
- outputPage = new CustomTxtParserOutputWizardPage(this);\r
- addPage(outputPage);\r
- }\r
-\r
- @Override\r
- public void init(IWorkbench workbench, IStructuredSelection selection) {\r
- this.selection = selection;\r
- }\r
-\r
-}\r
+package org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+
+public class CustomTxtParserWizard extends Wizard implements INewWizard {
+
+ CustomTxtParserInputWizardPage inputPage;
+ CustomTxtParserOutputWizardPage outputPage;
+ private ISelection selection;
+ CustomTxtTraceDefinition definition;
+
+ public CustomTxtParserWizard() {
+ super();
+ }
+
+ public CustomTxtParserWizard(CustomTxtTraceDefinition definition) {
+ super();
+ this.definition = definition;
+ }
+
+ @Override
+ public boolean performFinish() {
+ CustomTxtTraceDefinition def = outputPage.getDefinition();
+ if (definition != null && !definition.definitionName.equals(def.definitionName)) {
+ CustomTxtTraceDefinition.delete(definition.definitionName);
+ }
+ def.save();
+ return true;
+ }
+
+ /**
+ * Adding the page to the wizard.
+ */
+
+ @Override
+ public void addPages() {
+ inputPage = new CustomTxtParserInputWizardPage(selection, definition);
+ addPage(inputPage);
+ outputPage = new CustomTxtParserOutputWizardPage(this);
+ addPage(outputPage);
+ }
+
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.selection = selection;
+ }
+
+}
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;\r
-\r
-import java.io.BufferedReader;\r
-import java.io.ByteArrayInputStream;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.InputStreamReader;\r
-import java.text.ParseException;\r
-import java.text.SimpleDateFormat;\r
-import java.util.ArrayList;\r
-import java.util.Date;\r
-import java.util.List;\r
-\r
-import javax.xml.parsers.DocumentBuilder;\r
-import javax.xml.parsers.DocumentBuilderFactory;\r
-import javax.xml.parsers.ParserConfigurationException;\r
-\r
-import org.eclipse.core.resources.IFile;\r
-import org.eclipse.core.runtime.CoreException;\r
-import org.eclipse.jface.viewers.AbstractTreeViewer;\r
-import org.eclipse.jface.viewers.ColumnLabelProvider;\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.jface.viewers.ISelectionChangedListener;\r
-import org.eclipse.jface.viewers.IStructuredSelection;\r
-import org.eclipse.jface.viewers.ITreeContentProvider;\r
-import org.eclipse.jface.viewers.SelectionChangedEvent;\r
-import org.eclipse.jface.viewers.StructuredSelection;\r
-import org.eclipse.jface.viewers.TreeViewer;\r
-import org.eclipse.jface.viewers.Viewer;\r
-import org.eclipse.jface.wizard.WizardPage;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputAttribute;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputElement;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.browser.Browser;\r
-import org.eclipse.swt.browser.TitleEvent;\r
-import org.eclipse.swt.browser.TitleListener;\r
-import org.eclipse.swt.custom.SashForm;\r
-import org.eclipse.swt.custom.ScrolledComposite;\r
-import org.eclipse.swt.custom.StyleRange;\r
-import org.eclipse.swt.custom.StyledText;\r
-import org.eclipse.swt.events.ModifyEvent;\r
-import org.eclipse.swt.events.ModifyListener;\r
-import org.eclipse.swt.events.SelectionAdapter;\r
-import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.events.SelectionListener;\r
-import org.eclipse.swt.graphics.Color;\r
-import org.eclipse.swt.graphics.Font;\r
-import org.eclipse.swt.graphics.FontData;\r
-import org.eclipse.swt.graphics.Image;\r
-import org.eclipse.swt.layout.FillLayout;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Button;\r
-import org.eclipse.swt.widgets.Combo;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.Group;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.swt.widgets.Text;\r
-import org.w3c.dom.Document;\r
-import org.w3c.dom.Element;\r
-import org.w3c.dom.NamedNodeMap;\r
-import org.w3c.dom.Node;\r
-import org.w3c.dom.NodeList;\r
-import org.xml.sax.EntityResolver;\r
-import org.xml.sax.ErrorHandler;\r
-import org.xml.sax.InputSource;\r
-import org.xml.sax.SAXException;\r
-import org.xml.sax.SAXParseException;\r
-\r
-public class CustomXmlParserInputWizardPage extends WizardPage {\r
-\r
- private static final String DEFAULT_TIMESTAMP_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$\r
- private static final String SIMPLE_DATE_FORMAT_URL = "http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html#skip-navbar_top"; //$NON-NLS-1$\r
- private static final Image elementImage = Activator.getDefault().getImageFromPath("/icons/elcl16/element_icon.gif"); //$NON-NLS-1$\r
- private static final Image addImage = Activator.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$\r
- private static final Image addNextImage = Activator.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$\r
- private static final Image addChildImage = Activator.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$\r
- private static final Image addManyImage = Activator.getDefault().getImageFromPath("/icons/elcl16/addmany_button.gif"); //$NON-NLS-1$\r
- private static final Image deleteImage = Activator.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$\r
- private static final Image moveUpImage = Activator.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$\r
- private static final Image moveDownImage = Activator.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$\r
- private static final Image helpImage = Activator.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$\r
- private static final Color COLOR_LIGHT_RED = new Color(Display.getDefault(), 255, 192, 192);\r
- private static final Color COLOR_TEXT_BACKGROUND = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);\r
- private static final Color COLOR_WIDGET_BACKGROUND = Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);\r
-\r
- private final ISelection selection;\r
- private CustomXmlTraceDefinition definition;\r
- private String editDefinitionName;\r
- private String defaultDescription;\r
- private ElementNode selectedElement;\r
- private Composite container;\r
- private Text logtypeText;\r
- private Text timeStampOutputFormatText;\r
- private Text timeStampPreviewText;\r
- private Button removeButton;\r
- private Button addChildButton;\r
- private Button addNextButton;\r
- private Button moveUpButton;\r
- private Button moveDownButton;\r
- private Button feelingLuckyButton;\r
- private ScrolledComposite treeScrolledComposite;\r
- private ScrolledComposite elementScrolledComposite;\r
- private TreeViewer treeViewer;\r
- private Composite treeContainer;\r
- private Composite elementContainer;\r
- private Text errorText;\r
- private StyledText inputText;\r
- private Font fixedFont;\r
- private UpdateListener updateListener;\r
- private Browser helpBrowser;\r
- private Element documentElement;\r
-\r
- // variables used recursively through element traversal\r
- private String timeStampValue;\r
- private String timeStampFormat;\r
- private boolean timeStampFound;\r
- private int logEntriesCount;\r
- private boolean logEntryFound;\r
-\r
- protected CustomXmlParserInputWizardPage(ISelection selection, CustomXmlTraceDefinition definition) {\r
- super("CustomXmlParserWizardPage"); //$NON-NLS-1$\r
- if (definition == null) {\r
- setTitle(Messages.CustomXmlParserInputWizardPage_titleNew);\r
- defaultDescription = Messages.CustomXmlParserInputWizardPage_descriptionNew;\r
- } else {\r
- setTitle(Messages.CustomXmlParserInputWizardPage_titleEdit);\r
- defaultDescription = Messages.CustomXmlParserInputWizardPage_descriptionEdit;\r
- }\r
- setDescription(defaultDescription);\r
- this.selection = selection;\r
- this.definition = definition;\r
- if (definition != null) {\r
- this.editDefinitionName = definition.definitionName;\r
- }\r
- }\r
-\r
- @Override\r
- public void createControl(Composite parent) {\r
- container = new Composite(parent, SWT.NULL);\r
- container.setLayout(new GridLayout());\r
-\r
- updateListener = new UpdateListener();\r
-\r
- Composite headerComposite = new Composite(container, SWT.FILL);\r
- GridLayout headerLayout = new GridLayout(5, false);\r
- headerLayout.marginHeight = 0;\r
- headerLayout.marginWidth = 0;\r
- headerComposite.setLayout(headerLayout);\r
- headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
-\r
- Label logtypeLabel = new Label(headerComposite, SWT.NULL);\r
- logtypeLabel.setText(Messages.CustomXmlParserInputWizardPage_logType);\r
-\r
- logtypeText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);\r
- logtypeText.setLayoutData(new GridData(120, SWT.DEFAULT));\r
-\r
- Label timeStampFormatLabel = new Label(headerComposite, SWT.NULL);\r
- timeStampFormatLabel.setText(Messages.CustomXmlParserInputWizardPage_timestampFormat);\r
-\r
- timeStampOutputFormatText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);\r
- timeStampOutputFormatText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- timeStampOutputFormatText.setText(DEFAULT_TIMESTAMP_FORMAT);\r
-\r
- Button dateFormatHelpButton = new Button(headerComposite, SWT.PUSH);\r
- dateFormatHelpButton.setImage(helpImage);\r
- dateFormatHelpButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_dateFormatHelp);\r
- dateFormatHelpButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- openHelpShell(SIMPLE_DATE_FORMAT_URL);\r
- }\r
- });\r
-\r
- Label timeStampPreviewLabel = new Label(headerComposite, SWT.NULL);\r
- timeStampPreviewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 3, 1));\r
- timeStampPreviewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview);\r
-\r
- timeStampPreviewText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);\r
- timeStampPreviewText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));\r
- timeStampPreviewText.setText("*no time stamp element or attribute*"); //$NON-NLS-1$\r
-\r
- createButtonBar();\r
-\r
- SashForm vSash = new SashForm(container, SWT.VERTICAL);\r
- vSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- vSash.setBackground(vSash.getDisplay().getSystemColor(SWT.COLOR_GRAY));\r
-\r
- SashForm hSash = new SashForm(vSash, SWT.HORIZONTAL);\r
- hSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
-\r
- treeScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL | SWT.H_SCROLL);\r
- treeScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- treeContainer = new Composite(treeScrolledComposite, SWT.NONE);\r
- treeContainer.setLayout(new FillLayout());\r
- treeScrolledComposite.setContent(treeContainer);\r
- treeScrolledComposite.setExpandHorizontal(true);\r
- treeScrolledComposite.setExpandVertical(true);\r
-\r
- treeViewer = new TreeViewer(treeContainer, SWT.SINGLE | SWT.BORDER);\r
- treeViewer.setContentProvider(new InputElementTreeNodeContentProvider());\r
- treeViewer.setLabelProvider(new InputElementTreeLabelProvider());\r
- treeViewer.addSelectionChangedListener(new InputElementTreeSelectionChangedListener());\r
- treeContainer.layout();\r
-\r
- treeScrolledComposite\r
- .setMinSize(treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);\r
-\r
- elementScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL);\r
- elementScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- elementContainer = new Composite(elementScrolledComposite, SWT.NONE);\r
- GridLayout gl = new GridLayout();\r
- gl.marginHeight = 1;\r
- gl.marginWidth = 0;\r
- elementContainer.setLayout(gl);\r
- elementScrolledComposite.setContent(elementContainer);\r
- elementScrolledComposite.setExpandHorizontal(true);\r
- elementScrolledComposite.setExpandVertical(true);\r
-\r
- if (definition == null) {\r
- definition = new CustomXmlTraceDefinition();\r
- }\r
- loadDefinition(definition);\r
- treeViewer.expandAll();\r
- elementContainer.layout();\r
-\r
- logtypeText.addModifyListener(updateListener);\r
- timeStampOutputFormatText.addModifyListener(updateListener);\r
-\r
- elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,\r
- elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);\r
-\r
- hSash.setWeights(new int[] { 1, 2 });\r
-\r
- if (definition.rootInputElement == null) {\r
- removeButton.setEnabled(false);\r
- addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addDocumentElement);\r
- addNextButton.setEnabled(false);\r
- moveUpButton.setEnabled(false);\r
- moveDownButton.setEnabled(false);\r
- } else { // root is selected\r
- addNextButton.setEnabled(false);\r
- }\r
-\r
- Composite sashBottom = new Composite(vSash, SWT.NONE);\r
- GridLayout sashBottomLayout = new GridLayout(2, false);\r
- sashBottomLayout.marginHeight = 0;\r
- sashBottomLayout.marginWidth = 0;\r
- sashBottom.setLayout(sashBottomLayout);\r
-\r
- Label previewLabel = new Label(sashBottom, SWT.NULL);\r
- previewLabel.setText(Messages.CustomXmlParserInputWizardPage_previewInput);\r
-\r
- errorText = new Text(sashBottom, SWT.SINGLE | SWT.READ_ONLY);\r
- errorText.setBackground(COLOR_WIDGET_BACKGROUND);\r
- errorText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- errorText.setVisible(false);\r
-\r
- inputText = new StyledText(sashBottom, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);\r
- if (fixedFont == null) {\r
- if (System.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$\r
- fixedFont = new Font(Display.getCurrent(), new FontData("Courier New", 10, SWT.NORMAL)); //$NON-NLS-1$\r
- } else {\r
- fixedFont = new Font(Display.getCurrent(), new FontData("Monospace", 10, SWT.NORMAL)); //$NON-NLS-1$\r
- }\r
- }\r
- inputText.setFont(fixedFont);\r
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);\r
- gd.heightHint = inputText.computeSize(SWT.DEFAULT, inputText.getLineHeight() * 4).y;\r
- gd.widthHint = 800;\r
- inputText.setLayoutData(gd);\r
- inputText.setText(getSelectionText());\r
- inputText.addModifyListener(new ModifyListener() {\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- parseXmlInput(inputText.getText());\r
- }\r
- });\r
- inputText.addModifyListener(updateListener);\r
-\r
- vSash.setWeights(new int[] { hSash.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, sashBottom.computeSize(SWT.DEFAULT, SWT.DEFAULT).y });\r
-\r
- setControl(container);\r
- }\r
-\r
- private void createButtonBar() {\r
- Composite buttonBar = new Composite(container, SWT.NONE);\r
- GridLayout buttonBarLayout = new GridLayout(6, false);\r
- buttonBarLayout.marginHeight = 0;\r
- buttonBarLayout.marginWidth = 0;\r
- buttonBar.setLayout(buttonBarLayout);\r
-\r
- removeButton = new Button(buttonBar, SWT.PUSH);\r
- removeButton.setImage(deleteImage);\r
- removeButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_removeElement);\r
- removeButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (treeViewer.getSelection().isEmpty() || selectedElement == null) {\r
- return;\r
- }\r
- removeElement();\r
- InputElement inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r
- if (inputElement == definition.rootInputElement) {\r
- definition.rootInputElement = null;\r
- } else {\r
- inputElement.parentElement.childElements.remove(inputElement);\r
- }\r
- treeViewer.refresh();\r
- validate();\r
- updatePreviews();\r
- removeButton.setEnabled(false);\r
- if (definition.rootInputElement == null) {\r
- addChildButton.setEnabled(true);\r
- addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addDocumentEleemnt);\r
- } else {\r
- addChildButton.setEnabled(false);\r
- }\r
- addNextButton.setEnabled(false);\r
- moveUpButton.setEnabled(false);\r
- moveDownButton.setEnabled(false);\r
- }\r
- });\r
-\r
- addChildButton = new Button(buttonBar, SWT.PUSH);\r
- addChildButton.setImage(addChildImage);\r
- addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addChildElement);\r
- addChildButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- InputElement inputElement = new InputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$\r
- if (definition.rootInputElement == null) {\r
- definition.rootInputElement = inputElement;\r
- inputElement.elementName = getChildNameSuggestion(null);\r
- } else if (treeViewer.getSelection().isEmpty()) {\r
- return;\r
- } else {\r
- InputElement parentInputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r
- parentInputElement.addChild(inputElement);\r
- inputElement.elementName = getChildNameSuggestion(parentInputElement);\r
- }\r
- treeViewer.refresh();\r
- treeViewer.setSelection(new StructuredSelection(inputElement), true);\r
- }\r
- });\r
-\r
- addNextButton = new Button(buttonBar, SWT.PUSH);\r
- addNextButton.setImage(addNextImage);\r
- addNextButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addNextElement);\r
- addNextButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- InputElement inputElement = new InputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$\r
- if (definition.rootInputElement == null) {\r
- definition.rootInputElement = inputElement;\r
- inputElement.elementName = getChildNameSuggestion(null);\r
- } else if (treeViewer.getSelection().isEmpty()) {\r
- return;\r
- } else {\r
- InputElement previousInputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r
- if (previousInputElement == definition.rootInputElement) {\r
- return;\r
- }\r
- previousInputElement.addNext(inputElement);\r
- inputElement.elementName = getChildNameSuggestion(inputElement.parentElement);\r
- }\r
- treeViewer.refresh();\r
- treeViewer.setSelection(new StructuredSelection(inputElement), true);\r
- }\r
- });\r
-\r
- feelingLuckyButton = new Button(buttonBar, SWT.PUSH);\r
- feelingLuckyButton.setImage(addManyImage);\r
- feelingLuckyButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_feelingLucky);\r
- feelingLuckyButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- InputElement inputElement = null;\r
- if (definition.rootInputElement == null) {\r
- if (getChildNameSuggestion(null).length() != 0) {\r
- inputElement = new InputElement(getChildNameSuggestion(null), false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$\r
- definition.rootInputElement = inputElement;\r
- feelingLucky(inputElement);\r
- } else {\r
- return;\r
- }\r
- } else if (treeViewer.getSelection().isEmpty()) {\r
- return;\r
- } else {\r
- inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r
- feelingLucky(inputElement);\r
- }\r
- treeViewer.refresh();\r
- treeViewer.setSelection(new StructuredSelection(inputElement), true);\r
- treeViewer.expandToLevel(inputElement, AbstractTreeViewer.ALL_LEVELS);\r
- }\r
- });\r
-\r
- moveUpButton = new Button(buttonBar, SWT.PUSH);\r
- moveUpButton.setImage(moveUpImage);\r
- moveUpButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_moveUp);\r
- moveUpButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (treeViewer.getSelection().isEmpty()) {\r
- return;\r
- }\r
- InputElement inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r
- if (inputElement == definition.rootInputElement) {\r
- return;\r
- }\r
- inputElement.moveUp();\r
- treeViewer.refresh();\r
- validate();\r
- updatePreviews();\r
- }\r
- });\r
-\r
- moveDownButton = new Button(buttonBar, SWT.PUSH);\r
- moveDownButton.setImage(moveDownImage);\r
- moveDownButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_moveDown);\r
- moveDownButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (treeViewer.getSelection().isEmpty()) {\r
- return;\r
- }\r
- InputElement inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r
- if (inputElement == definition.rootInputElement) {\r
- return;\r
- }\r
- inputElement.moveDown();\r
- treeViewer.refresh();\r
- validate();\r
- updatePreviews();\r
- }\r
- });\r
- }\r
-\r
- private void feelingLucky(InputElement inputElement) {\r
- while (true) {\r
- String attributeName = getAttributeNameSuggestion(inputElement);\r
- if (attributeName.length() == 0) {\r
- break;\r
- }\r
- InputAttribute attribute = new InputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$\r
- inputElement.addAttribute(attribute);\r
- }\r
- while (true) {\r
- String childName = getChildNameSuggestion(inputElement);\r
- if (childName.length() == 0) {\r
- break;\r
- }\r
- InputElement childElement = new InputElement(childName, false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$\r
- inputElement.addChild(childElement);\r
- feelingLucky(childElement);\r
- }\r
- }\r
-\r
- private static class InputElementTreeNodeContentProvider implements ITreeContentProvider {\r
-\r
- @Override\r
- public Object[] getElements(Object inputElement) {\r
- CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) inputElement;\r
- if (def.rootInputElement != null) {\r
- return new Object[] { def.rootInputElement };\r
- }\r
- return new Object[0];\r
- }\r
-\r
- @Override\r
- public Object[] getChildren(Object parentElement) {\r
- InputElement inputElement = (InputElement) parentElement;\r
- if (inputElement.childElements == null) {\r
- return new InputElement[0];\r
- }\r
- return inputElement.childElements.toArray();\r
- }\r
-\r
- @Override\r
- public boolean hasChildren(Object element) {\r
- InputElement inputElement = (InputElement) element;\r
- return (inputElement.childElements != null && inputElement.childElements.size() > 0);\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- }\r
-\r
- @Override\r
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {\r
- }\r
-\r
- @Override\r
- public Object getParent(Object element) {\r
- InputElement inputElement = (InputElement) element;\r
- return inputElement.parentElement;\r
- }\r
- }\r
-\r
- private static class InputElementTreeLabelProvider extends ColumnLabelProvider {\r
-\r
- @Override\r
- public Image getImage(Object element) {\r
- return elementImage;\r
- }\r
-\r
- @Override\r
- public String getText(Object element) {\r
- InputElement inputElement = (InputElement) element;\r
- return (inputElement.elementName.trim().length() == 0) ? "?" : inputElement.elementName; //$NON-NLS-1$\r
- }\r
- }\r
-\r
- private class InputElementTreeSelectionChangedListener implements ISelectionChangedListener {\r
- @Override\r
- public void selectionChanged(SelectionChangedEvent event) {\r
- if (selectedElement != null) {\r
- selectedElement.dispose();\r
- }\r
- if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) {\r
- IStructuredSelection selection = (IStructuredSelection) event.getSelection();\r
- InputElement inputElement = (InputElement) selection.getFirstElement();\r
- selectedElement = new ElementNode(elementContainer, inputElement);\r
- elementContainer.layout();\r
- elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,\r
- elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);\r
- container.layout();\r
- validate();\r
- updatePreviews();\r
- removeButton.setEnabled(true);\r
- addChildButton.setEnabled(true);\r
- addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addChildElement);\r
- if (definition.rootInputElement == inputElement) {\r
- addNextButton.setEnabled(false);\r
- } else {\r
- addNextButton.setEnabled(true);\r
- }\r
- moveUpButton.setEnabled(true);\r
- moveDownButton.setEnabled(true);\r
- } else {\r
- removeButton.setEnabled(false);\r
- if (definition.rootInputElement == null) {\r
- addChildButton.setEnabled(true);\r
- addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addDocumentElement);\r
- } else {\r
- addChildButton.setEnabled(false);\r
- }\r
- addNextButton.setEnabled(false);\r
- moveUpButton.setEnabled(false);\r
- moveDownButton.setEnabled(false);\r
- }\r
- }\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- *\r
- * @see org.eclipse.jface.dialogs.DialogPage#dispose()\r
- */\r
- @Override\r
- public void dispose() {\r
- if (fixedFont != null) {\r
- fixedFont.dispose();\r
- fixedFont = null;\r
- }\r
- super.dispose();\r
- }\r
-\r
- private void loadDefinition(CustomXmlTraceDefinition def) {\r
- logtypeText.setText(def.definitionName);\r
- timeStampOutputFormatText.setText(def.timeStampOutputFormat);\r
- treeViewer.setInput(def);\r
-\r
- if (def.rootInputElement != null) {\r
- treeViewer.setSelection(new StructuredSelection(def.rootInputElement));\r
- }\r
- }\r
-\r
- private String getName(InputElement inputElement) {\r
- String name = (inputElement.elementName.trim().length() == 0) ? "?" : inputElement.elementName.trim(); //$NON-NLS-1$\r
- if (inputElement.parentElement == null) {\r
- return name;\r
- }\r
- return getName(inputElement.parentElement) + " : " + name; //$NON-NLS-1$\r
- }\r
-\r
- private String getName(InputAttribute inputAttribute, InputElement inputElement) {\r
- String name = (inputAttribute.attributeName.trim().length() == 0) ? "?" : inputAttribute.attributeName.trim(); //$NON-NLS-1$\r
- return getName(inputElement) + " : " + name; //$NON-NLS-1$\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- *\r
- * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)\r
- */\r
- @Override\r
- public void setVisible(boolean visible) {\r
- if (visible) {\r
- validate();\r
- updatePreviews();\r
- }\r
- super.setVisible(visible);\r
- }\r
-\r
- public List<String> getInputNames() {\r
- return getInputNames(definition.rootInputElement);\r
- }\r
-\r
- public List<String> getInputNames(InputElement inputElement) {\r
- List<String> inputs = new ArrayList<String>();\r
- if (inputElement.inputName != null && !inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) {\r
- String inputName = inputElement.inputName;\r
- if (!inputs.contains(inputName)) {\r
- inputs.add(inputName);\r
- }\r
- }\r
- if (inputElement.attributes != null) {\r
- for (InputAttribute attribute : inputElement.attributes) {\r
- String inputName = attribute.inputName;\r
- if (!inputs.contains(inputName)) {\r
- inputs.add(inputName);\r
- }\r
- }\r
- }\r
- if (inputElement.childElements != null) {\r
- for (InputElement childInputElement : inputElement.childElements) {\r
- for (String inputName : getInputNames(childInputElement)) {\r
- if (!inputs.contains(inputName)) {\r
- inputs.add(inputName);\r
- }\r
- }\r
- }\r
- }\r
- return inputs;\r
- }\r
-\r
- private void removeElement() {\r
- selectedElement.dispose();\r
- selectedElement = null;\r
- elementContainer.layout();\r
- elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,\r
- elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);\r
- container.layout();\r
- }\r
-\r
- private String getSelectionText() {\r
- InputStream inputStream = null;\r
- if (this.selection instanceof IStructuredSelection) {\r
- Object selection = ((IStructuredSelection) this.selection).getFirstElement();\r
- if (selection instanceof IFile) {\r
- IFile file = (IFile) selection;\r
- try {\r
- inputStream = file.getContents();\r
- } catch (CoreException e) {\r
- return ""; //$NON-NLS-1$\r
- }\r
- }\r
- }\r
- if (inputStream != null) {\r
- BufferedReader reader = null;\r
- try {\r
- reader = new BufferedReader(new InputStreamReader(inputStream));\r
- StringBuilder sb = new StringBuilder();\r
- String line = null;\r
- while ((line = reader.readLine()) != null) {\r
- sb.append(line + "\n"); //$NON-NLS-1$\r
- }\r
- parseXmlInput(sb.toString());\r
- reader.close();\r
- return sb.toString();\r
- } catch (IOException e) {\r
- return ""; //$NON-NLS-1$\r
- }\r
- }\r
- return ""; //$NON-NLS-1$\r
- }\r
-\r
- private void parseXmlInput(final String string) {\r
- try {\r
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\r
- DocumentBuilder db = dbf.newDocumentBuilder();\r
-\r
- // The following allows xml parsing without access to the dtd\r
- EntityResolver resolver = new EntityResolver() {\r
- @Override\r
- public InputSource resolveEntity(String publicId, String systemId) {\r
- String empty = ""; //$NON-NLS-1$\r
- ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());\r
- return new InputSource(bais);\r
- }\r
- };\r
- db.setEntityResolver(resolver);\r
-\r
- // The following catches xml parsing exceptions\r
- db.setErrorHandler(new ErrorHandler() {\r
- @Override\r
- public void error(SAXParseException saxparseexception) throws SAXException {\r
- }\r
-\r
- @Override\r
- public void warning(SAXParseException saxparseexception) throws SAXException {\r
- }\r
-\r
- @Override\r
- public void fatalError(SAXParseException saxparseexception) throws SAXException {\r
- if (string.trim().length() != 0) {\r
- errorText.setText(saxparseexception.getMessage());\r
- errorText.setBackground(COLOR_LIGHT_RED);\r
- errorText.setVisible(true);\r
- }\r
- throw saxparseexception;\r
- }\r
- });\r
-\r
- errorText.setVisible(false);\r
- Document doc = null;\r
- doc = db.parse(new ByteArrayInputStream(string.getBytes()));\r
- documentElement = doc.getDocumentElement();\r
- } catch (ParserConfigurationException e) {\r
- Activator.getDefault().logError("Error pasing XML input string: " + string, e); //$NON-NLS-1$\r
- documentElement = null;\r
- } catch (SAXException e) {\r
- documentElement = null;\r
- } catch (IOException e) {\r
- Activator.getDefault().logError("Error pasing XML input string: " + string, e); //$NON-NLS-1$\r
- documentElement = null;\r
- }\r
- }\r
-\r
- private void updatePreviews() {\r
- updatePreviews(false);\r
- }\r
-\r
- private void initValues() {\r
- timeStampValue = null;\r
- timeStampFormat = null;\r
- logEntriesCount = 0;\r
- logEntryFound = false;\r
- }\r
-\r
- private void updatePreviews(boolean updateAll) {\r
- if (inputText == null) {\r
- // early update during construction\r
- return;\r
- }\r
- inputText.setStyleRanges(new StyleRange[] {});\r
- if (selectedElement == null) {\r
- return;\r
- }\r
-\r
- initValues();\r
-\r
- selectedElement.updatePreview();\r
-\r
- if (timeStampValue != null && timeStampFormat != null) {\r
- try {\r
- SimpleDateFormat dateFormat = new SimpleDateFormat(timeStampFormat);\r
- Date date = dateFormat.parse(timeStampValue);\r
- dateFormat = new SimpleDateFormat(timeStampOutputFormatText.getText().trim());\r
- timeStampPreviewText.setText(dateFormat.format(date));\r
- } catch (ParseException e) {\r
- timeStampPreviewText.setText("*parse exception* [" + timeStampValue + "] <> [" + timeStampFormat + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- } catch (IllegalArgumentException e) {\r
- timeStampPreviewText.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$\r
- }\r
- } else {\r
- timeStampPreviewText.setText("*no matching time stamp*"); //$NON-NLS-1$\r
- }\r
- }\r
-\r
- private void openHelpShell(String url) {\r
- if (helpBrowser != null && !helpBrowser.isDisposed()) {\r
- helpBrowser.getShell().setActive();\r
- if (!helpBrowser.getUrl().equals(url)) {\r
- helpBrowser.setUrl(url);\r
- }\r
- return;\r
- }\r
- final Shell helpShell = new Shell(getShell(), SWT.SHELL_TRIM);\r
- helpShell.setLayout(new FillLayout());\r
- helpBrowser = new Browser(helpShell, SWT.NONE);\r
- helpBrowser.addTitleListener(new TitleListener() {\r
- @Override\r
- public void changed(TitleEvent event) {\r
- helpShell.setText(event.title);\r
- }\r
- });\r
- helpBrowser.setBounds(0, 0, 600, 400);\r
- helpShell.pack();\r
- helpShell.open();\r
- helpBrowser.setUrl(url);\r
- }\r
-\r
- private class UpdateListener implements ModifyListener, SelectionListener {\r
-\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- validate();\r
- updatePreviews();\r
- }\r
-\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {\r
- validate();\r
- updatePreviews();\r
- }\r
-\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- validate();\r
- updatePreviews();\r
- }\r
-\r
- }\r
-\r
- private class ElementNode {\r
- final InputElement inputElement;\r
- final Group group;\r
- List<Attribute> attributes = new ArrayList<Attribute>();\r
- List<ElementNode> childElements = new ArrayList<ElementNode>();\r
- Text elementNameText;\r
- Composite tagComposite;\r
- Combo tagCombo;\r
- Label tagLabel;\r
- Text tagText;\r
- Combo actionCombo;\r
- Label previewLabel;\r
- Text previewText;\r
- Button logEntryButton;\r
- Label fillerLabel;\r
- Composite addAttributeComposite;\r
- Button addAttributeButton;\r
- Label addAttributeLabel;\r
-\r
- public ElementNode(Composite parent, InputElement inputElement) {\r
- this.inputElement = inputElement;\r
-\r
- group = new Group(parent, SWT.NONE);\r
- GridLayout gl = new GridLayout(2, false);\r
- gl.marginHeight = 0;\r
- group.setLayout(gl);\r
- group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- group.setText(getName(inputElement));\r
-\r
- Label label = new Label(group, SWT.NULL);\r
- label.setText(Messages.CustomXmlParserInputWizardPage_elementName);\r
- label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
-\r
- elementNameText = new Text(group, SWT.BORDER | SWT.SINGLE);\r
- GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r
- gd.widthHint = 0;\r
- elementNameText.setLayoutData(gd);\r
- elementNameText.addModifyListener(new ModifyListener() {\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- ElementNode.this.inputElement.elementName = elementNameText.getText().trim();\r
- group.setText(getName(ElementNode.this.inputElement));\r
- }\r
- });\r
- elementNameText.setText(inputElement.elementName);\r
- elementNameText.addModifyListener(updateListener);\r
-\r
- if (inputElement.parentElement != null) {\r
- previewLabel = new Label(group, SWT.NULL);\r
- previewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
- previewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview);\r
-\r
- previewText = new Text(group, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);\r
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r
- gd.widthHint = 0;\r
- previewText.setLayoutData(gd);\r
- previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement);\r
- previewText.setBackground(COLOR_WIDGET_BACKGROUND);\r
-\r
- logEntryButton = new Button(group, SWT.CHECK);\r
- logEntryButton.setText(Messages.CustomXmlParserInputWizardPage_logEntry);\r
- logEntryButton.setSelection(inputElement.logEntry);\r
- logEntryButton.addSelectionListener(new SelectionListener() {\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {\r
- }\r
-\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- InputElement parent = ElementNode.this.inputElement.parentElement;\r
- while (parent != null) {\r
- parent.logEntry = false;\r
- parent = parent.parentElement;\r
- }\r
- }\r
- });\r
- logEntryButton.addSelectionListener(updateListener);\r
-\r
- tagComposite = new Composite(group, SWT.FILL);\r
- GridLayout tagLayout = new GridLayout(4, false);\r
- tagLayout.marginWidth = 0;\r
- tagLayout.marginHeight = 0;\r
- tagComposite.setLayout(tagLayout);\r
- tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
-\r
- tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);\r
- tagCombo.setItems(new String[] { CustomXmlTraceDefinition.TAG_IGNORE, CustomTraceDefinition.TAG_TIMESTAMP,\r
- CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.TAG_OTHER });\r
- tagCombo.setVisibleItemCount(tagCombo.getItemCount());\r
- tagCombo.addSelectionListener(new SelectionListener() {\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {\r
- }\r
-\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- tagText.removeModifyListener(updateListener);\r
- switch (tagCombo.getSelectionIndex()) {\r
- case 0: // Ignore\r
- tagLabel.setVisible(false);\r
- tagText.setVisible(false);\r
- actionCombo.setVisible(false);\r
- break;\r
- case 1: // Time Stamp\r
- tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);\r
- tagLabel.setVisible(true);\r
- tagText.setVisible(true);\r
- tagText.addModifyListener(updateListener);\r
- actionCombo.setVisible(true);\r
- break;\r
- case 2: // Message\r
- tagLabel.setVisible(false);\r
- tagText.setVisible(false);\r
- actionCombo.setVisible(true);\r
- break;\r
- case 3: // Other\r
- tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);\r
- tagLabel.setVisible(true);\r
- if (tagText.getText().trim().length() == 0) {\r
- tagText.setText(elementNameText.getText().trim());\r
- }\r
- tagText.setVisible(true);\r
- tagText.addModifyListener(updateListener);\r
- actionCombo.setVisible(true);\r
- break;\r
- default:\r
- break;\r
- }\r
- tagComposite.layout();\r
- validate();\r
- updatePreviews();\r
- }\r
- });\r
-\r
- tagLabel = new Label(tagComposite, SWT.NULL);\r
- tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
-\r
- tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE);\r
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r
- gd.widthHint = 0;\r
- tagText.setLayoutData(gd);\r
-\r
- actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);\r
- actionCombo.setItems(new String[] { Messages.CustomXmlParserInputWizardPage_set, Messages.CustomXmlParserInputWizardPage_append,\r
- Messages.CustomXmlParserInputWizardPage_appendWith });\r
- actionCombo.select(inputElement.inputAction);\r
- actionCombo.addSelectionListener(updateListener);\r
-\r
- if (inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) {\r
- tagCombo.select(0);\r
- tagLabel.setVisible(false);\r
- tagText.setVisible(false);\r
- actionCombo.setVisible(false);\r
- } else if (inputElement.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- tagCombo.select(1);\r
- tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);\r
- tagText.setText(inputElement.inputFormat);\r
- tagText.addModifyListener(updateListener);\r
- } else if (inputElement.inputName.equals(CustomTraceDefinition.TAG_MESSAGE)) {\r
- tagCombo.select(2);\r
- tagLabel.setVisible(false);\r
- tagText.setVisible(false);\r
- } else {\r
- tagCombo.select(3);\r
- tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);\r
- tagText.setText(inputElement.inputName);\r
- tagText.addModifyListener(updateListener);\r
- }\r
- }\r
-\r
- if (inputElement.attributes != null) {\r
- for (InputAttribute inputAttribute : inputElement.attributes) {\r
- Attribute attribute = new Attribute(group, this, inputAttribute, attributes.size() + 1);\r
- attributes.add(attribute);\r
- }\r
- }\r
-\r
- createAddButton();\r
- }\r
-\r
- private void updatePreview() {\r
- Element element = getPreviewElement(inputElement);\r
- if (inputElement.parentElement != null) { // no preview text for\r
- // document element\r
- previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement);\r
- if (element != null) {\r
- previewText.setText(CustomXmlTrace.parseElement(element, new StringBuffer()).toString());\r
- if (logEntryButton.getSelection()) {\r
- if (!logEntryFound) {\r
- logEntryFound = true;\r
- logEntriesCount++;\r
- } else {\r
- logEntryButton.setSelection(false); // remove nested\r
- // log entry\r
- }\r
- }\r
- if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) {\r
- String value = previewText.getText().trim();\r
- if (value.length() != 0) {\r
- if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_SET) {\r
- timeStampValue = value;\r
- timeStampFormat = tagText.getText().trim();\r
- } else if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND) {\r
- if (timeStampValue != null) {\r
- timeStampValue += value;\r
- timeStampFormat += tagText.getText().trim();\r
- } else {\r
- timeStampValue = value;\r
- timeStampFormat = tagText.getText().trim();\r
- }\r
- } else if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {\r
- if (timeStampValue != null) {\r
- timeStampValue += " | " + value; //$NON-NLS-1$\r
- timeStampFormat += " | " + tagText.getText().trim(); //$NON-NLS-1$\r
- } else {\r
- timeStampValue = value;\r
- timeStampFormat = tagText.getText().trim();\r
- }\r
- }\r
- }\r
- }\r
- }\r
- }\r
- for (Attribute attribute : attributes) {\r
- if (element != null) {\r
- String value = element.getAttribute(attribute.attributeNameText.getText().trim());\r
- if (value.length() != 0) {\r
- attribute.previewText.setText(value);\r
- if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) {\r
- if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_SET) {\r
- timeStampValue = value;\r
- timeStampFormat = attribute.tagText.getText().trim();\r
- } else if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND) {\r
- if (timeStampValue != null) {\r
- timeStampValue += value;\r
- timeStampFormat += attribute.tagText.getText().trim();\r
- } else {\r
- timeStampValue = value;\r
- timeStampFormat = attribute.tagText.getText().trim();\r
- }\r
- } else if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {\r
- if (timeStampValue != null) {\r
- timeStampValue += " | " + value; //$NON-NLS-1$\r
- timeStampFormat += " | " + attribute.tagText.getText().trim(); //$NON-NLS-1$\r
- } else {\r
- timeStampValue = value;\r
- timeStampFormat = attribute.tagText.getText().trim();\r
- }\r
- }\r
- }\r
- } else {\r
- attribute.previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingAttribute);\r
- }\r
- } else {\r
- attribute.previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement);\r
- }\r
- }\r
- for (ElementNode child : childElements) {\r
- child.updatePreview();\r
- }\r
- if (logEntryButton != null && logEntryButton.getSelection()) {\r
- logEntryFound = false;\r
- }\r
- }\r
-\r
- private void createAddButton() {\r
- fillerLabel = new Label(group, SWT.NONE);\r
-\r
- addAttributeComposite = new Composite(group, SWT.NONE);\r
- addAttributeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- GridLayout addAttributeLayout = new GridLayout(2, false);\r
- addAttributeLayout.marginHeight = 0;\r
- addAttributeLayout.marginWidth = 0;\r
- addAttributeComposite.setLayout(addAttributeLayout);\r
-\r
- addAttributeButton = new Button(addAttributeComposite, SWT.PUSH);\r
- addAttributeButton.setImage(addImage);\r
- addAttributeButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addAttribute);\r
- addAttributeButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- removeAddButton();\r
- String attributeName = getAttributeNameSuggestion(inputElement);\r
- InputAttribute inputAttribute = new InputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$\r
- attributes.add(new Attribute(group, ElementNode.this, inputAttribute, attributes.size() + 1));\r
- createAddButton();\r
- elementContainer.layout();\r
- elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,\r
- elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);\r
- group.getParent().layout();\r
- validate();\r
- updatePreviews();\r
- }\r
- });\r
-\r
- addAttributeLabel = new Label(addAttributeComposite, SWT.NULL);\r
- addAttributeLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- addAttributeLabel.setText(Messages.CustomXmlParserInputWizardPage_newAttibute);\r
- }\r
-\r
- private void removeAddButton() {\r
- fillerLabel.dispose();\r
- addAttributeComposite.dispose();\r
- }\r
-\r
- private void removeAttribute(int attributeNumber) {\r
- if (--attributeNumber < attributes.size()) {\r
- attributes.remove(attributeNumber).dispose();\r
- for (int i = attributeNumber; i < attributes.size(); i++) {\r
- attributes.get(i).setAttributeNumber(i + 1);\r
- }\r
- elementContainer.layout();\r
- elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,\r
- elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);\r
- group.getParent().layout();\r
- }\r
- }\r
-\r
- private void dispose() {\r
- group.dispose();\r
- }\r
-\r
- private void extractInputs() {\r
- inputElement.elementName = elementNameText.getText().trim();\r
- if (inputElement.parentElement != null) {\r
- inputElement.logEntry = logEntryButton.getSelection();\r
- if (tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {\r
- inputElement.inputName = tagText.getText().trim();\r
- } else {\r
- inputElement.inputName = tagCombo.getText();\r
- if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- inputElement.inputFormat = tagText.getText().trim();\r
- }\r
- }\r
- inputElement.inputAction = actionCombo.getSelectionIndex();\r
- }\r
- inputElement.attributes = new ArrayList<InputAttribute>(attributes.size());\r
- for (int i = 0; i < attributes.size(); i++) {\r
- Attribute attribute = attributes.get(i);\r
- InputAttribute inputAttribute = new InputAttribute();\r
- inputAttribute.attributeName = attribute.attributeNameText.getText().trim();\r
- if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {\r
- inputAttribute.inputName = attribute.tagText.getText().trim();\r
- } else {\r
- inputAttribute.inputName = attribute.tagCombo.getText();\r
- if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- inputAttribute.inputFormat = attribute.tagText.getText().trim();\r
- }\r
- }\r
- inputAttribute.inputAction = attribute.actionCombo.getSelectionIndex();\r
- inputElement.addAttribute(inputAttribute);\r
- }\r
- }\r
- }\r
-\r
- private class Attribute {\r
- ElementNode element;\r
- int attributeNumber;\r
-\r
- // children of parent (must be disposed)\r
- Composite labelComposite;\r
- Composite attributeComposite;\r
- Label filler;\r
- Composite tagComposite;\r
-\r
- // children of labelComposite\r
- Label attributeLabel;\r
-\r
- // children of attributeComposite\r
- Text attributeNameText;\r
- Text previewText;\r
-\r
- // children of tagComposite\r
- Combo tagCombo;\r
- Label tagLabel;\r
- Text tagText;\r
- Combo actionCombo;\r
-\r
- public Attribute(Composite parent, ElementNode element, InputAttribute inputAttribute, int attributeNumber) {\r
- this.element = element;\r
- this.attributeNumber = attributeNumber;\r
-\r
- labelComposite = new Composite(parent, SWT.FILL);\r
- GridLayout labelLayout = new GridLayout(2, false);\r
- labelLayout.marginWidth = 0;\r
- labelLayout.marginHeight = 0;\r
- labelComposite.setLayout(labelLayout);\r
- labelComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
-\r
- Button deleteButton = new Button(labelComposite, SWT.PUSH);\r
- deleteButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
- deleteButton.setImage(deleteImage);\r
- deleteButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_removeAttribute);\r
- deleteButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- Attribute.this.element.removeAttribute(Attribute.this.attributeNumber);\r
- validate();\r
- updatePreviews();\r
- }\r
- });\r
-\r
- attributeLabel = new Label(labelComposite, SWT.NULL);\r
- attributeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
- attributeLabel.setText(Messages.CustomXmlParserInputWizardPage_attibute);\r
-\r
- attributeComposite = new Composite(parent, SWT.FILL);\r
- GridLayout attributeLayout = new GridLayout(4, false);\r
- attributeLayout.marginWidth = 0;\r
- attributeLayout.marginHeight = 0;\r
- attributeComposite.setLayout(attributeLayout);\r
- attributeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
-\r
- Label nameLabel = new Label(attributeComposite, SWT.NONE);\r
- nameLabel.setText(Messages.CustomXmlParserInputWizardPage_name);\r
-\r
- attributeNameText = new Text(attributeComposite, SWT.BORDER | SWT.SINGLE);\r
- attributeNameText.setLayoutData(new GridData(120, SWT.DEFAULT));\r
- attributeNameText.setText(inputAttribute.attributeName);\r
- attributeNameText.addModifyListener(updateListener);\r
-\r
- Label previewLabel = new Label(attributeComposite, SWT.NONE);\r
- previewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview);\r
-\r
- previewText = new Text(attributeComposite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);\r
- GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r
- gd.widthHint = 0;\r
- previewText.setLayoutData(gd);\r
- previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatch);\r
- previewText.setBackground(COLOR_WIDGET_BACKGROUND);\r
-\r
- filler = new Label(parent, SWT.NULL);\r
-\r
- tagComposite = new Composite(parent, SWT.FILL);\r
- GridLayout tagLayout = new GridLayout(4, false);\r
- tagLayout.marginWidth = 0;\r
- tagLayout.marginHeight = 0;\r
- tagComposite.setLayout(tagLayout);\r
- tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
-\r
- tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);\r
- tagCombo.setItems(new String[] { CustomTraceDefinition.TAG_TIMESTAMP, CustomTraceDefinition.TAG_MESSAGE,\r
- CustomTraceDefinition.TAG_OTHER });\r
- tagCombo.select(2); // Other\r
- tagCombo.addSelectionListener(new SelectionListener() {\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {\r
- }\r
-\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- tagText.removeModifyListener(updateListener);\r
- switch (tagCombo.getSelectionIndex()) {\r
- case 0: // Time Stamp\r
- tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);\r
- tagLabel.setVisible(true);\r
- tagText.setVisible(true);\r
- tagText.addModifyListener(updateListener);\r
- break;\r
- case 1: // Message\r
- tagLabel.setVisible(false);\r
- tagText.setVisible(false);\r
- break;\r
- case 2: // Other\r
- tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);\r
- tagLabel.setVisible(true);\r
- if (tagText.getText().trim().length() == 0) {\r
- tagText.setText(attributeNameText.getText().trim());\r
- }\r
- tagText.setVisible(true);\r
- tagText.addModifyListener(updateListener);\r
- break;\r
- default:\r
- break;\r
- }\r
- tagComposite.layout();\r
- validate();\r
- updatePreviews();\r
- }\r
- });\r
-\r
- tagLabel = new Label(tagComposite, SWT.NULL);\r
- tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
-\r
- tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE);\r
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r
- gd.widthHint = 0;\r
- tagText.setLayoutData(gd);\r
- tagText.setText(attributeNameText.getText());\r
-\r
- actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);\r
- actionCombo.setItems(new String[] { Messages.CustomXmlParserInputWizardPage_set, Messages.CustomXmlParserInputWizardPage_append,\r
- Messages.CustomXmlParserInputWizardPage_appendWith });\r
- actionCombo.select(inputAttribute.inputAction);\r
- actionCombo.addSelectionListener(updateListener);\r
-\r
- if (inputAttribute.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- tagCombo.select(0);\r
- tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);\r
- tagText.setText(inputAttribute.inputFormat);\r
- tagText.addModifyListener(updateListener);\r
- } else if (inputAttribute.inputName.equals(CustomTraceDefinition.TAG_MESSAGE)) {\r
- tagCombo.select(1);\r
- tagLabel.setVisible(false);\r
- tagText.setVisible(false);\r
- } else {\r
- tagCombo.select(2);\r
- tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);\r
- tagText.setText(inputAttribute.inputName);\r
- tagText.addModifyListener(updateListener);\r
- }\r
- }\r
-\r
- private void dispose() {\r
- labelComposite.dispose();\r
- attributeComposite.dispose();\r
- filler.dispose();\r
- tagComposite.dispose();\r
- }\r
-\r
- private void setAttributeNumber(int attributeNumber) {\r
- this.attributeNumber = attributeNumber;\r
- labelComposite.layout();\r
- }\r
- }\r
-\r
- private Element getPreviewElement(InputElement inputElement) {\r
- Element element = documentElement;\r
- if (element != null) {\r
- if (!documentElement.getNodeName().equals(definition.rootInputElement.elementName)) {\r
- return null;\r
- }\r
- ArrayList<String> elementNames = new ArrayList<String>();\r
- while (inputElement != null) {\r
- elementNames.add(inputElement.elementName);\r
- inputElement = inputElement.parentElement;\r
- }\r
- for (int i = elementNames.size() - 1; --i >= 0;) {\r
- NodeList childList = element.getChildNodes();\r
- element = null;\r
- for (int j = 0; j < childList.getLength(); j++) {\r
- Node child = childList.item(j);\r
- if (child instanceof Element && child.getNodeName().equals(elementNames.get(i))) {\r
- element = (Element) child;\r
- break;\r
- }\r
- }\r
- if (element == null) {\r
- break;\r
- }\r
- }\r
- if (element != null) {\r
- return element;\r
- }\r
- }\r
- return null;\r
- }\r
-\r
- private String getChildNameSuggestion(InputElement inputElement) {\r
- if (inputElement == null) {\r
- if (documentElement != null) {\r
- return documentElement.getNodeName();\r
- }\r
- } else {\r
- Element element = getPreviewElement(inputElement);\r
- if (element != null) {\r
- NodeList childNodes = element.getChildNodes();\r
- for (int i = 0; i < childNodes.getLength(); i++) {\r
- Node node = childNodes.item(i);\r
- if (node instanceof Element) {\r
- boolean unused = true;\r
- if (inputElement.childElements != null) {\r
- for (InputElement child : inputElement.childElements) {\r
- if (child.elementName.equals(node.getNodeName())) {\r
- unused = false;\r
- break;\r
- }\r
- }\r
- }\r
- if (unused) {\r
- return node.getNodeName();\r
- }\r
- }\r
- }\r
- }\r
- }\r
- return ""; //$NON-NLS-1$\r
- }\r
-\r
- private String getAttributeNameSuggestion(InputElement inputElement) {\r
- Element element = getPreviewElement(inputElement);\r
- if (element != null) {\r
- NamedNodeMap attributeMap = element.getAttributes();\r
- for (int i = 0; i < attributeMap.getLength(); i++) {\r
- Node node = attributeMap.item(i);\r
- boolean unused = true;\r
- if (inputElement.attributes != null) {\r
- for (InputAttribute attribute : inputElement.attributes) {\r
- if (attribute.attributeName.equals(node.getNodeName())) {\r
- unused = false;\r
- break;\r
- }\r
- }\r
- }\r
- if (unused) {\r
- return node.getNodeName();\r
- }\r
- }\r
- }\r
- return ""; //$NON-NLS-1$\r
- }\r
-\r
- private void validate() {\r
- definition.definitionName = logtypeText.getText().trim();\r
- definition.timeStampOutputFormat = timeStampOutputFormatText.getText().trim();\r
-\r
- if (selectedElement != null) {\r
- selectedElement.extractInputs();\r
- treeViewer.refresh();\r
- }\r
-\r
- StringBuffer errors = new StringBuffer();\r
-\r
- if (definition.definitionName.length() == 0) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_emptyLogTypeError);\r
- logtypeText.setBackground(COLOR_LIGHT_RED);\r
- } else {\r
- logtypeText.setBackground(COLOR_TEXT_BACKGROUND);\r
- for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {\r
- if (definition.definitionName.equals(def.definitionName)) {\r
- if (editDefinitionName == null || !editDefinitionName.equals(definition.definitionName)) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_duplicatelogTypeError);\r
- logtypeText.setBackground(COLOR_LIGHT_RED);\r
- break;\r
- }\r
- }\r
- }\r
- }\r
-\r
- if (definition.rootInputElement == null) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_noDocumentError);\r
- }\r
-\r
- if (definition.rootInputElement != null) {\r
- logEntryFound = false;\r
- timeStampFound = false;\r
-\r
- errors.append(validateElement(definition.rootInputElement));\r
-\r
- if ((definition.rootInputElement.attributes != null && definition.rootInputElement.attributes.size() != 0)\r
- || (definition.rootInputElement.childElements != null && definition.rootInputElement.childElements.size() != 0)\r
- || errors.length() == 0) {\r
- if (!logEntryFound) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_missingLogEntryError);\r
- }\r
-\r
- if (timeStampFound) {\r
- if (timeStampOutputFormatText.getText().trim().length() == 0) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_missingTimestampFmtError);\r
- timeStampOutputFormatText.setBackground(COLOR_LIGHT_RED);\r
- } else {\r
- try {\r
- new SimpleDateFormat(timeStampOutputFormatText.getText().trim());\r
- timeStampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);\r
- } catch (IllegalArgumentException e) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_invalidTimestampFmtError);\r
- timeStampOutputFormatText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- }\r
- } else {\r
- timeStampPreviewText.setText(Messages.CustomXmlParserInputWizardPage_notimestamporAttributeError);\r
- }\r
- }\r
- } else {\r
- timeStampPreviewText.setText(Messages.CustomXmlParserInputWizardPage_notimestamporAttributeError);\r
- }\r
-\r
- if (errors.length() == 0) {\r
- setDescription(defaultDescription);\r
- setPageComplete(true);\r
- } else {\r
- setDescription(errors.toString());\r
- setPageComplete(false);\r
- }\r
- }\r
-\r
- public StringBuffer validateElement(InputElement inputElement) {\r
- StringBuffer errors = new StringBuffer();\r
- ElementNode elementNode = null;\r
- if (selectedElement != null && selectedElement.inputElement.equals(inputElement)) {\r
- elementNode = selectedElement;\r
- }\r
- if (inputElement == definition.rootInputElement) {\r
- if (inputElement.elementName.length() == 0) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_missingDocumentElementError);\r
- if (elementNode != null) {\r
- elementNode.elementNameText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- } else {\r
- if (elementNode != null) {\r
- elementNode.elementNameText.setBackground(COLOR_TEXT_BACKGROUND);\r
- }\r
- }\r
- }\r
- if (inputElement != definition.rootInputElement) {\r
- if (inputElement.logEntry) {\r
- logEntryFound = true;\r
- }\r
- if (inputElement.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- timeStampFound = true;\r
- if (inputElement.inputFormat.length() == 0) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_timestampFormatPrompt\r
- + " (" + Messages.CustomXmlParserInputWizardPage_timestampElementPrompt + " " + getName(inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- if (elementNode != null) {\r
- elementNode.tagText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- } else {\r
- try {\r
- new SimpleDateFormat(inputElement.inputFormat);\r
- if (elementNode != null) {\r
- elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND);\r
- }\r
- } catch (IllegalArgumentException e) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_invalidTimestampFmtError\r
- + " (" + Messages.CustomXmlParserInputWizardPage_timestampElementPrompt + " " + getName(inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- if (elementNode != null) {\r
- elementNode.tagText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- }\r
- }\r
- } else if (inputElement.inputName.length() == 0) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_missingInputElementNameError);\r
- if (elementNode != null) {\r
- elementNode.tagText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- } else {\r
- if (elementNode != null) {\r
- elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND);\r
- }\r
- }\r
- }\r
- if (inputElement.attributes != null) {\r
- if (elementNode != null) {\r
- for (Attribute attribute : elementNode.attributes) {\r
- attribute.attributeNameText.setBackground(COLOR_TEXT_BACKGROUND);\r
- }\r
- }\r
- for (int i = 0; i < inputElement.attributes.size(); i++) {\r
- InputAttribute attribute = inputElement.attributes.get(i);\r
- boolean duplicate = false;\r
- for (int j = i + 1; j < inputElement.attributes.size(); j++) {\r
- InputAttribute otherAttribute = inputElement.attributes.get(j);\r
- if (otherAttribute.attributeName.equals(attribute.attributeName)) {\r
- duplicate = true;\r
- if (elementNode != null) {\r
- elementNode.attributes.get(j).attributeNameText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- }\r
- }\r
- if (attribute.attributeName.length() == 0) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_missingAttribute\r
- + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(inputElement) + ": ?). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- if (elementNode != null) {\r
- elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- } else if (duplicate) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_duplicateAttributeError\r
- + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- if (elementNode != null) {\r
- elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- }\r
- if (attribute.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {\r
- timeStampFound = true;\r
- if (attribute.inputFormat.length() == 0) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_missingTimestampInFmtError\r
- + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- if (elementNode != null) {\r
- elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- } else {\r
- try {\r
- new SimpleDateFormat(attribute.inputFormat);\r
- if (elementNode != null) {\r
- elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND);\r
- }\r
- } catch (IllegalArgumentException e) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_invalidTimestampInFmtError\r
- + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- if (elementNode != null) {\r
- elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- }\r
- }\r
- } else if (attribute.inputName.length() == 0) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_missingDataGroupNameError\r
- + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- if (elementNode != null) {\r
- elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- } else {\r
- if (elementNode != null) {\r
- elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND);\r
- }\r
- }\r
- }\r
- }\r
- if (inputElement.childElements != null) {\r
- for (InputElement child : inputElement.childElements) {\r
- ElementNode childElementNode = null;\r
- if (selectedElement != null && selectedElement.inputElement.equals(child)) {\r
- childElementNode = selectedElement;\r
- }\r
- if (childElementNode != null) {\r
- childElementNode.elementNameText.setBackground(COLOR_TEXT_BACKGROUND);\r
- }\r
- }\r
- for (int i = 0; i < inputElement.childElements.size(); i++) {\r
- InputElement child = inputElement.childElements.get(i);\r
- ElementNode childElementNode = null;\r
- if (selectedElement != null && selectedElement.inputElement.equals(child)) {\r
- childElementNode = selectedElement;\r
- }\r
- if (child.elementName.length() == 0) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_missingElementNameError\r
- + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(child) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- if (childElementNode != null) {\r
- childElementNode.elementNameText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- } else {\r
- boolean duplicate = false;\r
- for (int j = i + 1; j < inputElement.childElements.size(); j++) {\r
- InputElement otherChild = inputElement.childElements.get(j);\r
- if (otherChild.elementName.equals(child.elementName)) {\r
- duplicate = true;\r
- ElementNode otherChildElementNode = null;\r
- if (selectedElement != null && selectedElement.inputElement.equals(otherChild)) {\r
- otherChildElementNode = selectedElement;\r
- }\r
- if (otherChildElementNode != null) {\r
- otherChildElementNode.elementNameText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- }\r
- }\r
- if (duplicate) {\r
- errors.append(Messages.CustomXmlParserInputWizardPage_duplicateElementNameError\r
- + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(child) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- if (childElementNode != null) {\r
- childElementNode.elementNameText.setBackground(COLOR_LIGHT_RED);\r
- }\r
- }\r
- }\r
-\r
- errors.append(validateElement(child));\r
- }\r
- }\r
- return errors;\r
- }\r
-\r
- public CustomXmlTraceDefinition getDefinition() {\r
- return definition;\r
- }\r
-\r
- public char[] getInputText() {\r
- return inputText.getText().toCharArray();\r
- }\r
-}\r
+package org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputAttribute;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputElement;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.browser.TitleEvent;
+import org.eclipse.swt.browser.TitleListener;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
+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.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.Image;
+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.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+public class CustomXmlParserInputWizardPage extends WizardPage {
+
+ private static final String DEFAULT_TIMESTAMP_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$
+ private static final String SIMPLE_DATE_FORMAT_URL = "http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html#skip-navbar_top"; //$NON-NLS-1$
+ private static final Image elementImage = Activator.getDefault().getImageFromPath("/icons/elcl16/element_icon.gif"); //$NON-NLS-1$
+ private static final Image addImage = Activator.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
+ private static final Image addNextImage = Activator.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$
+ private static final Image addChildImage = Activator.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$
+ private static final Image addManyImage = Activator.getDefault().getImageFromPath("/icons/elcl16/addmany_button.gif"); //$NON-NLS-1$
+ private static final Image deleteImage = Activator.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
+ private static final Image moveUpImage = Activator.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$
+ private static final Image moveDownImage = Activator.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$
+ private static final Image helpImage = Activator.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$
+ private static final Color COLOR_LIGHT_RED = new Color(Display.getDefault(), 255, 192, 192);
+ private static final Color COLOR_TEXT_BACKGROUND = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
+ private static final Color COLOR_WIDGET_BACKGROUND = Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
+
+ private final ISelection selection;
+ private CustomXmlTraceDefinition definition;
+ private String editDefinitionName;
+ private String defaultDescription;
+ private ElementNode selectedElement;
+ private Composite container;
+ private Text logtypeText;
+ private Text timeStampOutputFormatText;
+ private Text timeStampPreviewText;
+ private Button removeButton;
+ private Button addChildButton;
+ private Button addNextButton;
+ private Button moveUpButton;
+ private Button moveDownButton;
+ private Button feelingLuckyButton;
+ private ScrolledComposite treeScrolledComposite;
+ private ScrolledComposite elementScrolledComposite;
+ private TreeViewer treeViewer;
+ private Composite treeContainer;
+ private Composite elementContainer;
+ private Text errorText;
+ private StyledText inputText;
+ private Font fixedFont;
+ private UpdateListener updateListener;
+ private Browser helpBrowser;
+ private Element documentElement;
+
+ // variables used recursively through element traversal
+ private String timeStampValue;
+ private String timeStampFormat;
+ private boolean timeStampFound;
+ private int logEntriesCount;
+ private boolean logEntryFound;
+
+ protected CustomXmlParserInputWizardPage(ISelection selection, CustomXmlTraceDefinition definition) {
+ super("CustomXmlParserWizardPage"); //$NON-NLS-1$
+ if (definition == null) {
+ setTitle(Messages.CustomXmlParserInputWizardPage_titleNew);
+ defaultDescription = Messages.CustomXmlParserInputWizardPage_descriptionNew;
+ } else {
+ setTitle(Messages.CustomXmlParserInputWizardPage_titleEdit);
+ defaultDescription = Messages.CustomXmlParserInputWizardPage_descriptionEdit;
+ }
+ setDescription(defaultDescription);
+ this.selection = selection;
+ this.definition = definition;
+ if (definition != null) {
+ this.editDefinitionName = definition.definitionName;
+ }
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ container = new Composite(parent, SWT.NULL);
+ container.setLayout(new GridLayout());
+
+ updateListener = new UpdateListener();
+
+ Composite headerComposite = new Composite(container, SWT.FILL);
+ GridLayout headerLayout = new GridLayout(5, false);
+ headerLayout.marginHeight = 0;
+ headerLayout.marginWidth = 0;
+ headerComposite.setLayout(headerLayout);
+ headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ Label logtypeLabel = new Label(headerComposite, SWT.NULL);
+ logtypeLabel.setText(Messages.CustomXmlParserInputWizardPage_logType);
+
+ logtypeText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);
+ logtypeText.setLayoutData(new GridData(120, SWT.DEFAULT));
+
+ Label timeStampFormatLabel = new Label(headerComposite, SWT.NULL);
+ timeStampFormatLabel.setText(Messages.CustomXmlParserInputWizardPage_timestampFormat);
+
+ timeStampOutputFormatText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);
+ timeStampOutputFormatText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ timeStampOutputFormatText.setText(DEFAULT_TIMESTAMP_FORMAT);
+
+ Button dateFormatHelpButton = new Button(headerComposite, SWT.PUSH);
+ dateFormatHelpButton.setImage(helpImage);
+ dateFormatHelpButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_dateFormatHelp);
+ dateFormatHelpButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ openHelpShell(SIMPLE_DATE_FORMAT_URL);
+ }
+ });
+
+ Label timeStampPreviewLabel = new Label(headerComposite, SWT.NULL);
+ timeStampPreviewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 3, 1));
+ timeStampPreviewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview);
+
+ timeStampPreviewText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
+ timeStampPreviewText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+ timeStampPreviewText.setText("*no time stamp element or attribute*"); //$NON-NLS-1$
+
+ createButtonBar();
+
+ SashForm vSash = new SashForm(container, SWT.VERTICAL);
+ vSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ vSash.setBackground(vSash.getDisplay().getSystemColor(SWT.COLOR_GRAY));
+
+ SashForm hSash = new SashForm(vSash, SWT.HORIZONTAL);
+ hSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ treeScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL | SWT.H_SCROLL);
+ treeScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ treeContainer = new Composite(treeScrolledComposite, SWT.NONE);
+ treeContainer.setLayout(new FillLayout());
+ treeScrolledComposite.setContent(treeContainer);
+ treeScrolledComposite.setExpandHorizontal(true);
+ treeScrolledComposite.setExpandVertical(true);
+
+ treeViewer = new TreeViewer(treeContainer, SWT.SINGLE | SWT.BORDER);
+ treeViewer.setContentProvider(new InputElementTreeNodeContentProvider());
+ treeViewer.setLabelProvider(new InputElementTreeLabelProvider());
+ treeViewer.addSelectionChangedListener(new InputElementTreeSelectionChangedListener());
+ treeContainer.layout();
+
+ treeScrolledComposite
+ .setMinSize(treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
+
+ elementScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL);
+ elementScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ elementContainer = new Composite(elementScrolledComposite, SWT.NONE);
+ GridLayout gl = new GridLayout();
+ gl.marginHeight = 1;
+ gl.marginWidth = 0;
+ elementContainer.setLayout(gl);
+ elementScrolledComposite.setContent(elementContainer);
+ elementScrolledComposite.setExpandHorizontal(true);
+ elementScrolledComposite.setExpandVertical(true);
+
+ if (definition == null) {
+ definition = new CustomXmlTraceDefinition();
+ }
+ loadDefinition(definition);
+ treeViewer.expandAll();
+ elementContainer.layout();
+
+ logtypeText.addModifyListener(updateListener);
+ timeStampOutputFormatText.addModifyListener(updateListener);
+
+ elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,
+ elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);
+
+ hSash.setWeights(new int[] { 1, 2 });
+
+ if (definition.rootInputElement == null) {
+ removeButton.setEnabled(false);
+ addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addDocumentElement);
+ addNextButton.setEnabled(false);
+ moveUpButton.setEnabled(false);
+ moveDownButton.setEnabled(false);
+ } else { // root is selected
+ addNextButton.setEnabled(false);
+ }
+
+ Composite sashBottom = new Composite(vSash, SWT.NONE);
+ GridLayout sashBottomLayout = new GridLayout(2, false);
+ sashBottomLayout.marginHeight = 0;
+ sashBottomLayout.marginWidth = 0;
+ sashBottom.setLayout(sashBottomLayout);
+
+ Label previewLabel = new Label(sashBottom, SWT.NULL);
+ previewLabel.setText(Messages.CustomXmlParserInputWizardPage_previewInput);
+
+ errorText = new Text(sashBottom, SWT.SINGLE | SWT.READ_ONLY);
+ errorText.setBackground(COLOR_WIDGET_BACKGROUND);
+ errorText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ errorText.setVisible(false);
+
+ inputText = new StyledText(sashBottom, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
+ if (fixedFont == null) {
+ if (System.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
+ fixedFont = new Font(Display.getCurrent(), new FontData("Courier New", 10, SWT.NORMAL)); //$NON-NLS-1$
+ } else {
+ fixedFont = new Font(Display.getCurrent(), new FontData("Monospace", 10, SWT.NORMAL)); //$NON-NLS-1$
+ }
+ }
+ inputText.setFont(fixedFont);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
+ gd.heightHint = inputText.computeSize(SWT.DEFAULT, inputText.getLineHeight() * 4).y;
+ gd.widthHint = 800;
+ inputText.setLayoutData(gd);
+ inputText.setText(getSelectionText());
+ inputText.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ parseXmlInput(inputText.getText());
+ }
+ });
+ inputText.addModifyListener(updateListener);
+
+ vSash.setWeights(new int[] { hSash.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, sashBottom.computeSize(SWT.DEFAULT, SWT.DEFAULT).y });
+
+ setControl(container);
+ }
+
+ private void createButtonBar() {
+ Composite buttonBar = new Composite(container, SWT.NONE);
+ GridLayout buttonBarLayout = new GridLayout(6, false);
+ buttonBarLayout.marginHeight = 0;
+ buttonBarLayout.marginWidth = 0;
+ buttonBar.setLayout(buttonBarLayout);
+
+ removeButton = new Button(buttonBar, SWT.PUSH);
+ removeButton.setImage(deleteImage);
+ removeButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_removeElement);
+ removeButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (treeViewer.getSelection().isEmpty() || selectedElement == null) {
+ return;
+ }
+ removeElement();
+ InputElement inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
+ if (inputElement == definition.rootInputElement) {
+ definition.rootInputElement = null;
+ } else {
+ inputElement.parentElement.childElements.remove(inputElement);
+ }
+ treeViewer.refresh();
+ validate();
+ updatePreviews();
+ removeButton.setEnabled(false);
+ if (definition.rootInputElement == null) {
+ addChildButton.setEnabled(true);
+ addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addDocumentEleemnt);
+ } else {
+ addChildButton.setEnabled(false);
+ }
+ addNextButton.setEnabled(false);
+ moveUpButton.setEnabled(false);
+ moveDownButton.setEnabled(false);
+ }
+ });
+
+ addChildButton = new Button(buttonBar, SWT.PUSH);
+ addChildButton.setImage(addChildImage);
+ addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addChildElement);
+ addChildButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ InputElement inputElement = new InputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
+ if (definition.rootInputElement == null) {
+ definition.rootInputElement = inputElement;
+ inputElement.elementName = getChildNameSuggestion(null);
+ } else if (treeViewer.getSelection().isEmpty()) {
+ return;
+ } else {
+ InputElement parentInputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
+ parentInputElement.addChild(inputElement);
+ inputElement.elementName = getChildNameSuggestion(parentInputElement);
+ }
+ treeViewer.refresh();
+ treeViewer.setSelection(new StructuredSelection(inputElement), true);
+ }
+ });
+
+ addNextButton = new Button(buttonBar, SWT.PUSH);
+ addNextButton.setImage(addNextImage);
+ addNextButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addNextElement);
+ addNextButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ InputElement inputElement = new InputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
+ if (definition.rootInputElement == null) {
+ definition.rootInputElement = inputElement;
+ inputElement.elementName = getChildNameSuggestion(null);
+ } else if (treeViewer.getSelection().isEmpty()) {
+ return;
+ } else {
+ InputElement previousInputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
+ if (previousInputElement == definition.rootInputElement) {
+ return;
+ }
+ previousInputElement.addNext(inputElement);
+ inputElement.elementName = getChildNameSuggestion(inputElement.parentElement);
+ }
+ treeViewer.refresh();
+ treeViewer.setSelection(new StructuredSelection(inputElement), true);
+ }
+ });
+
+ feelingLuckyButton = new Button(buttonBar, SWT.PUSH);
+ feelingLuckyButton.setImage(addManyImage);
+ feelingLuckyButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_feelingLucky);
+ feelingLuckyButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ InputElement inputElement = null;
+ if (definition.rootInputElement == null) {
+ if (getChildNameSuggestion(null).length() != 0) {
+ inputElement = new InputElement(getChildNameSuggestion(null), false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$
+ definition.rootInputElement = inputElement;
+ feelingLucky(inputElement);
+ } else {
+ return;
+ }
+ } else if (treeViewer.getSelection().isEmpty()) {
+ return;
+ } else {
+ inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
+ feelingLucky(inputElement);
+ }
+ treeViewer.refresh();
+ treeViewer.setSelection(new StructuredSelection(inputElement), true);
+ treeViewer.expandToLevel(inputElement, AbstractTreeViewer.ALL_LEVELS);
+ }
+ });
+
+ moveUpButton = new Button(buttonBar, SWT.PUSH);
+ moveUpButton.setImage(moveUpImage);
+ moveUpButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_moveUp);
+ moveUpButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (treeViewer.getSelection().isEmpty()) {
+ return;
+ }
+ InputElement inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
+ if (inputElement == definition.rootInputElement) {
+ return;
+ }
+ inputElement.moveUp();
+ treeViewer.refresh();
+ validate();
+ updatePreviews();
+ }
+ });
+
+ moveDownButton = new Button(buttonBar, SWT.PUSH);
+ moveDownButton.setImage(moveDownImage);
+ moveDownButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_moveDown);
+ moveDownButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (treeViewer.getSelection().isEmpty()) {
+ return;
+ }
+ InputElement inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
+ if (inputElement == definition.rootInputElement) {
+ return;
+ }
+ inputElement.moveDown();
+ treeViewer.refresh();
+ validate();
+ updatePreviews();
+ }
+ });
+ }
+
+ private void feelingLucky(InputElement inputElement) {
+ while (true) {
+ String attributeName = getAttributeNameSuggestion(inputElement);
+ if (attributeName.length() == 0) {
+ break;
+ }
+ InputAttribute attribute = new InputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$
+ inputElement.addAttribute(attribute);
+ }
+ while (true) {
+ String childName = getChildNameSuggestion(inputElement);
+ if (childName.length() == 0) {
+ break;
+ }
+ InputElement childElement = new InputElement(childName, false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$
+ inputElement.addChild(childElement);
+ feelingLucky(childElement);
+ }
+ }
+
+ private static class InputElementTreeNodeContentProvider implements ITreeContentProvider {
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) inputElement;
+ if (def.rootInputElement != null) {
+ return new Object[] { def.rootInputElement };
+ }
+ return new Object[0];
+ }
+
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ InputElement inputElement = (InputElement) parentElement;
+ if (inputElement.childElements == null) {
+ return new InputElement[0];
+ }
+ return inputElement.childElements.toArray();
+ }
+
+ @Override
+ public boolean hasChildren(Object element) {
+ InputElement inputElement = (InputElement) element;
+ return (inputElement.childElements != null && inputElement.childElements.size() > 0);
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ @Override
+ public Object getParent(Object element) {
+ InputElement inputElement = (InputElement) element;
+ return inputElement.parentElement;
+ }
+ }
+
+ private static class InputElementTreeLabelProvider extends ColumnLabelProvider {
+
+ @Override
+ public Image getImage(Object element) {
+ return elementImage;
+ }
+
+ @Override
+ public String getText(Object element) {
+ InputElement inputElement = (InputElement) element;
+ return (inputElement.elementName.trim().length() == 0) ? "?" : inputElement.elementName; //$NON-NLS-1$
+ }
+ }
+
+ private class InputElementTreeSelectionChangedListener implements ISelectionChangedListener {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (selectedElement != null) {
+ selectedElement.dispose();
+ }
+ if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) {
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ InputElement inputElement = (InputElement) selection.getFirstElement();
+ selectedElement = new ElementNode(elementContainer, inputElement);
+ elementContainer.layout();
+ elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,
+ elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);
+ container.layout();
+ validate();
+ updatePreviews();
+ removeButton.setEnabled(true);
+ addChildButton.setEnabled(true);
+ addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addChildElement);
+ if (definition.rootInputElement == inputElement) {
+ addNextButton.setEnabled(false);
+ } else {
+ addNextButton.setEnabled(true);
+ }
+ moveUpButton.setEnabled(true);
+ moveDownButton.setEnabled(true);
+ } else {
+ removeButton.setEnabled(false);
+ if (definition.rootInputElement == null) {
+ addChildButton.setEnabled(true);
+ addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addDocumentElement);
+ } else {
+ addChildButton.setEnabled(false);
+ }
+ addNextButton.setEnabled(false);
+ moveUpButton.setEnabled(false);
+ moveDownButton.setEnabled(false);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.dialogs.DialogPage#dispose()
+ */
+ @Override
+ public void dispose() {
+ if (fixedFont != null) {
+ fixedFont.dispose();
+ fixedFont = null;
+ }
+ super.dispose();
+ }
+
+ private void loadDefinition(CustomXmlTraceDefinition def) {
+ logtypeText.setText(def.definitionName);
+ timeStampOutputFormatText.setText(def.timeStampOutputFormat);
+ treeViewer.setInput(def);
+
+ if (def.rootInputElement != null) {
+ treeViewer.setSelection(new StructuredSelection(def.rootInputElement));
+ }
+ }
+
+ private String getName(InputElement inputElement) {
+ String name = (inputElement.elementName.trim().length() == 0) ? "?" : inputElement.elementName.trim(); //$NON-NLS-1$
+ if (inputElement.parentElement == null) {
+ return name;
+ }
+ return getName(inputElement.parentElement) + " : " + name; //$NON-NLS-1$
+ }
+
+ private String getName(InputAttribute inputAttribute, InputElement inputElement) {
+ String name = (inputAttribute.attributeName.trim().length() == 0) ? "?" : inputAttribute.attributeName.trim(); //$NON-NLS-1$
+ return getName(inputElement) + " : " + name; //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
+ */
+ @Override
+ public void setVisible(boolean visible) {
+ if (visible) {
+ validate();
+ updatePreviews();
+ }
+ super.setVisible(visible);
+ }
+
+ public List<String> getInputNames() {
+ return getInputNames(definition.rootInputElement);
+ }
+
+ public List<String> getInputNames(InputElement inputElement) {
+ List<String> inputs = new ArrayList<String>();
+ if (inputElement.inputName != null && !inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) {
+ String inputName = inputElement.inputName;
+ if (!inputs.contains(inputName)) {
+ inputs.add(inputName);
+ }
+ }
+ if (inputElement.attributes != null) {
+ for (InputAttribute attribute : inputElement.attributes) {
+ String inputName = attribute.inputName;
+ if (!inputs.contains(inputName)) {
+ inputs.add(inputName);
+ }
+ }
+ }
+ if (inputElement.childElements != null) {
+ for (InputElement childInputElement : inputElement.childElements) {
+ for (String inputName : getInputNames(childInputElement)) {
+ if (!inputs.contains(inputName)) {
+ inputs.add(inputName);
+ }
+ }
+ }
+ }
+ return inputs;
+ }
+
+ private void removeElement() {
+ selectedElement.dispose();
+ selectedElement = null;
+ elementContainer.layout();
+ elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,
+ elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);
+ container.layout();
+ }
+
+ private String getSelectionText() {
+ InputStream inputStream = null;
+ if (this.selection instanceof IStructuredSelection) {
+ Object selection = ((IStructuredSelection) this.selection).getFirstElement();
+ if (selection instanceof IFile) {
+ IFile file = (IFile) selection;
+ try {
+ inputStream = file.getContents();
+ } catch (CoreException e) {
+ return ""; //$NON-NLS-1$
+ }
+ }
+ }
+ if (inputStream != null) {
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(inputStream));
+ StringBuilder sb = new StringBuilder();
+ String line = null;
+ while ((line = reader.readLine()) != null) {
+ sb.append(line + "\n"); //$NON-NLS-1$
+ }
+ parseXmlInput(sb.toString());
+ reader.close();
+ return sb.toString();
+ } catch (IOException e) {
+ return ""; //$NON-NLS-1$
+ }
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ private void parseXmlInput(final String string) {
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ // The following allows xml parsing without access to the dtd
+ EntityResolver resolver = new EntityResolver() {
+ @Override
+ public InputSource resolveEntity(String publicId, String systemId) {
+ String empty = ""; //$NON-NLS-1$
+ ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());
+ return new InputSource(bais);
+ }
+ };
+ db.setEntityResolver(resolver);
+
+ // The following catches xml parsing exceptions
+ db.setErrorHandler(new ErrorHandler() {
+ @Override
+ public void error(SAXParseException saxparseexception) throws SAXException {
+ }
+
+ @Override
+ public void warning(SAXParseException saxparseexception) throws SAXException {
+ }
+
+ @Override
+ public void fatalError(SAXParseException saxparseexception) throws SAXException {
+ if (string.trim().length() != 0) {
+ errorText.setText(saxparseexception.getMessage());
+ errorText.setBackground(COLOR_LIGHT_RED);
+ errorText.setVisible(true);
+ }
+ throw saxparseexception;
+ }
+ });
+
+ errorText.setVisible(false);
+ Document doc = null;
+ doc = db.parse(new ByteArrayInputStream(string.getBytes()));
+ documentElement = doc.getDocumentElement();
+ } catch (ParserConfigurationException e) {
+ Activator.getDefault().logError("Error pasing XML input string: " + string, e); //$NON-NLS-1$
+ documentElement = null;
+ } catch (SAXException e) {
+ documentElement = null;
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error pasing XML input string: " + string, e); //$NON-NLS-1$
+ documentElement = null;
+ }
+ }
+
+ private void updatePreviews() {
+ updatePreviews(false);
+ }
+
+ private void initValues() {
+ timeStampValue = null;
+ timeStampFormat = null;
+ logEntriesCount = 0;
+ logEntryFound = false;
+ }
+
+ private void updatePreviews(boolean updateAll) {
+ if (inputText == null) {
+ // early update during construction
+ return;
+ }
+ inputText.setStyleRanges(new StyleRange[] {});
+ if (selectedElement == null) {
+ return;
+ }
+
+ initValues();
+
+ selectedElement.updatePreview();
+
+ if (timeStampValue != null && timeStampFormat != null) {
+ try {
+ SimpleDateFormat dateFormat = new SimpleDateFormat(timeStampFormat);
+ Date date = dateFormat.parse(timeStampValue);
+ dateFormat = new SimpleDateFormat(timeStampOutputFormatText.getText().trim());
+ timeStampPreviewText.setText(dateFormat.format(date));
+ } catch (ParseException e) {
+ timeStampPreviewText.setText("*parse exception* [" + timeStampValue + "] <> [" + timeStampFormat + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ } catch (IllegalArgumentException e) {
+ timeStampPreviewText.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$
+ }
+ } else {
+ timeStampPreviewText.setText("*no matching time stamp*"); //$NON-NLS-1$
+ }
+ }
+
+ private void openHelpShell(String url) {
+ if (helpBrowser != null && !helpBrowser.isDisposed()) {
+ helpBrowser.getShell().setActive();
+ if (!helpBrowser.getUrl().equals(url)) {
+ helpBrowser.setUrl(url);
+ }
+ return;
+ }
+ final Shell helpShell = new Shell(getShell(), SWT.SHELL_TRIM);
+ helpShell.setLayout(new FillLayout());
+ helpBrowser = new Browser(helpShell, SWT.NONE);
+ helpBrowser.addTitleListener(new TitleListener() {
+ @Override
+ public void changed(TitleEvent event) {
+ helpShell.setText(event.title);
+ }
+ });
+ helpBrowser.setBounds(0, 0, 600, 400);
+ helpShell.pack();
+ helpShell.open();
+ helpBrowser.setUrl(url);
+ }
+
+ private class UpdateListener implements ModifyListener, SelectionListener {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ validate();
+ updatePreviews();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ validate();
+ updatePreviews();
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ validate();
+ updatePreviews();
+ }
+
+ }
+
+ private class ElementNode {
+ final InputElement inputElement;
+ final Group group;
+ List<Attribute> attributes = new ArrayList<Attribute>();
+ List<ElementNode> childElements = new ArrayList<ElementNode>();
+ Text elementNameText;
+ Composite tagComposite;
+ Combo tagCombo;
+ Label tagLabel;
+ Text tagText;
+ Combo actionCombo;
+ Label previewLabel;
+ Text previewText;
+ Button logEntryButton;
+ Label fillerLabel;
+ Composite addAttributeComposite;
+ Button addAttributeButton;
+ Label addAttributeLabel;
+
+ public ElementNode(Composite parent, InputElement inputElement) {
+ this.inputElement = inputElement;
+
+ group = new Group(parent, SWT.NONE);
+ GridLayout gl = new GridLayout(2, false);
+ gl.marginHeight = 0;
+ group.setLayout(gl);
+ group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ group.setText(getName(inputElement));
+
+ Label label = new Label(group, SWT.NULL);
+ label.setText(Messages.CustomXmlParserInputWizardPage_elementName);
+ label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+
+ elementNameText = new Text(group, SWT.BORDER | SWT.SINGLE);
+ GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ gd.widthHint = 0;
+ elementNameText.setLayoutData(gd);
+ elementNameText.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ ElementNode.this.inputElement.elementName = elementNameText.getText().trim();
+ group.setText(getName(ElementNode.this.inputElement));
+ }
+ });
+ elementNameText.setText(inputElement.elementName);
+ elementNameText.addModifyListener(updateListener);
+
+ if (inputElement.parentElement != null) {
+ previewLabel = new Label(group, SWT.NULL);
+ previewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ previewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview);
+
+ previewText = new Text(group, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ gd.widthHint = 0;
+ previewText.setLayoutData(gd);
+ previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement);
+ previewText.setBackground(COLOR_WIDGET_BACKGROUND);
+
+ logEntryButton = new Button(group, SWT.CHECK);
+ logEntryButton.setText(Messages.CustomXmlParserInputWizardPage_logEntry);
+ logEntryButton.setSelection(inputElement.logEntry);
+ logEntryButton.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ InputElement parent = ElementNode.this.inputElement.parentElement;
+ while (parent != null) {
+ parent.logEntry = false;
+ parent = parent.parentElement;
+ }
+ }
+ });
+ logEntryButton.addSelectionListener(updateListener);
+
+ tagComposite = new Composite(group, SWT.FILL);
+ GridLayout tagLayout = new GridLayout(4, false);
+ tagLayout.marginWidth = 0;
+ tagLayout.marginHeight = 0;
+ tagComposite.setLayout(tagLayout);
+ tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
+ tagCombo.setItems(new String[] { CustomXmlTraceDefinition.TAG_IGNORE, CustomTraceDefinition.TAG_TIMESTAMP,
+ CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.TAG_OTHER });
+ tagCombo.setVisibleItemCount(tagCombo.getItemCount());
+ tagCombo.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ tagText.removeModifyListener(updateListener);
+ switch (tagCombo.getSelectionIndex()) {
+ case 0: // Ignore
+ tagLabel.setVisible(false);
+ tagText.setVisible(false);
+ actionCombo.setVisible(false);
+ break;
+ case 1: // Time Stamp
+ tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);
+ tagLabel.setVisible(true);
+ tagText.setVisible(true);
+ tagText.addModifyListener(updateListener);
+ actionCombo.setVisible(true);
+ break;
+ case 2: // Message
+ tagLabel.setVisible(false);
+ tagText.setVisible(false);
+ actionCombo.setVisible(true);
+ break;
+ case 3: // Other
+ tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);
+ tagLabel.setVisible(true);
+ if (tagText.getText().trim().length() == 0) {
+ tagText.setText(elementNameText.getText().trim());
+ }
+ tagText.setVisible(true);
+ tagText.addModifyListener(updateListener);
+ actionCombo.setVisible(true);
+ break;
+ default:
+ break;
+ }
+ tagComposite.layout();
+ validate();
+ updatePreviews();
+ }
+ });
+
+ tagLabel = new Label(tagComposite, SWT.NULL);
+ tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+
+ tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE);
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ gd.widthHint = 0;
+ tagText.setLayoutData(gd);
+
+ actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
+ actionCombo.setItems(new String[] { Messages.CustomXmlParserInputWizardPage_set, Messages.CustomXmlParserInputWizardPage_append,
+ Messages.CustomXmlParserInputWizardPage_appendWith });
+ actionCombo.select(inputElement.inputAction);
+ actionCombo.addSelectionListener(updateListener);
+
+ if (inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) {
+ tagCombo.select(0);
+ tagLabel.setVisible(false);
+ tagText.setVisible(false);
+ actionCombo.setVisible(false);
+ } else if (inputElement.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ tagCombo.select(1);
+ tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);
+ tagText.setText(inputElement.inputFormat);
+ tagText.addModifyListener(updateListener);
+ } else if (inputElement.inputName.equals(CustomTraceDefinition.TAG_MESSAGE)) {
+ tagCombo.select(2);
+ tagLabel.setVisible(false);
+ tagText.setVisible(false);
+ } else {
+ tagCombo.select(3);
+ tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);
+ tagText.setText(inputElement.inputName);
+ tagText.addModifyListener(updateListener);
+ }
+ }
+
+ if (inputElement.attributes != null) {
+ for (InputAttribute inputAttribute : inputElement.attributes) {
+ Attribute attribute = new Attribute(group, this, inputAttribute, attributes.size() + 1);
+ attributes.add(attribute);
+ }
+ }
+
+ createAddButton();
+ }
+
+ private void updatePreview() {
+ Element element = getPreviewElement(inputElement);
+ if (inputElement.parentElement != null) { // no preview text for
+ // document element
+ previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement);
+ if (element != null) {
+ previewText.setText(CustomXmlTrace.parseElement(element, new StringBuffer()).toString());
+ if (logEntryButton.getSelection()) {
+ if (!logEntryFound) {
+ logEntryFound = true;
+ logEntriesCount++;
+ } else {
+ logEntryButton.setSelection(false); // remove nested
+ // log entry
+ }
+ }
+ if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) {
+ String value = previewText.getText().trim();
+ if (value.length() != 0) {
+ if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_SET) {
+ timeStampValue = value;
+ timeStampFormat = tagText.getText().trim();
+ } else if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND) {
+ if (timeStampValue != null) {
+ timeStampValue += value;
+ timeStampFormat += tagText.getText().trim();
+ } else {
+ timeStampValue = value;
+ timeStampFormat = tagText.getText().trim();
+ }
+ } else if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
+ if (timeStampValue != null) {
+ timeStampValue += " | " + value; //$NON-NLS-1$
+ timeStampFormat += " | " + tagText.getText().trim(); //$NON-NLS-1$
+ } else {
+ timeStampValue = value;
+ timeStampFormat = tagText.getText().trim();
+ }
+ }
+ }
+ }
+ }
+ }
+ for (Attribute attribute : attributes) {
+ if (element != null) {
+ String value = element.getAttribute(attribute.attributeNameText.getText().trim());
+ if (value.length() != 0) {
+ attribute.previewText.setText(value);
+ if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) {
+ if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_SET) {
+ timeStampValue = value;
+ timeStampFormat = attribute.tagText.getText().trim();
+ } else if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND) {
+ if (timeStampValue != null) {
+ timeStampValue += value;
+ timeStampFormat += attribute.tagText.getText().trim();
+ } else {
+ timeStampValue = value;
+ timeStampFormat = attribute.tagText.getText().trim();
+ }
+ } else if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
+ if (timeStampValue != null) {
+ timeStampValue += " | " + value; //$NON-NLS-1$
+ timeStampFormat += " | " + attribute.tagText.getText().trim(); //$NON-NLS-1$
+ } else {
+ timeStampValue = value;
+ timeStampFormat = attribute.tagText.getText().trim();
+ }
+ }
+ }
+ } else {
+ attribute.previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingAttribute);
+ }
+ } else {
+ attribute.previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement);
+ }
+ }
+ for (ElementNode child : childElements) {
+ child.updatePreview();
+ }
+ if (logEntryButton != null && logEntryButton.getSelection()) {
+ logEntryFound = false;
+ }
+ }
+
+ private void createAddButton() {
+ fillerLabel = new Label(group, SWT.NONE);
+
+ addAttributeComposite = new Composite(group, SWT.NONE);
+ addAttributeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ GridLayout addAttributeLayout = new GridLayout(2, false);
+ addAttributeLayout.marginHeight = 0;
+ addAttributeLayout.marginWidth = 0;
+ addAttributeComposite.setLayout(addAttributeLayout);
+
+ addAttributeButton = new Button(addAttributeComposite, SWT.PUSH);
+ addAttributeButton.setImage(addImage);
+ addAttributeButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addAttribute);
+ addAttributeButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ removeAddButton();
+ String attributeName = getAttributeNameSuggestion(inputElement);
+ InputAttribute inputAttribute = new InputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$
+ attributes.add(new Attribute(group, ElementNode.this, inputAttribute, attributes.size() + 1));
+ createAddButton();
+ elementContainer.layout();
+ elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,
+ elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);
+ group.getParent().layout();
+ validate();
+ updatePreviews();
+ }
+ });
+
+ addAttributeLabel = new Label(addAttributeComposite, SWT.NULL);
+ addAttributeLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ addAttributeLabel.setText(Messages.CustomXmlParserInputWizardPage_newAttibute);
+ }
+
+ private void removeAddButton() {
+ fillerLabel.dispose();
+ addAttributeComposite.dispose();
+ }
+
+ private void removeAttribute(int attributeNumber) {
+ if (--attributeNumber < attributes.size()) {
+ attributes.remove(attributeNumber).dispose();
+ for (int i = attributeNumber; i < attributes.size(); i++) {
+ attributes.get(i).setAttributeNumber(i + 1);
+ }
+ elementContainer.layout();
+ elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,
+ elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);
+ group.getParent().layout();
+ }
+ }
+
+ private void dispose() {
+ group.dispose();
+ }
+
+ private void extractInputs() {
+ inputElement.elementName = elementNameText.getText().trim();
+ if (inputElement.parentElement != null) {
+ inputElement.logEntry = logEntryButton.getSelection();
+ if (tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {
+ inputElement.inputName = tagText.getText().trim();
+ } else {
+ inputElement.inputName = tagCombo.getText();
+ if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ inputElement.inputFormat = tagText.getText().trim();
+ }
+ }
+ inputElement.inputAction = actionCombo.getSelectionIndex();
+ }
+ inputElement.attributes = new ArrayList<InputAttribute>(attributes.size());
+ for (int i = 0; i < attributes.size(); i++) {
+ Attribute attribute = attributes.get(i);
+ InputAttribute inputAttribute = new InputAttribute();
+ inputAttribute.attributeName = attribute.attributeNameText.getText().trim();
+ if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {
+ inputAttribute.inputName = attribute.tagText.getText().trim();
+ } else {
+ inputAttribute.inputName = attribute.tagCombo.getText();
+ if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ inputAttribute.inputFormat = attribute.tagText.getText().trim();
+ }
+ }
+ inputAttribute.inputAction = attribute.actionCombo.getSelectionIndex();
+ inputElement.addAttribute(inputAttribute);
+ }
+ }
+ }
+
+ private class Attribute {
+ ElementNode element;
+ int attributeNumber;
+
+ // children of parent (must be disposed)
+ Composite labelComposite;
+ Composite attributeComposite;
+ Label filler;
+ Composite tagComposite;
+
+ // children of labelComposite
+ Label attributeLabel;
+
+ // children of attributeComposite
+ Text attributeNameText;
+ Text previewText;
+
+ // children of tagComposite
+ Combo tagCombo;
+ Label tagLabel;
+ Text tagText;
+ Combo actionCombo;
+
+ public Attribute(Composite parent, ElementNode element, InputAttribute inputAttribute, int attributeNumber) {
+ this.element = element;
+ this.attributeNumber = attributeNumber;
+
+ labelComposite = new Composite(parent, SWT.FILL);
+ GridLayout labelLayout = new GridLayout(2, false);
+ labelLayout.marginWidth = 0;
+ labelLayout.marginHeight = 0;
+ labelComposite.setLayout(labelLayout);
+ labelComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+
+ Button deleteButton = new Button(labelComposite, SWT.PUSH);
+ deleteButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ deleteButton.setImage(deleteImage);
+ deleteButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_removeAttribute);
+ deleteButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Attribute.this.element.removeAttribute(Attribute.this.attributeNumber);
+ validate();
+ updatePreviews();
+ }
+ });
+
+ attributeLabel = new Label(labelComposite, SWT.NULL);
+ attributeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ attributeLabel.setText(Messages.CustomXmlParserInputWizardPage_attibute);
+
+ attributeComposite = new Composite(parent, SWT.FILL);
+ GridLayout attributeLayout = new GridLayout(4, false);
+ attributeLayout.marginWidth = 0;
+ attributeLayout.marginHeight = 0;
+ attributeComposite.setLayout(attributeLayout);
+ attributeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ Label nameLabel = new Label(attributeComposite, SWT.NONE);
+ nameLabel.setText(Messages.CustomXmlParserInputWizardPage_name);
+
+ attributeNameText = new Text(attributeComposite, SWT.BORDER | SWT.SINGLE);
+ attributeNameText.setLayoutData(new GridData(120, SWT.DEFAULT));
+ attributeNameText.setText(inputAttribute.attributeName);
+ attributeNameText.addModifyListener(updateListener);
+
+ Label previewLabel = new Label(attributeComposite, SWT.NONE);
+ previewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview);
+
+ previewText = new Text(attributeComposite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
+ GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ gd.widthHint = 0;
+ previewText.setLayoutData(gd);
+ previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatch);
+ previewText.setBackground(COLOR_WIDGET_BACKGROUND);
+
+ filler = new Label(parent, SWT.NULL);
+
+ tagComposite = new Composite(parent, SWT.FILL);
+ GridLayout tagLayout = new GridLayout(4, false);
+ tagLayout.marginWidth = 0;
+ tagLayout.marginHeight = 0;
+ tagComposite.setLayout(tagLayout);
+ tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
+ tagCombo.setItems(new String[] { CustomTraceDefinition.TAG_TIMESTAMP, CustomTraceDefinition.TAG_MESSAGE,
+ CustomTraceDefinition.TAG_OTHER });
+ tagCombo.select(2); // Other
+ tagCombo.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ tagText.removeModifyListener(updateListener);
+ switch (tagCombo.getSelectionIndex()) {
+ case 0: // Time Stamp
+ tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);
+ tagLabel.setVisible(true);
+ tagText.setVisible(true);
+ tagText.addModifyListener(updateListener);
+ break;
+ case 1: // Message
+ tagLabel.setVisible(false);
+ tagText.setVisible(false);
+ break;
+ case 2: // Other
+ tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);
+ tagLabel.setVisible(true);
+ if (tagText.getText().trim().length() == 0) {
+ tagText.setText(attributeNameText.getText().trim());
+ }
+ tagText.setVisible(true);
+ tagText.addModifyListener(updateListener);
+ break;
+ default:
+ break;
+ }
+ tagComposite.layout();
+ validate();
+ updatePreviews();
+ }
+ });
+
+ tagLabel = new Label(tagComposite, SWT.NULL);
+ tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+
+ tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE);
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ gd.widthHint = 0;
+ tagText.setLayoutData(gd);
+ tagText.setText(attributeNameText.getText());
+
+ actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
+ actionCombo.setItems(new String[] { Messages.CustomXmlParserInputWizardPage_set, Messages.CustomXmlParserInputWizardPage_append,
+ Messages.CustomXmlParserInputWizardPage_appendWith });
+ actionCombo.select(inputAttribute.inputAction);
+ actionCombo.addSelectionListener(updateListener);
+
+ if (inputAttribute.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ tagCombo.select(0);
+ tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);
+ tagText.setText(inputAttribute.inputFormat);
+ tagText.addModifyListener(updateListener);
+ } else if (inputAttribute.inputName.equals(CustomTraceDefinition.TAG_MESSAGE)) {
+ tagCombo.select(1);
+ tagLabel.setVisible(false);
+ tagText.setVisible(false);
+ } else {
+ tagCombo.select(2);
+ tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);
+ tagText.setText(inputAttribute.inputName);
+ tagText.addModifyListener(updateListener);
+ }
+ }
+
+ private void dispose() {
+ labelComposite.dispose();
+ attributeComposite.dispose();
+ filler.dispose();
+ tagComposite.dispose();
+ }
+
+ private void setAttributeNumber(int attributeNumber) {
+ this.attributeNumber = attributeNumber;
+ labelComposite.layout();
+ }
+ }
+
+ private Element getPreviewElement(InputElement inputElement) {
+ Element element = documentElement;
+ if (element != null) {
+ if (!documentElement.getNodeName().equals(definition.rootInputElement.elementName)) {
+ return null;
+ }
+ ArrayList<String> elementNames = new ArrayList<String>();
+ while (inputElement != null) {
+ elementNames.add(inputElement.elementName);
+ inputElement = inputElement.parentElement;
+ }
+ for (int i = elementNames.size() - 1; --i >= 0;) {
+ NodeList childList = element.getChildNodes();
+ element = null;
+ for (int j = 0; j < childList.getLength(); j++) {
+ Node child = childList.item(j);
+ if (child instanceof Element && child.getNodeName().equals(elementNames.get(i))) {
+ element = (Element) child;
+ break;
+ }
+ }
+ if (element == null) {
+ break;
+ }
+ }
+ if (element != null) {
+ return element;
+ }
+ }
+ return null;
+ }
+
+ private String getChildNameSuggestion(InputElement inputElement) {
+ if (inputElement == null) {
+ if (documentElement != null) {
+ return documentElement.getNodeName();
+ }
+ } else {
+ Element element = getPreviewElement(inputElement);
+ if (element != null) {
+ NodeList childNodes = element.getChildNodes();
+ for (int i = 0; i < childNodes.getLength(); i++) {
+ Node node = childNodes.item(i);
+ if (node instanceof Element) {
+ boolean unused = true;
+ if (inputElement.childElements != null) {
+ for (InputElement child : inputElement.childElements) {
+ if (child.elementName.equals(node.getNodeName())) {
+ unused = false;
+ break;
+ }
+ }
+ }
+ if (unused) {
+ return node.getNodeName();
+ }
+ }
+ }
+ }
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ private String getAttributeNameSuggestion(InputElement inputElement) {
+ Element element = getPreviewElement(inputElement);
+ if (element != null) {
+ NamedNodeMap attributeMap = element.getAttributes();
+ for (int i = 0; i < attributeMap.getLength(); i++) {
+ Node node = attributeMap.item(i);
+ boolean unused = true;
+ if (inputElement.attributes != null) {
+ for (InputAttribute attribute : inputElement.attributes) {
+ if (attribute.attributeName.equals(node.getNodeName())) {
+ unused = false;
+ break;
+ }
+ }
+ }
+ if (unused) {
+ return node.getNodeName();
+ }
+ }
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ private void validate() {
+ definition.definitionName = logtypeText.getText().trim();
+ definition.timeStampOutputFormat = timeStampOutputFormatText.getText().trim();
+
+ if (selectedElement != null) {
+ selectedElement.extractInputs();
+ treeViewer.refresh();
+ }
+
+ StringBuffer errors = new StringBuffer();
+
+ if (definition.definitionName.length() == 0) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_emptyLogTypeError);
+ logtypeText.setBackground(COLOR_LIGHT_RED);
+ } else {
+ logtypeText.setBackground(COLOR_TEXT_BACKGROUND);
+ for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
+ if (definition.definitionName.equals(def.definitionName)) {
+ if (editDefinitionName == null || !editDefinitionName.equals(definition.definitionName)) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_duplicatelogTypeError);
+ logtypeText.setBackground(COLOR_LIGHT_RED);
+ break;
+ }
+ }
+ }
+ }
+
+ if (definition.rootInputElement == null) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_noDocumentError);
+ }
+
+ if (definition.rootInputElement != null) {
+ logEntryFound = false;
+ timeStampFound = false;
+
+ errors.append(validateElement(definition.rootInputElement));
+
+ if ((definition.rootInputElement.attributes != null && definition.rootInputElement.attributes.size() != 0)
+ || (definition.rootInputElement.childElements != null && definition.rootInputElement.childElements.size() != 0)
+ || errors.length() == 0) {
+ if (!logEntryFound) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_missingLogEntryError);
+ }
+
+ if (timeStampFound) {
+ if (timeStampOutputFormatText.getText().trim().length() == 0) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_missingTimestampFmtError);
+ timeStampOutputFormatText.setBackground(COLOR_LIGHT_RED);
+ } else {
+ try {
+ new SimpleDateFormat(timeStampOutputFormatText.getText().trim());
+ timeStampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);
+ } catch (IllegalArgumentException e) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_invalidTimestampFmtError);
+ timeStampOutputFormatText.setBackground(COLOR_LIGHT_RED);
+ }
+ }
+ } else {
+ timeStampPreviewText.setText(Messages.CustomXmlParserInputWizardPage_notimestamporAttributeError);
+ }
+ }
+ } else {
+ timeStampPreviewText.setText(Messages.CustomXmlParserInputWizardPage_notimestamporAttributeError);
+ }
+
+ if (errors.length() == 0) {
+ setDescription(defaultDescription);
+ setPageComplete(true);
+ } else {
+ setDescription(errors.toString());
+ setPageComplete(false);
+ }
+ }
+
+ public StringBuffer validateElement(InputElement inputElement) {
+ StringBuffer errors = new StringBuffer();
+ ElementNode elementNode = null;
+ if (selectedElement != null && selectedElement.inputElement.equals(inputElement)) {
+ elementNode = selectedElement;
+ }
+ if (inputElement == definition.rootInputElement) {
+ if (inputElement.elementName.length() == 0) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_missingDocumentElementError);
+ if (elementNode != null) {
+ elementNode.elementNameText.setBackground(COLOR_LIGHT_RED);
+ }
+ } else {
+ if (elementNode != null) {
+ elementNode.elementNameText.setBackground(COLOR_TEXT_BACKGROUND);
+ }
+ }
+ }
+ if (inputElement != definition.rootInputElement) {
+ if (inputElement.logEntry) {
+ logEntryFound = true;
+ }
+ if (inputElement.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ timeStampFound = true;
+ if (inputElement.inputFormat.length() == 0) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_timestampFormatPrompt
+ + " (" + Messages.CustomXmlParserInputWizardPage_timestampElementPrompt + " " + getName(inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (elementNode != null) {
+ elementNode.tagText.setBackground(COLOR_LIGHT_RED);
+ }
+ } else {
+ try {
+ new SimpleDateFormat(inputElement.inputFormat);
+ if (elementNode != null) {
+ elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND);
+ }
+ } catch (IllegalArgumentException e) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_invalidTimestampFmtError
+ + " (" + Messages.CustomXmlParserInputWizardPage_timestampElementPrompt + " " + getName(inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (elementNode != null) {
+ elementNode.tagText.setBackground(COLOR_LIGHT_RED);
+ }
+ }
+ }
+ } else if (inputElement.inputName.length() == 0) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_missingInputElementNameError);
+ if (elementNode != null) {
+ elementNode.tagText.setBackground(COLOR_LIGHT_RED);
+ }
+ } else {
+ if (elementNode != null) {
+ elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND);
+ }
+ }
+ }
+ if (inputElement.attributes != null) {
+ if (elementNode != null) {
+ for (Attribute attribute : elementNode.attributes) {
+ attribute.attributeNameText.setBackground(COLOR_TEXT_BACKGROUND);
+ }
+ }
+ for (int i = 0; i < inputElement.attributes.size(); i++) {
+ InputAttribute attribute = inputElement.attributes.get(i);
+ boolean duplicate = false;
+ for (int j = i + 1; j < inputElement.attributes.size(); j++) {
+ InputAttribute otherAttribute = inputElement.attributes.get(j);
+ if (otherAttribute.attributeName.equals(attribute.attributeName)) {
+ duplicate = true;
+ if (elementNode != null) {
+ elementNode.attributes.get(j).attributeNameText.setBackground(COLOR_LIGHT_RED);
+ }
+ }
+ }
+ if (attribute.attributeName.length() == 0) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_missingAttribute
+ + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(inputElement) + ": ?). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (elementNode != null) {
+ elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED);
+ }
+ } else if (duplicate) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_duplicateAttributeError
+ + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (elementNode != null) {
+ elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED);
+ }
+ }
+ if (attribute.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ timeStampFound = true;
+ if (attribute.inputFormat.length() == 0) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_missingTimestampInFmtError
+ + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (elementNode != null) {
+ elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);
+ }
+ } else {
+ try {
+ new SimpleDateFormat(attribute.inputFormat);
+ if (elementNode != null) {
+ elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND);
+ }
+ } catch (IllegalArgumentException e) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_invalidTimestampInFmtError
+ + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (elementNode != null) {
+ elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);
+ }
+ }
+ }
+ } else if (attribute.inputName.length() == 0) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_missingDataGroupNameError
+ + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (elementNode != null) {
+ elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);
+ }
+ } else {
+ if (elementNode != null) {
+ elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND);
+ }
+ }
+ }
+ }
+ if (inputElement.childElements != null) {
+ for (InputElement child : inputElement.childElements) {
+ ElementNode childElementNode = null;
+ if (selectedElement != null && selectedElement.inputElement.equals(child)) {
+ childElementNode = selectedElement;
+ }
+ if (childElementNode != null) {
+ childElementNode.elementNameText.setBackground(COLOR_TEXT_BACKGROUND);
+ }
+ }
+ for (int i = 0; i < inputElement.childElements.size(); i++) {
+ InputElement child = inputElement.childElements.get(i);
+ ElementNode childElementNode = null;
+ if (selectedElement != null && selectedElement.inputElement.equals(child)) {
+ childElementNode = selectedElement;
+ }
+ if (child.elementName.length() == 0) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_missingElementNameError
+ + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(child) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (childElementNode != null) {
+ childElementNode.elementNameText.setBackground(COLOR_LIGHT_RED);
+ }
+ } else {
+ boolean duplicate = false;
+ for (int j = i + 1; j < inputElement.childElements.size(); j++) {
+ InputElement otherChild = inputElement.childElements.get(j);
+ if (otherChild.elementName.equals(child.elementName)) {
+ duplicate = true;
+ ElementNode otherChildElementNode = null;
+ if (selectedElement != null && selectedElement.inputElement.equals(otherChild)) {
+ otherChildElementNode = selectedElement;
+ }
+ if (otherChildElementNode != null) {
+ otherChildElementNode.elementNameText.setBackground(COLOR_LIGHT_RED);
+ }
+ }
+ }
+ if (duplicate) {
+ errors.append(Messages.CustomXmlParserInputWizardPage_duplicateElementNameError
+ + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(child) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (childElementNode != null) {
+ childElementNode.elementNameText.setBackground(COLOR_LIGHT_RED);
+ }
+ }
+ }
+
+ errors.append(validateElement(child));
+ }
+ }
+ return errors;
+ }
+
+ public CustomXmlTraceDefinition getDefinition() {
+ return definition;
+ }
+
+ public char[] getInputText() {
+ return inputText.getText().toCharArray();
+ }
+}
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;\r
-\r
-import java.io.File;\r
-import java.io.FileWriter;\r
-import java.io.IOException;\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-\r
-import org.eclipse.jface.wizard.WizardPage;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomEventsTable;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.SashForm;\r
-import org.eclipse.swt.custom.ScrolledComposite;\r
-import org.eclipse.swt.events.SelectionAdapter;\r
-import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.graphics.Image;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Button;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Text;\r
-\r
-public class CustomXmlParserOutputWizardPage extends WizardPage {\r
-\r
- private static final Image upImage = Activator.getDefault().getImageFromPath("/icons/elcl16/up_button.gif"); //$NON-NLS-1$\r
- private static final Image downImage = Activator.getDefault().getImageFromPath("/icons/elcl16/down_button.gif"); //$NON-NLS-1$\r
- private final CustomXmlParserWizard wizard;\r
- private CustomXmlTraceDefinition definition;\r
- List<Output> outputs = new ArrayList<Output>();\r
- // Output messageOutput;\r
- Composite container;\r
- SashForm sash;\r
- // Text timestampFormatText;\r
- // Text timestampPreviewText;\r
- ScrolledComposite outputsScrolledComposite;\r
- Composite outputsContainer;\r
- // ScrolledComposite inputScrolledComposite;\r
- Composite tableContainer;\r
- CustomEventsTable previewTable;\r
- File tmpFile;\r
-\r
- protected CustomXmlParserOutputWizardPage(final CustomXmlParserWizard wizard) {\r
- super("CustomParserOutputWizardPage"); //$NON-NLS-1$\r
- setTitle(wizard.inputPage.getTitle());\r
- setDescription(Messages.CustomXmlParserOutputWizardPage_description);\r
- this.wizard = wizard;\r
- setPageComplete(false);\r
- }\r
-\r
- @Override\r
- public void createControl(final Composite parent) {\r
- container = new Composite(parent, SWT.NULL);\r
- container.setLayout(new GridLayout());\r
-\r
- sash = new SashForm(container, SWT.VERTICAL);\r
- sash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- sash.setBackground(sash.getDisplay().getSystemColor(SWT.COLOR_GRAY));\r
-\r
- outputsScrolledComposite = new ScrolledComposite(sash, SWT.V_SCROLL);\r
- outputsScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- outputsContainer = new Composite(outputsScrolledComposite, SWT.NONE);\r
- final GridLayout outputsLayout = new GridLayout(4, false);\r
- outputsLayout.marginHeight = 10;\r
- outputsLayout.marginWidth = 0;\r
- outputsContainer.setLayout(outputsLayout);\r
- outputsScrolledComposite.setContent(outputsContainer);\r
- outputsScrolledComposite.setExpandHorizontal(true);\r
- outputsScrolledComposite.setExpandVertical(true);\r
-\r
- outputsContainer.layout();\r
-\r
- outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);\r
-\r
- tableContainer = new Composite(sash, SWT.NONE);\r
- final GridLayout tableLayout = new GridLayout();\r
- tableLayout.marginHeight = 0;\r
- tableLayout.marginWidth = 0;\r
- tableContainer.setLayout(tableLayout);\r
- previewTable = new CustomEventsTable(new CustomXmlTraceDefinition(), tableContainer, 0);\r
- previewTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
-\r
- if (wizard.definition != null) {\r
- loadDefinition(wizard.definition);\r
- }\r
- setControl(container);\r
-\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- previewTable.dispose();\r
- super.dispose();\r
- }\r
-\r
- private void loadDefinition(final CustomTraceDefinition definition) {\r
- for (final OutputColumn outputColumn : definition.outputs) {\r
- final Output output = new Output(outputsContainer, outputColumn.name);\r
- outputs.add(output);\r
- }\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)\r
- */\r
- @Override\r
- public void setVisible(final boolean visible) {\r
- if (visible) {\r
- this.definition = wizard.inputPage.getDefinition();\r
- final List<String> outputNames = wizard.inputPage.getInputNames();\r
-\r
- // dispose outputs that have been removed in the input page\r
- final Iterator<Output> iter = outputs.iterator();\r
- while (iter.hasNext()) {\r
- final Output output = iter.next();\r
- boolean found = false;\r
- for (final String name : outputNames) {\r
- if (output.name.equals(name)) {\r
- found = true;\r
- break;\r
- }\r
- }\r
- if (!found) {\r
- output.dispose();\r
- iter.remove();\r
- }\r
- }\r
-\r
- // create outputs that have been added in the input page\r
- for (final String name : outputNames) {\r
- boolean found = false;\r
- for (final Output output : outputs) {\r
- if (output.name.equals(name)) {\r
- found = true;\r
- break;\r
- }\r
- }\r
- if (!found) {\r
- outputs.add(new Output(outputsContainer, name));\r
- }\r
- }\r
-\r
- outputsContainer.layout();\r
- outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);\r
- updatePreviewTable();\r
- if (sash.getSize().y > outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y + previewTable.getTable().getItemHeight()) {\r
- sash.setWeights(new int[] {outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, sash.getSize().y - outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y});\r
- } else {\r
- sash.setWeights(new int[] {outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, previewTable.getTable().getItemHeight()});\r
- }\r
- setPageComplete(true);\r
- } else {\r
- setPageComplete(false);\r
- }\r
- super.setVisible(visible);\r
- }\r
-\r
- private void moveBefore(final Output moved) {\r
- final int i = outputs.indexOf(moved);\r
- if (i > 0) {\r
- final Output previous = outputs.get(i-1);\r
- moved.enabledButton.moveAbove(previous.enabledButton);\r
- moved.nameLabel.moveBelow(moved.enabledButton);\r
- moved.upButton.moveBelow(moved.nameLabel);\r
- moved.downButton.moveBelow(moved.upButton);\r
- outputs.add(i-1, outputs.remove(i));\r
- outputsContainer.layout();\r
- outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);\r
- container.layout();\r
- updatePreviewTable();\r
- }\r
- }\r
-\r
- private void moveAfter(final Output moved) {\r
- final int i = outputs.indexOf(moved);\r
- if (i+1 < outputs.size()) {\r
- final Output next = outputs.get(i+1);\r
- moved.enabledButton.moveBelow(next.downButton);\r
- moved.nameLabel.moveBelow(moved.enabledButton);\r
- moved.upButton.moveBelow(moved.nameLabel);\r
- moved.downButton.moveBelow(moved.upButton);\r
- outputs.add(i+1, outputs.remove(i));\r
- outputsContainer.layout();\r
- outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);\r
- container.layout();\r
- updatePreviewTable();\r
- }\r
- }\r
-\r
- private void updatePreviewTable() {\r
- final int CACHE_SIZE = 50;\r
- definition.outputs = extractOutputs();\r
-\r
- try {\r
- tmpFile = Activator.getDefault().getStateLocation().addTrailingSeparator().append("customwizard.tmp").toFile(); //$NON-NLS-1$\r
- final FileWriter writer = new FileWriter(tmpFile);\r
- writer.write(wizard.inputPage.getInputText());\r
- writer.close();\r
-\r
- final ITmfTrace trace = new CustomXmlTrace(null, definition, tmpFile.getAbsolutePath(), CACHE_SIZE);\r
- previewTable.dispose();\r
- previewTable = new CustomEventsTable(definition, tableContainer, CACHE_SIZE);\r
- previewTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- previewTable.setTrace(trace, true);\r
- } catch (final TmfTraceException e) {\r
- Activator.getDefault().logError("Error creating CustomXmlTrace. File:" + tmpFile.getAbsolutePath(), e); //$NON-NLS-1$\r
- } catch (final IOException e) {\r
- Activator.getDefault().logError("Error creating CustomXmlTrace. File:" + tmpFile.getAbsolutePath(), e); //$NON-NLS-1$\r
- }\r
-\r
- tableContainer.layout();\r
- container.layout();\r
- }\r
-\r
- public List<OutputColumn> extractOutputs() {\r
- int numColumns = 0;\r
- for (int i = 0; i < outputs.size(); i++) {\r
- if (outputs.get(i).enabledButton.getSelection()) {\r
- numColumns++;\r
- }\r
- }\r
- final List<OutputColumn> outputColumns = new ArrayList<OutputColumn>(numColumns);\r
- numColumns = 0;\r
- for (int i = 0; i < outputs.size(); i++) {\r
- final Output output = outputs.get(i);\r
- if (output.enabledButton.getSelection()) {\r
- final OutputColumn column = new OutputColumn();\r
- column.name = output.nameLabel.getText();\r
- outputColumns.add(column);\r
- }\r
- }\r
- return outputColumns;\r
- }\r
-\r
- private class Output {\r
- String name;\r
- Button enabledButton;\r
- Text nameLabel;\r
- Button upButton;\r
- Button downButton;\r
-\r
- public Output(final Composite parent, final String name) {\r
- this.name = name;\r
-\r
- enabledButton = new Button(parent, SWT.CHECK);\r
- enabledButton.setToolTipText(Messages.CustomXmlParserOutputWizardPage_visible);\r
- enabledButton.setSelection(true);\r
- enabledButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(final SelectionEvent e) {\r
- updatePreviewTable();\r
- }\r
- });\r
- // if (messageOutput != null) {\r
- // enabledButton.moveAbove(messageOutput.enabledButton);\r
- // }\r
-\r
- nameLabel = new Text(parent, SWT.BORDER | SWT.READ_ONLY | SWT.SINGLE);\r
- nameLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));\r
- nameLabel.setText(name);\r
- nameLabel.moveBelow(enabledButton);\r
-\r
- upButton = new Button(parent, SWT.PUSH);\r
- upButton.setImage(upImage);\r
- upButton.setToolTipText(Messages.CustomXmlParserOutputWizardPage_moveBefore);\r
- upButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(final SelectionEvent e) {\r
- moveBefore(Output.this);\r
- }\r
- });\r
- upButton.moveBelow(nameLabel);\r
-\r
- downButton = new Button(parent, SWT.PUSH);\r
- downButton.setImage(downImage);\r
- downButton.setToolTipText(Messages.CustomXmlParserOutputWizardPage_moveAfter);\r
- downButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(final SelectionEvent e) {\r
- moveAfter(Output.this);\r
- }\r
- });\r
- downButton.moveBelow(upButton);\r
- }\r
-\r
- private void dispose() {\r
- enabledButton.dispose();\r
- nameLabel.dispose();\r
- upButton.dispose();\r
- downButton.dispose();\r
- }\r
- }\r
-\r
- public CustomXmlTraceDefinition getDefinition() {\r
- return definition;\r
- }\r
-\r
-}\r
+package org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomEventsTable;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+
+public class CustomXmlParserOutputWizardPage extends WizardPage {
+
+ private static final Image upImage = Activator.getDefault().getImageFromPath("/icons/elcl16/up_button.gif"); //$NON-NLS-1$
+ private static final Image downImage = Activator.getDefault().getImageFromPath("/icons/elcl16/down_button.gif"); //$NON-NLS-1$
+ private final CustomXmlParserWizard wizard;
+ private CustomXmlTraceDefinition definition;
+ List<Output> outputs = new ArrayList<Output>();
+ // Output messageOutput;
+ Composite container;
+ SashForm sash;
+ // Text timestampFormatText;
+ // Text timestampPreviewText;
+ ScrolledComposite outputsScrolledComposite;
+ Composite outputsContainer;
+ // ScrolledComposite inputScrolledComposite;
+ Composite tableContainer;
+ CustomEventsTable previewTable;
+ File tmpFile;
+
+ protected CustomXmlParserOutputWizardPage(final CustomXmlParserWizard wizard) {
+ super("CustomParserOutputWizardPage"); //$NON-NLS-1$
+ setTitle(wizard.inputPage.getTitle());
+ setDescription(Messages.CustomXmlParserOutputWizardPage_description);
+ this.wizard = wizard;
+ setPageComplete(false);
+ }
+
+ @Override
+ public void createControl(final Composite parent) {
+ container = new Composite(parent, SWT.NULL);
+ container.setLayout(new GridLayout());
+
+ sash = new SashForm(container, SWT.VERTICAL);
+ sash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ sash.setBackground(sash.getDisplay().getSystemColor(SWT.COLOR_GRAY));
+
+ outputsScrolledComposite = new ScrolledComposite(sash, SWT.V_SCROLL);
+ outputsScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ outputsContainer = new Composite(outputsScrolledComposite, SWT.NONE);
+ final GridLayout outputsLayout = new GridLayout(4, false);
+ outputsLayout.marginHeight = 10;
+ outputsLayout.marginWidth = 0;
+ outputsContainer.setLayout(outputsLayout);
+ outputsScrolledComposite.setContent(outputsContainer);
+ outputsScrolledComposite.setExpandHorizontal(true);
+ outputsScrolledComposite.setExpandVertical(true);
+
+ outputsContainer.layout();
+
+ outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);
+
+ tableContainer = new Composite(sash, SWT.NONE);
+ final GridLayout tableLayout = new GridLayout();
+ tableLayout.marginHeight = 0;
+ tableLayout.marginWidth = 0;
+ tableContainer.setLayout(tableLayout);
+ previewTable = new CustomEventsTable(new CustomXmlTraceDefinition(), tableContainer, 0);
+ previewTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ if (wizard.definition != null) {
+ loadDefinition(wizard.definition);
+ }
+ setControl(container);
+
+ }
+
+ @Override
+ public void dispose() {
+ previewTable.dispose();
+ super.dispose();
+ }
+
+ private void loadDefinition(final CustomTraceDefinition definition) {
+ for (final OutputColumn outputColumn : definition.outputs) {
+ final Output output = new Output(outputsContainer, outputColumn.name);
+ outputs.add(output);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
+ */
+ @Override
+ public void setVisible(final boolean visible) {
+ if (visible) {
+ this.definition = wizard.inputPage.getDefinition();
+ final List<String> outputNames = wizard.inputPage.getInputNames();
+
+ // dispose outputs that have been removed in the input page
+ final Iterator<Output> iter = outputs.iterator();
+ while (iter.hasNext()) {
+ final Output output = iter.next();
+ boolean found = false;
+ for (final String name : outputNames) {
+ if (output.name.equals(name)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ output.dispose();
+ iter.remove();
+ }
+ }
+
+ // create outputs that have been added in the input page
+ for (final String name : outputNames) {
+ boolean found = false;
+ for (final Output output : outputs) {
+ if (output.name.equals(name)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ outputs.add(new Output(outputsContainer, name));
+ }
+ }
+
+ outputsContainer.layout();
+ outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);
+ updatePreviewTable();
+ if (sash.getSize().y > outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y + previewTable.getTable().getItemHeight()) {
+ sash.setWeights(new int[] {outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, sash.getSize().y - outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y});
+ } else {
+ sash.setWeights(new int[] {outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, previewTable.getTable().getItemHeight()});
+ }
+ setPageComplete(true);
+ } else {
+ setPageComplete(false);
+ }
+ super.setVisible(visible);
+ }
+
+ private void moveBefore(final Output moved) {
+ final int i = outputs.indexOf(moved);
+ if (i > 0) {
+ final Output previous = outputs.get(i-1);
+ moved.enabledButton.moveAbove(previous.enabledButton);
+ moved.nameLabel.moveBelow(moved.enabledButton);
+ moved.upButton.moveBelow(moved.nameLabel);
+ moved.downButton.moveBelow(moved.upButton);
+ outputs.add(i-1, outputs.remove(i));
+ outputsContainer.layout();
+ outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);
+ container.layout();
+ updatePreviewTable();
+ }
+ }
+
+ private void moveAfter(final Output moved) {
+ final int i = outputs.indexOf(moved);
+ if (i+1 < outputs.size()) {
+ final Output next = outputs.get(i+1);
+ moved.enabledButton.moveBelow(next.downButton);
+ moved.nameLabel.moveBelow(moved.enabledButton);
+ moved.upButton.moveBelow(moved.nameLabel);
+ moved.downButton.moveBelow(moved.upButton);
+ outputs.add(i+1, outputs.remove(i));
+ outputsContainer.layout();
+ outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);
+ container.layout();
+ updatePreviewTable();
+ }
+ }
+
+ private void updatePreviewTable() {
+ final int CACHE_SIZE = 50;
+ definition.outputs = extractOutputs();
+
+ try {
+ tmpFile = Activator.getDefault().getStateLocation().addTrailingSeparator().append("customwizard.tmp").toFile(); //$NON-NLS-1$
+ final FileWriter writer = new FileWriter(tmpFile);
+ writer.write(wizard.inputPage.getInputText());
+ writer.close();
+
+ final ITmfTrace trace = new CustomXmlTrace(null, definition, tmpFile.getAbsolutePath(), CACHE_SIZE);
+ previewTable.dispose();
+ previewTable = new CustomEventsTable(definition, tableContainer, CACHE_SIZE);
+ previewTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ previewTable.setTrace(trace, true);
+ } catch (final TmfTraceException e) {
+ Activator.getDefault().logError("Error creating CustomXmlTrace. File:" + tmpFile.getAbsolutePath(), e); //$NON-NLS-1$
+ } catch (final IOException e) {
+ Activator.getDefault().logError("Error creating CustomXmlTrace. File:" + tmpFile.getAbsolutePath(), e); //$NON-NLS-1$
+ }
+
+ tableContainer.layout();
+ container.layout();
+ }
+
+ public List<OutputColumn> extractOutputs() {
+ int numColumns = 0;
+ for (int i = 0; i < outputs.size(); i++) {
+ if (outputs.get(i).enabledButton.getSelection()) {
+ numColumns++;
+ }
+ }
+ final List<OutputColumn> outputColumns = new ArrayList<OutputColumn>(numColumns);
+ numColumns = 0;
+ for (int i = 0; i < outputs.size(); i++) {
+ final Output output = outputs.get(i);
+ if (output.enabledButton.getSelection()) {
+ final OutputColumn column = new OutputColumn();
+ column.name = output.nameLabel.getText();
+ outputColumns.add(column);
+ }
+ }
+ return outputColumns;
+ }
+
+ private class Output {
+ String name;
+ Button enabledButton;
+ Text nameLabel;
+ Button upButton;
+ Button downButton;
+
+ public Output(final Composite parent, final String name) {
+ this.name = name;
+
+ enabledButton = new Button(parent, SWT.CHECK);
+ enabledButton.setToolTipText(Messages.CustomXmlParserOutputWizardPage_visible);
+ enabledButton.setSelection(true);
+ enabledButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ updatePreviewTable();
+ }
+ });
+ // if (messageOutput != null) {
+ // enabledButton.moveAbove(messageOutput.enabledButton);
+ // }
+
+ nameLabel = new Text(parent, SWT.BORDER | SWT.READ_ONLY | SWT.SINGLE);
+ nameLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
+ nameLabel.setText(name);
+ nameLabel.moveBelow(enabledButton);
+
+ upButton = new Button(parent, SWT.PUSH);
+ upButton.setImage(upImage);
+ upButton.setToolTipText(Messages.CustomXmlParserOutputWizardPage_moveBefore);
+ upButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ moveBefore(Output.this);
+ }
+ });
+ upButton.moveBelow(nameLabel);
+
+ downButton = new Button(parent, SWT.PUSH);
+ downButton.setImage(downImage);
+ downButton.setToolTipText(Messages.CustomXmlParserOutputWizardPage_moveAfter);
+ downButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ moveAfter(Output.this);
+ }
+ });
+ downButton.moveBelow(upButton);
+ }
+
+ private void dispose() {
+ enabledButton.dispose();
+ nameLabel.dispose();
+ upButton.dispose();
+ downButton.dispose();
+ }
+ }
+
+ public CustomXmlTraceDefinition getDefinition() {
+ return definition;
+ }
+
+}
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;\r
-\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.jface.viewers.IStructuredSelection;\r
-import org.eclipse.jface.wizard.Wizard;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;\r
-import org.eclipse.ui.INewWizard;\r
-import org.eclipse.ui.IWorkbench;\r
-\r
-public class CustomXmlParserWizard extends Wizard implements INewWizard {\r
-\r
- CustomXmlParserInputWizardPage inputPage;\r
- CustomXmlParserOutputWizardPage outputPage;\r
- private ISelection selection;\r
- CustomXmlTraceDefinition definition;\r
-\r
- public CustomXmlParserWizard() {\r
- super();\r
- }\r
-\r
- public CustomXmlParserWizard(CustomXmlTraceDefinition definition) {\r
- super();\r
- this.definition = definition;\r
- }\r
-\r
- @Override\r
- public boolean performFinish() {\r
- CustomXmlTraceDefinition def = outputPage.getDefinition();\r
- if (definition != null && !definition.definitionName.equals(def.definitionName)) {\r
- CustomXmlTraceDefinition.delete(definition.definitionName);\r
- }\r
- def.save();\r
- return true;\r
- }\r
-\r
- /**\r
- * Adding the page to the wizard.\r
- */\r
-\r
- @Override\r
- public void addPages() {\r
- inputPage = new CustomXmlParserInputWizardPage(selection, definition);\r
- addPage(inputPage);\r
- outputPage = new CustomXmlParserOutputWizardPage(this);\r
- addPage(outputPage);\r
- }\r
-\r
- @Override\r
- public void init(IWorkbench workbench, IStructuredSelection selection) {\r
- this.selection = selection;\r
- }\r
-\r
-}\r
+package org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+
+public class CustomXmlParserWizard extends Wizard implements INewWizard {
+
+ CustomXmlParserInputWizardPage inputPage;
+ CustomXmlParserOutputWizardPage outputPage;
+ private ISelection selection;
+ CustomXmlTraceDefinition definition;
+
+ public CustomXmlParserWizard() {
+ super();
+ }
+
+ public CustomXmlParserWizard(CustomXmlTraceDefinition definition) {
+ super();
+ this.definition = definition;
+ }
+
+ @Override
+ public boolean performFinish() {
+ CustomXmlTraceDefinition def = outputPage.getDefinition();
+ if (definition != null && !definition.definitionName.equals(def.definitionName)) {
+ CustomXmlTraceDefinition.delete(definition.definitionName);
+ }
+ def.save();
+ return true;
+ }
+
+ /**
+ * Adding the page to the wizard.
+ */
+
+ @Override
+ public void addPages() {
+ inputPage = new CustomXmlParserInputWizardPage(selection, definition);
+ addPage(inputPage);
+ outputPage = new CustomXmlParserOutputWizardPage(this);
+ addPage(outputPage);
+ }
+
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.selection = selection;
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.signal;\r
-\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-\r
-/**\r
- * Signal that a trace was closed\r
- * \r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TmfTraceClosedSignal extends TmfSignal {\r
-\r
- private final ITmfTrace fTrace;\r
-\r
- public TmfTraceClosedSignal(Object source, ITmfTrace trace) {\r
- super(source);\r
- fTrace = trace;\r
- }\r
-\r
- public ITmfTrace getTrace() {\r
- return fTrace;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return "[TmfTraceClosedSignal (" + fTrace.getName() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.signal;
+
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+
+/**
+ * Signal that a trace was closed
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+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$
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.signal;\r
-\r
-import org.eclipse.core.resources.IFile;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-import org.eclipse.linuxtools.tmf.ui.viewers.events.ITmfEventsFilterProvider;\r
-\r
-/**\r
- * Signal that a trace was opened\r
- * \r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TmfTraceOpenedSignal extends TmfSignal {\r
-\r
- private final ITmfTrace fTrace;\r
- private final IFile fBookmarksFile;\r
- private final ITmfEventsFilterProvider fEventsFilterProvider;\r
-\r
- public TmfTraceOpenedSignal(Object source, ITmfTrace trace, IFile bookmarksFile, ITmfEventsFilterProvider eventsFilterProvider) {\r
- super(source);\r
- fTrace = trace;\r
- fBookmarksFile = bookmarksFile;\r
- fEventsFilterProvider = eventsFilterProvider;\r
- }\r
-\r
- public ITmfTrace getTrace() {\r
- return fTrace;\r
- }\r
-\r
- public IFile getBookmarksFile() {\r
- return fBookmarksFile;\r
- }\r
-\r
- public ITmfEventsFilterProvider getEventsFilterProvider() {\r
- return fEventsFilterProvider;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return "[TmfTraceOpenedSignal (" + fTrace.getName() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.signal;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.ITmfEventsFilterProvider;
+
+/**
+ * Signal that a trace was opened
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TmfTraceOpenedSignal extends TmfSignal {
+
+ private final ITmfTrace fTrace;
+ private final IFile fBookmarksFile;
+ private final ITmfEventsFilterProvider fEventsFilterProvider;
+
+ public TmfTraceOpenedSignal(Object source, ITmfTrace trace, IFile bookmarksFile, ITmfEventsFilterProvider eventsFilterProvider) {
+ super(source);
+ fTrace = trace;
+ fBookmarksFile = bookmarksFile;
+ fEventsFilterProvider = eventsFilterProvider;
+ }
+
+ public ITmfTrace getTrace() {
+ return fTrace;
+ }
+
+ public IFile getBookmarksFile() {
+ return fBookmarksFile;
+ }
+
+ public ITmfEventsFilterProvider getEventsFilterProvider() {
+ return fEventsFilterProvider;
+ }
+
+ @Override
+ public String toString() {
+ return "[TmfTraceOpenedSignal (" + fTrace.getName() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- * \r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- * \r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.signal;\r
-\r
-import org.eclipse.core.resources.IResource;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;\r
-\r
-/**\r
- * Signal that a trace parser was updated\r
- * \r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TmfTraceParserUpdatedSignal extends TmfSignal {\r
-\r
- private final IResource fTraceResource;\r
- \r
- public TmfTraceParserUpdatedSignal(Object source, IResource traceResource) {\r
- super(source);\r
- fTraceResource = traceResource;\r
- }\r
-\r
- public IResource getTraceResource() {\r
- return fTraceResource;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return "[TmfTraceParserUpdatedSignal (" + fTraceResource.getName() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.signal;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
+
+/**
+ * Signal that a trace parser was updated
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+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$
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.editors;\r
-\r
-import org.eclipse.core.resources.IFile;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-\r
-/**\r
- * The trace editor interface\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public interface ITmfTraceEditor {\r
-\r
- /**\r
- * Get the trace to which this editor is assigned\r
- *\r
- * @return The trace\r
- */\r
- public ITmfTrace getTrace();\r
-\r
- /**\r
- * Get the bookmark file associated to this trace\r
- *\r
- * @return The IFile object pointing to the bookmark file\r
- */\r
- public IFile getBookmarksFile();\r
-}\r
+/*******************************************************************************
+ * 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.editors;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+
+/**
+ * The trace editor interface
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public interface ITmfTraceEditor {
+
+ /**
+ * Get the trace to which this editor is assigned
+ *
+ * @return The trace
+ */
+ public ITmfTrace getTrace();
+
+ /**
+ * Get the bookmark file associated to this trace
+ *
+ * @return The IFile object pointing to the bookmark file
+ */
+ public IFile getBookmarksFile();
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.editors;\r
-\r
-import org.eclipse.linuxtools.tmf.core.component.ITmfComponent;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;\r
-import org.eclipse.ui.part.EditorPart;\r
-\r
-/**\r
- * The main editor abstract class for use in TMF.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public abstract class TmfEditor extends EditorPart implements ITmfComponent {\r
-\r
- private final String fName;\r
-\r
- // ------------------------------------------------------------------------\r
- // Constructor\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Default constructor\r
- */\r
- public TmfEditor() {\r
- super();\r
- fName = "TmfEditor"; //$NON-NLS-1$\r
- TmfSignalManager.register(this);\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- TmfSignalManager.deregister(this);\r
- super.dispose();\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // ITmfComponent\r
- // ------------------------------------------------------------------------\r
-\r
- @Override\r
- public String getName() {\r
- return fName;\r
- }\r
-\r
- @Override\r
- public void broadcast(TmfSignal signal) {\r
- TmfSignalManager.dispatchSignal(signal);\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.editors;
+
+import org.eclipse.linuxtools.tmf.core.component.ITmfComponent;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
+import org.eclipse.ui.part.EditorPart;
+
+/**
+ * The main editor abstract class for use in TMF.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public abstract class TmfEditor extends EditorPart implements ITmfComponent {
+
+ private final String fName;
+
+ // ------------------------------------------------------------------------
+ // Constructor
+ // ------------------------------------------------------------------------
+
+ /**
+ * Default constructor
+ */
+ public TmfEditor() {
+ super();
+ fName = "TmfEditor"; //$NON-NLS-1$
+ TmfSignalManager.register(this);
+ }
+
+ @Override
+ public void dispose() {
+ TmfSignalManager.deregister(this);
+ super.dispose();
+ }
+
+ // ------------------------------------------------------------------------
+ // ITmfComponent
+ // ------------------------------------------------------------------------
+
+ @Override
+ public String getName() {
+ return fName;
+ }
+
+ @Override
+ public void broadcast(TmfSignal signal) {
+ TmfSignalManager.dispatchSignal(signal);
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.editors;\r
-\r
-import org.eclipse.core.resources.IFile;\r
-import org.eclipse.core.runtime.content.IContentType;\r
-import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-import org.eclipse.ui.IEditorInput;\r
-import org.eclipse.ui.IPersistableElement;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.eclipse.ui.ide.IDE;\r
-\r
-/**\r
- * The input interface for TMF editors.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TmfEditorInput implements IEditorInput {\r
-\r
- private final IFile fFile;\r
- private final ITmfTrace fTrace;\r
-\r
- /**\r
- * Standard constructor\r
- *\r
- * @param file The IFile pointer\r
- * @param trace Reference to the trace\r
- */\r
- public TmfEditorInput(IFile file, ITmfTrace trace) {\r
- fFile = file;\r
- fTrace = trace;\r
- }\r
-\r
- @Override\r
- public Object getAdapter(Class adapter) {\r
- return null;\r
- }\r
-\r
- @Override\r
- public boolean exists() {\r
- return fFile.exists();\r
- }\r
-\r
- @Override\r
- public ImageDescriptor getImageDescriptor() {\r
- IContentType contentType = IDE.getContentType(fFile);\r
- return PlatformUI.getWorkbench().getEditorRegistry()\r
- .getImageDescriptor(fFile.getName(), contentType);\r
- }\r
-\r
- @Override\r
- public String getName() {\r
- return fTrace.getName();\r
- }\r
-\r
- @Override\r
- public IPersistableElement getPersistable() {\r
- return null;\r
- }\r
-\r
- @Override\r
- public String getToolTipText() {\r
- return fFile.getFullPath().makeRelative().toString();\r
- }\r
-\r
- /**\r
- * Get this editor input's file object\r
- *\r
- * @return The IFile\r
- */\r
- public IFile getFile() {\r
- return fFile;\r
- }\r
-\r
- /**\r
- * Get this editor input's trace\r
- *\r
- * @return The trace\r
- */\r
- public ITmfTrace getTrace() {\r
- return fTrace;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#hashCode()\r
- */\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result + ((fFile == null) ? 0 : fFile.getLocation().hashCode());\r
- result = prime * result + ((fTrace == null) ? 0 : fTrace.getName().hashCode());\r
- return result;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#equals(java.lang.Object)\r
- */\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj) {\r
- return true;\r
- }\r
- if (obj == null) {\r
- return false;\r
- }\r
- if (getClass() != obj.getClass()) {\r
- return false;\r
- }\r
- TmfEditorInput other = (TmfEditorInput) obj;\r
- if (fFile == null) {\r
- if (other.fFile != null) {\r
- return false;\r
- }\r
- } else if (!fFile.getLocation().equals(other.fFile.getLocation())) {\r
- return false;\r
- }\r
- if (fTrace == null) {\r
- if (other.fTrace != null) {\r
- return false;\r
- }\r
- } else if (!fTrace.getName().equals(other.fTrace.getName())) {\r
- return false;\r
- }\r
- return true;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.editors;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+
+/**
+ * The input interface for TMF editors.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TmfEditorInput implements IEditorInput {
+
+ private final IFile fFile;
+ private final ITmfTrace fTrace;
+
+ /**
+ * Standard constructor
+ *
+ * @param file The IFile pointer
+ * @param trace Reference to the trace
+ */
+ public TmfEditorInput(IFile file, ITmfTrace trace) {
+ fFile = file;
+ fTrace = trace;
+ }
+
+ @Override
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+
+ @Override
+ public boolean exists() {
+ return fFile.exists();
+ }
+
+ @Override
+ public ImageDescriptor getImageDescriptor() {
+ IContentType contentType = IDE.getContentType(fFile);
+ return PlatformUI.getWorkbench().getEditorRegistry()
+ .getImageDescriptor(fFile.getName(), contentType);
+ }
+
+ @Override
+ public String getName() {
+ return fTrace.getName();
+ }
+
+ @Override
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ @Override
+ public String getToolTipText() {
+ return fFile.getFullPath().makeRelative().toString();
+ }
+
+ /**
+ * Get this editor input's file object
+ *
+ * @return The IFile
+ */
+ public IFile getFile() {
+ return fFile;
+ }
+
+ /**
+ * Get this editor input's trace
+ *
+ * @return The trace
+ */
+ public ITmfTrace getTrace() {
+ return fTrace;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((fFile == null) ? 0 : fFile.getLocation().hashCode());
+ result = prime * result + ((fTrace == null) ? 0 : fTrace.getName().hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ TmfEditorInput other = (TmfEditorInput) obj;
+ if (fFile == null) {
+ if (other.fFile != null) {
+ return false;
+ }
+ } else if (!fFile.getLocation().equals(other.fFile.getLocation())) {
+ return false;
+ }
+ if (fTrace == null) {
+ if (other.fTrace != null) {
+ return false;
+ }
+ } else if (!fTrace.getName().equals(other.fTrace.getName())) {
+ return false;
+ }
+ return true;
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.editors;\r
-\r
-import java.lang.reflect.Constructor;\r
-import java.lang.reflect.InvocationTargetException;\r
-import java.util.List;\r
-\r
-import org.eclipse.core.resources.IFile;\r
-import org.eclipse.core.resources.IMarker;\r
-import org.eclipse.core.resources.IMarkerDelta;\r
-import org.eclipse.core.resources.IResource;\r
-import org.eclipse.core.resources.IResourceChangeEvent;\r
-import org.eclipse.core.resources.IResourceChangeListener;\r
-import org.eclipse.core.resources.IResourceDelta;\r
-import org.eclipse.core.resources.ResourcesPlugin;\r
-import org.eclipse.core.runtime.CoreException;\r
-import org.eclipse.core.runtime.IConfigurationElement;\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.core.runtime.InvalidRegistryObjectException;\r
-import org.eclipse.core.runtime.Platform;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomEventsTable;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTrace;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace;\r
-import org.eclipse.linuxtools.internal.tmf.ui.project.handlers.Messages;\r
-import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;\r
-import org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement;\r
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;\r
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorContentProvider;\r
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement;\r
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;\r
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;\r
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceType;\r
-import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceClosedSignal;\r
-import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceOpenedSignal;\r
-import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceParserUpdatedSignal;\r
-import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.ui.IEditorInput;\r
-import org.eclipse.ui.IEditorPart;\r
-import org.eclipse.ui.IEditorSite;\r
-import org.eclipse.ui.IFileEditorInput;\r
-import org.eclipse.ui.IPropertyListener;\r
-import org.eclipse.ui.IReusableEditor;\r
-import org.eclipse.ui.PartInitException;\r
-import org.eclipse.ui.ide.IGotoMarker;\r
-import org.eclipse.ui.part.FileEditorInput;\r
-import org.osgi.framework.Bundle;\r
-\r
-/**\r
- * Editor for TMF events\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReusableEditor, IPropertyListener, IResourceChangeListener {\r
-\r
- /** ID for this class */\r
- public static final String ID = "org.eclipse.linuxtools.tmf.ui.editors.events"; //$NON-NLS-1$\r
-\r
- private TmfEventsTable fEventsTable;\r
- private IFile fFile;\r
- private ITmfTrace fTrace;\r
- private Composite fParent;\r
-\r
- @Override\r
- public void doSave(final IProgressMonitor monitor) {\r
- }\r
-\r
- @Override\r
- public void doSaveAs() {\r
- }\r
-\r
- @SuppressWarnings({ "unchecked", "rawtypes" })\r
- @Override\r
- public void init(final IEditorSite site, IEditorInput input) throws PartInitException {\r
- if (input instanceof TmfEditorInput) {\r
- fFile = ((TmfEditorInput) input).getFile();\r
- fTrace = ((TmfEditorInput) input).getTrace();\r
- input = new FileEditorInput(fFile);\r
- } else if (input instanceof IFileEditorInput) {\r
- fFile = ((IFileEditorInput) input).getFile();\r
- if (fFile == null)\r
- {\r
- throw new PartInitException("Invalid IFileEditorInput: " + input); //$NON-NLS-1$\r
- }\r
- try {\r
- final String traceTypeId = fFile.getPersistentProperty(TmfCommonConstants.TRACETYPE);\r
- if (traceTypeId == null) {\r
- throw new PartInitException(Messages.OpenTraceHandler_NoTraceType);\r
- }\r
- if (traceTypeId.equals(TmfExperiment.class.getCanonicalName())) {\r
- // Special case: experiment bookmark resource\r
- final TmfNavigatorContentProvider ncp = new TmfNavigatorContentProvider();\r
- ncp.getChildren(fFile.getProject()); // force the model to be populated\r
- final TmfProjectElement project = TmfProjectRegistry.getProject(fFile.getProject());\r
- if (project == null) {\r
- throw new PartInitException(Messages.OpenExperimentHandler_NoTraceType);\r
- }\r
- for (final ITmfProjectModelElement projectElement : project.getExperimentsFolder().getChildren()) {\r
- final String traceName = fFile.getParent().getName();\r
- if (projectElement.getName().equals(traceName)) {\r
- final TmfExperimentElement experimentElement = (TmfExperimentElement) projectElement;\r
- // Instantiate the experiment's traces\r
- final List<TmfTraceElement> traceEntries = experimentElement.getTraces();\r
- final int nbTraces = traceEntries.size();\r
- int cacheSize = Integer.MAX_VALUE;\r
- final ITmfTrace[] traces = new ITmfTrace[nbTraces];\r
- for (int i = 0; i < nbTraces; i++) {\r
- final TmfTraceElement traceElement = traceEntries.get(i);\r
- final ITmfTrace trace = traceElement.instantiateTrace();\r
- final ITmfEvent traceEvent = traceElement.instantiateEvent();\r
- if ((trace == null) || (traceEvent == null)) {\r
- for (int j = 0; j < i; j++) {\r
- traces[j].dispose();\r
- }\r
- throw new PartInitException(Messages.OpenExperimentHandler_NoTraceType);\r
- }\r
- try {\r
- trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass());\r
- } catch (final TmfTraceException e) {\r
- }\r
- cacheSize = Math.min(cacheSize, trace.getCacheSize());\r
- traces[i] = trace;\r
- }\r
- final TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, experimentElement.getName(), traces, cacheSize) {\r
- @Override\r
- public void initTrace(IResource resource, String path, Class type) {\r
- super.initTrace(resource, path, type);\r
- getIndexer().buildIndex(getNbEvents(), TmfTimeRange.ETERNITY, false);\r
- }\r
- };\r
- experiment.setBookmarksFile(fFile);\r
- fTrace = experiment;\r
- experiment.initTrace(null, null, null);\r
- break;\r
- }\r
- }\r
- } else if (traceTypeId.equals(TmfTrace.class.getCanonicalName())) {\r
- // Special case: trace bookmark resource\r
- final TmfNavigatorContentProvider ncp = new TmfNavigatorContentProvider();\r
- ncp.getChildren(fFile.getProject()); // force the model to be populated\r
- final TmfProjectElement project = TmfProjectRegistry.getProject(fFile.getProject());\r
- for (final ITmfProjectModelElement projectElement : project.getTracesFolder().getChildren()) {\r
- final String traceName = fFile.getParent().getName();\r
- if (projectElement.getName().equals(traceName)) {\r
- final TmfTraceElement traceElement = (TmfTraceElement) projectElement;\r
- // Instantiate the trace\r
- final ITmfTrace trace = traceElement.instantiateTrace();\r
- final ITmfEvent traceEvent = traceElement.instantiateEvent();\r
- if ((trace == null) || (traceEvent == null)) {\r
- throw new PartInitException(Messages.OpenTraceHandler_NoTraceType);\r
- }\r
- try {\r
- trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass());\r
- } catch (final TmfTraceException e) {\r
- }\r
- fTrace = trace;\r
- break;\r
- }\r
- }\r
- } else {\r
- final TmfNavigatorContentProvider ncp = new TmfNavigatorContentProvider();\r
- ncp.getChildren(fFile.getProject()); // force the model to be populated\r
- final TmfProjectElement project = TmfProjectRegistry.getProject(fFile.getProject());\r
- for (final ITmfProjectModelElement projectElement : project.getTracesFolder().getChildren()) {\r
- if (projectElement.getResource().equals(fFile)) {\r
- final TmfTraceElement traceElement = (TmfTraceElement) projectElement;\r
- // Instantiate the trace\r
- final ITmfTrace trace = traceElement.instantiateTrace();\r
- final ITmfEvent traceEvent = traceElement.instantiateEvent();\r
- if ((trace == null) || (traceEvent == null)) {\r
- throw new PartInitException(Messages.OpenTraceHandler_NoTraceType);\r
- }\r
- try {\r
- trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass());\r
- } catch (final TmfTraceException e) {\r
- }\r
- fTrace = trace;\r
- break;\r
- }\r
- }\r
- }\r
- } catch (final InvalidRegistryObjectException e) {\r
- Activator.getDefault().logError("Error initializing TmfEventsEditor", e); //$NON-NLS-1$\r
- } catch (final CoreException e) {\r
- Activator.getDefault().logError("Error initializing TmfEventsEditor", e); //$NON-NLS-1$\r
- }\r
- }\r
- else {\r
- throw new PartInitException("Invalid IEditorInput: " + input.getClass()); //$NON-NLS-1$\r
- }\r
- if (fTrace == null)\r
- {\r
- throw new PartInitException("Invalid IEditorInput: " + fFile.getName()); //$NON-NLS-1$\r
- }\r
- super.setSite(site);\r
- super.setInput(input);\r
- }\r
-\r
- @Override\r
- public boolean isDirty() {\r
- return false;\r
- }\r
-\r
- @Override\r
- public boolean isSaveAsAllowed() {\r
- return false;\r
- }\r
-\r
- @Override\r
- public void setInput(final IEditorInput input) {\r
- super.setInput(input);\r
- firePropertyChange(IEditorPart.PROP_INPUT);\r
- }\r
-\r
- @Override\r
- public void propertyChanged(final Object source, final int propId) {\r
- if (propId == IEditorPart.PROP_INPUT) {\r
- broadcast(new TmfTraceClosedSignal(this, fTrace));\r
- fFile = ((TmfEditorInput) getEditorInput()).getFile();\r
- fTrace = ((TmfEditorInput) getEditorInput()).getTrace();\r
- super.setInput(new FileEditorInput(fFile));\r
- fEventsTable.dispose();\r
- if (fTrace != null) {\r
- fEventsTable = createEventsTable(fParent, fTrace.getCacheSize());\r
- fEventsTable.setTrace(fTrace, true);\r
- fEventsTable.refreshBookmarks(fFile);\r
- broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile, fEventsTable));\r
- } else {\r
- fEventsTable = new TmfEventsTable(fParent, 0);\r
- }\r
- fParent.layout();\r
- }\r
- }\r
-\r
- @Override\r
- public void createPartControl(final Composite parent) {\r
- fParent = parent;\r
- if (fTrace != null) {\r
- setPartName(fTrace.getName());\r
- fEventsTable = createEventsTable(parent, fTrace.getCacheSize());\r
- fEventsTable.setTrace(fTrace, true);\r
- fEventsTable.refreshBookmarks(fFile);\r
- broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile, fEventsTable));\r
- } else {\r
- setPartName(getEditorInput().getName());\r
- fEventsTable = new TmfEventsTable(parent, 0);\r
- }\r
- addPropertyListener(this);\r
- ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);\r
- removePropertyListener(this);\r
- if (fTrace != null) {\r
- broadcast(new TmfTraceClosedSignal(this, fTrace));\r
- }\r
- if (fEventsTable != null) {\r
- fEventsTable.dispose();\r
- }\r
- super.dispose();\r
- }\r
-\r
- protected TmfEventsTable createEventsTable(final Composite parent, final int cacheSize) {\r
- TmfEventsTable eventsTable = getEventsTable(parent, cacheSize);\r
- if (eventsTable == null) {\r
- eventsTable = new TmfEventsTable(parent, cacheSize);\r
- }\r
- return eventsTable;\r
- }\r
-\r
- private TmfEventsTable getEventsTable(final Composite parent, final int cacheSize) {\r
- if (fTrace instanceof TmfExperiment) {\r
- return getExperimentEventsTable((TmfExperiment) fTrace, parent, cacheSize);\r
- }\r
- TmfEventsTable eventsTable = null;\r
- try {\r
- if (fTrace.getResource() == null) {\r
- return null;\r
- }\r
- final String traceType = fTrace.getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE);\r
- if (traceType == null) {\r
- return null;\r
- }\r
- if (traceType.startsWith(CustomTxtTrace.class.getCanonicalName())) {\r
- return new CustomEventsTable(((CustomTxtTrace) fTrace).getDefinition(), parent, cacheSize);\r
- }\r
- if (traceType.startsWith(CustomXmlTrace.class.getCanonicalName())) {\r
- return new CustomEventsTable(((CustomXmlTrace) fTrace).getDefinition(), parent, cacheSize);\r
- }\r
- for (final IConfigurationElement ce : TmfTraceType.getTypeElements()) {\r
- if (ce.getAttribute(TmfTraceType.ID_ATTR).equals(traceType)) {\r
- final IConfigurationElement[] eventsTableTypeCE = ce.getChildren(TmfTraceType.EVENTS_TABLE_TYPE_ELEM);\r
- if (eventsTableTypeCE.length != 1) {\r
- break;\r
- }\r
- final String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceType.CLASS_ATTR);\r
- if ((eventsTableType == null) || (eventsTableType.length() == 0)) {\r
- break;\r
- }\r
- final Bundle bundle = Platform.getBundle(ce.getContributor().getName());\r
- final Class<?> c = bundle.loadClass(eventsTableType);\r
- final Class<?>[] constructorArgs = new Class[] { Composite.class, int.class };\r
- final Constructor<?> constructor = c.getConstructor(constructorArgs);\r
- final Object[] args = new Object[] { parent, cacheSize };\r
- eventsTable = (TmfEventsTable) constructor.newInstance(args);\r
- break;\r
- }\r
- }\r
- } catch (final InvalidRegistryObjectException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$\r
- } catch (final CoreException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$\r
- } catch (final ClassNotFoundException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$\r
- } catch (final SecurityException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$\r
- } catch (final NoSuchMethodException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$\r
- } catch (final IllegalArgumentException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$\r
- } catch (final InstantiationException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$\r
- } catch (final IllegalAccessException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$\r
- } catch (final InvocationTargetException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$\r
- }\r
- return eventsTable;\r
- }\r
-\r
- /**\r
- * Get the events table for an experiment. If all traces in the experiment\r
- * are of the same type, use the extension point specified event table\r
- *\r
- * @param experiment\r
- * the experiment\r
- * @param parent\r
- * the parent Composite\r
- * @param cacheSize\r
- * the event table cache size\r
- * @return an events table of the appropriate type\r
- */\r
- private static TmfEventsTable getExperimentEventsTable(\r
- final TmfExperiment experiment, final Composite parent,\r
- final int cacheSize) {\r
- TmfEventsTable eventsTable = null;\r
- String commonTraceType = null;\r
- try {\r
- for (final ITmfTrace trace : experiment.getTraces()) {\r
- final IResource resource = trace.getResource();\r
- if (resource == null) {\r
- return null;\r
- }\r
- final String traceType = resource.getPersistentProperty(TmfCommonConstants.TRACETYPE);\r
- if ((commonTraceType != null) && !commonTraceType.equals(traceType)) {\r
- return null;\r
- }\r
- commonTraceType = traceType;\r
- }\r
- if (commonTraceType == null) {\r
- return null;\r
- }\r
- if (commonTraceType.startsWith(CustomTxtTrace.class.getCanonicalName())) {\r
- return new CustomEventsTable(((CustomTxtTrace) experiment.getTraces()[0]).getDefinition(), parent, cacheSize);\r
- }\r
- if (commonTraceType.startsWith(CustomXmlTrace.class.getCanonicalName())) {\r
- return new CustomEventsTable(((CustomXmlTrace) experiment.getTraces()[0]).getDefinition(), parent, cacheSize);\r
- }\r
- for (final IConfigurationElement ce : TmfTraceType.getTypeElements()) {\r
- if (ce.getAttribute(TmfTraceType.ID_ATTR).equals(commonTraceType)) {\r
- final IConfigurationElement[] eventsTableTypeCE = ce.getChildren(TmfTraceType.EVENTS_TABLE_TYPE_ELEM);\r
- if (eventsTableTypeCE.length != 1) {\r
- break;\r
- }\r
- final String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceType.CLASS_ATTR);\r
- if ((eventsTableType == null) || (eventsTableType.length() == 0)) {\r
- break;\r
- }\r
- final Bundle bundle = Platform.getBundle(ce.getContributor().getName());\r
- final Class<?> c = bundle.loadClass(eventsTableType);\r
- final Class<?>[] constructorArgs = new Class[] { Composite.class, int.class };\r
- final Constructor<?> constructor = c.getConstructor(constructorArgs);\r
- final Object[] args = new Object[] { parent, cacheSize };\r
- eventsTable = (TmfEventsTable) constructor.newInstance(args);\r
- break;\r
- }\r
- }\r
- } catch (final CoreException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$\r
- } catch (final InvalidRegistryObjectException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$\r
- } catch (final SecurityException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$\r
- } catch (final IllegalArgumentException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$\r
- } catch (final ClassNotFoundException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$\r
- } catch (final NoSuchMethodException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$\r
- } catch (final InstantiationException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$\r
- } catch (final IllegalAccessException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$\r
- } catch (final InvocationTargetException e) {\r
- Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$\r
- }\r
- return eventsTable;\r
- }\r
-\r
- @Override\r
- public ITmfTrace getTrace() {\r
- return fTrace;\r
- }\r
-\r
- @Override\r
- public IFile getBookmarksFile() {\r
- return fFile;\r
- }\r
-\r
- @Override\r
- public void setFocus() {\r
- fEventsTable.setFocus();\r
- if (fTrace != null) {\r
- broadcast(new TmfTraceSelectedSignal(this, fTrace));\r
- }\r
- }\r
-\r
- @Override\r
- public Object getAdapter(final Class adapter) {\r
- if (IGotoMarker.class.equals(adapter)) {\r
- return fEventsTable;\r
- }\r
- return super.getAdapter(adapter);\r
- }\r
-\r
- @Override\r
- public void resourceChanged(final IResourceChangeEvent event) {\r
- for (final IMarkerDelta delta : event.findMarkerDeltas(IMarker.BOOKMARK, false)) {\r
- if (delta.getResource().equals(fFile)) {\r
- if (delta.getKind() == IResourceDelta.REMOVED) {\r
- final IMarker bookmark = delta.getMarker();\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- fEventsTable.removeBookmark(bookmark);\r
- }\r
- });\r
- } else if (delta.getKind() == IResourceDelta.CHANGED) {\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- fEventsTable.getTable().refresh();\r
- }\r
- });\r
- }\r
- }\r
- }\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Global commands\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Add a bookmark\r
- */\r
- public void addBookmark() {\r
- fEventsTable.addBookmark(fFile);\r
- }\r
-\r
-\r
- // ------------------------------------------------------------------------\r
- // Signal handlers\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Handler for the Trace Parser Updated signal\r
- *\r
- * @param signal The incoming signal\r
- */\r
- @TmfSignalHandler\r
- public void traceParserUpdated(final TmfTraceParserUpdatedSignal signal) {\r
- if (signal.getTraceResource().equals(fFile)) {\r
- broadcast(new TmfTraceClosedSignal(this, fTrace));\r
- try {\r
- fTrace.getName();\r
- fTrace = null;\r
- final String traceTypeId = fFile.getPersistentProperty(TmfCommonConstants.TRACETYPE);\r
- if (traceTypeId != null) {\r
- for (final IConfigurationElement ce : TmfTraceType.getTypeElements()) {\r
- if (traceTypeId.equals(ce.getAttribute(TmfTraceType.ID_ATTR))) {\r
- fTrace = (ITmfTrace) ce.createExecutableExtension(TmfTraceType.TRACE_TYPE_ATTR);\r
- final ITmfEvent event = (TmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);\r
- final String path = fFile.getLocationURI().getPath();\r
- fTrace.initTrace(null, path, event.getClass());\r
- break;\r
- }\r
- }\r
- }\r
- } catch (final InvalidRegistryObjectException e) {\r
- Activator.getDefault().logError("Error handling signal TmfTraceParserUpdatedSignal", e); //$NON-NLS-1$\r
- } catch (final TmfTraceException e) {\r
- Activator.getDefault().logError("Error handling signal TmfTraceParserUpdatedSignal", e); //$NON-NLS-1$\r
- } catch (final CoreException e) {\r
- Activator.getDefault().logError("Error handling signal TmfTraceParserUpdatedSignal", e); //$NON-NLS-1$\r
- }\r
- fEventsTable.dispose();\r
- if (fTrace != null) {\r
- fEventsTable = createEventsTable(fParent, fTrace.getCacheSize());\r
- fEventsTable.setTrace(fTrace, true);\r
- broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile, fEventsTable));\r
- } else {\r
- fEventsTable = new TmfEventsTable(fParent, 0);\r
- }\r
- fParent.layout();\r
- }\r
- }\r
-\r
- /**\r
- * Handler for the Trace Selected signal\r
- *\r
- * @param signal The incoming signal\r
- */\r
- @TmfSignalHandler\r
- public void traceSelected(final TmfTraceSelectedSignal signal) {\r
- if ((signal.getSource() != this) && signal.getTrace().equals(fTrace)) {\r
- getSite().getPage().bringToTop(this);\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.editors;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IMarkerDelta;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.InvalidRegistryObjectException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomEventsTable;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTrace;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace;
+import org.eclipse.linuxtools.internal.tmf.ui.project.handlers.Messages;
+import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
+import org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorContentProvider;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceType;
+import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceClosedSignal;
+import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceOpenedSignal;
+import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceParserUpdatedSignal;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IPropertyListener;
+import org.eclipse.ui.IReusableEditor;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.IGotoMarker;
+import org.eclipse.ui.part.FileEditorInput;
+import org.osgi.framework.Bundle;
+
+/**
+ * Editor for TMF events
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReusableEditor, IPropertyListener, IResourceChangeListener {
+
+ /** ID for this class */
+ public static final String ID = "org.eclipse.linuxtools.tmf.ui.editors.events"; //$NON-NLS-1$
+
+ private TmfEventsTable fEventsTable;
+ private IFile fFile;
+ private ITmfTrace fTrace;
+ private Composite fParent;
+
+ @Override
+ public void doSave(final IProgressMonitor monitor) {
+ }
+
+ @Override
+ public void doSaveAs() {
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Override
+ public void init(final IEditorSite site, IEditorInput input) throws PartInitException {
+ if (input instanceof TmfEditorInput) {
+ fFile = ((TmfEditorInput) input).getFile();
+ fTrace = ((TmfEditorInput) input).getTrace();
+ input = new FileEditorInput(fFile);
+ } else if (input instanceof IFileEditorInput) {
+ fFile = ((IFileEditorInput) input).getFile();
+ if (fFile == null)
+ {
+ throw new PartInitException("Invalid IFileEditorInput: " + input); //$NON-NLS-1$
+ }
+ try {
+ final String traceTypeId = fFile.getPersistentProperty(TmfCommonConstants.TRACETYPE);
+ if (traceTypeId == null) {
+ throw new PartInitException(Messages.OpenTraceHandler_NoTraceType);
+ }
+ if (traceTypeId.equals(TmfExperiment.class.getCanonicalName())) {
+ // Special case: experiment bookmark resource
+ final TmfNavigatorContentProvider ncp = new TmfNavigatorContentProvider();
+ ncp.getChildren(fFile.getProject()); // force the model to be populated
+ final TmfProjectElement project = TmfProjectRegistry.getProject(fFile.getProject());
+ if (project == null) {
+ throw new PartInitException(Messages.OpenExperimentHandler_NoTraceType);
+ }
+ for (final ITmfProjectModelElement projectElement : project.getExperimentsFolder().getChildren()) {
+ final String traceName = fFile.getParent().getName();
+ if (projectElement.getName().equals(traceName)) {
+ final TmfExperimentElement experimentElement = (TmfExperimentElement) projectElement;
+ // Instantiate the experiment's traces
+ final List<TmfTraceElement> traceEntries = experimentElement.getTraces();
+ final int nbTraces = traceEntries.size();
+ int cacheSize = Integer.MAX_VALUE;
+ final ITmfTrace[] traces = new ITmfTrace[nbTraces];
+ for (int i = 0; i < nbTraces; i++) {
+ final TmfTraceElement traceElement = traceEntries.get(i);
+ final ITmfTrace trace = traceElement.instantiateTrace();
+ final ITmfEvent traceEvent = traceElement.instantiateEvent();
+ if ((trace == null) || (traceEvent == null)) {
+ for (int j = 0; j < i; j++) {
+ traces[j].dispose();
+ }
+ throw new PartInitException(Messages.OpenExperimentHandler_NoTraceType);
+ }
+ try {
+ trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass());
+ } catch (final TmfTraceException e) {
+ }
+ cacheSize = Math.min(cacheSize, trace.getCacheSize());
+ traces[i] = trace;
+ }
+ final TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, experimentElement.getName(), traces, cacheSize) {
+ @Override
+ public void initTrace(IResource resource, String path, Class type) {
+ super.initTrace(resource, path, type);
+ getIndexer().buildIndex(getNbEvents(), TmfTimeRange.ETERNITY, false);
+ }
+ };
+ experiment.setBookmarksFile(fFile);
+ fTrace = experiment;
+ experiment.initTrace(null, null, null);
+ break;
+ }
+ }
+ } else if (traceTypeId.equals(TmfTrace.class.getCanonicalName())) {
+ // Special case: trace bookmark resource
+ final TmfNavigatorContentProvider ncp = new TmfNavigatorContentProvider();
+ ncp.getChildren(fFile.getProject()); // force the model to be populated
+ final TmfProjectElement project = TmfProjectRegistry.getProject(fFile.getProject());
+ for (final ITmfProjectModelElement projectElement : project.getTracesFolder().getChildren()) {
+ final String traceName = fFile.getParent().getName();
+ if (projectElement.getName().equals(traceName)) {
+ final TmfTraceElement traceElement = (TmfTraceElement) projectElement;
+ // Instantiate the trace
+ final ITmfTrace trace = traceElement.instantiateTrace();
+ final ITmfEvent traceEvent = traceElement.instantiateEvent();
+ if ((trace == null) || (traceEvent == null)) {
+ throw new PartInitException(Messages.OpenTraceHandler_NoTraceType);
+ }
+ try {
+ trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass());
+ } catch (final TmfTraceException e) {
+ }
+ fTrace = trace;
+ break;
+ }
+ }
+ } else {
+ final TmfNavigatorContentProvider ncp = new TmfNavigatorContentProvider();
+ ncp.getChildren(fFile.getProject()); // force the model to be populated
+ final TmfProjectElement project = TmfProjectRegistry.getProject(fFile.getProject());
+ for (final ITmfProjectModelElement projectElement : project.getTracesFolder().getChildren()) {
+ if (projectElement.getResource().equals(fFile)) {
+ final TmfTraceElement traceElement = (TmfTraceElement) projectElement;
+ // Instantiate the trace
+ final ITmfTrace trace = traceElement.instantiateTrace();
+ final ITmfEvent traceEvent = traceElement.instantiateEvent();
+ if ((trace == null) || (traceEvent == null)) {
+ throw new PartInitException(Messages.OpenTraceHandler_NoTraceType);
+ }
+ try {
+ trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass());
+ } catch (final TmfTraceException e) {
+ }
+ fTrace = trace;
+ break;
+ }
+ }
+ }
+ } catch (final InvalidRegistryObjectException e) {
+ Activator.getDefault().logError("Error initializing TmfEventsEditor", e); //$NON-NLS-1$
+ } catch (final CoreException e) {
+ Activator.getDefault().logError("Error initializing TmfEventsEditor", e); //$NON-NLS-1$
+ }
+ }
+ else {
+ throw new PartInitException("Invalid IEditorInput: " + input.getClass()); //$NON-NLS-1$
+ }
+ if (fTrace == null)
+ {
+ throw new PartInitException("Invalid IEditorInput: " + fFile.getName()); //$NON-NLS-1$
+ }
+ super.setSite(site);
+ super.setInput(input);
+ }
+
+ @Override
+ public boolean isDirty() {
+ return false;
+ }
+
+ @Override
+ public boolean isSaveAsAllowed() {
+ return false;
+ }
+
+ @Override
+ public void setInput(final IEditorInput input) {
+ super.setInput(input);
+ firePropertyChange(IEditorPart.PROP_INPUT);
+ }
+
+ @Override
+ public void propertyChanged(final Object source, final int propId) {
+ if (propId == IEditorPart.PROP_INPUT) {
+ broadcast(new TmfTraceClosedSignal(this, fTrace));
+ fFile = ((TmfEditorInput) getEditorInput()).getFile();
+ fTrace = ((TmfEditorInput) getEditorInput()).getTrace();
+ super.setInput(new FileEditorInput(fFile));
+ fEventsTable.dispose();
+ if (fTrace != null) {
+ fEventsTable = createEventsTable(fParent, fTrace.getCacheSize());
+ fEventsTable.setTrace(fTrace, true);
+ fEventsTable.refreshBookmarks(fFile);
+ broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile, fEventsTable));
+ } else {
+ fEventsTable = new TmfEventsTable(fParent, 0);
+ }
+ fParent.layout();
+ }
+ }
+
+ @Override
+ public void createPartControl(final Composite parent) {
+ fParent = parent;
+ if (fTrace != null) {
+ setPartName(fTrace.getName());
+ fEventsTable = createEventsTable(parent, fTrace.getCacheSize());
+ fEventsTable.setTrace(fTrace, true);
+ fEventsTable.refreshBookmarks(fFile);
+ broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile, fEventsTable));
+ } else {
+ setPartName(getEditorInput().getName());
+ fEventsTable = new TmfEventsTable(parent, 0);
+ }
+ addPropertyListener(this);
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
+ }
+
+ @Override
+ public void dispose() {
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+ removePropertyListener(this);
+ if (fTrace != null) {
+ broadcast(new TmfTraceClosedSignal(this, fTrace));
+ }
+ if (fEventsTable != null) {
+ fEventsTable.dispose();
+ }
+ super.dispose();
+ }
+
+ protected TmfEventsTable createEventsTable(final Composite parent, final int cacheSize) {
+ TmfEventsTable eventsTable = getEventsTable(parent, cacheSize);
+ if (eventsTable == null) {
+ eventsTable = new TmfEventsTable(parent, cacheSize);
+ }
+ return eventsTable;
+ }
+
+ private TmfEventsTable getEventsTable(final Composite parent, final int cacheSize) {
+ if (fTrace instanceof TmfExperiment) {
+ return getExperimentEventsTable((TmfExperiment) fTrace, parent, cacheSize);
+ }
+ TmfEventsTable eventsTable = null;
+ try {
+ if (fTrace.getResource() == null) {
+ return null;
+ }
+ final String traceType = fTrace.getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE);
+ if (traceType == null) {
+ return null;
+ }
+ if (traceType.startsWith(CustomTxtTrace.class.getCanonicalName())) {
+ return new CustomEventsTable(((CustomTxtTrace) fTrace).getDefinition(), parent, cacheSize);
+ }
+ if (traceType.startsWith(CustomXmlTrace.class.getCanonicalName())) {
+ return new CustomEventsTable(((CustomXmlTrace) fTrace).getDefinition(), parent, cacheSize);
+ }
+ for (final IConfigurationElement ce : TmfTraceType.getTypeElements()) {
+ if (ce.getAttribute(TmfTraceType.ID_ATTR).equals(traceType)) {
+ final IConfigurationElement[] eventsTableTypeCE = ce.getChildren(TmfTraceType.EVENTS_TABLE_TYPE_ELEM);
+ if (eventsTableTypeCE.length != 1) {
+ break;
+ }
+ final String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceType.CLASS_ATTR);
+ if ((eventsTableType == null) || (eventsTableType.length() == 0)) {
+ break;
+ }
+ final Bundle bundle = Platform.getBundle(ce.getContributor().getName());
+ final Class<?> c = bundle.loadClass(eventsTableType);
+ final Class<?>[] constructorArgs = new Class[] { Composite.class, int.class };
+ final Constructor<?> constructor = c.getConstructor(constructorArgs);
+ final Object[] args = new Object[] { parent, cacheSize };
+ eventsTable = (TmfEventsTable) constructor.newInstance(args);
+ break;
+ }
+ }
+ } catch (final InvalidRegistryObjectException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ } catch (final CoreException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ } catch (final ClassNotFoundException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ } catch (final SecurityException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ } catch (final NoSuchMethodException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ } catch (final IllegalArgumentException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ } catch (final InstantiationException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ } catch (final IllegalAccessException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ } catch (final InvocationTargetException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ }
+ return eventsTable;
+ }
+
+ /**
+ * Get the events table for an experiment. If all traces in the experiment
+ * are of the same type, use the extension point specified event table
+ *
+ * @param experiment
+ * the experiment
+ * @param parent
+ * the parent Composite
+ * @param cacheSize
+ * the event table cache size
+ * @return an events table of the appropriate type
+ */
+ private static TmfEventsTable getExperimentEventsTable(
+ final TmfExperiment experiment, final Composite parent,
+ final int cacheSize) {
+ TmfEventsTable eventsTable = null;
+ String commonTraceType = null;
+ try {
+ for (final ITmfTrace trace : experiment.getTraces()) {
+ final IResource resource = trace.getResource();
+ if (resource == null) {
+ return null;
+ }
+ final String traceType = resource.getPersistentProperty(TmfCommonConstants.TRACETYPE);
+ if ((commonTraceType != null) && !commonTraceType.equals(traceType)) {
+ return null;
+ }
+ commonTraceType = traceType;
+ }
+ if (commonTraceType == null) {
+ return null;
+ }
+ if (commonTraceType.startsWith(CustomTxtTrace.class.getCanonicalName())) {
+ return new CustomEventsTable(((CustomTxtTrace) experiment.getTraces()[0]).getDefinition(), parent, cacheSize);
+ }
+ if (commonTraceType.startsWith(CustomXmlTrace.class.getCanonicalName())) {
+ return new CustomEventsTable(((CustomXmlTrace) experiment.getTraces()[0]).getDefinition(), parent, cacheSize);
+ }
+ for (final IConfigurationElement ce : TmfTraceType.getTypeElements()) {
+ if (ce.getAttribute(TmfTraceType.ID_ATTR).equals(commonTraceType)) {
+ final IConfigurationElement[] eventsTableTypeCE = ce.getChildren(TmfTraceType.EVENTS_TABLE_TYPE_ELEM);
+ if (eventsTableTypeCE.length != 1) {
+ break;
+ }
+ final String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceType.CLASS_ATTR);
+ if ((eventsTableType == null) || (eventsTableType.length() == 0)) {
+ break;
+ }
+ final Bundle bundle = Platform.getBundle(ce.getContributor().getName());
+ final Class<?> c = bundle.loadClass(eventsTableType);
+ final Class<?>[] constructorArgs = new Class[] { Composite.class, int.class };
+ final Constructor<?> constructor = c.getConstructor(constructorArgs);
+ final Object[] args = new Object[] { parent, cacheSize };
+ eventsTable = (TmfEventsTable) constructor.newInstance(args);
+ break;
+ }
+ }
+ } catch (final CoreException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ } catch (final InvalidRegistryObjectException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ } catch (final SecurityException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ } catch (final IllegalArgumentException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ } catch (final ClassNotFoundException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ } catch (final NoSuchMethodException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ } catch (final InstantiationException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ } catch (final IllegalAccessException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ } catch (final InvocationTargetException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ }
+ return eventsTable;
+ }
+
+ @Override
+ public ITmfTrace getTrace() {
+ return fTrace;
+ }
+
+ @Override
+ public IFile getBookmarksFile() {
+ return fFile;
+ }
+
+ @Override
+ public void setFocus() {
+ fEventsTable.setFocus();
+ if (fTrace != null) {
+ broadcast(new TmfTraceSelectedSignal(this, fTrace));
+ }
+ }
+
+ @Override
+ public Object getAdapter(final Class adapter) {
+ if (IGotoMarker.class.equals(adapter)) {
+ return fEventsTable;
+ }
+ return super.getAdapter(adapter);
+ }
+
+ @Override
+ public void resourceChanged(final IResourceChangeEvent event) {
+ for (final IMarkerDelta delta : event.findMarkerDeltas(IMarker.BOOKMARK, false)) {
+ if (delta.getResource().equals(fFile)) {
+ if (delta.getKind() == IResourceDelta.REMOVED) {
+ final IMarker bookmark = delta.getMarker();
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ fEventsTable.removeBookmark(bookmark);
+ }
+ });
+ } else if (delta.getKind() == IResourceDelta.CHANGED) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ fEventsTable.getTable().refresh();
+ }
+ });
+ }
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Global commands
+ // ------------------------------------------------------------------------
+
+ /**
+ * Add a bookmark
+ */
+ public void addBookmark() {
+ fEventsTable.addBookmark(fFile);
+ }
+
+
+ // ------------------------------------------------------------------------
+ // Signal handlers
+ // ------------------------------------------------------------------------
+
+ /**
+ * Handler for the Trace Parser Updated signal
+ *
+ * @param signal The incoming signal
+ */
+ @TmfSignalHandler
+ public void traceParserUpdated(final TmfTraceParserUpdatedSignal signal) {
+ if (signal.getTraceResource().equals(fFile)) {
+ broadcast(new TmfTraceClosedSignal(this, fTrace));
+ try {
+ fTrace.getName();
+ fTrace = null;
+ final String traceTypeId = fFile.getPersistentProperty(TmfCommonConstants.TRACETYPE);
+ if (traceTypeId != null) {
+ for (final IConfigurationElement ce : TmfTraceType.getTypeElements()) {
+ if (traceTypeId.equals(ce.getAttribute(TmfTraceType.ID_ATTR))) {
+ fTrace = (ITmfTrace) ce.createExecutableExtension(TmfTraceType.TRACE_TYPE_ATTR);
+ final ITmfEvent event = (TmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
+ final String path = fFile.getLocationURI().getPath();
+ fTrace.initTrace(null, path, event.getClass());
+ break;
+ }
+ }
+ }
+ } catch (final InvalidRegistryObjectException e) {
+ Activator.getDefault().logError("Error handling signal TmfTraceParserUpdatedSignal", e); //$NON-NLS-1$
+ } catch (final TmfTraceException e) {
+ Activator.getDefault().logError("Error handling signal TmfTraceParserUpdatedSignal", e); //$NON-NLS-1$
+ } catch (final CoreException e) {
+ Activator.getDefault().logError("Error handling signal TmfTraceParserUpdatedSignal", e); //$NON-NLS-1$
+ }
+ fEventsTable.dispose();
+ if (fTrace != null) {
+ fEventsTable = createEventsTable(fParent, fTrace.getCacheSize());
+ fEventsTable.setTrace(fTrace, true);
+ broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile, fEventsTable));
+ } else {
+ fEventsTable = new TmfEventsTable(fParent, 0);
+ }
+ fParent.layout();
+ }
+ }
+
+ /**
+ * Handler for the Trace Selected signal
+ *
+ * @param signal The incoming signal
+ */
+ @TmfSignalHandler
+ public void traceSelected(final TmfTraceSelectedSignal signal) {
+ if ((signal.getSource() != this) && signal.getTrace().equals(fTrace)) {
+ getSite().getPage().bringToTop(this);
+ }
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.editors;\r
-\r
-import org.eclipse.linuxtools.tmf.core.component.ITmfComponent;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;\r
-import org.eclipse.ui.part.MultiPageEditorPart;\r
-\r
-/**\r
- * Multi-page editor part abstract class for use in TMF.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public abstract class TmfMultiPageEditorPart extends MultiPageEditorPart implements ITmfComponent {\r
-\r
- private final String fName;\r
-\r
- // ------------------------------------------------------------------------\r
- // Constructor\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Default constructor\r
- */\r
- public TmfMultiPageEditorPart() {\r
- super();\r
- fName = "TmfMultiPageEditorPart"; //$NON-NLS-1$\r
- TmfSignalManager.register(this);\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- TmfSignalManager.deregister(this);\r
- super.dispose();\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // ITmfComponent\r
- // ------------------------------------------------------------------------\r
-\r
- @Override\r
- public String getName() {\r
- return fName;\r
- }\r
-\r
- @Override\r
- public void broadcast(TmfSignal signal) {\r
- TmfSignalManager.dispatchSignal(signal);\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.editors;
+
+import org.eclipse.linuxtools.tmf.core.component.ITmfComponent;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
+import org.eclipse.ui.part.MultiPageEditorPart;
+
+/**
+ * Multi-page editor part abstract class for use in TMF.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public abstract class TmfMultiPageEditorPart extends MultiPageEditorPart implements ITmfComponent {
+
+ private final String fName;
+
+ // ------------------------------------------------------------------------
+ // Constructor
+ // ------------------------------------------------------------------------
+
+ /**
+ * Default constructor
+ */
+ public TmfMultiPageEditorPart() {
+ super();
+ fName = "TmfMultiPageEditorPart"; //$NON-NLS-1$
+ TmfSignalManager.register(this);
+ }
+
+ @Override
+ public void dispose() {
+ TmfSignalManager.deregister(this);
+ super.dispose();
+ }
+
+ // ------------------------------------------------------------------------
+ // ITmfComponent
+ // ------------------------------------------------------------------------
+
+ @Override
+ public String getName() {
+ return fName;
+ }
+
+ @Override
+ public void broadcast(TmfSignal signal) {
+ TmfSignalManager.dispatchSignal(signal);
+ }
+}
}
// ------------------------------------------------------------------------
- // IPropertySource2\r // ------------------------------------------------------------------------\r
+ // IPropertySource2\r // ------------------------------------------------------------------------
/*
* (non-Javadoc)
* @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
- */\r @Override\r public Object getEditableValue() {\r return null;\r }\r
+ */\r @Override\r public Object getEditableValue() {\r return null;\r }
/*
* (non-Javadoc)
* @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
*/\r @Override\r public Object getPropertyValue(Object id) {\r\r if (sfName.equals(id))\r return getName();\r\r if (sfPath.equals(id))\r return getPath().toString();\r\r if (sfLocation.equals(id))\r return getLocation().toString();\r\r return null;\r }\r /*
* (non-Javadoc)
* @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
- */\r @Override\r public void resetPropertyValue(Object id) {\r }\r
+ */\r @Override\r public void resetPropertyValue(Object id) {\r }
/*
* (non-Javadoc)
* @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
- */\r @Override\r public void setPropertyValue(Object id, Object value) {\r }\r
+ */\r @Override\r public void setPropertyValue(Object id, Object value) {\r }
/*
* (non-Javadoc)
* @see org.eclipse.ui.views.properties.IPropertySource2#isPropertyResettable(java.lang.Object)
- */\r @Override\r public boolean isPropertyResettable(Object id) {\r return false;\r }\r
+ */\r @Override\r public boolean isPropertyResettable(Object id) {\r return false;\r }
/*
* (non-Javadoc)
* @see org.eclipse.ui.views.properties.IPropertySource2#isPropertySet(java.lang.Object)
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.signal;\r
-\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-\r
-/**\r
- * Signal indicating a trace is now closed\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TmfTraceClosedSignal extends TmfSignal {\r
-\r
- private final ITmfTrace fTrace;\r
-\r
- /**\r
- * Constructor for a new signal\r
- *\r
- * @param source\r
- * The object sending this signal\r
- * @param trace\r
- * The trace being closed\r
- */\r
- public TmfTraceClosedSignal(Object source, ITmfTrace trace) {\r
- super(source);\r
- fTrace = trace;\r
- }\r
-\r
- /**\r
- * Get a reference to the trace being closed\r
- *\r
- * @return The trace object\r
- */\r
- public ITmfTrace getTrace() {\r
- return fTrace;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return "[TmfTraceClosedSignal (" + fTrace.getName() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.core.signal.TmfSignal;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+
+/**
+ * Signal indicating a trace is now closed
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TmfTraceClosedSignal extends TmfSignal {
+
+ private final ITmfTrace fTrace;
+
+ /**
+ * Constructor for a new signal
+ *
+ * @param source
+ * The object sending this signal
+ * @param trace
+ * The trace being closed
+ */
+ public TmfTraceClosedSignal(Object source, ITmfTrace trace) {
+ super(source);
+ fTrace = trace;
+ }
+
+ /**
+ * Get a reference to the trace being closed
+ *
+ * @return The trace object
+ */
+ public ITmfTrace getTrace() {
+ return fTrace;
+ }
+
+ @Override
+ public String toString() {
+ return "[TmfTraceClosedSignal (" + fTrace.getName() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.signal;\r
-\r
-import org.eclipse.core.resources.IFile;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-import org.eclipse.linuxtools.tmf.ui.viewers.events.ITmfEventsFilterProvider;\r
-\r
-/**\r
- * Signal indicating a trace has been opened.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TmfTraceOpenedSignal extends TmfSignal {\r
-\r
- private final ITmfTrace fTrace;\r
- private final IFile fBookmarksFile;\r
- private final ITmfEventsFilterProvider fEventsFilterProvider;\r
-\r
- /**\r
- * Constructor for a new signal.\r
- *\r
- * @param source\r
- * The object sending this signal\r
- * @param trace\r
- * The trace that has been opened\r
- * @param bookmarksFile\r
- * Pointer to the bookmark file\r
- * @param eventsFilterProvider\r
- * Provider for the event filter in use\r
- */\r
- public TmfTraceOpenedSignal(Object source, ITmfTrace trace,\r
- IFile bookmarksFile, ITmfEventsFilterProvider eventsFilterProvider) {\r
- super(source);\r
- fTrace = trace;\r
- fBookmarksFile = bookmarksFile;\r
- fEventsFilterProvider = eventsFilterProvider;\r
- }\r
-\r
- /**\r
- * Get the trace object concerning this signal\r
- *\r
- * @return The trace\r
- */\r
- public ITmfTrace getTrace() {\r
- return fTrace;\r
- }\r
-\r
- /**\r
- * Get a pointer to the bookmark file of this trace\r
- *\r
- * @return The IFile object\r
- */\r
- public IFile getBookmarksFile() {\r
- return fBookmarksFile;\r
- }\r
-\r
- /**\r
- * Get the events filter provider of this trace\r
- *\r
- * @return The EventsFilterProvider\r
- */\r
- public ITmfEventsFilterProvider getEventsFilterProvider() {\r
- return fEventsFilterProvider;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return "[TmfTraceOpenedSignal (" + fTrace.getName() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.IFile;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.ITmfEventsFilterProvider;
+
+/**
+ * Signal indicating a trace has been opened.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TmfTraceOpenedSignal extends TmfSignal {
+
+ private final ITmfTrace fTrace;
+ private final IFile fBookmarksFile;
+ private final ITmfEventsFilterProvider fEventsFilterProvider;
+
+ /**
+ * Constructor for a new signal.
+ *
+ * @param source
+ * The object sending this signal
+ * @param trace
+ * The trace that has been opened
+ * @param bookmarksFile
+ * Pointer to the bookmark file
+ * @param eventsFilterProvider
+ * Provider for the event filter in use
+ */
+ public TmfTraceOpenedSignal(Object source, ITmfTrace trace,
+ IFile bookmarksFile, ITmfEventsFilterProvider eventsFilterProvider) {
+ super(source);
+ fTrace = trace;
+ fBookmarksFile = bookmarksFile;
+ fEventsFilterProvider = eventsFilterProvider;
+ }
+
+ /**
+ * Get the trace object concerning this signal
+ *
+ * @return The trace
+ */
+ public ITmfTrace getTrace() {
+ return fTrace;
+ }
+
+ /**
+ * Get a pointer to the bookmark file of this trace
+ *
+ * @return The IFile object
+ */
+ public IFile getBookmarksFile() {
+ return fBookmarksFile;
+ }
+
+ /**
+ * Get the events filter provider of this trace
+ *
+ * @return The EventsFilterProvider
+ */
+ public ITmfEventsFilterProvider getEventsFilterProvider() {
+ return fEventsFilterProvider;
+ }
+
+ @Override
+ public String toString() {
+ return "[TmfTraceOpenedSignal (" + fTrace.getName() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.signal;\r
-\r
-import org.eclipse.core.resources.IResource;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;\r
-\r
-/**\r
- * Signal indicating the trace parser has finished reading a chunk, so the\r
- * parsing has been updated.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TmfTraceParserUpdatedSignal extends TmfSignal {\r
-\r
- private final IResource fTraceResource;\r
-\r
- /**\r
- * Constructor for the signal.\r
- *\r
- * @param source The object sending this signal\r
- * @param traceResource The trace resource concerning this signal\r
- */\r
- public TmfTraceParserUpdatedSignal(Object source, IResource traceResource) {\r
- super(source);\r
- fTraceResource = traceResource;\r
- }\r
-\r
- /**\r
- * Get the trace resource object of this signal.\r
- *\r
- * @return The trace resource.\r
- */\r
- public IResource getTraceResource() {\r
- return fTraceResource;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return "[TmfTraceParserUpdatedSignal (" + fTraceResource.getName() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.core.signal.TmfSignal;
+
+/**
+ * Signal indicating the trace parser has finished reading a chunk, so the
+ * parsing has been updated.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TmfTraceParserUpdatedSignal extends TmfSignal {
+
+ private final IResource fTraceResource;
+
+ /**
+ * Constructor for the signal.
+ *
+ * @param source The object sending this signal
+ * @param traceResource The trace resource concerning this signal
+ */
+ public TmfTraceParserUpdatedSignal(Object source, IResource traceResource) {
+ super(source);
+ fTraceResource = traceResource;
+ }
+
+ /**
+ * Get the trace resource object of this signal.
+ *
+ * @return The trace resource.
+ */
+ public IResource getTraceResource() {
+ return fTraceResource;
+ }
+
+ @Override
+ public String toString() {
+ return "[TmfTraceParserUpdatedSignal (" + fTraceResource.getName() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.viewers.events;\r
-\r
-import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-\r
-/**\r
- * A filter/search event listener\r
- * \r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public interface ITmfEventsFilterListener {\r
-\r
- /**\r
- * Notify this listener that a filter has been applied.\r
- *\r
- * @param filter\r
- * The filter that was applied\r
- * @param trace\r
- * The trace on which this filter is applied\r
- */\r
- public void filterApplied(ITmfFilter filter, ITmfTrace trace);\r
-\r
- /**\r
- * Notify this listener that a new search has been run.\r
- *\r
- * @param filter\r
- * The filter that was applied\r
- * @param trace\r
- * The trace on which this filter is applied\r
- */\r
- public void searchApplied(ITmfFilter filter, ITmfTrace trace);\r
-}\r
+/*******************************************************************************
+ * 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.core.filter.ITmfFilter;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+
+/**
+ * A filter/search event listener
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public interface ITmfEventsFilterListener {
+
+ /**
+ * Notify this listener that a filter has been applied.
+ *
+ * @param filter
+ * The filter that was applied
+ * @param trace
+ * The trace on which this filter is applied
+ */
+ public void filterApplied(ITmfFilter filter, ITmfTrace trace);
+
+ /**
+ * Notify this listener that a new search has been run.
+ *
+ * @param filter
+ * The filter that was applied
+ * @param trace
+ * The trace on which this filter is applied
+ */
+ public void searchApplied(ITmfFilter filter, ITmfTrace trace);
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.viewers.events;\r
-\r
-/**\r
- * A filter/search event provider\r
- * \r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public interface ITmfEventsFilterProvider {\r
-\r
- /**\r
- * Add a listener to this provider.\r
- *\r
- * @param listener\r
- * The listener to add\r
- */\r
- public void addEventsFilterListener(ITmfEventsFilterListener listener);\r
-\r
- /**\r
- * Remove a listener from this provider.\r
- *\r
- * @param listener\r
- * The listener to remove\r
- */\r
- public void removeEventsFilterListener (ITmfEventsFilterListener listener);\r
-\r
-}\r
+/*******************************************************************************
+ * 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;
+
+/**
+ * A filter/search event provider
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public interface ITmfEventsFilterProvider {
+
+ /**
+ * Add a listener to this provider.
+ *
+ * @param listener
+ * The listener to add
+ */
+ public void addEventsFilterListener(ITmfEventsFilterListener listener);
+
+ /**
+ * Remove a listener from this provider.
+ *
+ * @param listener
+ * The listener to remove
+ */
+ public void removeEventsFilterListener (ITmfEventsFilterListener listener);
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2011 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- ******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.viewers.events;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.List;\r
-\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.core.runtime.IStatus;\r
-import org.eclipse.core.runtime.Status;\r
-import org.eclipse.core.runtime.jobs.Job;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;\r
-import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-\r
-/**\r
- * The generic TMF Events table events cache\r
- *\r
- * This can help avoid re-reading the trace when the user scrolls a window,\r
- * for example.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TmfEventsCache {\r
-\r
- /**\r
- * The generic TMF Events table cached event\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
- public static class CachedEvent {\r
- ITmfEvent event;\r
- long rank;\r
-\r
- /**\r
- * Constructor for new cached events.\r
- *\r
- * @param iTmfEvent\r
- * The original trace event\r
- * @param rank\r
- * The rank of this event in the trace\r
- */\r
- public CachedEvent (ITmfEvent iTmfEvent, long rank) {\r
- this.event = iTmfEvent;\r
- this.rank = rank;\r
- }\r
- }\r
-\r
- private final CachedEvent[] fCache;\r
- private int fCacheStartIndex = 0;\r
- private int fCacheEndIndex = 0;\r
-\r
- private ITmfTrace fTrace;\r
- private final TmfEventsTable fTable;\r
- private ITmfFilter fFilter;\r
- private final List<Integer> fFilterIndex = new ArrayList<Integer>(); // contains the event rank at each 'cache size' filtered events\r
-\r
- /**\r
- * Constructor for the event cache\r
- *\r
- * @param cacheSize\r
- * The size of the cache, in number of events\r
- * @param table\r
- * The Events table this cache will cover\r
- */\r
- public TmfEventsCache(int cacheSize, TmfEventsTable table) {\r
- fCache = new CachedEvent[cacheSize];\r
- fTable = table;\r
- }\r
-\r
- /**\r
- * Assign a new trace to this events cache. This clears the current\r
- * contents.\r
- *\r
- * @param trace\r
- * The trace to assign.\r
- */\r
- public void setTrace(ITmfTrace trace) {\r
- fTrace = trace;\r
- clear();\r
- }\r
-\r
- /**\r
- * Clear the current contents of this cache.\r
- */\r
- public synchronized void clear() {\r
- Arrays.fill(fCache, null);\r
- fCacheStartIndex = 0;\r
- fCacheEndIndex = 0;\r
- fFilterIndex.clear();\r
- }\r
-\r
- /**\r
- * Apply a filter on this event cache. This clears the current cache\r
- * contents.\r
- *\r
- * @param filter\r
- * The ITmfFilter to apply.\r
- */\r
- public void applyFilter(ITmfFilter filter) {\r
- fFilter = filter;\r
- clear();\r
- }\r
-\r
- /**\r
- * Clear the current filter on this cache. This also clears the current\r
- * cache contents.\r
- */\r
- public void clearFilter() {\r
- fFilter = null;\r
- clear();\r
- }\r
-\r
- /**\r
- * Get an event from the cache. This will remove the event from the cache.\r
- *\r
- * FIXME this does not currently remove the event!\r
- *\r
- * @param index\r
- * The index of this event in the cache\r
- * @return The cached event, or 'null' if there is no event at that index\r
- */\r
- public synchronized CachedEvent getEvent(int index) {\r
- if ((index >= fCacheStartIndex) && (index < fCacheEndIndex)) {\r
- int i = index - fCacheStartIndex;\r
- return fCache[i];\r
- }\r
- populateCache(index);\r
- return null;\r
- }\r
-\r
- /**\r
- * Read an event, but without removing it from the cache.\r
- *\r
- * @param index\r
- * Index of the event to peek\r
- * @return A reference to the event, or 'null' if there is no event at this\r
- * index\r
- */\r
- public synchronized CachedEvent peekEvent(int index) {\r
- if ((index >= fCacheStartIndex) && (index < fCacheEndIndex)) {\r
- int i = index - fCacheStartIndex;\r
- return fCache[i];\r
- }\r
- return null;\r
- }\r
-\r
- /**\r
- * Add a trace event to the cache.\r
- *\r
- * @param event\r
- * The original trace event to be cached\r
- * @param rank\r
- * The rank of this event in the trace\r
- * @param index\r
- * The index this event will occupy in the cache\r
- */\r
- public synchronized void storeEvent(ITmfEvent event, long rank, int index) {\r
- if (index == fCacheEndIndex) {\r
- int i = index - fCacheStartIndex;\r
- if (i < fCache.length) {\r
- fCache[i] = new CachedEvent(event.clone(), rank);\r
- fCacheEndIndex++;\r
- }\r
- }\r
- if ((fFilter != null) && ((index % fCache.length) == 0)) {\r
- int i = index / fCache.length;\r
- fFilterIndex.add(i, Integer.valueOf((int) rank));\r
- }\r
- }\r
-\r
- /**\r
- * Get the cache index of an event from his rank in the trace. This will\r
- * take in consideration any filter that might be applied.\r
- *\r
- * @param rank\r
- * The rank of the event in the trace\r
- * @return The position (index) this event should use once cached\r
- */\r
- public int getFilteredEventIndex(final long rank) {\r
- int current;\r
- int startRank;\r
- TmfDataRequest request;\r
- final ITmfFilter filter = fFilter;\r
- synchronized (this) {\r
- int start = 0;\r
- int end = fFilterIndex.size();\r
-\r
- if ((fCacheEndIndex - fCacheStartIndex) > 1) {\r
- if (rank < fCache[0].rank) {\r
- end = (fCacheStartIndex / fCache.length) + 1;\r
- } else if (rank > fCache[fCacheEndIndex - fCacheStartIndex - 1].rank) {\r
- start = fCacheEndIndex / fCache.length;\r
- } else {\r
- for (int i = 0; i < (fCacheEndIndex - fCacheStartIndex); i++) {\r
- if (fCache[i].rank >= rank) {\r
- return fCacheStartIndex + i;\r
- }\r
- }\r
- return fCacheEndIndex;\r
- }\r
- }\r
-\r
- current = (start + end) / 2;\r
- while (current != start) {\r
- if (rank < fFilterIndex.get(current)) {\r
- end = current;\r
- current = (start + end) / 2;\r
- } else {\r
- start = current;\r
- current = (start + end) / 2;\r
- }\r
- }\r
- startRank = fFilterIndex.size() > 0 ? fFilterIndex.get(current) : 0;\r
- }\r
-\r
- final int index = current * fCache.length;\r
-\r
- class DataRequest extends TmfDataRequest {\r
- ITmfFilter fFilter;\r
- int fRank;\r
- int fIndex;\r
-\r
- DataRequest(Class<? extends ITmfEvent> dataType, ITmfFilter filter, int start, int nbRequested) {\r
- super(dataType, start, nbRequested);\r
- fFilter = filter;\r
- fRank = start;\r
- fIndex = index;\r
- }\r
-\r
- @Override\r
- public void handleData(ITmfEvent event) {\r
- super.handleData(event);\r
- if (isCancelled()) {\r
- return;\r
- }\r
- if (fRank >= rank) {\r
- cancel();\r
- return;\r
- }\r
- fRank++;\r
- if (fFilter.matches(event)) {\r
- fIndex++;\r
- }\r
- }\r
-\r
- public int getFilteredIndex() {\r
- return fIndex;\r
- }\r
- }\r
-\r
- request = new DataRequest(ITmfEvent.class, filter, startRank, TmfDataRequest.ALL_DATA);\r
- ((ITmfDataProvider) fTrace).sendRequest(request);\r
- try {\r
- request.waitForCompletion();\r
- return ((DataRequest) request).getFilteredIndex();\r
- } catch (InterruptedException e) {\r
- Activator.getDefault().logError("Filter request interrupted!", e); //$NON-NLS-1$\r
- }\r
- return 0;\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Event cache population\r
- // ------------------------------------------------------------------------\r
-\r
- // The event fetching job\r
- private Job job;\r
- private synchronized void populateCache(final int index) {\r
-\r
- /* Check if the current job will fetch the requested event:\r
- * 1. The job must exist\r
- * 2. It must be running (i.e. not completed)\r
- * 3. The requested index must be within the cache range\r
- *\r
- * If the job meets these conditions, we simply exit.\r
- * Otherwise, we create a new job but we might have to cancel\r
- * an existing job for an obsolete range.\r
- */\r
- if (job != null) {\r
- if (job.getState() != Job.NONE) {\r
- if ((index >= fCacheStartIndex) && (index < (fCacheStartIndex + fCache.length))) {\r
- return;\r
- }\r
- // The new index is out of the requested range\r
- // Kill the job and start a new one\r
- job.cancel();\r
- }\r
- }\r
-\r
- fCacheStartIndex = index;\r
- fCacheEndIndex = index;\r
-\r
- job = new Job("Fetching Events") { //$NON-NLS-1$\r
- private int startIndex = index;\r
- private int skipCount = 0;\r
- @Override\r
- protected IStatus run(final IProgressMonitor monitor) {\r
-\r
- int nbRequested;\r
- if (fFilter == null) {\r
- nbRequested = fCache.length;\r
- } else {\r
- nbRequested = TmfDataRequest.ALL_DATA;\r
- int i = index / fCache.length;\r
- if (i < fFilterIndex.size()) {\r
- startIndex = fFilterIndex.get(i);\r
- skipCount = index - (i * fCache.length);\r
- }\r
- }\r
-\r
- TmfDataRequest request = new TmfDataRequest(ITmfEvent.class, startIndex, nbRequested) {\r
- private int count = 0;\r
- private long rank = startIndex;\r
- @Override\r
- public void handleData(ITmfEvent event) {\r
- // If the job is canceled, cancel the request so waitForCompletion() will unlock\r
- if (monitor.isCanceled()) {\r
- cancel();\r
- return;\r
- }\r
- super.handleData(event);\r
- if (event != null) {\r
- if (((fFilter == null) || fFilter.matches(event)) && (skipCount-- <= 0)) {\r
- synchronized (TmfEventsCache.this) {\r
- fCache[count] = new CachedEvent(event.clone(), rank);\r
- count++;\r
- fCacheEndIndex++;\r
- }\r
- if (fFilter != null) {\r
- fTable.cacheUpdated(false);\r
- }\r
- }\r
- }\r
- if (count >= fCache.length) {\r
- cancel();\r
- } else if ((fFilter != null) && (count >= (fTable.getTable().getItemCount() - 3))) { // -1 for header row, -2 for top and bottom filter status rows\r
- cancel();\r
- }\r
- rank++;\r
- }\r
- };\r
-\r
- ((ITmfDataProvider) fTrace).sendRequest(request);\r
- try {\r
- request.waitForCompletion();\r
- } catch (InterruptedException e) {\r
- Activator.getDefault().logError("Wait for completion interrupted for populateCache ", e); //$NON-NLS-1$\r
- }\r
-\r
- fTable.cacheUpdated(true);\r
-\r
- // Flag the UI thread that the cache is ready\r
- if (monitor.isCanceled()) {\r
- return Status.CANCEL_STATUS;\r
- }\r
- return Status.OK_STATUS;\r
- }\r
- };\r
- //job.setSystem(true);\r
- job.setPriority(Job.SHORT);\r
- job.schedule();\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2011 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 java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
+import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+
+/**
+ * The generic TMF Events table events cache
+ *
+ * This can help avoid re-reading the trace when the user scrolls a window,
+ * for example.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TmfEventsCache {
+
+ /**
+ * The generic TMF Events table cached event
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+ public static class CachedEvent {
+ ITmfEvent event;
+ long rank;
+
+ /**
+ * Constructor for new cached events.
+ *
+ * @param iTmfEvent
+ * The original trace event
+ * @param rank
+ * The rank of this event in the trace
+ */
+ public CachedEvent (ITmfEvent iTmfEvent, long rank) {
+ this.event = iTmfEvent;
+ this.rank = rank;
+ }
+ }
+
+ private final CachedEvent[] fCache;
+ private int fCacheStartIndex = 0;
+ private int fCacheEndIndex = 0;
+
+ private ITmfTrace fTrace;
+ private final TmfEventsTable fTable;
+ private ITmfFilter fFilter;
+ private final List<Integer> fFilterIndex = new ArrayList<Integer>(); // contains the event rank at each 'cache size' filtered events
+
+ /**
+ * Constructor for the event cache
+ *
+ * @param cacheSize
+ * The size of the cache, in number of events
+ * @param table
+ * The Events table this cache will cover
+ */
+ public TmfEventsCache(int cacheSize, TmfEventsTable table) {
+ fCache = new CachedEvent[cacheSize];
+ fTable = table;
+ }
+
+ /**
+ * Assign a new trace to this events cache. This clears the current
+ * contents.
+ *
+ * @param trace
+ * The trace to assign.
+ */
+ public void setTrace(ITmfTrace trace) {
+ fTrace = trace;
+ clear();
+ }
+
+ /**
+ * Clear the current contents of this cache.
+ */
+ public synchronized void clear() {
+ Arrays.fill(fCache, null);
+ fCacheStartIndex = 0;
+ fCacheEndIndex = 0;
+ fFilterIndex.clear();
+ }
+
+ /**
+ * Apply a filter on this event cache. This clears the current cache
+ * contents.
+ *
+ * @param filter
+ * The ITmfFilter to apply.
+ */
+ public void applyFilter(ITmfFilter filter) {
+ fFilter = filter;
+ clear();
+ }
+
+ /**
+ * Clear the current filter on this cache. This also clears the current
+ * cache contents.
+ */
+ public void clearFilter() {
+ fFilter = null;
+ clear();
+ }
+
+ /**
+ * Get an event from the cache. This will remove the event from the cache.
+ *
+ * FIXME this does not currently remove the event!
+ *
+ * @param index
+ * The index of this event in the cache
+ * @return The cached event, or 'null' if there is no event at that index
+ */
+ public synchronized CachedEvent getEvent(int index) {
+ if ((index >= fCacheStartIndex) && (index < fCacheEndIndex)) {
+ int i = index - fCacheStartIndex;
+ return fCache[i];
+ }
+ populateCache(index);
+ return null;
+ }
+
+ /**
+ * Read an event, but without removing it from the cache.
+ *
+ * @param index
+ * Index of the event to peek
+ * @return A reference to the event, or 'null' if there is no event at this
+ * index
+ */
+ public synchronized CachedEvent peekEvent(int index) {
+ if ((index >= fCacheStartIndex) && (index < fCacheEndIndex)) {
+ int i = index - fCacheStartIndex;
+ return fCache[i];
+ }
+ return null;
+ }
+
+ /**
+ * Add a trace event to the cache.
+ *
+ * @param event
+ * The original trace event to be cached
+ * @param rank
+ * The rank of this event in the trace
+ * @param index
+ * The index this event will occupy in the cache
+ */
+ public synchronized void storeEvent(ITmfEvent event, long rank, int index) {
+ if (index == fCacheEndIndex) {
+ int i = index - fCacheStartIndex;
+ if (i < fCache.length) {
+ fCache[i] = new CachedEvent(event.clone(), rank);
+ fCacheEndIndex++;
+ }
+ }
+ if ((fFilter != null) && ((index % fCache.length) == 0)) {
+ int i = index / fCache.length;
+ fFilterIndex.add(i, Integer.valueOf((int) rank));
+ }
+ }
+
+ /**
+ * Get the cache index of an event from his rank in the trace. This will
+ * take in consideration any filter that might be applied.
+ *
+ * @param rank
+ * The rank of the event in the trace
+ * @return The position (index) this event should use once cached
+ */
+ public int getFilteredEventIndex(final long rank) {
+ int current;
+ int startRank;
+ TmfDataRequest request;
+ final ITmfFilter filter = fFilter;
+ synchronized (this) {
+ int start = 0;
+ int end = fFilterIndex.size();
+
+ if ((fCacheEndIndex - fCacheStartIndex) > 1) {
+ if (rank < fCache[0].rank) {
+ end = (fCacheStartIndex / fCache.length) + 1;
+ } else if (rank > fCache[fCacheEndIndex - fCacheStartIndex - 1].rank) {
+ start = fCacheEndIndex / fCache.length;
+ } else {
+ for (int i = 0; i < (fCacheEndIndex - fCacheStartIndex); i++) {
+ if (fCache[i].rank >= rank) {
+ return fCacheStartIndex + i;
+ }
+ }
+ return fCacheEndIndex;
+ }
+ }
+
+ current = (start + end) / 2;
+ while (current != start) {
+ if (rank < fFilterIndex.get(current)) {
+ end = current;
+ current = (start + end) / 2;
+ } else {
+ start = current;
+ current = (start + end) / 2;
+ }
+ }
+ startRank = fFilterIndex.size() > 0 ? fFilterIndex.get(current) : 0;
+ }
+
+ final int index = current * fCache.length;
+
+ class DataRequest extends TmfDataRequest {
+ ITmfFilter fFilter;
+ int fRank;
+ int fIndex;
+
+ DataRequest(Class<? extends ITmfEvent> dataType, ITmfFilter filter, int start, int nbRequested) {
+ super(dataType, start, nbRequested);
+ fFilter = filter;
+ fRank = start;
+ fIndex = index;
+ }
+
+ @Override
+ public void handleData(ITmfEvent event) {
+ super.handleData(event);
+ if (isCancelled()) {
+ return;
+ }
+ if (fRank >= rank) {
+ cancel();
+ return;
+ }
+ fRank++;
+ if (fFilter.matches(event)) {
+ fIndex++;
+ }
+ }
+
+ public int getFilteredIndex() {
+ return fIndex;
+ }
+ }
+
+ request = new DataRequest(ITmfEvent.class, filter, startRank, TmfDataRequest.ALL_DATA);
+ ((ITmfDataProvider) fTrace).sendRequest(request);
+ try {
+ request.waitForCompletion();
+ return ((DataRequest) request).getFilteredIndex();
+ } catch (InterruptedException e) {
+ Activator.getDefault().logError("Filter request interrupted!", e); //$NON-NLS-1$
+ }
+ return 0;
+ }
+
+ // ------------------------------------------------------------------------
+ // Event cache population
+ // ------------------------------------------------------------------------
+
+ // The event fetching job
+ private Job job;
+ private synchronized void populateCache(final int index) {
+
+ /* Check if the current job will fetch the requested event:
+ * 1. The job must exist
+ * 2. It must be running (i.e. not completed)
+ * 3. The requested index must be within the cache range
+ *
+ * If the job meets these conditions, we simply exit.
+ * Otherwise, we create a new job but we might have to cancel
+ * an existing job for an obsolete range.
+ */
+ if (job != null) {
+ if (job.getState() != Job.NONE) {
+ if ((index >= fCacheStartIndex) && (index < (fCacheStartIndex + fCache.length))) {
+ return;
+ }
+ // The new index is out of the requested range
+ // Kill the job and start a new one
+ job.cancel();
+ }
+ }
+
+ fCacheStartIndex = index;
+ fCacheEndIndex = index;
+
+ job = new Job("Fetching Events") { //$NON-NLS-1$
+ private int startIndex = index;
+ private int skipCount = 0;
+ @Override
+ protected IStatus run(final IProgressMonitor monitor) {
+
+ int nbRequested;
+ if (fFilter == null) {
+ nbRequested = fCache.length;
+ } else {
+ nbRequested = TmfDataRequest.ALL_DATA;
+ int i = index / fCache.length;
+ if (i < fFilterIndex.size()) {
+ startIndex = fFilterIndex.get(i);
+ skipCount = index - (i * fCache.length);
+ }
+ }
+
+ TmfDataRequest request = new TmfDataRequest(ITmfEvent.class, startIndex, nbRequested) {
+ private int count = 0;
+ private long rank = startIndex;
+ @Override
+ public void handleData(ITmfEvent event) {
+ // If the job is canceled, cancel the request so waitForCompletion() will unlock
+ if (monitor.isCanceled()) {
+ cancel();
+ return;
+ }
+ super.handleData(event);
+ if (event != null) {
+ if (((fFilter == null) || fFilter.matches(event)) && (skipCount-- <= 0)) {
+ synchronized (TmfEventsCache.this) {
+ if (monitor.isCanceled()) {
+ return;
+ }
+ fCache[count] = new CachedEvent(event.clone(), rank);
+ count++;
+ fCacheEndIndex++;
+ }
+ if (fFilter != null) {
+ fTable.cacheUpdated(false);
+ }
+ }
+ }
+ if (count >= fCache.length) {
+ cancel();
+ } else if ((fFilter != null) && (count >= (fTable.getTable().getItemCount() - 3))) { // -1 for header row, -2 for top and bottom filter status rows
+ cancel();
+ }
+ rank++;
+ }
+ };
+
+ ((ITmfDataProvider) fTrace).sendRequest(request);
+ try {
+ request.waitForCompletion();
+ } catch (InterruptedException e) {
+ Activator.getDefault().logError("Wait for completion interrupted for populateCache ", e); //$NON-NLS-1$
+ }
+
+ fTable.cacheUpdated(true);
+
+ // Flag the UI thread that the cache is ready
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ //job.setSystem(true);
+ job.setPriority(Job.SHORT);
+ job.schedule();
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010, 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- * Bernd Hufmann - Updated to use RGB for the tick color\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.colors;\r
-\r
-import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.graphics.Color;\r
-import org.eclipse.swt.graphics.RGB;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.ui.themes.ColorUtil;\r
-\r
-/**\r
- * Class for storing color settings of a TMF filter.\r
- *\r
- * Application code must explicitly invoke the ColorSetting.dispose() method to release the operating system\r
- * resources managed by each instance when those instances are no longer required.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class ColorSetting {\r
-\r
- private RGB fForegroundRGB;\r
- private RGB fBackgroundRGB;\r
- private RGB fTickColorRGB;\r
- private Color fForegroundColor;\r
- private Color fBackgroundColor;\r
- private Color fDimmedForegroundColor;\r
- private Color fDimmedBackgroundColor;\r
- private Color fTickColor;\r
- private ITmfFilterTreeNode fFilter;\r
-\r
- /**\r
- * Constructor\r
- *\r
- * You must dispose the color setting when it is no longer required.\r
- *\r
- * @param foreground\r
- * The foreground color\r
- * @param background\r
- * The background color\r
- * @param tickColorRGB\r
- * The color for the checkbox ticks\r
- * @param filter\r
- * The filter tree node\r
- */\r
- public ColorSetting(RGB foreground, RGB background, RGB tickColorRGB, ITmfFilterTreeNode filter) {\r
- fForegroundRGB = foreground;\r
- fBackgroundRGB = background;\r
- fTickColorRGB = tickColorRGB;\r
- fFilter = filter;\r
- Display display = Display.getDefault();\r
- fForegroundColor = new Color(display, fForegroundRGB);\r
- fBackgroundColor = new Color(display, fBackgroundRGB);\r
- fDimmedForegroundColor = new Color(display, ColorUtil.blend(\r
- fForegroundRGB, fBackgroundRGB));\r
- fDimmedBackgroundColor = new Color(display, ColorUtil.blend(\r
- fBackgroundRGB, display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB()));\r
- fTickColor = new Color(display, fTickColorRGB);\r
- }\r
-\r
- /**\r
- * Dispose the color setting resources\r
- */\r
- public void dispose() {\r
- fForegroundColor.dispose();\r
- fBackgroundColor.dispose();\r
- fDimmedForegroundColor.dispose();\r
- fDimmedBackgroundColor.dispose();\r
- fTickColor.dispose();\r
- }\r
-\r
- /**\r
- * Returns foreground RGB value.\r
- *\r
- * @return the foreground RGB\r
- */\r
- public RGB getForegroundRGB() {\r
- return fForegroundRGB;\r
- }\r
-\r
- /**\r
- * Sets the foreground RGB value\r
- *\r
- * @param foreground the foreground to set\r
- */\r
- public void setForegroundRGB(RGB foreground) {\r
- fForegroundRGB = foreground;\r
- fForegroundColor.dispose();\r
- fDimmedForegroundColor.dispose();\r
- Display display = Display.getDefault();\r
- fForegroundColor = new Color(display, fForegroundRGB);\r
- fDimmedForegroundColor = new Color(display, ColorUtil.blend(\r
- fForegroundRGB, fBackgroundRGB));\r
- }\r
-\r
- /**\r
- * Returns the background RGB value.\r
- *\r
- * @return the background RGB\r
- */\r
- public RGB getBackgroundRGB() {\r
- return fBackgroundRGB;\r
- }\r
-\r
- /**\r
- * Sets the background RGB value.\r
- *\r
- * @param background the background to set\r
- */\r
- public void setBackgroundRGB(RGB background) {\r
- fBackgroundRGB = background;\r
- fBackgroundColor.dispose();\r
- fDimmedBackgroundColor.dispose();\r
- Display display = Display.getDefault();\r
- fBackgroundColor = new Color(display, fBackgroundRGB);\r
- fDimmedBackgroundColor = new Color(display, ColorUtil.blend(\r
- fBackgroundRGB, display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB()));\r
- }\r
-\r
- /**\r
- * Returns the RGB of the tick color\r
- *\r
- * @return the RGB of the tick color\r
- */\r
- public RGB getTickColorRGB() {\r
- return fTickColorRGB;\r
- }\r
-\r
- /**\r
- * Sets the RGB of the tick color\r
- *\r
- * @param tickColorRGB the tick color TGB\r
- */\r
- public void setTickColorRGB(RGB tickColorRGB) {\r
- fTickColorRGB = tickColorRGB;\r
- fTickColor.dispose();\r
- Display display = Display.getDefault();\r
- fTickColor = new Color(display, fTickColorRGB);\r
- }\r
-\r
- /**\r
- * Returns the filter implementation.\r
- * @return the filter\r
- */\r
- public ITmfFilterTreeNode getFilter() {\r
- return fFilter;\r
- }\r
-\r
- /**\r
- * Sets the filter implementation.\r
- *\r
- * @param filter the filter to set\r
- */\r
- public void setFilter(ITmfFilterTreeNode filter) {\r
- fFilter = filter;\r
- }\r
-\r
- /**\r
- * Returns the foreground color.\r
- *\r
- * @return the foreground color\r
- */\r
- public Color getForegroundColor() {\r
- return fForegroundColor;\r
- }\r
-\r
- /**\r
- * Returns the background color.\r
- *\r
- * @return the background color\r
- */\r
- public Color getBackgroundColor() {\r
- return fBackgroundColor;\r
- }\r
-\r
- /**\r
- * Returns the dimmed foreground color.\r
- *\r
- * @return the dimmed foreground color\r
- */\r
- public Color getDimmedForegroundColor() {\r
- return fDimmedForegroundColor;\r
- }\r
-\r
- /**\r
- * Returns the dimmed background color.\r
- *\r
- * @return the dimmed background color\r
- */\r
- public Color getDimmedBackgroundColor() {\r
- return fDimmedBackgroundColor;\r
- }\r
-\r
- /**\r
- * Returns the tick color.\r
- *\r
- * @return the tick color\r
- */\r
- public Color getTickColor() {\r
- return fTickColor;\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2010, 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ * Bernd Hufmann - Updated to use RGB for the tick color
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.views.colors;
+
+import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.themes.ColorUtil;
+
+/**
+ * Class for storing color settings of a TMF filter.
+ *
+ * Application code must explicitly invoke the ColorSetting.dispose() method to release the operating system
+ * resources managed by each instance when those instances are no longer required.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class ColorSetting {
+
+ private RGB fForegroundRGB;
+ private RGB fBackgroundRGB;
+ private RGB fTickColorRGB;
+ private Color fForegroundColor;
+ private Color fBackgroundColor;
+ private Color fDimmedForegroundColor;
+ private Color fDimmedBackgroundColor;
+ private Color fTickColor;
+ private ITmfFilterTreeNode fFilter;
+
+ /**
+ * Constructor
+ *
+ * You must dispose the color setting when it is no longer required.
+ *
+ * @param foreground
+ * The foreground color
+ * @param background
+ * The background color
+ * @param tickColorRGB
+ * The color for the checkbox ticks
+ * @param filter
+ * The filter tree node
+ */
+ public ColorSetting(RGB foreground, RGB background, RGB tickColorRGB, ITmfFilterTreeNode filter) {
+ fForegroundRGB = foreground;
+ fBackgroundRGB = background;
+ fTickColorRGB = tickColorRGB;
+ fFilter = filter;
+ Display display = Display.getDefault();
+ fForegroundColor = new Color(display, fForegroundRGB);
+ fBackgroundColor = new Color(display, fBackgroundRGB);
+ fDimmedForegroundColor = new Color(display, ColorUtil.blend(
+ fForegroundRGB, fBackgroundRGB));
+ fDimmedBackgroundColor = new Color(display, ColorUtil.blend(
+ fBackgroundRGB, display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB()));
+ fTickColor = new Color(display, fTickColorRGB);
+ }
+
+ /**
+ * Dispose the color setting resources
+ */
+ public void dispose() {
+ fForegroundColor.dispose();
+ fBackgroundColor.dispose();
+ fDimmedForegroundColor.dispose();
+ fDimmedBackgroundColor.dispose();
+ fTickColor.dispose();
+ }
+
+ /**
+ * Returns foreground RGB value.
+ *
+ * @return the foreground RGB
+ */
+ public RGB getForegroundRGB() {
+ return fForegroundRGB;
+ }
+
+ /**
+ * Sets the foreground RGB value
+ *
+ * @param foreground the foreground to set
+ */
+ public void setForegroundRGB(RGB foreground) {
+ fForegroundRGB = foreground;
+ fForegroundColor.dispose();
+ fDimmedForegroundColor.dispose();
+ Display display = Display.getDefault();
+ fForegroundColor = new Color(display, fForegroundRGB);
+ fDimmedForegroundColor = new Color(display, ColorUtil.blend(
+ fForegroundRGB, fBackgroundRGB));
+ }
+
+ /**
+ * Returns the background RGB value.
+ *
+ * @return the background RGB
+ */
+ public RGB getBackgroundRGB() {
+ return fBackgroundRGB;
+ }
+
+ /**
+ * Sets the background RGB value.
+ *
+ * @param background the background to set
+ */
+ public void setBackgroundRGB(RGB background) {
+ fBackgroundRGB = background;
+ fBackgroundColor.dispose();
+ fDimmedBackgroundColor.dispose();
+ Display display = Display.getDefault();
+ fBackgroundColor = new Color(display, fBackgroundRGB);
+ fDimmedBackgroundColor = new Color(display, ColorUtil.blend(
+ fBackgroundRGB, display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB()));
+ }
+
+ /**
+ * Returns the RGB of the tick color
+ *
+ * @return the RGB of the tick color
+ */
+ public RGB getTickColorRGB() {
+ return fTickColorRGB;
+ }
+
+ /**
+ * Sets the RGB of the tick color
+ *
+ * @param tickColorRGB the tick color TGB
+ */
+ public void setTickColorRGB(RGB tickColorRGB) {
+ fTickColorRGB = tickColorRGB;
+ fTickColor.dispose();
+ Display display = Display.getDefault();
+ fTickColor = new Color(display, fTickColorRGB);
+ }
+
+ /**
+ * Returns the filter implementation.
+ * @return the filter
+ */
+ public ITmfFilterTreeNode getFilter() {
+ return fFilter;
+ }
+
+ /**
+ * Sets the filter implementation.
+ *
+ * @param filter the filter to set
+ */
+ public void setFilter(ITmfFilterTreeNode filter) {
+ fFilter = filter;
+ }
+
+ /**
+ * Returns the foreground color.
+ *
+ * @return the foreground color
+ */
+ public Color getForegroundColor() {
+ return fForegroundColor;
+ }
+
+ /**
+ * Returns the background color.
+ *
+ * @return the background color
+ */
+ public Color getBackgroundColor() {
+ return fBackgroundColor;
+ }
+
+ /**
+ * Returns the dimmed foreground color.
+ *
+ * @return the dimmed foreground color
+ */
+ public Color getDimmedForegroundColor() {
+ return fDimmedForegroundColor;
+ }
+
+ /**
+ * Returns the dimmed background color.
+ *
+ * @return the dimmed background color
+ */
+ public Color getDimmedBackgroundColor() {
+ return fDimmedBackgroundColor;
+ }
+
+ /**
+ * Returns the tick color.
+ *
+ * @return the tick color
+ */
+ public Color getTickColor() {
+ return fTickColor;
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010, 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- * Bernd Hufmann - Updated to use RGB for the tick color\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.colors;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.List;\r
-\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.widgets.Display;\r
-\r
-/**\r
- * Static class for managing color settings.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- *\r
- */\r
-public class ColorSettingsManager {\r
-\r
- // The color settings file name\r
- private static final String COLOR_SETTINGS_FILE_NAME = "color_settings.xml"; //$NON-NLS-1$\r
-\r
- // The path for the color settings file\r
- private static final String COLOR_SETTINGS_PATH_NAME =\r
- Activator.getDefault().getStateLocation().addTrailingSeparator().append(COLOR_SETTINGS_FILE_NAME).toString();\r
-\r
- // The default color setting\r
- private static final ColorSetting DEFAULT_COLOR_SETTING = new ColorSetting(\r
- Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(),\r
- Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(),\r
- Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(),\r
- null);\r
-\r
- /**\r
- * Special value for priority if unknown.\r
- */\r
- public static final int PRIORITY_NONE = Integer.MAX_VALUE;\r
-\r
- // The stored color settings\r
- private static ColorSetting[] fColorSettings = ColorSettingsXML.load(COLOR_SETTINGS_PATH_NAME);\r
-\r
- // The listener list\r
- private static List<IColorSettingsListener> fListeners = new ArrayList<IColorSettingsListener>();\r
-\r
- /**\r
- * Returns an array of color settings.\r
- *\r
- * @return an array of color settings.\r
- */\r
- public static ColorSetting[] getColorSettings() {\r
- return (fColorSettings != null) ? Arrays.copyOf(fColorSettings, fColorSettings.length) : null;\r
- }\r
-\r
- /**\r
- * Sets the array of color settings.\r
- *\r
- * @param colorSettings A array of color settings to set\r
- */\r
- public static void setColorSettings(ColorSetting[] colorSettings) {\r
- fColorSettings = (colorSettings != null) ? Arrays.copyOf(colorSettings, colorSettings.length) : null;\r
- ColorSettingsXML.save(COLOR_SETTINGS_PATH_NAME, fColorSettings);\r
- fireColorSettingsChanged();\r
- }\r
-\r
- /**\r
- * Gets the color settings that matches the filter for given event.\r
- *\r
- * @param event\r
- * The event to check\r
- *\r
- * @return color settings defined for filter if found else default color\r
- * settings\r
- */\r
- public static ColorSetting getColorSetting(ITmfEvent event) {\r
- for (int i = 0; i < fColorSettings.length; i++) {\r
- ColorSetting colorSetting = fColorSettings[i];\r
- if (colorSetting.getFilter() != null && colorSetting.getFilter().matches(event)) {\r
- return colorSetting;\r
- }\r
- }\r
- return DEFAULT_COLOR_SETTING;\r
- }\r
-\r
- /**\r
- * Gets the color settings priority for the given event.\r
- *\r
- * @param event A event the event to check\r
- * @return the priority defined for the filter else PRIORITY_NONE\r
- */\r
- public static int getColorSettingPriority(ITmfEvent event) {\r
- for (int i = 0; i < fColorSettings.length; i++) {\r
- ColorSetting colorSetting = fColorSettings[i];\r
- if (colorSetting.getFilter() != null && colorSetting.getFilter().matches(event)) {\r
- return i;\r
- }\r
- }\r
- return PRIORITY_NONE;\r
- }\r
-\r
- /**\r
- * Returns the color settings based the priority.\r
- *\r
- * @param priority A priority (index) of color settings\r
- * @return the color settings defined for the priority else default color settings\r
- */\r
- public static ColorSetting getColorSetting(int priority) {\r
- if (priority < fColorSettings.length) {\r
- return fColorSettings[priority];\r
- }\r
- return DEFAULT_COLOR_SETTING;\r
- }\r
-\r
- /**\r
- * Adds a color settings listener.\r
- *\r
- * @param listener A listener to add.\r
- */\r
- public static void addColorSettingsListener(IColorSettingsListener listener) {\r
- if (! fListeners.contains(listener)) {\r
- fListeners.add(listener);\r
- }\r
- }\r
-\r
- /**\r
- * Removes a color settings listener.\r
- *\r
- * @param listener A listener to remove.\r
- */\r
- public static void removeColorSettingsListener(IColorSettingsListener listener) {\r
- fListeners.remove(listener);\r
- }\r
-\r
- // Notify listeners\r
- private static void fireColorSettingsChanged() {\r
- for (IColorSettingsListener listener : fListeners) {\r
- listener.colorSettingsChanged(fColorSettings);\r
- }\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2010, 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ * Bernd Hufmann - Updated to use RGB for the tick color
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.views.colors;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Static class for managing color settings.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ *
+ */
+public class ColorSettingsManager {
+
+ // The color settings file name
+ private static final String COLOR_SETTINGS_FILE_NAME = "color_settings.xml"; //$NON-NLS-1$
+
+ // The path for the color settings file
+ private static final String COLOR_SETTINGS_PATH_NAME =
+ Activator.getDefault().getStateLocation().addTrailingSeparator().append(COLOR_SETTINGS_FILE_NAME).toString();
+
+ // The default color setting
+ private static final ColorSetting DEFAULT_COLOR_SETTING = new ColorSetting(
+ Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(),
+ Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(),
+ Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(),
+ null);
+
+ /**
+ * Special value for priority if unknown.
+ */
+ public static final int PRIORITY_NONE = Integer.MAX_VALUE;
+
+ // The stored color settings
+ private static ColorSetting[] fColorSettings = ColorSettingsXML.load(COLOR_SETTINGS_PATH_NAME);
+
+ // The listener list
+ private static List<IColorSettingsListener> fListeners = new ArrayList<IColorSettingsListener>();
+
+ /**
+ * Returns an array of color settings.
+ *
+ * @return an array of color settings.
+ */
+ public static ColorSetting[] getColorSettings() {
+ return (fColorSettings != null) ? Arrays.copyOf(fColorSettings, fColorSettings.length) : null;
+ }
+
+ /**
+ * Sets the array of color settings.
+ *
+ * @param colorSettings A array of color settings to set
+ */
+ public static void setColorSettings(ColorSetting[] colorSettings) {
+ fColorSettings = (colorSettings != null) ? Arrays.copyOf(colorSettings, colorSettings.length) : null;
+ ColorSettingsXML.save(COLOR_SETTINGS_PATH_NAME, fColorSettings);
+ fireColorSettingsChanged();
+ }
+
+ /**
+ * Gets the color settings that matches the filter for given event.
+ *
+ * @param event
+ * The event to check
+ *
+ * @return color settings defined for filter if found else default color
+ * settings
+ */
+ public static ColorSetting getColorSetting(ITmfEvent event) {
+ for (int i = 0; i < fColorSettings.length; i++) {
+ ColorSetting colorSetting = fColorSettings[i];
+ if (colorSetting.getFilter() != null && colorSetting.getFilter().matches(event)) {
+ return colorSetting;
+ }
+ }
+ return DEFAULT_COLOR_SETTING;
+ }
+
+ /**
+ * Gets the color settings priority for the given event.
+ *
+ * @param event A event the event to check
+ * @return the priority defined for the filter else PRIORITY_NONE
+ */
+ public static int getColorSettingPriority(ITmfEvent event) {
+ for (int i = 0; i < fColorSettings.length; i++) {
+ ColorSetting colorSetting = fColorSettings[i];
+ if (colorSetting.getFilter() != null && colorSetting.getFilter().matches(event)) {
+ return i;
+ }
+ }
+ return PRIORITY_NONE;
+ }
+
+ /**
+ * Returns the color settings based the priority.
+ *
+ * @param priority A priority (index) of color settings
+ * @return the color settings defined for the priority else default color settings
+ */
+ public static ColorSetting getColorSetting(int priority) {
+ if (priority < fColorSettings.length) {
+ return fColorSettings[priority];
+ }
+ return DEFAULT_COLOR_SETTING;
+ }
+
+ /**
+ * Adds a color settings listener.
+ *
+ * @param listener A listener to add.
+ */
+ public static void addColorSettingsListener(IColorSettingsListener listener) {
+ if (! fListeners.contains(listener)) {
+ fListeners.add(listener);
+ }
+ }
+
+ /**
+ * Removes a color settings listener.
+ *
+ * @param listener A listener to remove.
+ */
+ public static void removeColorSettingsListener(IColorSettingsListener listener) {
+ fListeners.remove(listener);
+ }
+
+ // Notify listeners
+ private static void fireColorSettingsChanged() {
+ for (IColorSettingsListener listener : fListeners) {
+ listener.colorSettingsChanged(fColorSettings);
+ }
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010, 2012 Ericsson\r
- * \r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- * \r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- * Bernd Hufmann - Updated to use RGB for the tick color\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.colors;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import javax.xml.parsers.DocumentBuilder;\r
-import javax.xml.parsers.DocumentBuilderFactory;\r
-import javax.xml.parsers.ParserConfigurationException;\r
-import javax.xml.parsers.SAXParserFactory;\r
-import javax.xml.transform.Transformer;\r
-import javax.xml.transform.TransformerConfigurationException;\r
-import javax.xml.transform.TransformerException;\r
-import javax.xml.transform.TransformerFactory;\r
-import javax.xml.transform.dom.DOMSource;\r
-import javax.xml.transform.stream.StreamResult;\r
-\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterContentHandler;\r
-import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLWriter;\r
-import org.eclipse.swt.graphics.RGB;\r
-import org.w3c.dom.Document;\r
-import org.w3c.dom.Element;\r
-import org.xml.sax.Attributes;\r
-import org.xml.sax.SAXException;\r
-import org.xml.sax.XMLReader;\r
-import org.xml.sax.helpers.DefaultHandler;\r
-\r
-/**\r
- * Class for saving and loading of color settings to/from file.\r
- * \r
- * @version 1.0\r
- * @author Patrick Tasse\r
- *\r
- */\r
-public class ColorSettingsXML {\r
-\r
- // XML Tags and attributes\r
- private static final String COLOR_SETTINGS_TAG = "COLOR_SETTINGS"; //$NON-NLS-1$\r
- private static final String COLOR_SETTING_TAG = "COLOR_SETTING"; //$NON-NLS-1$\r
- private static final String FG_TAG = "FG"; //$NON-NLS-1$\r
- private static final String BG_TAG = "BG"; //$NON-NLS-1$\r
- private static final String R_ATTR = "R"; //$NON-NLS-1$\r
- private static final String G_ATTR = "G"; //$NON-NLS-1$\r
- private static final String B_ATTR = "B"; //$NON-NLS-1$\r
- private static final String TICK_TAG = "TICK"; //$NON-NLS-1$\r
- private static final String FILTER_TAG = "FILTER"; //$NON-NLS-1$\r
-\r
- /**\r
- * Saves the given color settings to file.\r
- * \r
- * @param pathName A file name with path \r
- * @param colorSettings -An array of color settings to save.\r
- */\r
- public static void save(String pathName, ColorSetting[] colorSettings) {\r
- try {\r
- DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();\r
- DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();\r
- Document document = documentBuilder.newDocument();\r
- \r
- Element rootElement = document.createElement(COLOR_SETTINGS_TAG);\r
- document.appendChild(rootElement);\r
- \r
- for (ColorSetting colorSetting : colorSettings) {\r
- Element colorSettingElement = document.createElement(COLOR_SETTING_TAG);\r
- rootElement.appendChild(colorSettingElement);\r
- \r
- Element fgElement = document.createElement(FG_TAG);\r
- colorSettingElement.appendChild(fgElement);\r
- RGB foreground = colorSetting.getForegroundRGB();\r
- fgElement.setAttribute(R_ATTR, Integer.toString(foreground.red));\r
- fgElement.setAttribute(G_ATTR, Integer.toString(foreground.green));\r
- fgElement.setAttribute(B_ATTR, Integer.toString(foreground.blue));\r
- \r
- Element bgElement = document.createElement(BG_TAG);\r
- colorSettingElement.appendChild(bgElement);\r
- RGB background = colorSetting.getBackgroundRGB();\r
- bgElement.setAttribute(R_ATTR, Integer.toString(background.red));\r
- bgElement.setAttribute(G_ATTR, Integer.toString(background.green));\r
- bgElement.setAttribute(B_ATTR, Integer.toString(background.blue));\r
- \r
- Element tickColorElement = document.createElement(TICK_TAG);\r
- colorSettingElement.appendChild(tickColorElement);\r
- RGB tickColor = colorSetting.getTickColorRGB();\r
- tickColorElement.setAttribute(R_ATTR, Integer.toString(tickColor.red));\r
- tickColorElement.setAttribute(G_ATTR, Integer.toString(tickColor.green));\r
- tickColorElement.setAttribute(B_ATTR, Integer.toString(tickColor.blue));\r
-\r
- if (colorSetting.getFilter() != null) {\r
- Element filterElement = document.createElement(FILTER_TAG);\r
- colorSettingElement.appendChild(filterElement);\r
- TmfFilterXMLWriter.buildXMLTree(document, colorSetting.getFilter(), filterElement);\r
- }\r
- }\r
- \r
- TransformerFactory transformerFactory = TransformerFactory.newInstance();\r
- \r
- Transformer transformer = transformerFactory.newTransformer();\r
- DOMSource source = new DOMSource(document);\r
- StreamResult result = new StreamResult(new File(pathName));\r
- transformer.transform(source, result);\r
- } catch (ParserConfigurationException e) {\r
- Activator.getDefault().logError("Error saving color xml file: " + pathName, e); //$NON-NLS-1$\r
- } catch (TransformerConfigurationException e) {\r
- Activator.getDefault().logError("Error saving color xml file: " + pathName, e); //$NON-NLS-1$\r
- } catch (TransformerException e) {\r
- Activator.getDefault().logError("Error saving color xml file: " + pathName, e); //$NON-NLS-1$\r
- }\r
- }\r
- \r
- /**\r
- * Loads color settings from file and returns it in an array.\r
- * \r
- * @param pathName A file name with path\r
- * \r
- * @return the color settings array loaded from file\r
- */\r
- public static ColorSetting[] load(String pathName) {\r
- if (! new File(pathName).canRead()) {\r
- return new ColorSetting[0];\r
- }\r
- SAXParserFactory parserFactory = SAXParserFactory.newInstance(); \r
- parserFactory.setNamespaceAware(true); \r
-\r
- ColorSettingsContentHandler handler = new ColorSettingsContentHandler();\r
- try {\r
- XMLReader saxReader = parserFactory.newSAXParser().getXMLReader();\r
- saxReader.setContentHandler(handler);\r
- saxReader.parse(pathName);\r
- return handler.colorSettings.toArray(new ColorSetting[0]);\r
- } catch (ParserConfigurationException e) {\r
- Activator.getDefault().logError("Error loading color xml file: " + pathName, e); //$NON-NLS-1$\r
- } catch (SAXException e) {\r
- Activator.getDefault().logError("Error loading color xml file: " + pathName, e); //$NON-NLS-1$\r
- } catch (IOException e) {\r
- Activator.getDefault().logError("Error loading color xml file: " + pathName, e); //$NON-NLS-1$\r
- }\r
- // In case of error, dispose the partial list of color settings\r
- for (ColorSetting colorSetting : handler.colorSettings) {\r
- colorSetting.dispose();\r
- }\r
- return new ColorSetting[0];\r
- }\r
- \r
- // Helper class\r
- private static class ColorSettingsContentHandler extends DefaultHandler {\r
-\r
- private List<ColorSetting> colorSettings = new ArrayList<ColorSetting>(0);\r
- private RGB fg = new RGB(0, 0, 0);\r
- private RGB bg = new RGB(255, 255, 255);\r
- private RGB tickColor = new RGB(0, 0, 0);\r
- private ITmfFilterTreeNode filter;\r
- private TmfFilterContentHandler filterContentHandler;\r
- \r
- /* (non-Javadoc)\r
- * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)\r
- */\r
- @Override\r
- public void startElement(String uri, String localName, String qName, Attributes attributes)\r
- throws SAXException {\r
- if (localName.equals(COLOR_SETTINGS_TAG)) {\r
- colorSettings = new ArrayList<ColorSetting>();\r
- } else if (localName.equals(COLOR_SETTING_TAG)) {\r
- fg = null;\r
- bg = null;\r
- filter = null;\r
- } else if (localName.equals(FG_TAG)) {\r
- int r = Integer.valueOf(attributes.getValue(R_ATTR));\r
- int g = Integer.valueOf(attributes.getValue(G_ATTR));\r
- int b = Integer.valueOf(attributes.getValue(B_ATTR));\r
- fg = new RGB(r, g, b);\r
- } else if (localName.equals(BG_TAG)) {\r
- int r = Integer.valueOf(attributes.getValue(R_ATTR));\r
- int g = Integer.valueOf(attributes.getValue(G_ATTR));\r
- int b = Integer.valueOf(attributes.getValue(B_ATTR));\r
- bg = new RGB(r, g, b);\r
- } else if (localName.equals(TICK_TAG)) {\r
- int r = Integer.valueOf(attributes.getValue(R_ATTR));\r
- int g = Integer.valueOf(attributes.getValue(G_ATTR));\r
- int b = Integer.valueOf(attributes.getValue(B_ATTR));\r
- tickColor = new RGB(r, g, b);\r
- } else if (localName.equals(FILTER_TAG)) {\r
- filterContentHandler = new TmfFilterContentHandler();\r
- } else if (filterContentHandler != null) {\r
- filterContentHandler.startElement(uri, localName, qName, attributes);\r
- }\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)\r
- */\r
- @Override\r
- public void endElement(String uri, String localName, String qName)\r
- throws SAXException {\r
- if (localName.equals(COLOR_SETTINGS_TAG)) {\r
- // Nothing to do\r
- } else if (localName.equals(COLOR_SETTING_TAG)) {\r
- ColorSetting colorSetting = new ColorSetting(fg, bg, tickColor, filter);\r
- colorSettings.add(colorSetting);\r
- } else if (localName.equals(FILTER_TAG)) {\r
- filter = filterContentHandler.getTree();\r
- filterContentHandler = null;\r
- } else if (filterContentHandler != null) {\r
- filterContentHandler.endElement(uri, localName, qName);\r
- }\r
- }\r
-\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2010, 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ * Bernd Hufmann - Updated to use RGB for the tick color
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.views.colors;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+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.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
+import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterContentHandler;
+import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLWriter;
+import org.eclipse.swt.graphics.RGB;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Class for saving and loading of color settings to/from file.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ *
+ */
+public class ColorSettingsXML {
+
+ // XML Tags and attributes
+ private static final String COLOR_SETTINGS_TAG = "COLOR_SETTINGS"; //$NON-NLS-1$
+ private static final String COLOR_SETTING_TAG = "COLOR_SETTING"; //$NON-NLS-1$
+ private static final String FG_TAG = "FG"; //$NON-NLS-1$
+ private static final String BG_TAG = "BG"; //$NON-NLS-1$
+ private static final String R_ATTR = "R"; //$NON-NLS-1$
+ private static final String G_ATTR = "G"; //$NON-NLS-1$
+ private static final String B_ATTR = "B"; //$NON-NLS-1$
+ private static final String TICK_TAG = "TICK"; //$NON-NLS-1$
+ private static final String FILTER_TAG = "FILTER"; //$NON-NLS-1$
+
+ /**
+ * Saves the given color settings to file.
+ *
+ * @param pathName A file name with path
+ * @param colorSettings -An array of color settings to save.
+ */
+ public static void save(String pathName, ColorSetting[] colorSettings) {
+ try {
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+ Document document = documentBuilder.newDocument();
+
+ Element rootElement = document.createElement(COLOR_SETTINGS_TAG);
+ document.appendChild(rootElement);
+
+ for (ColorSetting colorSetting : colorSettings) {
+ Element colorSettingElement = document.createElement(COLOR_SETTING_TAG);
+ rootElement.appendChild(colorSettingElement);
+
+ Element fgElement = document.createElement(FG_TAG);
+ colorSettingElement.appendChild(fgElement);
+ RGB foreground = colorSetting.getForegroundRGB();
+ fgElement.setAttribute(R_ATTR, Integer.toString(foreground.red));
+ fgElement.setAttribute(G_ATTR, Integer.toString(foreground.green));
+ fgElement.setAttribute(B_ATTR, Integer.toString(foreground.blue));
+
+ Element bgElement = document.createElement(BG_TAG);
+ colorSettingElement.appendChild(bgElement);
+ RGB background = colorSetting.getBackgroundRGB();
+ bgElement.setAttribute(R_ATTR, Integer.toString(background.red));
+ bgElement.setAttribute(G_ATTR, Integer.toString(background.green));
+ bgElement.setAttribute(B_ATTR, Integer.toString(background.blue));
+
+ Element tickColorElement = document.createElement(TICK_TAG);
+ colorSettingElement.appendChild(tickColorElement);
+ RGB tickColor = colorSetting.getTickColorRGB();
+ tickColorElement.setAttribute(R_ATTR, Integer.toString(tickColor.red));
+ tickColorElement.setAttribute(G_ATTR, Integer.toString(tickColor.green));
+ tickColorElement.setAttribute(B_ATTR, Integer.toString(tickColor.blue));
+
+ if (colorSetting.getFilter() != null) {
+ Element filterElement = document.createElement(FILTER_TAG);
+ colorSettingElement.appendChild(filterElement);
+ TmfFilterXMLWriter.buildXMLTree(document, colorSetting.getFilter(), filterElement);
+ }
+ }
+
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+
+ Transformer transformer = transformerFactory.newTransformer();
+ DOMSource source = new DOMSource(document);
+ StreamResult result = new StreamResult(new File(pathName));
+ transformer.transform(source, result);
+ } catch (ParserConfigurationException e) {
+ Activator.getDefault().logError("Error saving color xml file: " + pathName, e); //$NON-NLS-1$
+ } catch (TransformerConfigurationException e) {
+ Activator.getDefault().logError("Error saving color xml file: " + pathName, e); //$NON-NLS-1$
+ } catch (TransformerException e) {
+ Activator.getDefault().logError("Error saving color xml file: " + pathName, e); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Loads color settings from file and returns it in an array.
+ *
+ * @param pathName A file name with path
+ *
+ * @return the color settings array loaded from file
+ */
+ public static ColorSetting[] load(String pathName) {
+ if (! new File(pathName).canRead()) {
+ return new ColorSetting[0];
+ }
+ SAXParserFactory parserFactory = SAXParserFactory.newInstance();
+ parserFactory.setNamespaceAware(true);
+
+ ColorSettingsContentHandler handler = new ColorSettingsContentHandler();
+ try {
+ XMLReader saxReader = parserFactory.newSAXParser().getXMLReader();
+ saxReader.setContentHandler(handler);
+ saxReader.parse(pathName);
+ return handler.colorSettings.toArray(new ColorSetting[0]);
+ } catch (ParserConfigurationException e) {
+ Activator.getDefault().logError("Error loading color xml file: " + pathName, e); //$NON-NLS-1$
+ } catch (SAXException e) {
+ Activator.getDefault().logError("Error loading color xml file: " + pathName, e); //$NON-NLS-1$
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error loading color xml file: " + pathName, e); //$NON-NLS-1$
+ }
+ // In case of error, dispose the partial list of color settings
+ for (ColorSetting colorSetting : handler.colorSettings) {
+ colorSetting.dispose();
+ }
+ return new ColorSetting[0];
+ }
+
+ // Helper class
+ private static class ColorSettingsContentHandler extends DefaultHandler {
+
+ private List<ColorSetting> colorSettings = new ArrayList<ColorSetting>(0);
+ private RGB fg = new RGB(0, 0, 0);
+ private RGB bg = new RGB(255, 255, 255);
+ private RGB tickColor = new RGB(0, 0, 0);
+ private ITmfFilterTreeNode filter;
+ private TmfFilterContentHandler filterContentHandler;
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.helpers.DefaultHandler#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 attributes)
+ throws SAXException {
+ if (localName.equals(COLOR_SETTINGS_TAG)) {
+ colorSettings = new ArrayList<ColorSetting>();
+ } else if (localName.equals(COLOR_SETTING_TAG)) {
+ fg = null;
+ bg = null;
+ filter = null;
+ } else if (localName.equals(FG_TAG)) {
+ int r = Integer.valueOf(attributes.getValue(R_ATTR));
+ int g = Integer.valueOf(attributes.getValue(G_ATTR));
+ int b = Integer.valueOf(attributes.getValue(B_ATTR));
+ fg = new RGB(r, g, b);
+ } else if (localName.equals(BG_TAG)) {
+ int r = Integer.valueOf(attributes.getValue(R_ATTR));
+ int g = Integer.valueOf(attributes.getValue(G_ATTR));
+ int b = Integer.valueOf(attributes.getValue(B_ATTR));
+ bg = new RGB(r, g, b);
+ } else if (localName.equals(TICK_TAG)) {
+ int r = Integer.valueOf(attributes.getValue(R_ATTR));
+ int g = Integer.valueOf(attributes.getValue(G_ATTR));
+ int b = Integer.valueOf(attributes.getValue(B_ATTR));
+ tickColor = new RGB(r, g, b);
+ } else if (localName.equals(FILTER_TAG)) {
+ filterContentHandler = new TmfFilterContentHandler();
+ } else if (filterContentHandler != null) {
+ filterContentHandler.startElement(uri, localName, qName, attributes);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException {
+ if (localName.equals(COLOR_SETTINGS_TAG)) {
+ // Nothing to do
+ } else if (localName.equals(COLOR_SETTING_TAG)) {
+ ColorSetting colorSetting = new ColorSetting(fg, bg, tickColor, filter);
+ colorSettings.add(colorSetting);
+ } else if (localName.equals(FILTER_TAG)) {
+ filter = filterContentHandler.getTree();
+ filterContentHandler = null;
+ } else if (filterContentHandler != null) {
+ filterContentHandler.endElement(uri, localName, qName);
+ }
+ }
+
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010, 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- * Bernd Hufmann - Updated to use RGB for the tick color\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.colors;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.List;\r
-\r
-import org.eclipse.jface.action.Action;\r
-import org.eclipse.jface.action.IToolBarManager;\r
-import org.eclipse.jface.action.Separator;\r
-import org.eclipse.jface.dialogs.MessageDialog;\r
-import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.eclipse.jface.window.Window;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.eclipse.linuxtools.tmf.ui.views.TmfView;\r
-import org.eclipse.linuxtools.tmf.ui.views.filter.FilterDialog;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.ScrolledComposite;\r
-import org.eclipse.swt.events.MouseAdapter;\r
-import org.eclipse.swt.events.MouseEvent;\r
-import org.eclipse.swt.events.MouseListener;\r
-import org.eclipse.swt.events.PaintEvent;\r
-import org.eclipse.swt.events.PaintListener;\r
-import org.eclipse.swt.events.SelectionAdapter;\r
-import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.graphics.Color;\r
-import org.eclipse.swt.graphics.GC;\r
-import org.eclipse.swt.graphics.Image;\r
-import org.eclipse.swt.graphics.Point;\r
-import org.eclipse.swt.graphics.Rectangle;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Button;\r
-import org.eclipse.swt.widgets.Canvas;\r
-import org.eclipse.swt.widgets.ColorDialog;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.FileDialog;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.ui.IActionBars;\r
-\r
-/**\r
- * Color view implementation. This view provides support for managing color settings for filters.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- *\r
- */\r
-public class ColorsView extends TmfView {\r
-\r
- /** ID for the color view */\r
- public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.colors"; //$NON-NLS-1$\r
-\r
- private static final Image ADD_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$\r
- private static final Image DELETE_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$\r
- private static final Image MOVE_UP_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$\r
- private static final Image MOVE_DOWN_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$\r
- private static final Image IMPORT_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/import_button.gif"); //$NON-NLS-1$\r
- private static final Image EXPORT_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/export_button.gif"); //$NON-NLS-1$\r
-\r
- // ------------------------------------------------------------------------\r
- // Main data structures\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * The composite shell.\r
- */\r
- protected Shell fShell;\r
- /**\r
- * The main composite (scrolled composite)\r
- */\r
- protected ScrolledComposite fScrolledComposite;\r
- /**\r
- * The list composite.\r
- */\r
- protected Composite fListComposite;\r
- /**\r
- * The filler composite.\r
- */\r
- protected Composite fFillerComposite;\r
- /**\r
- * The selected color settings row\r
- */\r
- protected ColorSettingRow fSelectedRow = null;\r
- /**\r
- * The color scheme instance for managing colors\r
- */\r
- protected TimeGraphColorScheme traceColorScheme = new TimeGraphColorScheme();\r
- /**\r
- * An action to add a color settings row\r
- */\r
- protected Action fAddAction;\r
- /**\r
- * An action to delete a color settings row\r
- */\r
- protected Action fDeleteAction;\r
- /**\r
- * An action to move up a color settings row in the list.\r
- */\r
- protected Action fMoveUpAction;\r
- /**\r
- * An action to move down a color settings row in the list.\r
- */\r
- protected Action fMoveDownAction;\r
- /**\r
- * An action to import color settings from file.\r
- */\r
- protected Action fImportAction;\r
- /**\r
- * An action to export color settings from file.\r
- */\r
- protected Action fExportAction;\r
- /**\r
- * The list of existing color settings\r
- */\r
- protected List<ColorSetting> fColorSettings;\r
-\r
- // ------------------------------------------------------------------------\r
- // Constructor\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Default Constructor\r
- */\r
- public ColorsView() {\r
- super("Colors"); //$NON-NLS-1$\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(Composite)\r
- */\r
- @Override\r
- public void createPartControl(Composite parent) {\r
- fShell = parent.getShell();\r
-\r
- fScrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);\r
- fScrolledComposite.setExpandHorizontal(true);\r
- fScrolledComposite.setExpandVertical(true);\r
- fListComposite = new Composite(fScrolledComposite, SWT.NONE);\r
- fScrolledComposite.setContent(fListComposite);\r
-\r
- GridLayout gl = new GridLayout();\r
- gl.marginHeight = 0;\r
- gl.marginWidth = 0;\r
- gl.verticalSpacing = 1;\r
- fListComposite.setLayout(gl);\r
-\r
- fColorSettings = new ArrayList<ColorSetting>(Arrays.asList(ColorSettingsManager.getColorSettings()));\r
- for (ColorSetting colorSetting : fColorSettings) {\r
- new ColorSettingRow(fListComposite, colorSetting);\r
- }\r
-\r
- fFillerComposite = new Composite(fListComposite, SWT.NONE);\r
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);\r
- gd.heightHint = 0;\r
- fFillerComposite.setLayoutData(gd);\r
- gl = new GridLayout();\r
- gl.marginHeight = 1;\r
- gl.marginWidth = 1;\r
- fFillerComposite.setLayout(gl);\r
- Label fillerLabel = new Label(fFillerComposite, SWT.NONE);\r
- fillerLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- fillerLabel.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));\r
-\r
- fFillerComposite.addPaintListener(new PaintListener() {\r
- @Override\r
- public void paintControl(PaintEvent e) {\r
- if (fSelectedRow == null) {\r
- Color lineColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);\r
- Point p = fFillerComposite.getSize();\r
- GC gc = e.gc;\r
- gc.setForeground(lineColor);\r
- gc.drawLine(0, 0, p.x - 1, 0);\r
- }\r
- }\r
- });\r
-\r
- MouseListener mouseListener = new MouseAdapter() {\r
- @Override\r
- public void mouseDown(MouseEvent e) {\r
- fSelectedRow = null;\r
- refresh();\r
- }\r
- };\r
- fillerLabel.addMouseListener(mouseListener);\r
-\r
- fScrolledComposite.setMinSize(fListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));\r
-\r
- fillToolBar();\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.ui.part.WorkbenchPart#setFocus()\r
- */\r
- @Override\r
- public void setFocus() {\r
- fScrolledComposite.setFocus();\r
- }\r
-\r
- /**\r
- * Refreshes the view display and updates the view actions enablements.\r
- */\r
- public void refresh() {\r
- fListComposite.layout();\r
- fScrolledComposite.setMinSize(fListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));\r
- fListComposite.redraw(0, 0, fListComposite.getBounds().width, fListComposite.getBounds().height, true);\r
- if (fSelectedRow == null) {\r
- fDeleteAction.setEnabled(false);\r
- fMoveUpAction.setEnabled(false);\r
- fMoveDownAction.setEnabled(false);\r
- } else {\r
- fDeleteAction.setEnabled(true);\r
- fMoveUpAction.setEnabled(true);\r
- fMoveDownAction.setEnabled(true);\r
- }\r
- }\r
-\r
- private void fillToolBar() {\r
-\r
- fAddAction = new AddAction();\r
- fAddAction.setImageDescriptor(ImageDescriptor.createFromImage(ADD_IMAGE));\r
- fAddAction.setToolTipText(Messages.ColorsView_AddActionToolTipText);\r
-\r
- fDeleteAction = new DeleteAction();\r
- fDeleteAction.setImageDescriptor(ImageDescriptor.createFromImage(DELETE_IMAGE));\r
- fDeleteAction.setToolTipText(Messages.ColorsView_DeleteActionToolTipText);\r
- fDeleteAction.setEnabled(false);\r
-\r
- fMoveUpAction = new MoveUpAction();\r
- fMoveUpAction.setImageDescriptor(ImageDescriptor.createFromImage(MOVE_UP_IMAGE));\r
- fMoveUpAction.setToolTipText(Messages.ColorsView_MoveUpActionToolTipText);\r
- fMoveUpAction.setEnabled(false);\r
-\r
- fMoveDownAction = new MoveDownAction();\r
- fMoveDownAction.setImageDescriptor(ImageDescriptor.createFromImage(MOVE_DOWN_IMAGE));\r
- fMoveDownAction.setToolTipText(Messages.ColorsView_MoveDownActionToolTipText);\r
- fMoveDownAction.setEnabled(false);\r
-\r
- fExportAction = new ExportAction();\r
- fExportAction.setImageDescriptor(ImageDescriptor.createFromImage(EXPORT_IMAGE));\r
- fExportAction.setToolTipText(Messages.ColorsView_ExportActionToolTipText);\r
-\r
- fImportAction = new ImportAction();\r
- fImportAction.setImageDescriptor(ImageDescriptor.createFromImage(IMPORT_IMAGE));\r
- fImportAction.setToolTipText(Messages.ColorsView_ImportActionToolTipText);\r
-\r
- IActionBars bars = getViewSite().getActionBars();\r
- IToolBarManager manager = bars.getToolBarManager();\r
- manager.add(fAddAction);\r
- manager.add(fDeleteAction);\r
- manager.add(fMoveUpAction);\r
- manager.add(fMoveDownAction);\r
- manager.add(new Separator());\r
- manager.add(fExportAction);\r
- manager.add(fImportAction);\r
- }\r
-\r
- private class AddAction extends Action {\r
- @Override\r
- public void run() {\r
- ColorSetting colorSetting = new ColorSetting(\r
- Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(),\r
- Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(),\r
- Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(),\r
- null);\r
- ColorSettingRow row = new ColorSettingRow(fListComposite, colorSetting);\r
- if (fSelectedRow == null) {\r
- fColorSettings.add(colorSetting);\r
- row.moveAbove(fFillerComposite);\r
- } else {\r
- fColorSettings.add(fColorSettings.indexOf(fSelectedRow.getColorSetting()), colorSetting);\r
- row.moveAbove(fSelectedRow);\r
- }\r
- fSelectedRow = row;\r
- refresh();\r
- ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));\r
- }\r
- }\r
-\r
- private class DeleteAction extends Action {\r
-\r
- @Override\r
- public void run() {\r
- if (fSelectedRow != null) {\r
- int index = fColorSettings.indexOf(fSelectedRow.getColorSetting());\r
- fColorSettings.remove(index);\r
- fSelectedRow.fColorSetting.dispose();\r
- fSelectedRow.dispose();\r
- if (index < fColorSettings.size()) {\r
- fSelectedRow = (ColorSettingRow) fListComposite.getChildren()[index];\r
- } else {\r
- fSelectedRow = null;\r
- }\r
- refresh();\r
- ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));\r
- }\r
- }\r
- }\r
-\r
- private class MoveUpAction extends Action {\r
- @Override\r
- public void run() {\r
- if (fSelectedRow != null) {\r
- int index = fColorSettings.indexOf(fSelectedRow.getColorSetting());\r
- if (index > 0) {\r
- fColorSettings.add(index - 1, fColorSettings.remove(index));\r
- fSelectedRow.moveAbove(fListComposite.getChildren()[index - 1]);\r
- refresh();\r
- ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));\r
- }\r
- }\r
- }\r
- }\r
-\r
- private class MoveDownAction extends Action {\r
- @Override\r
- public void run() {\r
- if (fSelectedRow != null) {\r
- int index = fColorSettings.indexOf(fSelectedRow.getColorSetting());\r
- if (index < fColorSettings.size() - 1) {\r
- fColorSettings.add(index + 1, fColorSettings.remove(index));\r
-\r
- fSelectedRow.moveBelow(fListComposite.getChildren()[index + 1]);\r
- refresh();\r
- ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));\r
- }\r
- }\r
- }\r
- }\r
-\r
- private class ExportAction extends Action {\r
- @Override\r
- public void run() {\r
- FileDialog fileDialog = new FileDialog(fShell, SWT.SAVE);\r
- fileDialog.setFilterExtensions(new String[] {"*.xml"}); //$NON-NLS-1$\r
- fileDialog.setOverwrite(true);\r
- String pathName = fileDialog.open();\r
- if (pathName != null) {\r
- ColorSettingsXML.save(pathName, fColorSettings.toArray(new ColorSetting[0]));\r
- }\r
- }\r
- }\r
-\r
- private class ImportAction extends Action {\r
- @Override\r
- public void run() {\r
- FileDialog fileDialog = new FileDialog(fShell, SWT.OPEN);\r
- fileDialog.setFilterExtensions(new String[] {"*.xml"}); //$NON-NLS-1$\r
- String pathName = fileDialog.open();\r
- if (pathName != null) {\r
- ColorSetting[] colorSettings = ColorSettingsXML.load(pathName);\r
- if (colorSettings.length > 0) {\r
- if (fColorSettings.size() > 0) {\r
- boolean overwrite = MessageDialog.openQuestion(fShell,\r
- Messages.ColorsView_ImportOverwriteDialogTitle,\r
- Messages.ColorsView_ImportOverwriteDialogMessage1 +\r
- Messages.ColorsView_ImportOverwriteDialogMessage2);\r
- if (overwrite) {\r
- for (Control control : fListComposite.getChildren()) {\r
- if (control instanceof ColorSettingRow) {\r
- ((ColorSettingRow) control).fColorSetting.dispose();\r
- control.dispose();\r
- }\r
- }\r
- fColorSettings = new ArrayList<ColorSetting>();\r
- fSelectedRow = null;\r
- }\r
- }\r
- for (ColorSetting colorSetting : colorSettings) {\r
- ColorSettingRow row = new ColorSettingRow(fListComposite, colorSetting);\r
- if (fSelectedRow == null) {\r
- fColorSettings.add(colorSetting);\r
- row.moveAbove(fFillerComposite);\r
- } else {\r
- fColorSettings.add(fColorSettings.indexOf(fSelectedRow.getColorSetting()), colorSetting);\r
- row.moveAbove(fSelectedRow);\r
- }\r
- }\r
- refresh();\r
- ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));\r
- }\r
- }\r
- }\r
- }\r
-\r
- private class ColorSettingRow extends Composite {\r
-\r
- ColorSetting fColorSetting;\r
-\r
- public ColorSettingRow(final Composite parent, final ColorSetting colorSetting) {\r
- super(parent, SWT.NONE);\r
- fColorSetting = colorSetting;\r
-\r
- setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));\r
-\r
- setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- GridLayout gl = new GridLayout(7, false);\r
- gl.marginHeight = 1;\r
- gl.marginWidth = 1;\r
- gl.horizontalSpacing = 1;\r
- gl.verticalSpacing = 0;\r
- setLayout(gl);\r
-\r
- final Button fgButton = new Button(this, SWT.PUSH);\r
- fgButton.setText(Messages.ColorsView_ForegroundButtonText);\r
- fgButton.setSize(fgButton.computeSize(SWT.DEFAULT, 19));\r
- fgButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));\r
-\r
- final Button bgButton = new Button(this, SWT.PUSH);\r
- bgButton.setText(Messages.ColorsView_BackgroundButtonText);\r
- bgButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));\r
-\r
- final Composite labelComposite = new Composite(this, SWT.NONE);\r
- labelComposite.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, false));\r
- gl = new GridLayout();\r
- gl.marginHeight = 0;\r
- gl.marginWidth = 0;\r
- labelComposite.setLayout(gl);\r
- labelComposite.setBackground(colorSetting.getBackgroundColor());\r
-\r
- final Label label = new Label(labelComposite, SWT.NONE);\r
- label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, true));\r
- label.setText(" Text "); //$NON-NLS-1$\r
- label.setForeground(colorSetting.getForegroundColor());\r
- label.setBackground(colorSetting.getBackgroundColor());\r
-\r
- fgButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- fSelectedRow = ColorSettingRow.this;\r
- refresh();\r
- ColorDialog dialog = new ColorDialog(fShell);\r
- dialog.setRGB(colorSetting.getForegroundRGB());\r
- dialog.setText(Messages.ColorsView_ForegroundDialogText);\r
- dialog.open();\r
- colorSetting.setForegroundRGB(dialog.getRGB());\r
- ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));\r
- label.setForeground(colorSetting.getForegroundColor());\r
- }});\r
-\r
- bgButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- fSelectedRow = ColorSettingRow.this;\r
- refresh();\r
- ColorDialog dialog = new ColorDialog(fShell);\r
- dialog.setRGB(colorSetting.getBackgroundRGB());\r
- dialog.setText(Messages.ColorsView_BackgroundDialogText);\r
- dialog.open();\r
- colorSetting.setBackgroundRGB(dialog.getRGB());\r
- ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));\r
- labelComposite.setBackground(colorSetting.getBackgroundColor());\r
- label.setBackground(colorSetting.getBackgroundColor());\r
- }});\r
-\r
- final Button tickButton = new Button(this, SWT.PUSH);\r
- tickButton.setText(Messages.ColorsView_TickButtonText);\r
- tickButton.setSize(tickButton.computeSize(SWT.DEFAULT, 19));\r
- tickButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));\r
-\r
- final Canvas tickCanvas = new Canvas(this, SWT.NONE);\r
- GridData gd = new GridData(SWT.CENTER, SWT.FILL, false, false);\r
- gd.widthHint = 12;\r
- gd.heightHint = bgButton.getSize().y;\r
- tickCanvas.setLayoutData(gd);\r
- tickCanvas.setBackground(traceColorScheme.getBkColor(false, false, false));\r
- tickCanvas.addPaintListener(new PaintListener() {\r
- @Override\r
- public void paintControl(PaintEvent e) {\r
- Rectangle bounds = tickCanvas.getBounds();\r
- e.gc.setForeground(traceColorScheme.getColor(TimeGraphColorScheme.MID_LINE));\r
- int midy = bounds.y + bounds.height / 2 - 1;\r
- //int midy = e.y + e.height / 2;\r
- e.gc.drawLine(e.x, midy, e.x + e.width, midy);\r
- Rectangle rect = new Rectangle(e.x + 1, bounds.y + 2, 0, bounds.height - 6);\r
- for (int i = 1; i <= 3; i++) {\r
- rect.x += i;\r
- rect.width = i;\r
- e.gc.setBackground(fColorSetting.getTickColor());\r
- e.gc.fillRectangle(rect);\r
- }\r
- }});\r
-\r
- tickButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- fSelectedRow = ColorSettingRow.this;\r
- ColorDialog dialog = new ColorDialog(fShell);\r
- dialog.setRGB(colorSetting.getTickColorRGB());\r
- dialog.setText(Messages.TickColorDialog_TickColorDialogTitle);\r
- dialog.open();\r
- colorSetting.setTickColorRGB(dialog.getRGB());\r
- ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));\r
- refresh();\r
- }});\r
-\r
- final Button filterButton = new Button(this, SWT.PUSH);\r
- filterButton.setText(Messages.ColorsView_FilterButtonText);\r
- filterButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));\r
-\r
- final Label filterText = new Label(this, SWT.NONE);\r
- if (colorSetting.getFilter() != null) {\r
- filterText.setText(colorSetting.getFilter().toString());\r
- filterText.setToolTipText(colorSetting.getFilter().toString());\r
- }\r
- filterText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));\r
- filterText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
-\r
- filterButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- fSelectedRow = ColorSettingRow.this;\r
- refresh();\r
- FilterDialog dialog = new FilterDialog(fShell);\r
- dialog.setFilter(colorSetting.getFilter());\r
- dialog.open();\r
- if (dialog.getReturnCode() == Window.OK) {\r
- if (dialog.getFilter() != null) {\r
- colorSetting.setFilter(dialog.getFilter());\r
- filterText.setText(dialog.getFilter().toString());\r
- filterText.setToolTipText(dialog.getFilter().toString());\r
- } else {\r
- colorSetting.setFilter(null);\r
- filterText.setText(""); //$NON-NLS-1$\r
- filterText.setToolTipText(""); //$NON-NLS-1$\r
- }\r
- ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));\r
- refresh();\r
- }\r
- }});\r
-\r
- addPaintListener(new PaintListener() {\r
- @Override\r
- public void paintControl(PaintEvent e) {\r
- if (fSelectedRow == ColorSettingRow.this) {\r
- Color borderColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);\r
- Point p = ColorSettingRow.this.getSize();\r
- Rectangle rect = new Rectangle(0, 0, p.x - 1, p.y - 1);\r
- GC gc = e.gc;\r
- gc.setForeground(borderColor);\r
- gc.drawRectangle(rect);\r
- }\r
- }\r
- });\r
-\r
- MouseListener mouseListener = new MouseAdapter() {\r
- @Override\r
- public void mouseDown(MouseEvent e) {\r
- fSelectedRow = ColorSettingRow.this;\r
- refresh();\r
- }\r
- };\r
- addMouseListener(mouseListener);\r
- label.addMouseListener(mouseListener);\r
- tickCanvas.addMouseListener(mouseListener);\r
- filterText.addMouseListener(mouseListener);\r
- }\r
-\r
- /**\r
- * @return the ColorSetting\r
- */\r
- public ColorSetting getColorSetting() {\r
- return fColorSetting;\r
- }\r
-\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2010, 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ * Bernd Hufmann - Updated to use RGB for the tick color
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.views.colors;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.window.Window;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.tmf.ui.views.TmfView;
+import org.eclipse.linuxtools.tmf.ui.views.filter.FilterDialog;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+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.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.ColorDialog;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionBars;
+
+/**
+ * Color view implementation. This view provides support for managing color settings for filters.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ *
+ */
+public class ColorsView extends TmfView {
+
+ /** ID for the color view */
+ public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.colors"; //$NON-NLS-1$
+
+ private static final Image ADD_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
+ private static final Image DELETE_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
+ private static final Image MOVE_UP_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$
+ private static final Image MOVE_DOWN_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$
+ private static final Image IMPORT_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/import_button.gif"); //$NON-NLS-1$
+ private static final Image EXPORT_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/export_button.gif"); //$NON-NLS-1$
+
+ // ------------------------------------------------------------------------
+ // Main data structures
+ // ------------------------------------------------------------------------
+
+ /**
+ * The composite shell.
+ */
+ protected Shell fShell;
+ /**
+ * The main composite (scrolled composite)
+ */
+ protected ScrolledComposite fScrolledComposite;
+ /**
+ * The list composite.
+ */
+ protected Composite fListComposite;
+ /**
+ * The filler composite.
+ */
+ protected Composite fFillerComposite;
+ /**
+ * The selected color settings row
+ */
+ protected ColorSettingRow fSelectedRow = null;
+ /**
+ * The color scheme instance for managing colors
+ */
+ protected TimeGraphColorScheme traceColorScheme = new TimeGraphColorScheme();
+ /**
+ * An action to add a color settings row
+ */
+ protected Action fAddAction;
+ /**
+ * An action to delete a color settings row
+ */
+ protected Action fDeleteAction;
+ /**
+ * An action to move up a color settings row in the list.
+ */
+ protected Action fMoveUpAction;
+ /**
+ * An action to move down a color settings row in the list.
+ */
+ protected Action fMoveDownAction;
+ /**
+ * An action to import color settings from file.
+ */
+ protected Action fImportAction;
+ /**
+ * An action to export color settings from file.
+ */
+ protected Action fExportAction;
+ /**
+ * The list of existing color settings
+ */
+ protected List<ColorSetting> fColorSettings;
+
+ // ------------------------------------------------------------------------
+ // Constructor
+ // ------------------------------------------------------------------------
+
+ /**
+ * Default Constructor
+ */
+ public ColorsView() {
+ super("Colors"); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(Composite)
+ */
+ @Override
+ public void createPartControl(Composite parent) {
+ fShell = parent.getShell();
+
+ fScrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
+ fScrolledComposite.setExpandHorizontal(true);
+ fScrolledComposite.setExpandVertical(true);
+ fListComposite = new Composite(fScrolledComposite, SWT.NONE);
+ fScrolledComposite.setContent(fListComposite);
+
+ GridLayout gl = new GridLayout();
+ gl.marginHeight = 0;
+ gl.marginWidth = 0;
+ gl.verticalSpacing = 1;
+ fListComposite.setLayout(gl);
+
+ fColorSettings = new ArrayList<ColorSetting>(Arrays.asList(ColorSettingsManager.getColorSettings()));
+ for (ColorSetting colorSetting : fColorSettings) {
+ new ColorSettingRow(fListComposite, colorSetting);
+ }
+
+ fFillerComposite = new Composite(fListComposite, SWT.NONE);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gd.heightHint = 0;
+ fFillerComposite.setLayoutData(gd);
+ gl = new GridLayout();
+ gl.marginHeight = 1;
+ gl.marginWidth = 1;
+ fFillerComposite.setLayout(gl);
+ Label fillerLabel = new Label(fFillerComposite, SWT.NONE);
+ fillerLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ fillerLabel.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
+
+ fFillerComposite.addPaintListener(new PaintListener() {
+ @Override
+ public void paintControl(PaintEvent e) {
+ if (fSelectedRow == null) {
+ Color lineColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
+ Point p = fFillerComposite.getSize();
+ GC gc = e.gc;
+ gc.setForeground(lineColor);
+ gc.drawLine(0, 0, p.x - 1, 0);
+ }
+ }
+ });
+
+ MouseListener mouseListener = new MouseAdapter() {
+ @Override
+ public void mouseDown(MouseEvent e) {
+ fSelectedRow = null;
+ refresh();
+ }
+ };
+ fillerLabel.addMouseListener(mouseListener);
+
+ fScrolledComposite.setMinSize(fListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+
+ fillToolBar();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
+ */
+ @Override
+ public void setFocus() {
+ fScrolledComposite.setFocus();
+ }
+
+ /**
+ * Refreshes the view display and updates the view actions enablements.
+ */
+ public void refresh() {
+ fListComposite.layout();
+ fScrolledComposite.setMinSize(fListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ fListComposite.redraw(0, 0, fListComposite.getBounds().width, fListComposite.getBounds().height, true);
+ if (fSelectedRow == null) {
+ fDeleteAction.setEnabled(false);
+ fMoveUpAction.setEnabled(false);
+ fMoveDownAction.setEnabled(false);
+ } else {
+ fDeleteAction.setEnabled(true);
+ fMoveUpAction.setEnabled(true);
+ fMoveDownAction.setEnabled(true);
+ }
+ }
+
+ private void fillToolBar() {
+
+ fAddAction = new AddAction();
+ fAddAction.setImageDescriptor(ImageDescriptor.createFromImage(ADD_IMAGE));
+ fAddAction.setToolTipText(Messages.ColorsView_AddActionToolTipText);
+
+ fDeleteAction = new DeleteAction();
+ fDeleteAction.setImageDescriptor(ImageDescriptor.createFromImage(DELETE_IMAGE));
+ fDeleteAction.setToolTipText(Messages.ColorsView_DeleteActionToolTipText);
+ fDeleteAction.setEnabled(false);
+
+ fMoveUpAction = new MoveUpAction();
+ fMoveUpAction.setImageDescriptor(ImageDescriptor.createFromImage(MOVE_UP_IMAGE));
+ fMoveUpAction.setToolTipText(Messages.ColorsView_MoveUpActionToolTipText);
+ fMoveUpAction.setEnabled(false);
+
+ fMoveDownAction = new MoveDownAction();
+ fMoveDownAction.setImageDescriptor(ImageDescriptor.createFromImage(MOVE_DOWN_IMAGE));
+ fMoveDownAction.setToolTipText(Messages.ColorsView_MoveDownActionToolTipText);
+ fMoveDownAction.setEnabled(false);
+
+ fExportAction = new ExportAction();
+ fExportAction.setImageDescriptor(ImageDescriptor.createFromImage(EXPORT_IMAGE));
+ fExportAction.setToolTipText(Messages.ColorsView_ExportActionToolTipText);
+
+ fImportAction = new ImportAction();
+ fImportAction.setImageDescriptor(ImageDescriptor.createFromImage(IMPORT_IMAGE));
+ fImportAction.setToolTipText(Messages.ColorsView_ImportActionToolTipText);
+
+ IActionBars bars = getViewSite().getActionBars();
+ IToolBarManager manager = bars.getToolBarManager();
+ manager.add(fAddAction);
+ manager.add(fDeleteAction);
+ manager.add(fMoveUpAction);
+ manager.add(fMoveDownAction);
+ manager.add(new Separator());
+ manager.add(fExportAction);
+ manager.add(fImportAction);
+ }
+
+ private class AddAction extends Action {
+ @Override
+ public void run() {
+ ColorSetting colorSetting = new ColorSetting(
+ Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(),
+ Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(),
+ Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(),
+ null);
+ ColorSettingRow row = new ColorSettingRow(fListComposite, colorSetting);
+ if (fSelectedRow == null) {
+ fColorSettings.add(colorSetting);
+ row.moveAbove(fFillerComposite);
+ } else {
+ fColorSettings.add(fColorSettings.indexOf(fSelectedRow.getColorSetting()), colorSetting);
+ row.moveAbove(fSelectedRow);
+ }
+ fSelectedRow = row;
+ refresh();
+ ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));
+ }
+ }
+
+ private class DeleteAction extends Action {
+
+ @Override
+ public void run() {
+ if (fSelectedRow != null) {
+ int index = fColorSettings.indexOf(fSelectedRow.getColorSetting());
+ fColorSettings.remove(index);
+ fSelectedRow.fColorSetting.dispose();
+ fSelectedRow.dispose();
+ if (index < fColorSettings.size()) {
+ fSelectedRow = (ColorSettingRow) fListComposite.getChildren()[index];
+ } else {
+ fSelectedRow = null;
+ }
+ refresh();
+ ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));
+ }
+ }
+ }
+
+ private class MoveUpAction extends Action {
+ @Override
+ public void run() {
+ if (fSelectedRow != null) {
+ int index = fColorSettings.indexOf(fSelectedRow.getColorSetting());
+ if (index > 0) {
+ fColorSettings.add(index - 1, fColorSettings.remove(index));
+ fSelectedRow.moveAbove(fListComposite.getChildren()[index - 1]);
+ refresh();
+ ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));
+ }
+ }
+ }
+ }
+
+ private class MoveDownAction extends Action {
+ @Override
+ public void run() {
+ if (fSelectedRow != null) {
+ int index = fColorSettings.indexOf(fSelectedRow.getColorSetting());
+ if (index < fColorSettings.size() - 1) {
+ fColorSettings.add(index + 1, fColorSettings.remove(index));
+
+ fSelectedRow.moveBelow(fListComposite.getChildren()[index + 1]);
+ refresh();
+ ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));
+ }
+ }
+ }
+ }
+
+ private class ExportAction extends Action {
+ @Override
+ public void run() {
+ FileDialog fileDialog = new FileDialog(fShell, SWT.SAVE);
+ fileDialog.setFilterExtensions(new String[] {"*.xml"}); //$NON-NLS-1$
+ fileDialog.setOverwrite(true);
+ String pathName = fileDialog.open();
+ if (pathName != null) {
+ ColorSettingsXML.save(pathName, fColorSettings.toArray(new ColorSetting[0]));
+ }
+ }
+ }
+
+ private class ImportAction extends Action {
+ @Override
+ public void run() {
+ FileDialog fileDialog = new FileDialog(fShell, SWT.OPEN);
+ fileDialog.setFilterExtensions(new String[] {"*.xml"}); //$NON-NLS-1$
+ String pathName = fileDialog.open();
+ if (pathName != null) {
+ ColorSetting[] colorSettings = ColorSettingsXML.load(pathName);
+ if (colorSettings.length > 0) {
+ if (fColorSettings.size() > 0) {
+ boolean overwrite = MessageDialog.openQuestion(fShell,
+ Messages.ColorsView_ImportOverwriteDialogTitle,
+ Messages.ColorsView_ImportOverwriteDialogMessage1 +
+ Messages.ColorsView_ImportOverwriteDialogMessage2);
+ if (overwrite) {
+ for (Control control : fListComposite.getChildren()) {
+ if (control instanceof ColorSettingRow) {
+ ((ColorSettingRow) control).fColorSetting.dispose();
+ control.dispose();
+ }
+ }
+ fColorSettings = new ArrayList<ColorSetting>();
+ fSelectedRow = null;
+ }
+ }
+ for (ColorSetting colorSetting : colorSettings) {
+ ColorSettingRow row = new ColorSettingRow(fListComposite, colorSetting);
+ if (fSelectedRow == null) {
+ fColorSettings.add(colorSetting);
+ row.moveAbove(fFillerComposite);
+ } else {
+ fColorSettings.add(fColorSettings.indexOf(fSelectedRow.getColorSetting()), colorSetting);
+ row.moveAbove(fSelectedRow);
+ }
+ }
+ refresh();
+ ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));
+ }
+ }
+ }
+ }
+
+ private class ColorSettingRow extends Composite {
+
+ ColorSetting fColorSetting;
+
+ public ColorSettingRow(final Composite parent, final ColorSetting colorSetting) {
+ super(parent, SWT.NONE);
+ fColorSetting = colorSetting;
+
+ setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
+
+ setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ GridLayout gl = new GridLayout(7, false);
+ gl.marginHeight = 1;
+ gl.marginWidth = 1;
+ gl.horizontalSpacing = 1;
+ gl.verticalSpacing = 0;
+ setLayout(gl);
+
+ final Button fgButton = new Button(this, SWT.PUSH);
+ fgButton.setText(Messages.ColorsView_ForegroundButtonText);
+ fgButton.setSize(fgButton.computeSize(SWT.DEFAULT, 19));
+ fgButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
+
+ final Button bgButton = new Button(this, SWT.PUSH);
+ bgButton.setText(Messages.ColorsView_BackgroundButtonText);
+ bgButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
+
+ final Composite labelComposite = new Composite(this, SWT.NONE);
+ labelComposite.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, false));
+ gl = new GridLayout();
+ gl.marginHeight = 0;
+ gl.marginWidth = 0;
+ labelComposite.setLayout(gl);
+ labelComposite.setBackground(colorSetting.getBackgroundColor());
+
+ final Label label = new Label(labelComposite, SWT.NONE);
+ label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, true));
+ label.setText(" Text "); //$NON-NLS-1$
+ label.setForeground(colorSetting.getForegroundColor());
+ label.setBackground(colorSetting.getBackgroundColor());
+
+ fgButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ fSelectedRow = ColorSettingRow.this;
+ refresh();
+ ColorDialog dialog = new ColorDialog(fShell);
+ dialog.setRGB(colorSetting.getForegroundRGB());
+ dialog.setText(Messages.ColorsView_ForegroundDialogText);
+ dialog.open();
+ colorSetting.setForegroundRGB(dialog.getRGB());
+ ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));
+ label.setForeground(colorSetting.getForegroundColor());
+ }});
+
+ bgButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ fSelectedRow = ColorSettingRow.this;
+ refresh();
+ ColorDialog dialog = new ColorDialog(fShell);
+ dialog.setRGB(colorSetting.getBackgroundRGB());
+ dialog.setText(Messages.ColorsView_BackgroundDialogText);
+ dialog.open();
+ colorSetting.setBackgroundRGB(dialog.getRGB());
+ ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));
+ labelComposite.setBackground(colorSetting.getBackgroundColor());
+ label.setBackground(colorSetting.getBackgroundColor());
+ }});
+
+ final Button tickButton = new Button(this, SWT.PUSH);
+ tickButton.setText(Messages.ColorsView_TickButtonText);
+ tickButton.setSize(tickButton.computeSize(SWT.DEFAULT, 19));
+ tickButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
+
+ final Canvas tickCanvas = new Canvas(this, SWT.NONE);
+ GridData gd = new GridData(SWT.CENTER, SWT.FILL, false, false);
+ gd.widthHint = 12;
+ gd.heightHint = bgButton.getSize().y;
+ tickCanvas.setLayoutData(gd);
+ tickCanvas.setBackground(traceColorScheme.getBkColor(false, false, false));
+ tickCanvas.addPaintListener(new PaintListener() {
+ @Override
+ public void paintControl(PaintEvent e) {
+ Rectangle bounds = tickCanvas.getBounds();
+ e.gc.setForeground(traceColorScheme.getColor(TimeGraphColorScheme.MID_LINE));
+ int midy = bounds.y + bounds.height / 2 - 1;
+ //int midy = e.y + e.height / 2;
+ e.gc.drawLine(e.x, midy, e.x + e.width, midy);
+ Rectangle rect = new Rectangle(e.x + 1, bounds.y + 2, 0, bounds.height - 6);
+ for (int i = 1; i <= 3; i++) {
+ rect.x += i;
+ rect.width = i;
+ e.gc.setBackground(fColorSetting.getTickColor());
+ e.gc.fillRectangle(rect);
+ }
+ }});
+
+ tickButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ fSelectedRow = ColorSettingRow.this;
+ ColorDialog dialog = new ColorDialog(fShell);
+ dialog.setRGB(colorSetting.getTickColorRGB());
+ dialog.setText(Messages.TickColorDialog_TickColorDialogTitle);
+ dialog.open();
+ colorSetting.setTickColorRGB(dialog.getRGB());
+ ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));
+ refresh();
+ }});
+
+ final Button filterButton = new Button(this, SWT.PUSH);
+ filterButton.setText(Messages.ColorsView_FilterButtonText);
+ filterButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
+
+ final Label filterText = new Label(this, SWT.NONE);
+ if (colorSetting.getFilter() != null) {
+ filterText.setText(colorSetting.getFilter().toString());
+ filterText.setToolTipText(colorSetting.getFilter().toString());
+ }
+ filterText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
+ filterText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ filterButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ fSelectedRow = ColorSettingRow.this;
+ refresh();
+ FilterDialog dialog = new FilterDialog(fShell);
+ dialog.setFilter(colorSetting.getFilter());
+ dialog.open();
+ if (dialog.getReturnCode() == Window.OK) {
+ if (dialog.getFilter() != null) {
+ colorSetting.setFilter(dialog.getFilter());
+ filterText.setText(dialog.getFilter().toString());
+ filterText.setToolTipText(dialog.getFilter().toString());
+ } else {
+ colorSetting.setFilter(null);
+ filterText.setText(""); //$NON-NLS-1$
+ filterText.setToolTipText(""); //$NON-NLS-1$
+ }
+ ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0]));
+ refresh();
+ }
+ }});
+
+ addPaintListener(new PaintListener() {
+ @Override
+ public void paintControl(PaintEvent e) {
+ if (fSelectedRow == ColorSettingRow.this) {
+ Color borderColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
+ Point p = ColorSettingRow.this.getSize();
+ Rectangle rect = new Rectangle(0, 0, p.x - 1, p.y - 1);
+ GC gc = e.gc;
+ gc.setForeground(borderColor);
+ gc.drawRectangle(rect);
+ }
+ }
+ });
+
+ MouseListener mouseListener = new MouseAdapter() {
+ @Override
+ public void mouseDown(MouseEvent e) {
+ fSelectedRow = ColorSettingRow.this;
+ refresh();
+ }
+ };
+ addMouseListener(mouseListener);
+ label.addMouseListener(mouseListener);
+ tickCanvas.addMouseListener(mouseListener);
+ filterText.addMouseListener(mouseListener);
+ }
+
+ /**
+ * @return the ColorSetting
+ */
+ public ColorSetting getColorSetting() {
+ return fColorSetting;
+ }
+
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.colors;\r
-\r
-/**\r
- * A color change listener\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public interface IColorSettingsListener {\r
-\r
- /**\r
- * Notify the listener that the color settings have changed.\r
- *\r
- * @param colorSettings\r
- * The new color settings\r
- */\r
- public void colorSettingsChanged(ColorSetting[] colorSettings);\r
-}\r
+/*******************************************************************************
+ * 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.colors;
+
+/**
+ * A color change listener
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public interface IColorSettingsListener {
+
+ /**
+ * Notify the listener that the color settings have changed.
+ *
+ * @param colorSettings
+ * The new color settings
+ */
+ public void colorSettingsChanged(ColorSetting[] colorSettings);
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.filter;\r
-\r
-import org.eclipse.jface.dialogs.Dialog;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Shell;\r
-\r
-/**\r
- * The dialog for user-defined filters.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class FilterDialog extends Dialog {\r
-\r
- TmfFilterNode fRoot;\r
- FilterViewer fViewer;\r
-\r
- /**\r
- * Constructor.\r
- *\r
- * @param shell\r
- * The shell to which this dialog is attached\r
- */\r
- public FilterDialog(Shell shell) {\r
- super(shell);\r
- setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)\r
- */\r
- @Override\r
- protected Control createDialogArea(Composite parent) {\r
- getShell().setText(Messages.FilterDialog_FilterDialogTitle);\r
- getShell().setMinimumSize(getShell().computeSize(500, 200));\r
- Composite composite = (Composite) super.createDialogArea(parent);\r
-\r
- fViewer = new FilterViewer(composite, SWT.BORDER);\r
- fViewer.setInput(fRoot);\r
- return composite;\r
- }\r
-\r
- /**\r
- * @param filter the filter to set\r
- */\r
- public void setFilter(ITmfFilterTreeNode filter) {\r
- fRoot = new TmfFilterNode(null);\r
- if (filter != null) {\r
- fRoot.addChild(filter.clone());\r
- }\r
- if (fViewer != null) {\r
- fViewer.setInput(fRoot);\r
- }\r
- }\r
-\r
- /**\r
- * @return the filter\r
- */\r
- public ITmfFilterTreeNode getFilter() {\r
- if (fRoot != null && fRoot.hasChildren()) {\r
- return fRoot.getChild(0).clone();\r
- }\r
- return null;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * The dialog for user-defined filters.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class FilterDialog extends Dialog {
+
+ TmfFilterNode fRoot;
+ FilterViewer fViewer;
+
+ /**
+ * Constructor.
+ *
+ * @param shell
+ * The shell to which this dialog is attached
+ */
+ 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 filter 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 filter
+ */
+ public ITmfFilterTreeNode getFilter() {
+ if (fRoot != null && fRoot.hasChildren()) {
+ return fRoot.getChild(0).clone();
+ }
+ return null;
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.filter;\r
-\r
-import java.io.FileNotFoundException;\r
-import java.io.IOException;\r
-\r
-import javax.xml.parsers.ParserConfigurationException;\r
-\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLParser;\r
-import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLWriter;\r
-import org.xml.sax.SAXException;\r
-\r
-/**\r
- * Central filter manager\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class FilterManager {\r
-\r
- private static final String SAVED_FILTERS_FILE_NAME = "saved_filters.xml"; //$NON-NLS-1$\r
- private static final String SAVED_FILTERS_PATH_NAME =\r
- Activator.getDefault().getStateLocation().addTrailingSeparator().append(SAVED_FILTERS_FILE_NAME).toString();\r
-\r
- private static ITmfFilterTreeNode fRoot = new TmfFilterRootNode();\r
- static {\r
- try {\r
- fRoot = new TmfFilterXMLParser(SAVED_FILTERS_PATH_NAME).getTree();\r
- } catch (FileNotFoundException e) {\r
- } catch (SAXException e) {\r
- Activator.getDefault().logError("Error parsing saved filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$\r
- } catch (IOException e) {\r
- Activator.getDefault().logError("Error parsing saved filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$\r
- }\r
- }\r
-\r
- /**\r
- * Retrieve the currently saved filters\r
- *\r
- * @return The array of filters\r
- */\r
- public static ITmfFilterTreeNode[] getSavedFilters() {\r
- return fRoot.clone().getChildren();\r
- }\r
-\r
- /**\r
- * Set the passed filters as the currently saved ones.\r
- *\r
- * @param filters\r
- * The filters to save\r
- */\r
- public static void setSavedFilters(ITmfFilterTreeNode[] filters) {\r
- fRoot = new TmfFilterRootNode();\r
- for (ITmfFilterTreeNode filter : filters) {\r
- fRoot.addChild(filter.clone());\r
- }\r
- try {\r
- TmfFilterXMLWriter writerXML = new TmfFilterXMLWriter(fRoot);\r
- writerXML.saveTree(SAVED_FILTERS_PATH_NAME);\r
- } catch (ParserConfigurationException e) {\r
- Activator.getDefault().logError("Error saving filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$\r
- }\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode;
+import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLParser;
+import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLWriter;
+import org.xml.sax.SAXException;
+
+/**
+ * Central filter manager
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+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 =
+ Activator.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) {
+ Activator.getDefault().logError("Error parsing saved filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error parsing saved filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Retrieve the currently saved filters
+ *
+ * @return The array of filters
+ */
+ public static ITmfFilterTreeNode[] getSavedFilters() {
+ return fRoot.clone().getChildren();
+ }
+
+ /**
+ * Set the passed filters as the currently saved ones.
+ *
+ * @param filters
+ * The filters to save
+ */
+ 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 (ParserConfigurationException e) {
+ Activator.getDefault().logError("Error saving filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$
+ }
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Yuriy Vashchuk - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.filter;\r
-\r
-import java.util.ArrayList;\r
-\r
-import org.eclipse.jface.viewers.ITreeContentProvider;\r
-import org.eclipse.jface.viewers.Viewer;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;\r
-\r
-/**\r
- * This is the Content Provider of our tree\r
- *\r
- * @version 1.0\r
- * @author Yuriy Vashchuk\r
- */\r
-public class FilterTreeContentProvider implements ITreeContentProvider {\r
-\r
- /*\r
- * (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()\r
- */\r
- @Override\r
- public void dispose() {\r
- // TODO Auto-generated method stub\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)\r
- */\r
- @Override\r
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {\r
- // TODO Auto-generated method stub\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)\r
- */\r
- @Override\r
- public Object[] getElements(Object inputElement) {\r
- if (inputElement instanceof ITmfFilterTreeNode) {\r
- ArrayList<ITmfFilterTreeNode> result = new ArrayList<ITmfFilterTreeNode>();\r
- for(int i = 0; i < ((ITmfFilterTreeNode)inputElement).getChildrenCount(); i++) {\r
- result.add(((ITmfFilterTreeNode)inputElement).getChild(i));\r
- }\r
-\r
- return result.toArray();\r
- }\r
- return null;\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)\r
- */\r
- @Override\r
- public Object[] getChildren(Object parentElement) {\r
- ArrayList<ITmfFilterTreeNode> result = new ArrayList<ITmfFilterTreeNode>();\r
- for(int i = 0; i < ((ITmfFilterTreeNode)parentElement).getChildrenCount(); i++) {\r
- result.add(((ITmfFilterTreeNode)parentElement).getChild(i));\r
- }\r
- return result.toArray();\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)\r
- */\r
- @Override\r
- public Object getParent(Object element) {\r
- return ((ITmfFilterTreeNode) element).getParent();\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)\r
- */\r
- @Override\r
- public boolean hasChildren(Object element) {\r
- return ((ITmfFilterTreeNode) element).hasChildren();\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.core.filter.model.ITmfFilterTreeNode;
+
+/**
+ * This is the Content Provider of our tree
+ *
+ * @version 1.0
+ * @author Yuriy Vashchuk
+ */
+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<ITmfFilterTreeNode> result = new ArrayList<ITmfFilterTreeNode>();
+ 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<ITmfFilterTreeNode> result = new ArrayList<ITmfFilterTreeNode>();
+ 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();
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Yuriy Vashchuk - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.filter;\r
-\r
-import org.eclipse.jface.viewers.ILabelProvider;\r
-import org.eclipse.jface.viewers.ILabelProviderListener;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterAndNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode.Type;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterContainsNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEqualsNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEventTypeNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterMatchesNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterOrNode;\r
-import org.eclipse.swt.graphics.Image;\r
-\r
-/**\r
- * This is the Label Provider for our Filter Tree\r
- *\r
- * @version 1.0\r
- * @author Yuriy Vashchuk\r
- */\r
-public class FilterTreeLabelProvider implements ILabelProvider {\r
-\r
- /*\r
- * (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)\r
- */\r
- @Override\r
- public void addListener(ILabelProviderListener listener) {\r
- // TODO Auto-generated method stub\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()\r
- */\r
- @Override\r
- public void dispose() {\r
- // TODO Auto-generated method stub\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)\r
- */\r
- @Override\r
- public boolean isLabelProperty(Object element, String property) {\r
- // TODO Auto-generated method stub\r
- return false;\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)\r
- */\r
- @Override\r
- public void removeListener(ILabelProviderListener listener) {\r
- // TODO Auto-generated method stub\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)\r
- */\r
- @Override\r
- public Image getImage(Object element) {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)\r
- */\r
- @Override\r
- public String getText(Object element) {\r
- String label = null;\r
-\r
- if (element instanceof TmfFilterNode) {\r
-\r
- TmfFilterNode node = (TmfFilterNode) element;\r
- label = node.getNodeName() + " " + node.getFilterName(); //$NON-NLS-1$\r
-\r
- } else if (element instanceof TmfFilterEventTypeNode) {\r
-\r
- TmfFilterEventTypeNode node = (TmfFilterEventTypeNode) element;\r
- label = "WITH " + node.getNodeName() + (node.getName() != null ? " " + node.getName() : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
-\r
- } else if (element instanceof TmfFilterAndNode) {\r
-\r
- TmfFilterAndNode node = (TmfFilterAndNode) element;\r
- label = (node.isNot() ? "NOT " : "") + node.getNodeName(); //$NON-NLS-1$ //$NON-NLS-2$\r
-\r
- } else if (element instanceof TmfFilterOrNode) {\r
-\r
- TmfFilterOrNode node = (TmfFilterOrNode) element;\r
- label = (node.isNot() ? "NOT " : "") + node.getNodeName(); //$NON-NLS-1$ //$NON-NLS-2$\r
-\r
- } else if (element instanceof TmfFilterContainsNode) {\r
-\r
- TmfFilterContainsNode node = (TmfFilterContainsNode) element;\r
- label = (node.isNot() ? "NOT " : "") + //$NON-NLS-1$ //$NON-NLS-2$\r
- (node.getField() != null ? node.getField() + " " : "") + //$NON-NLS-1$ //$NON-NLS-2$\r
- node.getNodeName() +\r
- (node.getValue() != null && node.getValue().length() > 0 ? " \"" + node.getValue() + "\"" : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
-\r
- } else if (element instanceof TmfFilterEqualsNode) {\r
-\r
- TmfFilterEqualsNode node = (TmfFilterEqualsNode) element;\r
- label = (node.isNot() ? "NOT " : "") + //$NON-NLS-1$ //$NON-NLS-2$\r
- (node.getField() != null ? node.getField() + " " : "") + //$NON-NLS-1$ //$NON-NLS-2$\r
- node.getNodeName() +\r
- (node.getValue() != null && node.getValue().length() > 0 ? " \"" + node.getValue() + "\"" : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
-\r
- } else if (element instanceof TmfFilterMatchesNode) {\r
-\r
- TmfFilterMatchesNode node = (TmfFilterMatchesNode) element;\r
- label = (node.isNot() ? "NOT " : "") + //$NON-NLS-1$ //$NON-NLS-2$\r
- (node.getField() != null ? node.getField() + " " : "") + //$NON-NLS-1$ //$NON-NLS-2$\r
- node.getNodeName() +\r
- (node.getRegex() != null && node.getRegex().length() > 0 ? " \"" + node.getRegex() + "\"" : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
-\r
- } else if (element instanceof TmfFilterCompareNode) {\r
-\r
- TmfFilterCompareNode node = (TmfFilterCompareNode) element;\r
- label = (node.isNot() ? "NOT " : "") + //$NON-NLS-1$ //$NON-NLS-2$\r
- (node.getField() != null ? node.getField() + " " : "") + //$NON-NLS-1$ //$NON-NLS-2$\r
- (node.getResult() < 0 ? "<" : (node.getResult() > 0 ? ">" : "=")) + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- (node.getValue() != null && node.getValue().length() > 0 ?\r
- (node.getType() == Type.ALPHA ? " \"" + node.getValue() + "\"" : //$NON-NLS-1$ //$NON-NLS-2$\r
- (node.getType() == Type.TIMESTAMP ? " [" + node.getValue() + "]" : //$NON-NLS-1$ //$NON-NLS-2$\r
- " " + node.getValue())) : ""); //$NON-NLS-1$//$NON-NLS-2$\r
-\r
- }\r
- return label;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.core.filter.model.TmfFilterAndNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode.Type;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterContainsNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEqualsNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEventTypeNode;
+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.swt.graphics.Image;
+
+/**
+ * This is the Label Provider for our Filter Tree
+ *
+ * @version 1.0
+ * @author Yuriy Vashchuk
+ */
+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;
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Yuriy Vashchuk - Initial API and implementation\r
- * based on Francois Chouinard ProjectView code.\r
- */\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.filter;\r
-\r
-import java.io.IOException;\r
-\r
-import javax.xml.parsers.ParserConfigurationException;\r
-\r
-import org.eclipse.core.resources.IResource;\r
-import org.eclipse.core.resources.IWorkspace;\r
-import org.eclipse.core.resources.ResourcesPlugin;\r
-import org.eclipse.core.runtime.CoreException;\r
-import org.eclipse.jface.action.Action;\r
-import org.eclipse.jface.action.IToolBarManager;\r
-import org.eclipse.jface.action.Separator;\r
-import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.eclipse.jface.viewers.ISelectionChangedListener;\r
-import org.eclipse.jface.viewers.IStructuredSelection;\r
-import org.eclipse.jface.viewers.SelectionChangedEvent;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLParser;\r
-import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLWriter;\r
-import org.eclipse.linuxtools.tmf.ui.views.TmfView;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.graphics.Image;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.FileDialog;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.ui.IActionBars;\r
-import org.xml.sax.SAXException;\r
-\r
-/**\r
- * View that contain UI to the TMF filter.\r
- *\r
- * @version 1.0\r
- * @author Yuriy Vashchuk\r
- */\r
-public class FilterView extends TmfView {\r
-\r
- /** ID for the Filter view */\r
- public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.filter"; //$NON-NLS-1$\r
-\r
- private static final Image SAVE_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/save_button.gif"); //$NON-NLS-1$\r
- private static final Image ADD_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$\r
- private static final Image DELETE_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$\r
- private static final Image IMPORT_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/import_button.gif"); //$NON-NLS-1$\r
- private static final Image EXPORT_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/export_button.gif"); //$NON-NLS-1$\r
-\r
- // ------------------------------------------------------------------------\r
- // Main data structures\r
- // ------------------------------------------------------------------------\r
-\r
- private FilterViewer fViewer;\r
- private final ITmfFilterTreeNode fRoot;\r
-\r
- private final IWorkspace fWorkspace;\r
-\r
- private SaveAction fSaveAction;\r
- private AddAction fAddAction;\r
- private DeleteAction fDeleteAction;\r
- private ExportAction fExportAction;\r
- private ImportAction fImportAction;\r
-\r
- /**\r
- * Getter for the Filter Tree Root\r
- *\r
- * @return The root of builded tree\r
- */\r
- public ITmfFilterTreeNode getFilterRoot() {\r
- return fRoot;\r
- }\r
-\r
-\r
- // ------------------------------------------------------------------------\r
- // Constructor\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Default Constructor\r
- */\r
- public FilterView() {\r
- super("Filter"); //$NON-NLS-1$\r
-\r
- fWorkspace = ResourcesPlugin.getWorkspace();\r
- try {\r
- fWorkspace.getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);\r
- } catch (CoreException e) {\r
- Activator.getDefault().logError("Error refreshing workspace", e); //$NON-NLS-1$\r
- }\r
-\r
- fRoot = new TmfFilterRootNode();\r
- for (ITmfFilterTreeNode node : FilterManager.getSavedFilters()) {\r
- fRoot.addChild(node);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Refresh the tree widget\r
- */\r
- public void refresh() {\r
- fViewer.refresh();\r
- }\r
-\r
- /**\r
- * Setter for selection\r
- *\r
- * @param node The node to select\r
- */\r
- public void setSelection(ITmfFilterTreeNode node) {\r
- fViewer.setSelection(node, true);\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // ViewPart\r
- // ------------------------------------------------------------------------\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(Composite)\r
- */\r
- @Override\r
- public void createPartControl(Composite parent) {\r
-\r
- fViewer = new FilterViewer(parent, SWT.NONE);\r
- fViewer.setInput(fRoot);\r
-\r
- contributeToActionBars();\r
-\r
- fViewer.addSelectionChangedListener(new ISelectionChangedListener() {\r
- @Override\r
- public void selectionChanged(SelectionChangedEvent event) {\r
- if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) {\r
- fDeleteAction.setEnabled(true);\r
- fExportAction.setEnabled(true);\r
- } else {\r
- fDeleteAction.setEnabled(false);\r
- fExportAction.setEnabled(false);\r
- }\r
- }\r
- });\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.ui.part.WorkbenchPart#setFocus()\r
- */\r
- @Override\r
- public void setFocus() {\r
- fViewer.setFocus();\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * @see java.lang.Object#toString()\r
- */\r
- @Override\r
- public String toString() {\r
- return "[FilterView]"; //$NON-NLS-1$\r
- }\r
-\r
-\r
- /**\r
- * Builds the menu toolbar\r
- */\r
- private void contributeToActionBars() {\r
- IActionBars bars = getViewSite().getActionBars();\r
- //fillLocalPullDown(bars.getMenuManager());\r
- fillLocalToolBar(bars.getToolBarManager());\r
- }\r
-\r
-\r
- /**\r
- * Build the popup menu\r
- *\r
- * @param manager The manager to build\r
- */\r
- private void fillLocalToolBar(IToolBarManager manager) {\r
-\r
- fSaveAction = new SaveAction();\r
- fSaveAction.setImageDescriptor(ImageDescriptor.createFromImage(SAVE_IMAGE));\r
- fSaveAction.setToolTipText(Messages.FilterView_SaveActionToolTipText);\r
-\r
- fAddAction = new AddAction();\r
- fAddAction.setImageDescriptor(ImageDescriptor.createFromImage(ADD_IMAGE));\r
- fAddAction.setToolTipText(Messages.FilterView_AddActionToolTipText);\r
-\r
- fDeleteAction = new DeleteAction();\r
- fDeleteAction.setImageDescriptor(ImageDescriptor.createFromImage(DELETE_IMAGE));\r
- fDeleteAction.setToolTipText(Messages.FilterView_DeleteActionToolTipText);\r
- fDeleteAction.setEnabled(false);\r
-\r
- fExportAction = new ExportAction();\r
- fExportAction.setImageDescriptor(ImageDescriptor.createFromImage(EXPORT_IMAGE));\r
- fExportAction.setToolTipText(Messages.FilterView_ExportActionToolTipText);\r
-\r
- fImportAction = new ImportAction();\r
- fImportAction.setImageDescriptor(ImageDescriptor.createFromImage(IMPORT_IMAGE));\r
- fImportAction.setToolTipText(Messages.FilterView_ImportActionToolTipText);\r
-\r
- manager.add(fSaveAction);\r
- manager.add(new Separator());\r
- manager.add(fAddAction);\r
- manager.add(fDeleteAction);\r
- manager.add(new Separator());\r
- manager.add(fExportAction);\r
- manager.add(fImportAction);\r
- }\r
-\r
- private class SaveAction extends Action {\r
- @Override\r
- public void run() {\r
- FilterManager.setSavedFilters(fRoot.getChildren());\r
- }\r
- }\r
-\r
- private class AddAction extends Action {\r
- @Override\r
- public void run() {\r
-\r
- TmfFilterNode newNode = new TmfFilterNode(fRoot, ""); //$NON-NLS-1$\r
- refresh();\r
- setSelection(newNode);\r
- }\r
- }\r
-\r
- private class DeleteAction extends Action {\r
- @Override\r
- public void run() {\r
- ITmfFilterTreeNode node = fViewer.getSelection();\r
- if (node != null) {\r
- node.remove();\r
- }\r
- refresh();\r
- }\r
- }\r
-\r
- private class ExportAction extends Action {\r
- @Override\r
- public void run() {\r
- try {\r
- FileDialog dlg = new FileDialog(new Shell(), SWT.SAVE);\r
- dlg.setFilterNames(new String[] {Messages.FilterView_FileDialogFilterName + " (*.filter.xml)"}); //$NON-NLS-1$\r
- dlg.setFilterExtensions(new String[] {"*.filter.xml"}); //$NON-NLS-1$\r
-\r
- String fn = dlg.open();\r
- if (fn != null) {\r
- TmfFilterXMLWriter writerXML = new TmfFilterXMLWriter(fRoot);\r
- writerXML.saveTree(fn);\r
- }\r
-\r
- } catch (ParserConfigurationException e) {\r
- Activator.getDefault().logError("Error parsing filter xml file", e); //$NON-NLS-1$\r
- }\r
- }\r
- }\r
-\r
- private class ImportAction extends Action {\r
- @Override\r
- public void run() {\r
- if (fViewer != null) {\r
- ITmfFilterTreeNode root = null;\r
- try {\r
- FileDialog dlg = new FileDialog(new Shell(), SWT.OPEN);\r
- dlg.setFilterNames(new String[] {Messages.FilterView_FileDialogFilterName + " (*.filter.xml)"}); //$NON-NLS-1$\r
- dlg.setFilterExtensions(new String[] {"*.filter.xml"}); //$NON-NLS-1$\r
-\r
- TmfFilterXMLParser parserXML = null;\r
- String fn = dlg.open();\r
- if (fn != null) {\r
- parserXML = new TmfFilterXMLParser(fn);\r
- root = parserXML.getTree();\r
- }\r
-\r
- } catch (SAXException e) {\r
- Activator.getDefault().logError("Error importing filter xml file", e); //$NON-NLS-1$\r
- } catch (IOException e) {\r
- Activator.getDefault().logError("Error importing filter xml file", e); //$NON-NLS-1$\r
- }\r
-\r
- if (root != null) {\r
- for (ITmfFilterTreeNode node : root.getChildren()) {\r
- if (node instanceof TmfFilterNode) {\r
- fRoot.addChild(node);\r
- refresh();\r
- fViewer.setSelection(node);\r
- }\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
+/*******************************************************************************
+ * Copyright (c) 2010 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Yuriy Vashchuk - Initial API and implementation
+ * based on Francois Chouinard ProjectView code.
+ */
+
+package org.eclipse.linuxtools.tmf.ui.views.filter;
+
+import java.io.IOException;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode;
+import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLParser;
+import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLWriter;
+import org.eclipse.linuxtools.tmf.ui.views.TmfView;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionBars;
+import org.xml.sax.SAXException;
+
+/**
+ * View that contain UI to the TMF filter.
+ *
+ * @version 1.0
+ * @author Yuriy Vashchuk
+ */
+public class FilterView extends TmfView {
+
+ /** ID for the Filter view */
+ public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.filter"; //$NON-NLS-1$
+
+ private static final Image SAVE_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/save_button.gif"); //$NON-NLS-1$
+ private static final Image ADD_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
+ private static final Image DELETE_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
+ private static final Image IMPORT_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/import_button.gif"); //$NON-NLS-1$
+ private static final Image EXPORT_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/export_button.gif"); //$NON-NLS-1$
+
+ // ------------------------------------------------------------------------
+ // Main data structures
+ // ------------------------------------------------------------------------
+
+ private FilterViewer fViewer;
+ private final ITmfFilterTreeNode fRoot;
+
+ private final IWorkspace fWorkspace;
+
+ private SaveAction fSaveAction;
+ private AddAction fAddAction;
+ private DeleteAction fDeleteAction;
+ private ExportAction fExportAction;
+ private ImportAction fImportAction;
+
+ /**
+ * Getter for the Filter Tree Root
+ *
+ * @return The root of builded tree
+ */
+ public ITmfFilterTreeNode getFilterRoot() {
+ return fRoot;
+ }
+
+
+ // ------------------------------------------------------------------------
+ // Constructor
+ // ------------------------------------------------------------------------
+
+ /**
+ * Default Constructor
+ */
+ public FilterView() {
+ super("Filter"); //$NON-NLS-1$
+
+ fWorkspace = ResourcesPlugin.getWorkspace();
+ try {
+ fWorkspace.getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ Activator.getDefault().logError("Error refreshing workspace", e); //$NON-NLS-1$
+ }
+
+ fRoot = new TmfFilterRootNode();
+ for (ITmfFilterTreeNode node : FilterManager.getSavedFilters()) {
+ fRoot.addChild(node);
+ }
+ }
+
+
+ /**
+ * Refresh the tree widget
+ */
+ public void refresh() {
+ fViewer.refresh();
+ }
+
+ /**
+ * Setter for selection
+ *
+ * @param node The node to select
+ */
+ public void setSelection(ITmfFilterTreeNode node) {
+ fViewer.setSelection(node, true);
+ }
+
+ // ------------------------------------------------------------------------
+ // ViewPart
+ // ------------------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(Composite)
+ */
+ @Override
+ public void createPartControl(Composite parent) {
+
+ fViewer = new FilterViewer(parent, SWT.NONE);
+ fViewer.setInput(fRoot);
+
+ contributeToActionBars();
+
+ fViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) {
+ fDeleteAction.setEnabled(true);
+ fExportAction.setEnabled(true);
+ } else {
+ fDeleteAction.setEnabled(false);
+ fExportAction.setEnabled(false);
+ }
+ }
+ });
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
+ */
+ @Override
+ public void setFocus() {
+ fViewer.setFocus();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "[FilterView]"; //$NON-NLS-1$
+ }
+
+
+ /**
+ * Builds the menu toolbar
+ */
+ private void contributeToActionBars() {
+ IActionBars bars = getViewSite().getActionBars();
+ //fillLocalPullDown(bars.getMenuManager());
+ fillLocalToolBar(bars.getToolBarManager());
+ }
+
+
+ /**
+ * Build the popup menu
+ *
+ * @param manager The manager to build
+ */
+ private void fillLocalToolBar(IToolBarManager manager) {
+
+ fSaveAction = new SaveAction();
+ fSaveAction.setImageDescriptor(ImageDescriptor.createFromImage(SAVE_IMAGE));
+ fSaveAction.setToolTipText(Messages.FilterView_SaveActionToolTipText);
+
+ fAddAction = new AddAction();
+ fAddAction.setImageDescriptor(ImageDescriptor.createFromImage(ADD_IMAGE));
+ fAddAction.setToolTipText(Messages.FilterView_AddActionToolTipText);
+
+ fDeleteAction = new DeleteAction();
+ fDeleteAction.setImageDescriptor(ImageDescriptor.createFromImage(DELETE_IMAGE));
+ fDeleteAction.setToolTipText(Messages.FilterView_DeleteActionToolTipText);
+ fDeleteAction.setEnabled(false);
+
+ fExportAction = new ExportAction();
+ fExportAction.setImageDescriptor(ImageDescriptor.createFromImage(EXPORT_IMAGE));
+ fExportAction.setToolTipText(Messages.FilterView_ExportActionToolTipText);
+
+ fImportAction = new ImportAction();
+ fImportAction.setImageDescriptor(ImageDescriptor.createFromImage(IMPORT_IMAGE));
+ fImportAction.setToolTipText(Messages.FilterView_ImportActionToolTipText);
+
+ manager.add(fSaveAction);
+ manager.add(new Separator());
+ manager.add(fAddAction);
+ manager.add(fDeleteAction);
+ manager.add(new Separator());
+ manager.add(fExportAction);
+ manager.add(fImportAction);
+ }
+
+ private class SaveAction extends Action {
+ @Override
+ public void run() {
+ FilterManager.setSavedFilters(fRoot.getChildren());
+ }
+ }
+
+ private class AddAction extends Action {
+ @Override
+ public void run() {
+
+ TmfFilterNode newNode = new TmfFilterNode(fRoot, ""); //$NON-NLS-1$
+ refresh();
+ setSelection(newNode);
+ }
+ }
+
+ private class DeleteAction extends Action {
+ @Override
+ public void run() {
+ ITmfFilterTreeNode node = fViewer.getSelection();
+ if (node != null) {
+ node.remove();
+ }
+ refresh();
+ }
+ }
+
+ private class ExportAction extends Action {
+ @Override
+ public void run() {
+ try {
+ FileDialog dlg = new FileDialog(new Shell(), SWT.SAVE);
+ dlg.setFilterNames(new String[] {Messages.FilterView_FileDialogFilterName + " (*.filter.xml)"}); //$NON-NLS-1$
+ dlg.setFilterExtensions(new String[] {"*.filter.xml"}); //$NON-NLS-1$
+
+ String fn = dlg.open();
+ if (fn != null) {
+ TmfFilterXMLWriter writerXML = new TmfFilterXMLWriter(fRoot);
+ writerXML.saveTree(fn);
+ }
+
+ } catch (ParserConfigurationException e) {
+ Activator.getDefault().logError("Error parsing filter xml file", e); //$NON-NLS-1$
+ }
+ }
+ }
+
+ private class ImportAction extends Action {
+ @Override
+ public void run() {
+ if (fViewer != null) {
+ ITmfFilterTreeNode root = null;
+ try {
+ FileDialog dlg = new FileDialog(new Shell(), SWT.OPEN);
+ dlg.setFilterNames(new String[] {Messages.FilterView_FileDialogFilterName + " (*.filter.xml)"}); //$NON-NLS-1$
+ dlg.setFilterExtensions(new String[] {"*.filter.xml"}); //$NON-NLS-1$
+
+ TmfFilterXMLParser parserXML = null;
+ String fn = dlg.open();
+ if (fn != null) {
+ parserXML = new TmfFilterXMLParser(fn);
+ root = parserXML.getTree();
+ }
+
+ } catch (SAXException e) {
+ Activator.getDefault().logError("Error importing filter xml file", e); //$NON-NLS-1$
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error importing filter xml file", e); //$NON-NLS-1$
+ }
+
+ if (root != null) {
+ for (ITmfFilterTreeNode node : root.getChildren()) {
+ if (node instanceof TmfFilterNode) {
+ fRoot.addChild(node);
+ refresh();
+ fViewer.setSelection(node);
+ }
+ }
+ }
+ }
+ }
+ }
+
}
\ No newline at end of file
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- * \r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- * \r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.filter;\r
-\r
-import java.util.ArrayList;\r
-import java.util.LinkedHashMap;\r
-import java.util.Map;\r
-import java.util.Map.Entry;\r
-\r
-import org.eclipse.core.runtime.CoreException;\r
-import org.eclipse.core.runtime.IConfigurationElement;\r
-import org.eclipse.jface.action.Action;\r
-import org.eclipse.jface.action.IMenuListener;\r
-import org.eclipse.jface.action.IMenuManager;\r
-import org.eclipse.jface.action.MenuManager;\r
-import org.eclipse.jface.action.Separator;\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.jface.viewers.ISelectionChangedListener;\r
-import org.eclipse.jface.viewers.IStructuredSelection;\r
-import org.eclipse.jface.viewers.SelectionChangedEvent;\r
-import org.eclipse.jface.viewers.StructuredSelection;\r
-import org.eclipse.jface.viewers.TreeViewer;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtEvent;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlEvent;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterAndNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode.Type;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterContainsNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEqualsNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEventTypeNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterMatchesNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterOrNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode;\r
-import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterTreeNode;\r
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceType;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.SashForm;\r
-import org.eclipse.swt.events.FocusEvent;\r
-import org.eclipse.swt.events.FocusListener;\r
-import org.eclipse.swt.events.ModifyEvent;\r
-import org.eclipse.swt.events.ModifyListener;\r
-import org.eclipse.swt.events.PaintEvent;\r
-import org.eclipse.swt.events.PaintListener;\r
-import org.eclipse.swt.events.SelectionAdapter;\r
-import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.layout.FillLayout;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Button;\r
-import org.eclipse.swt.widgets.Combo;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Menu;\r
-import org.eclipse.swt.widgets.Text;\r
-import org.eclipse.swt.widgets.TreeItem;\r
-\r
-class FilterViewer extends Composite {\r
-\r
- private static final String CUSTOM_TXT_CATEGORY = "Custom Text"; //$NON-NLS-1$\r
- private static final String CUSTOM_XML_CATEGORY = "Custom XML"; //$NON-NLS-1$\r
-\r
- private TreeViewer fViewer;\r
- private Composite fComposite;\r
- \r
- public FilterViewer(Composite parent, int style) {\r
- super(parent, style);\r
-\r
- setLayout(new FillLayout());\r
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);\r
- setLayoutData(gd);\r
- \r
- final SashForm sash = new SashForm(this, SWT.HORIZONTAL);\r
-\r
- // Create the tree viewer to display the filter tree\r
- fViewer = new TreeViewer(sash, SWT.NONE);\r
- fViewer.setContentProvider(new FilterTreeContentProvider());\r
- fViewer.setLabelProvider(new FilterTreeLabelProvider());\r
- fViewer.setInput(new TmfFilterRootNode());\r
- \r
- // Create the empty filter node properties panel\r
- fComposite = new Composite(sash, SWT.NONE);\r
- GridLayout gl = new GridLayout();\r
- gl.marginHeight = 0;\r
- gl.marginWidth = 0;\r
- fComposite.setLayout(gl);\r
-\r
- createContextMenu();\r
- \r
- fViewer.addSelectionChangedListener(new ISelectionChangedListener() {\r
- @Override\r
- public void selectionChanged(SelectionChangedEvent event) {\r
- if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) {\r
- // Update the filter node properties panel to the selection\r
- IStructuredSelection selection = (IStructuredSelection) event.getSelection();\r
- ITmfFilterTreeNode node = (ITmfFilterTreeNode) selection.getFirstElement();\r
- updateFilterNodeComposite(node);\r
- // Highlight the selection's children\r
- highlightTreeItems(fViewer.getTree().getSelection()[0].getItems());\r
- } else {\r
- updateFilterNodeComposite(null);\r
- }\r
- }\r
- });\r
-\r
- fViewer.getTree().addPaintListener(new PaintListener() {\r
- @Override\r
- public void paintControl(PaintEvent e) {\r
- TmfFilterTreeNode root = (TmfFilterTreeNode) fViewer.getInput();\r
- if (root == null || root.getChildrenCount() == 0) {\r
- e.gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));\r
- e.gc.drawText(Messages.FilterViewer_EmptyTreeHintText, 5, 0);\r
- }\r
- }\r
- });\r
- }\r
- \r
- /**\r
- * Create the context menu for the tree viewer\r
- */\r
- private void createContextMenu() {\r
- // Adds root context menu\r
- MenuManager menuManager = new MenuManager();\r
- menuManager.setRemoveAllWhenShown(true);\r
- menuManager.addMenuListener(new IMenuListener() {\r
- @Override\r
- public void menuAboutToShow(IMenuManager manager) {\r
- fillContextMenu(manager);\r
- }\r
- });\r
-\r
- // Context\r
- Menu contextMenu = menuManager.createContextMenu(fViewer.getTree());\r
-\r
- // Publish it\r
- fViewer.getTree().setMenu(contextMenu);\r
- }\r
- \r
- /**\r
- * Fill the context menu for the tree viewer\r
- */\r
- protected void fillContextMenu(IMenuManager manager) {\r
- final ISelection selection = fViewer.getSelection();\r
- ITmfFilterTreeNode filterTreeNode = null;\r
- if (selection instanceof StructuredSelection) {\r
- Object element = ((StructuredSelection) selection).getFirstElement();\r
- if (element instanceof ITmfFilterTreeNode) {\r
- filterTreeNode = (ITmfFilterTreeNode) element;\r
- }\r
- }\r
-\r
- final ITmfFilterTreeNode selectedNode = filterTreeNode;\r
- \r
- if (selectedNode != null) {\r
- \r
- fillContextMenuForNode(selectedNode, manager);\r
- \r
- if (selectedNode.getValidChildren().size() > 0) {\r
- manager.add(new Separator());\r
- }\r
-\r
- Action deleteAction = new Action() {\r
- @Override\r
- public void run() {\r
- selectedNode.remove();\r
- fViewer.refresh();\r
- }\r
- };\r
- deleteAction.setText(Messages.FilterViewer_DeleteActionText);\r
- manager.add(deleteAction);\r
- \r
- manager.add(new Separator());\r
- }\r
-\r
- if (fViewer.getInput() instanceof TmfFilterRootNode || selectedNode == null) {\r
- final ITmfFilterTreeNode root = (ITmfFilterTreeNode) fViewer.getInput();\r
- \r
- fillContextMenuForNode(root, manager);\r
- }\r
- }\r
- \r
- /**\r
- * Fill the context menu with the valid children of the provided node\r
- */\r
- protected void fillContextMenuForNode(final ITmfFilterTreeNode node, IMenuManager manager) {\r
- for (final String child : node.getValidChildren()) {\r
- final Action action = new Action() {\r
- @Override\r
- public void run() {\r
- ITmfFilterTreeNode newNode = null;\r
- if (TmfFilterNode.NODE_NAME.equals(child)) {\r
- newNode = new TmfFilterNode(node, ""); //$NON-NLS-1$\r
- } else if (TmfFilterEventTypeNode.NODE_NAME.equals(child)) {\r
- newNode = new TmfFilterEventTypeNode(node);\r
- } else if (TmfFilterAndNode.NODE_NAME.equals(child)) {\r
- newNode = new TmfFilterAndNode(node);\r
- } else if (TmfFilterOrNode.NODE_NAME.equals(child)) {\r
- newNode = new TmfFilterOrNode(node);\r
- } else if (TmfFilterContainsNode.NODE_NAME.equals(child)) {\r
- newNode = new TmfFilterContainsNode(node);\r
- } else if (TmfFilterEqualsNode.NODE_NAME.equals(child)) {\r
- newNode = new TmfFilterEqualsNode(node);\r
- } else if (TmfFilterMatchesNode.NODE_NAME.equals(child)) {\r
- newNode = new TmfFilterMatchesNode(node);\r
- } else if (TmfFilterCompareNode.NODE_NAME.equals(child)) {\r
- newNode = new TmfFilterCompareNode(node);\r
- }\r
- if (newNode != null) {\r
- fViewer.refresh();\r
- fViewer.setSelection(new StructuredSelection(newNode), true);\r
- }\r
- }\r
- };\r
- if (TmfFilterNode.NODE_NAME.equals(child)) {\r
- action.setText(Messages.FilterViewer_NewPrefix + " " + child); //$NON-NLS-1$\r
- } else {\r
- action.setText(child);\r
- }\r
- manager.add(action);\r
- }\r
- }\r
- \r
- /**\r
- * Create the appropriate filter node properties composite\r
- */\r
- private void updateFilterNodeComposite(ITmfFilterTreeNode node) {\r
- for (Control control : fComposite.getChildren()) {\r
- control.dispose();\r
- }\r
- \r
- if (node instanceof TmfFilterNode) {\r
- new FilterNodeComposite(fComposite, (TmfFilterNode) node);\r
- } else if (node instanceof TmfFilterEventTypeNode) {\r
- new FilterEventTypeNodeComposite(fComposite, (TmfFilterEventTypeNode) node);\r
- } else if (node instanceof TmfFilterAndNode) {\r
- new FilterAndNodeComposite(fComposite, (TmfFilterAndNode) node);\r
- } else if (node instanceof TmfFilterOrNode) {\r
- new FilterOrNodeComposite(fComposite, (TmfFilterOrNode) node);\r
- } else if (node instanceof TmfFilterContainsNode) {\r
- new FilterContainsNodeComposite(fComposite, (TmfFilterContainsNode) node);\r
- } else if (node instanceof TmfFilterEqualsNode) {\r
- new FilterEqualsNodeComposite(fComposite, (TmfFilterEqualsNode) node);\r
- } else if (node instanceof TmfFilterMatchesNode) {\r
- new FilterMatchesNodeComposite(fComposite, (TmfFilterMatchesNode) node);\r
- } else if (node instanceof TmfFilterCompareNode) {\r
- new FilterCompareNodeComposite(fComposite, (TmfFilterCompareNode) node);\r
- } else {\r
- new FilterBaseNodeComposite(fComposite);\r
- }\r
- fComposite.layout();\r
- }\r
- \r
- /**\r
- * Highlight the provided tree items\r
- */\r
- private void highlightTreeItems(TreeItem[] items) {\r
- resetTreeItems(fViewer.getTree().getItems());\r
- for (TreeItem item : items) {\r
- item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));\r
- }\r
-\r
- }\r
- \r
- /**\r
- * Reset the provided tree items (remove highlight)\r
- */\r
- private void resetTreeItems(TreeItem[] items) {\r
- for (TreeItem item : items) {\r
- item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));\r
- resetTreeItems(item.getItems());\r
- }\r
- }\r
- \r
- public void setInput(ITmfFilterTreeNode root) {\r
- fViewer.setInput(root);\r
- fViewer.expandAll();\r
- \r
- updateFilterNodeComposite(null);\r
- }\r
- \r
- public ITmfFilterTreeNode getInput() {\r
- return (ITmfFilterTreeNode) fViewer.getInput();\r
- }\r
- \r
- public void refresh() {\r
- fViewer.refresh();\r
- }\r
-\r
- public void setSelection(ITmfFilterTreeNode node, boolean reveal) {\r
- fViewer.setSelection(new StructuredSelection(node), reveal);\r
- }\r
-\r
- public void setSelection(ITmfFilterTreeNode node) {\r
- fViewer.setSelection(new StructuredSelection(node));\r
- }\r
- \r
- public ITmfFilterTreeNode getSelection() {\r
- final ISelection selection = fViewer.getSelection();\r
- ITmfFilterTreeNode filterTreeNode = null;\r
- if (selection instanceof StructuredSelection) {\r
- Object element = ((StructuredSelection) selection).getFirstElement();\r
- if (element instanceof ITmfFilterTreeNode) {\r
- filterTreeNode = (ITmfFilterTreeNode) element;\r
- }\r
- }\r
-\r
- final ITmfFilterTreeNode selectedNode = filterTreeNode;\r
- return selectedNode;\r
- }\r
- \r
- public void addSelectionChangedListener(ISelectionChangedListener listener) {\r
- fViewer.addSelectionChangedListener(listener);\r
- }\r
- \r
- public void removeSelectionChangedListener(ISelectionChangedListener listener) {\r
- fViewer.removeSelectionChangedListener(listener);\r
- }\r
- \r
- private class FilterBaseNodeComposite extends Composite {\r
- \r
- FilterBaseNodeComposite(Composite parent) {\r
- super(parent, SWT.NONE);\r
- setLayout(new GridLayout(2, false));\r
- setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- }\r
- \r
- protected String[] getFieldsList(ITmfFilterTreeNode node) {\r
- ArrayList<String> fieldsList = new ArrayList<String>();\r
- while (node != null) {\r
- if (node instanceof TmfFilterEventTypeNode) {\r
- TmfFilterEventTypeNode eventTypeNode = (TmfFilterEventTypeNode) node;\r
- for (IConfigurationElement ce : TmfTraceType.getTypeElements()) {\r
- if (ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR).equals(eventTypeNode.getEventType())) {\r
- try {\r
- ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);\r
- ITmfEventType eventType = event.getType();\r
- if (eventType != null) {\r
- for (String field : eventType.getRootField().getFieldNames()) {\r
- fieldsList.add(field);\r
- }\r
- }\r
- } catch (CoreException e) {\r
- }\r
- if (fieldsList.size() == 0) {\r
- fieldsList.add(ITmfEvent.EVENT_FIELD_TIMESTAMP);\r
- fieldsList.add(ITmfEvent.EVENT_FIELD_SOURCE);\r
- fieldsList.add(ITmfEvent.EVENT_FIELD_TYPE);\r
- fieldsList.add(ITmfEvent.EVENT_FIELD_REFERENCE);\r
- fieldsList.add(ITmfEvent.EVENT_FIELD_CONTENT);\r
- }\r
- return fieldsList.toArray(new String[0]);\r
- }\r
- }\r
- if (eventTypeNode.getEventType() != null && eventTypeNode.getEventType().startsWith(CustomTxtEvent.class.getCanonicalName())) {\r
- for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {\r
- if (eventTypeNode.getEventType().equals(CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$\r
- for (OutputColumn output : def.outputs) {\r
- fieldsList.add(output.name);\r
- }\r
- return fieldsList.toArray(new String[0]);\r
- }\r
- }\r
- }\r
- if (eventTypeNode.getEventType() != null && eventTypeNode.getEventType().startsWith(CustomXmlEvent.class.getCanonicalName())) {\r
- for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {\r
- if (eventTypeNode.getEventType().equals(CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$\r
- for (OutputColumn output : def.outputs) {\r
- fieldsList.add(output.name);\r
- }\r
- return fieldsList.toArray(new String[0]);\r
- }\r
- }\r
- }\r
- }\r
- node = node.getParent();\r
- }\r
-\r
- fieldsList.add(Messages.FilterViewer_CommonCategory);\r
- fieldsList.add(ITmfEvent.EVENT_FIELD_TIMESTAMP);\r
- fieldsList.add(ITmfEvent.EVENT_FIELD_SOURCE);\r
- fieldsList.add(ITmfEvent.EVENT_FIELD_TYPE);\r
- fieldsList.add(ITmfEvent.EVENT_FIELD_REFERENCE);\r
- fieldsList.add(ITmfEvent.EVENT_FIELD_CONTENT);\r
- fieldsList.add(""); //$NON-NLS-1$\r
-\r
- for (IConfigurationElement ce : TmfTraceType.getTypeElements()) {\r
- try {\r
- ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);\r
- ITmfEventType eventType = event.getType();\r
- if (eventType != null && eventType.getFieldNames().length > 0) {\r
- fieldsList.add("[" + TmfTraceType.getCategoryName(ce.getAttribute(TmfTraceType.CATEGORY_ATTR)) + //$NON-NLS-1$\r
- " : " + ce.getAttribute(TmfTraceType.NAME_ATTR) + "]"); //$NON-NLS-1$ //$NON-NLS-2$\r
- for (String field : eventType.getFieldNames()) {\r
- fieldsList.add(field);\r
- }\r
- fieldsList.add(""); //$NON-NLS-1$\r
- }\r
- } catch (CoreException e) {\r
- }\r
- }\r
- for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {\r
- if (def.outputs.size() > 0) {\r
- fieldsList.add("[" + CUSTOM_TXT_CATEGORY + //$NON-NLS-1$\r
- " : " + def.definitionName + "]"); //$NON-NLS-1$ //$NON-NLS-2$\r
- for (OutputColumn output : def.outputs) {\r
- fieldsList.add(output.name);\r
- }\r
- fieldsList.add(""); //$NON-NLS-1$\r
- }\r
- }\r
- for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {\r
- if (def.outputs.size() > 0) {\r
- fieldsList.add("[" + CUSTOM_XML_CATEGORY + //$NON-NLS-1$\r
- " : " + def.definitionName + "]"); //$NON-NLS-1$ //$NON-NLS-2$\r
- for (OutputColumn output : def.outputs) {\r
- fieldsList.add(output.name);\r
- }\r
- fieldsList.add(""); //$NON-NLS-1$\r
- }\r
- }\r
- return fieldsList.toArray(new String[0]);\r
- }\r
- }\r
-\r
- private class FilterNodeComposite extends FilterBaseNodeComposite {\r
- TmfFilterNode fNode;\r
- Text fNameText;\r
- \r
- FilterNodeComposite(Composite parent, TmfFilterNode node) {\r
- super(parent);\r
- fNode = node;\r
- \r
- Label label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_NameLabel);\r
- \r
- fNameText = new Text(this, SWT.BORDER);\r
- fNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- if (node.getFilterName() != null && node.getFilterName().length() > 0) {\r
- fNameText.setText(node.getFilterName());\r
- } else {\r
- fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));\r
- fNameText.setText(Messages.FilterViewer_FilterNameHint);\r
- }\r
- fNameText.addFocusListener(new FocusListener() {\r
- @Override\r
- public void focusLost(FocusEvent e) {\r
- if (fNode.getFilterName() == null || fNode.getFilterName().length() == 0) {\r
- fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));\r
- fNameText.setText(Messages.FilterViewer_FilterNameHint);\r
- }\r
- }\r
- @Override\r
- public void focusGained(FocusEvent e) {\r
- if (fNameText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {\r
- fNameText.setText(""); //$NON-NLS-1$\r
- }\r
- fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));\r
- }\r
- });\r
- fNameText.addModifyListener(new ModifyListener() {\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- if (! fNameText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {\r
- fNode.setFilterName(fNameText.getText());\r
- fViewer.refresh(fNode);\r
- }\r
- }\r
- });\r
- }\r
- }\r
-\r
- private class FilterEventTypeNodeComposite extends FilterBaseNodeComposite {\r
- TmfFilterEventTypeNode fNode;\r
- Combo fTypeCombo;\r
- Map<String, Object> fEventsTypeMap;\r
- \r
- FilterEventTypeNodeComposite(Composite parent, TmfFilterEventTypeNode node) {\r
- super(parent);\r
- fNode = node;\r
- fEventsTypeMap = getEventsTypeMap();\r
-\r
- Label label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_TypeLabel);\r
- \r
- fTypeCombo = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY);\r
- fTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- fTypeCombo.setItems(fEventsTypeMap.keySet().toArray(new String[0]));\r
- if (fNode.getEventType() != null) {\r
- for (Entry <String, Object> eventTypeEntry : fEventsTypeMap.entrySet()) {\r
- Object value = eventTypeEntry.getValue();\r
- if (value instanceof IConfigurationElement) {\r
- IConfigurationElement ce = (IConfigurationElement) value;\r
- if (ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR).equals(fNode.getEventType())) {\r
- fTypeCombo.setText(eventTypeEntry.getKey());\r
- }\r
- } else if (value instanceof CustomTxtTraceDefinition) {\r
- CustomTxtTraceDefinition def = (CustomTxtTraceDefinition) value;\r
- String eventType = CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$\r
- if (eventType.equals(fNode.getEventType())) {\r
- fTypeCombo.setText(eventTypeEntry.getKey());\r
- }\r
- } else if (value instanceof CustomXmlTraceDefinition) {\r
- CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) value;\r
- String eventType = CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$\r
- if (eventType.equals(fNode.getEventType())) {\r
- fTypeCombo.setText(eventTypeEntry.getKey());\r
- }\r
- }\r
- }\r
- }\r
- fTypeCombo.addModifyListener(new ModifyListener() {\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- for (Entry <String, Object> eventTypeEntry : fEventsTypeMap.entrySet()) {\r
- if (eventTypeEntry.getKey().equals(fTypeCombo.getText())) {\r
- Object value = eventTypeEntry.getValue();\r
- if (value instanceof IConfigurationElement) {\r
- IConfigurationElement ce = (IConfigurationElement) value;\r
- fNode.setEventType(ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR));\r
- fNode.setName(ce.getAttribute(TmfTraceType.NAME_ATTR));\r
- } else if (value instanceof CustomTxtTraceDefinition) {\r
- CustomTxtTraceDefinition def = (CustomTxtTraceDefinition) value;\r
- fNode.setEventType(CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName); //$NON-NLS-1$\r
- fNode.setName(def.definitionName);\r
- } else if (value instanceof CustomXmlTraceDefinition) {\r
- CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) value;\r
- fNode.setEventType(CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName); //$NON-NLS-1$\r
- fNode.setName(def.definitionName);\r
- }\r
- fViewer.refresh(fNode);\r
- break;\r
- }\r
- }\r
- }\r
- });\r
- }\r
-\r
- protected Map<String, Object> getEventsTypeMap() {\r
- Map<String, Object> eventsTypeMap = new LinkedHashMap<String, Object>();\r
- for (IConfigurationElement ce : TmfTraceType.getTypeElements()) {\r
- String categoryName = TmfTraceType.getCategoryName(ce.getAttribute(TmfTraceType.CATEGORY_ATTR));\r
- String text = categoryName + " : " + ce.getAttribute(TmfTraceType.NAME_ATTR); //$NON-NLS-1$\r
- eventsTypeMap.put(text, ce);\r
- }\r
- for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {\r
- String text = CUSTOM_TXT_CATEGORY + " : " + def.definitionName; //$NON-NLS-1$\r
- eventsTypeMap.put(text, def);\r
- }\r
- for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {\r
- String text = CUSTOM_XML_CATEGORY + " : " + def.definitionName; //$NON-NLS-1$\r
- eventsTypeMap.put(text, def);\r
- }\r
- return eventsTypeMap;\r
- }\r
- }\r
- \r
- private class FilterAndNodeComposite extends FilterBaseNodeComposite {\r
- TmfFilterAndNode fNode;\r
- Button fNotButton;\r
- \r
- FilterAndNodeComposite(Composite parent, TmfFilterAndNode node) {\r
- super(parent);\r
- fNode = node;\r
- \r
- Label label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_NotLabel);\r
- \r
- fNotButton = new Button(this, SWT.CHECK);\r
- fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- fNotButton.setSelection(fNode.isNot());\r
- fNotButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- fNode.setNot(fNotButton.getSelection());\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- }\r
- }\r
-\r
- private class FilterOrNodeComposite extends FilterBaseNodeComposite {\r
- TmfFilterOrNode fNode;\r
- Button fNotButton;\r
- \r
- FilterOrNodeComposite(Composite parent, TmfFilterOrNode node) {\r
- super(parent);\r
- fNode = node;\r
- \r
- Label label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_NotLabel);\r
- \r
- fNotButton = new Button(this, SWT.CHECK);\r
- fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- fNotButton.setSelection(fNode.isNot());\r
- fNotButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- fNode.setNot(fNotButton.getSelection());\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- }\r
- }\r
- \r
- private class FilterContainsNodeComposite extends FilterBaseNodeComposite {\r
- TmfFilterContainsNode fNode;\r
- Button fNotButton;\r
- Combo fFieldCombo;\r
- Text fValueText;\r
- Button fIgnoreCaseButton;\r
- \r
- FilterContainsNodeComposite(Composite parent, TmfFilterContainsNode node) {\r
- super(parent);\r
- fNode = node;\r
- \r
- Label label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_NotLabel);\r
- \r
- fNotButton = new Button(this, SWT.CHECK);\r
- fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- fNotButton.setSelection(fNode.isNot());\r
- fNotButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- fNode.setNot(fNotButton.getSelection());\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- \r
- label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_FieldLabel);\r
- \r
- fFieldCombo = new Combo(this, SWT.DROP_DOWN);\r
- fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- fFieldCombo.setItems(getFieldsList(fNode));\r
- if (fNode.getField() != null) {\r
- fFieldCombo.setText(fNode.getField());\r
- }\r
- fFieldCombo.addModifyListener(new ModifyListener() {\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- fNode.setField(fFieldCombo.getText());\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- \r
- label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_ValueLabel);\r
- \r
- fValueText = new Text(this, SWT.BORDER);\r
- fValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- if (node.getValue() != null && node.getValue().length() > 0) {\r
- fValueText.setText(node.getValue());\r
- } else {\r
- fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));\r
- fValueText.setText(Messages.FilterViewer_ValueHint);\r
- }\r
- fValueText.addFocusListener(new FocusListener() {\r
- @Override\r
- public void focusLost(FocusEvent e) {\r
- if (fNode.getValue() == null || fNode.getValue().length() == 0) {\r
- fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));\r
- fValueText.setText(Messages.FilterViewer_ValueHint);\r
- }\r
- }\r
- @Override\r
- public void focusGained(FocusEvent e) {\r
- if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {\r
- fValueText.setText(""); //$NON-NLS-1$\r
- }\r
- fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));\r
- }\r
- });\r
- fValueText.addModifyListener(new ModifyListener() {\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- if (! fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {\r
- fNode.setValue(fValueText.getText());\r
- fViewer.refresh(fNode);\r
- }\r
- }\r
- });\r
- \r
- label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- \r
- fIgnoreCaseButton = new Button(this, SWT.CHECK);\r
- fIgnoreCaseButton.setSelection(fNode.isIgnoreCase());\r
- fIgnoreCaseButton.setText(Messages.FilterViewer_IgnoreCaseButtonText);\r
- fIgnoreCaseButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- fIgnoreCaseButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- fNode.setIgnoreCase(fIgnoreCaseButton.getSelection());\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- }\r
- }\r
-\r
- private class FilterEqualsNodeComposite extends FilterBaseNodeComposite {\r
- TmfFilterEqualsNode fNode;\r
- Button fNotButton;\r
- Combo fFieldCombo;\r
- Text fValueText;\r
- Button fIgnoreCaseButton;\r
- \r
- FilterEqualsNodeComposite(Composite parent, TmfFilterEqualsNode node) {\r
- super(parent);\r
- fNode = node;\r
- \r
- Label label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_NotLabel);\r
- \r
- fNotButton = new Button(this, SWT.CHECK);\r
- fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- fNotButton.setSelection(fNode.isNot());\r
- fNotButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- fNode.setNot(fNotButton.getSelection());\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- \r
- label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_FieldLabel);\r
- \r
- fFieldCombo = new Combo(this, SWT.DROP_DOWN);\r
- fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- fFieldCombo.setItems(getFieldsList(fNode));\r
- if (fNode.getField() != null) {\r
- fFieldCombo.setText(fNode.getField());\r
- }\r
- fFieldCombo.addModifyListener(new ModifyListener() {\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- fNode.setField(fFieldCombo.getText());\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- \r
- label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_ValueLabel);\r
- \r
- fValueText = new Text(this, SWT.BORDER);\r
- fValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- if (node.getValue() != null && node.getValue().length() > 0) {\r
- fValueText.setText(node.getValue());\r
- } else {\r
- fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));\r
- fValueText.setText(Messages.FilterViewer_ValueHint);\r
- }\r
- fValueText.addFocusListener(new FocusListener() {\r
- @Override\r
- public void focusLost(FocusEvent e) {\r
- if (fNode.getValue() == null || fNode.getValue().length() == 0) {\r
- fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));\r
- fValueText.setText(Messages.FilterViewer_ValueHint);\r
- }\r
- }\r
- @Override\r
- public void focusGained(FocusEvent e) {\r
- if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {\r
- fValueText.setText(""); //$NON-NLS-1$\r
- }\r
- fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));\r
- }\r
- });\r
- fValueText.addModifyListener(new ModifyListener() {\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- if (! fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {\r
- fNode.setValue(fValueText.getText());\r
- fViewer.refresh(fNode);\r
- }\r
- }\r
- });\r
- \r
- label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- \r
- fIgnoreCaseButton = new Button(this, SWT.CHECK);\r
- fIgnoreCaseButton.setSelection(fNode.isIgnoreCase());\r
- fIgnoreCaseButton.setText(Messages.FilterViewer_IgnoreCaseButtonText);\r
- fIgnoreCaseButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- fIgnoreCaseButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- fNode.setIgnoreCase(fIgnoreCaseButton.getSelection());\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- }\r
- }\r
-\r
- private class FilterMatchesNodeComposite extends FilterBaseNodeComposite {\r
- TmfFilterMatchesNode fNode;\r
- Button fNotButton;\r
- Combo fFieldCombo;\r
- Text fRegexText;\r
- \r
- FilterMatchesNodeComposite(Composite parent, TmfFilterMatchesNode node) {\r
- super(parent);\r
- fNode = node;\r
- \r
- Label label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_NotLabel);\r
- \r
- fNotButton = new Button(this, SWT.CHECK);\r
- fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- fNotButton.setSelection(fNode.isNot());\r
- fNotButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- fNode.setNot(fNotButton.getSelection());\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- \r
- label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_FieldLabel);\r
- \r
- fFieldCombo = new Combo(this, SWT.DROP_DOWN);\r
- fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- fFieldCombo.setItems(getFieldsList(fNode));\r
- if (fNode.getField() != null) {\r
- fFieldCombo.setText(fNode.getField());\r
- }\r
- fFieldCombo.addModifyListener(new ModifyListener() {\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- fNode.setField(fFieldCombo.getText());\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- \r
- label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_RegexLabel);\r
- \r
- fRegexText = new Text(this, SWT.BORDER);\r
- fRegexText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- if (node.getRegex() != null && node.getRegex().length() > 0) {\r
- fRegexText.setText(node.getRegex());\r
- } else {\r
- fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));\r
- fRegexText.setText(Messages.FilterViewer_RegexHint);\r
- }\r
- fRegexText.addFocusListener(new FocusListener() {\r
- @Override\r
- public void focusLost(FocusEvent e) {\r
- if (fNode.getRegex() == null || fNode.getRegex().length() == 0) {\r
- fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));\r
- fRegexText.setText(Messages.FilterViewer_RegexHint);\r
- }\r
- }\r
- @Override\r
- public void focusGained(FocusEvent e) {\r
- if (fRegexText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {\r
- fRegexText.setText(""); //$NON-NLS-1$\r
- }\r
- fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));\r
- }\r
- });\r
- fRegexText.addModifyListener(new ModifyListener() {\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- if (! fRegexText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {\r
- fNode.setRegex(fRegexText.getText());\r
- fViewer.refresh(fNode);\r
- }\r
- }\r
- });\r
- }\r
- }\r
-\r
- private class FilterCompareNodeComposite extends FilterBaseNodeComposite {\r
- TmfFilterCompareNode fNode;\r
- Button fNotButton;\r
- Combo fFieldCombo;\r
- Text fValueText;\r
- Button fLTButton;\r
- Button fEQButton;\r
- Button fGTButton;\r
- Button fNumButton;\r
- Button fAlphaButton;\r
- Button fTimestampButton;\r
- \r
- FilterCompareNodeComposite(Composite parent, TmfFilterCompareNode node) {\r
- super(parent);\r
- fNode = node;\r
- \r
- Label label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_NotLabel);\r
- \r
- fNotButton = new Button(this, SWT.CHECK);\r
- fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- fNotButton.setSelection(fNode.isNot());\r
- fNotButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- fNode.setNot(fNotButton.getSelection());\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- \r
- label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_FieldLabel);\r
- \r
- fFieldCombo = new Combo(this, SWT.DROP_DOWN);\r
- fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- fFieldCombo.setItems(getFieldsList(fNode));\r
- if (fNode.getField() != null) {\r
- fFieldCombo.setText(fNode.getField());\r
- }\r
- fFieldCombo.addModifyListener(new ModifyListener() {\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- fNode.setField(fFieldCombo.getText());\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- \r
- label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_ResultLabel);\r
- \r
- Composite resultGroup = new Composite(this, SWT.NONE);\r
- GridLayout rggl = new GridLayout(3, true);\r
- rggl.marginHeight = 0;\r
- rggl.marginWidth = 0;\r
- resultGroup.setLayout(rggl);\r
- resultGroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- \r
- fLTButton = new Button(resultGroup, SWT.RADIO);\r
- fLTButton.setSelection(fNode.getResult() < 0);\r
- fLTButton.setText("<"); //$NON-NLS-1$\r
- fLTButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- fLTButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (fLTButton.getSelection()) {\r
- fNode.setResult(-1);\r
- }\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- \r
- fEQButton = new Button(resultGroup, SWT.RADIO);\r
- fEQButton.setSelection(fNode.getResult() == 0);\r
- fEQButton.setText("="); //$NON-NLS-1$\r
- fEQButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- fEQButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (fEQButton.getSelection()) {\r
- fNode.setResult(0);\r
- }\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- \r
- fGTButton = new Button(resultGroup, SWT.RADIO);\r
- fGTButton.setSelection(fNode.getResult() > 0);\r
- fGTButton.setText(">"); //$NON-NLS-1$\r
- fGTButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- fGTButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (fGTButton.getSelection()) {\r
- fNode.setResult(1);\r
- }\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- \r
- label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_TypeLabel);\r
- \r
- Composite typeGroup = new Composite(this, SWT.NONE);\r
- GridLayout tggl = new GridLayout(3, false);\r
- tggl.marginHeight = 0;\r
- tggl.marginWidth = 0;\r
- typeGroup.setLayout(tggl);\r
- typeGroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- \r
- fNumButton = new Button(typeGroup, SWT.RADIO);\r
- fNumButton.setSelection(fNode.getType() == Type.NUM);\r
- fNumButton.setText(Messages.FilterViewer_NumButtonText);\r
- fNumButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- fNumButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (fNumButton.getSelection()) {\r
- fNode.setType(Type.NUM);\r
- }\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- \r
- fAlphaButton = new Button(typeGroup, SWT.RADIO);\r
- fAlphaButton.setSelection(fNode.getType() == Type.ALPHA);\r
- fAlphaButton.setText(Messages.FilterViewer_AlphaButtonText);\r
- fAlphaButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- fAlphaButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (fAlphaButton.getSelection()) {\r
- fNode.setType(Type.ALPHA);\r
- }\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- \r
- fTimestampButton = new Button(typeGroup, SWT.RADIO);\r
- fTimestampButton.setSelection(fNode.getType() == Type.TIMESTAMP);\r
- fTimestampButton.setText(Messages.FilterViewer_TimestampButtonText);\r
- fTimestampButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- fTimestampButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (fTimestampButton.getSelection()) {\r
- fNode.setType(Type.TIMESTAMP);\r
- }\r
- fViewer.refresh(fNode);\r
- }\r
- });\r
- \r
- label = new Label(this, SWT.NONE);\r
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- label.setText(Messages.FilterViewer_ValueLabel);\r
- \r
- fValueText = new Text(this, SWT.BORDER);\r
- fValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
- if (node.getValue() != null && node.getValue().length() > 0) {\r
- fValueText.setText(node.getValue());\r
- } else {\r
- fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));\r
- fValueText.setText(Messages.FilterViewer_ValueHint);\r
- }\r
- fValueText.addFocusListener(new FocusListener() {\r
- @Override\r
- public void focusLost(FocusEvent e) {\r
- if (fNode.getValue() == null || fNode.getValue().length() == 0) {\r
- fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));\r
- fValueText.setText(Messages.FilterViewer_ValueHint);\r
- }\r
- }\r
- @Override\r
- public void focusGained(FocusEvent e) {\r
- if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {\r
- fValueText.setText(""); //$NON-NLS-1$\r
- }\r
- fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));\r
- }\r
- });\r
- fValueText.addModifyListener(new ModifyListener() {\r
- @Override\r
- public void modifyText(ModifyEvent e) {\r
- if (! fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {\r
- fNode.setValue(fValueText.getText());\r
- fViewer.refresh(fNode);\r
- }\r
- }\r
- });\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+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.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtEvent;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlEvent;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
+import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterAndNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode.Type;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterContainsNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEqualsNode;
+import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEventTypeNode;
+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;
+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;
+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 String CUSTOM_TXT_CATEGORY = "Custom Text"; //$NON-NLS-1$
+ private static final String CUSTOM_XML_CATEGORY = "Custom XML"; //$NON-NLS-1$
+
+ 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);
+ }
+ }
+ });
+
+ 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);
+ }
+ }
+ });
+ }
+
+ /**
+ * 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) {
+ ArrayList<String> fieldsList = new ArrayList<String>();
+ while (node != null) {
+ if (node instanceof TmfFilterEventTypeNode) {
+ TmfFilterEventTypeNode eventTypeNode = (TmfFilterEventTypeNode) node;
+ for (IConfigurationElement ce : TmfTraceType.getTypeElements()) {
+ if (ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR).equals(eventTypeNode.getEventType())) {
+ try {
+ ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
+ ITmfEventType eventType = event.getType();
+ if (eventType != null) {
+ for (String field : eventType.getRootField().getFieldNames()) {
+ fieldsList.add(field);
+ }
+ }
+ } 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() != 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) {
+ fieldsList.add(output.name);
+ }
+ return fieldsList.toArray(new String[0]);
+ }
+ }
+ }
+ 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) {
+ fieldsList.add(output.name);
+ }
+ return fieldsList.toArray(new String[0]);
+ }
+ }
+ }
+ }
+ 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 && 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()) {
+ fieldsList.add(field);
+ }
+ fieldsList.add(""); //$NON-NLS-1$
+ }
+ } catch (CoreException e) {
+ }
+ }
+ for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
+ 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$
+ }
+ }
+ for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
+ 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$
+ }
+ }
+ return fieldsList.toArray(new String[0]);
+ }
+ }
+
+ 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;
+ Map<String, Object> fEventsTypeMap;
+
+ FilterEventTypeNodeComposite(Composite parent, TmfFilterEventTypeNode node) {
+ super(parent);
+ fNode = node;
+ fEventsTypeMap = getEventsTypeMap();
+
+ 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(fEventsTypeMap.keySet().toArray(new String[0]));
+ if (fNode.getEventType() != null) {
+ for (Entry <String, Object> eventTypeEntry : fEventsTypeMap.entrySet()) {
+ Object value = eventTypeEntry.getValue();
+ if (value instanceof IConfigurationElement) {
+ IConfigurationElement ce = (IConfigurationElement) value;
+ if (ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR).equals(fNode.getEventType())) {
+ fTypeCombo.setText(eventTypeEntry.getKey());
+ }
+ } else if (value instanceof CustomTxtTraceDefinition) {
+ CustomTxtTraceDefinition def = (CustomTxtTraceDefinition) value;
+ String eventType = CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$
+ if (eventType.equals(fNode.getEventType())) {
+ fTypeCombo.setText(eventTypeEntry.getKey());
+ }
+ } else if (value instanceof CustomXmlTraceDefinition) {
+ CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) value;
+ String eventType = CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$
+ if (eventType.equals(fNode.getEventType())) {
+ fTypeCombo.setText(eventTypeEntry.getKey());
+ }
+ }
+ }
+ }
+ fTypeCombo.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ for (Entry <String, Object> eventTypeEntry : fEventsTypeMap.entrySet()) {
+ if (eventTypeEntry.getKey().equals(fTypeCombo.getText())) {
+ Object value = eventTypeEntry.getValue();
+ if (value instanceof IConfigurationElement) {
+ IConfigurationElement ce = (IConfigurationElement) value;
+ fNode.setEventType(ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR));
+ fNode.setName(ce.getAttribute(TmfTraceType.NAME_ATTR));
+ } else if (value instanceof CustomTxtTraceDefinition) {
+ CustomTxtTraceDefinition def = (CustomTxtTraceDefinition) value;
+ fNode.setEventType(CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName); //$NON-NLS-1$
+ fNode.setName(def.definitionName);
+ } else if (value instanceof CustomXmlTraceDefinition) {
+ CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) value;
+ fNode.setEventType(CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName); //$NON-NLS-1$
+ fNode.setName(def.definitionName);
+ }
+ fViewer.refresh(fNode);
+ break;
+ }
+ }
+ }
+ });
+ }
+
+ protected Map<String, Object> getEventsTypeMap() {
+ Map<String, Object> eventsTypeMap = new LinkedHashMap<String, Object>();
+ for (IConfigurationElement ce : TmfTraceType.getTypeElements()) {
+ String categoryName = TmfTraceType.getCategoryName(ce.getAttribute(TmfTraceType.CATEGORY_ATTR));
+ String text = categoryName + " : " + ce.getAttribute(TmfTraceType.NAME_ATTR); //$NON-NLS-1$
+ eventsTypeMap.put(text, ce);
+ }
+ for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
+ String text = CUSTOM_TXT_CATEGORY + " : " + def.definitionName; //$NON-NLS-1$
+ eventsTypeMap.put(text, def);
+ }
+ for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
+ String text = CUSTOM_XML_CATEGORY + " : " + def.definitionName; //$NON-NLS-1$
+ eventsTypeMap.put(text, def);
+ }
+ return eventsTypeMap;
+ }
+ }
+
+ 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.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
+ 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.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
+ 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.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
+ 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.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
+ 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.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
+ 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.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
+ 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);
+ }
+ }
+ });
+ }
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.timechart;\r
-\r
-import java.util.Iterator;\r
-import java.util.NoSuchElementException;\r
-import java.util.Vector;\r
-\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-\r
-/**\r
- * An entry (row) in the time chart analysis view\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TimeChartAnalysisEntry implements ITimeGraphEntry {\r
-\r
- private final ITmfTrace fTrace;\r
- private final Vector<TimeChartEvent> fTraceEvents;\r
- private int fPower = 0; // 2^fPower nanoseconds per vector position\r
- private long fReferenceTime = -1; // time corresponding to beginning of index 0\r
- private long fStartTime = -1; // time of first event\r
- private long fStopTime = -1; // time of last event\r
- private long fLastRank = -1; // rank of last processed trace event\r
-\r
- TimeChartAnalysisEntry(ITmfTrace trace, int modelSize) {\r
- fTrace = trace;\r
- fTraceEvents = new Vector<TimeChartEvent>(modelSize);\r
- }\r
-\r
- @Override\r
- public ITimeGraphEntry[] getChildren() {\r
- return null;\r
- }\r
-\r
- @Override\r
- public ITimeGraphEntry getParent() {\r
- return null;\r
- }\r
-\r
- @Override\r
- public boolean hasChildren() {\r
- return false;\r
- }\r
-\r
- @Override\r
- public String getName() {\r
- return fTrace.getName();\r
- }\r
-\r
- @Override\r
- public long getStartTime() {\r
- return fStartTime;\r
- }\r
-\r
- @Override\r
- public long getEndTime() {\r
- return fStopTime;\r
- }\r
-\r
- @Override\r
- public boolean hasTimeEvents() {\r
- return true;\r
- }\r
-\r
- @Override\r
- public Iterator<ITimeEvent> getTimeEventsIterator() {\r
- return new EntryIterator(0, Long.MAX_VALUE, 0);\r
- }\r
-\r
- @Override\r
- public Iterator<ITimeEvent> getTimeEventsIterator(long startTime, long stopTime, long maxDuration) {\r
- return new EntryIterator(startTime, stopTime, maxDuration);\r
- }\r
-\r
- private class EntryIterator implements Iterator<ITimeEvent> {\r
- private final long fIteratorStartTime;\r
- private final long fIteratorStopTime;\r
- private final long fIteratorMaxDuration;\r
- private long lastTime = -1;\r
- private TimeChartEvent next = null;\r
- private Iterator<ITimeEvent> nestedIterator = null;\r
-\r
- public EntryIterator(long startTime, long stopTime, long maxDuration) {\r
- fIteratorStartTime = startTime;\r
- fIteratorStopTime = stopTime;\r
- fIteratorMaxDuration = maxDuration;\r
- }\r
-\r
- @Override\r
- public boolean hasNext() {\r
- synchronized (fTraceEvents) {\r
- if (next != null) {\r
- return true;\r
- }\r
- if (nestedIterator != null) {\r
- if (nestedIterator.hasNext()) {\r
- return true;\r
- }\r
- nestedIterator = null;\r
- }\r
- long time = (lastTime == -1) ? fStartTime : lastTime;\r
- int index = (fReferenceTime == -1) ? 0 : (int) ((time - fReferenceTime) >> fPower);\r
- while (index < fTraceEvents.size()) {\r
- TimeChartEvent event = fTraceEvents.get(index++);\r
- if (event != null && (lastTime == -1 || event.getTime() > time)) {\r
- if (event.getTime() + event.getDuration() >= fIteratorStartTime && event.getTime() <= fIteratorStopTime) {\r
- if (event.getItemizedEntry() == null || event.getDuration() <= fIteratorMaxDuration) {\r
- lastTime = event.getTime() + event.getDuration();\r
- next = event;\r
- return true;\r
- }\r
- nestedIterator = event.getItemizedEntry().getTimeEventsIterator(fIteratorStartTime, fIteratorStopTime, fIteratorMaxDuration);\r
- return nestedIterator.hasNext();\r
- }\r
- }\r
- }\r
- return false;\r
- }\r
- }\r
-\r
- @Override\r
- public TimeChartEvent next() {\r
- synchronized (fTraceEvents) {\r
- if (nestedIterator != null) {\r
- TimeChartEvent event = (TimeChartEvent) nestedIterator.next();\r
- lastTime = event.getTime() + event.getDuration();\r
- return event;\r
- }\r
- if (hasNext()) {\r
- TimeChartEvent event = next;\r
- next = null;\r
- return event;\r
- }\r
- throw new NoSuchElementException();\r
- }\r
- }\r
-\r
- @Override\r
- public void remove() {\r
- throw new UnsupportedOperationException();\r
- }\r
-\r
- }\r
-\r
- /**\r
- * Add a time event to the time chart entry\r
- *\r
- * @param timeEvent\r
- * The event to add\r
- */\r
- public void addTraceEvent(ITimeEvent timeEvent) {\r
- long time = timeEvent.getTime();\r
- synchronized (fTraceEvents) {\r
- long index = (fReferenceTime == -1) ? 0 : (time - fReferenceTime) >> fPower;\r
- if (index < 0) {\r
- if (fTraceEvents.capacity() - fTraceEvents.size() < -index) {\r
- int powershift = (-index + fTraceEvents.size() <= 2 * fTraceEvents.capacity()) ? 1 :\r
- (int) Math.ceil(Math.log((double) (-index + fTraceEvents.size()) / fTraceEvents.capacity()) / Math.log(2));\r
- merge(powershift);\r
- index = (int) ((time - fReferenceTime) >> fPower);\r
- }\r
- shift((int) -index);\r
- index = 0;\r
- fTraceEvents.set(0, (TimeChartEvent) timeEvent);\r
- } else if (index < fTraceEvents.capacity()) {\r
- if (index >= fTraceEvents.size()) {\r
- fTraceEvents.setSize((int) index + 1);\r
- }\r
- } else {\r
- int powershift = (index < 2 * fTraceEvents.capacity()) ? 1 :\r
- (int) Math.ceil(Math.log((double) (index + 1) / fTraceEvents.capacity()) / Math.log(2));\r
- merge(powershift);\r
- index = (int) ((time - fReferenceTime) >> fPower);\r
- fTraceEvents.setSize((int) index + 1);\r
- }\r
- TimeChartEvent event = fTraceEvents.get((int) index);\r
- if (event == null) {\r
- fTraceEvents.set((int) index, (TimeChartEvent) timeEvent);\r
- } else {\r
- if (event.getItemizedEntry() == null) {\r
- event.merge((TimeChartEvent) timeEvent);\r
- } else {\r
- event.mergeDecorations((TimeChartEvent) timeEvent);\r
- event.getItemizedEntry().addTraceEvent(timeEvent);\r
- }\r
- }\r
- if (fReferenceTime == -1 || time < fReferenceTime) {\r
- fReferenceTime = (time >> fPower) << fPower;\r
- }\r
- if (fStartTime == -1 || time < fStartTime) {\r
- fStartTime = time;\r
- }\r
- if (fStopTime == -1 || time > fStopTime) {\r
- fStopTime = time;\r
- }\r
- }\r
- }\r
-\r
- private void merge(int powershift) {\r
- fPower += powershift;\r
- fReferenceTime = (fReferenceTime >> fPower) << fPower;\r
- int index = 0;\r
- for (int i = 0; i < fTraceEvents.size(); i++) {\r
- TimeChartEvent event = fTraceEvents.get(i);\r
- if (event != null) {\r
- index = (int) ((event.getTime() - fReferenceTime) >> fPower);\r
- TimeChartEvent mergedEvent = fTraceEvents.get(index);\r
- if (mergedEvent == null) {\r
- fTraceEvents.set(index, event);\r
- } else {\r
- mergedEvent.merge(event);\r
- }\r
- if (i != index) {\r
- fTraceEvents.set(i, null);\r
- }\r
- }\r
- }\r
- fTraceEvents.setSize(index + 1);\r
- }\r
-\r
- private void shift(int indexshift) {\r
- int oldSize = fTraceEvents.size();\r
- fTraceEvents.setSize(oldSize + indexshift);\r
- for (int i = oldSize - 1; i >= 0; i--) {\r
- fTraceEvents.set(i + indexshift, fTraceEvents.get(i));\r
- }\r
- for (int i = 0; i < indexshift; i++) {\r
- fTraceEvents.set(i, null);\r
- }\r
- }\r
-\r
- /**\r
- * Retrieve the trace associated with this entry\r
- *\r
- * @return The trace object\r
- */\r
- public ITmfTrace getTrace() {\r
- return fTrace;\r
- }\r
-\r
- /**\r
- * Set the last rank of the entry\r
- *\r
- * @param rank\r
- * The rank to set\r
- */\r
- public void setLastRank(long rank) {\r
- fLastRank = rank;\r
- }\r
-\r
- /**\r
- * Retrieve the last rank of the entry\r
- *\r
- * @return The last rank\r
- */\r
- public long getLastRank() {\r
- return fLastRank;\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.timechart;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.Vector;
+
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+
+/**
+ * An entry (row) in the time chart analysis view
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TimeChartAnalysisEntry implements ITimeGraphEntry {
+
+ private final ITmfTrace fTrace;
+ private final Vector<TimeChartEvent> fTraceEvents;
+ private int fPower = 0; // 2^fPower nanoseconds per vector position
+ private long fReferenceTime = -1; // time corresponding to beginning of index 0
+ private long fStartTime = -1; // time of first event
+ private long fStopTime = -1; // time of last event
+ private long fLastRank = -1; // rank of last processed trace event
+
+ TimeChartAnalysisEntry(ITmfTrace trace, int modelSize) {
+ fTrace = trace;
+ fTraceEvents = new Vector<TimeChartEvent>(modelSize);
+ }
+
+ @Override
+ public ITimeGraphEntry[] getChildren() {
+ return null;
+ }
+
+ @Override
+ public ITimeGraphEntry getParent() {
+ return null;
+ }
+
+ @Override
+ public boolean hasChildren() {
+ return false;
+ }
+
+ @Override
+ public String getName() {
+ return fTrace.getName();
+ }
+
+ @Override
+ public long getStartTime() {
+ return fStartTime;
+ }
+
+ @Override
+ public long getEndTime() {
+ return fStopTime;
+ }
+
+ @Override
+ public boolean hasTimeEvents() {
+ return true;
+ }
+
+ @Override
+ public Iterator<ITimeEvent> getTimeEventsIterator() {
+ return new EntryIterator(0, Long.MAX_VALUE, 0);
+ }
+
+ @Override
+ public Iterator<ITimeEvent> getTimeEventsIterator(long startTime, long stopTime, long maxDuration) {
+ return new EntryIterator(startTime, stopTime, maxDuration);
+ }
+
+ private class EntryIterator implements Iterator<ITimeEvent> {
+ private final long fIteratorStartTime;
+ private final long fIteratorStopTime;
+ private final long fIteratorMaxDuration;
+ private long lastTime = -1;
+ private TimeChartEvent next = null;
+ private Iterator<ITimeEvent> nestedIterator = null;
+
+ public EntryIterator(long startTime, long stopTime, long maxDuration) {
+ fIteratorStartTime = startTime;
+ fIteratorStopTime = stopTime;
+ fIteratorMaxDuration = maxDuration;
+ }
+
+ @Override
+ public boolean hasNext() {
+ synchronized (fTraceEvents) {
+ if (next != null) {
+ return true;
+ }
+ if (nestedIterator != null) {
+ if (nestedIterator.hasNext()) {
+ return true;
+ }
+ nestedIterator = null;
+ }
+ long time = (lastTime == -1) ? fStartTime : lastTime;
+ int index = (fReferenceTime == -1) ? 0 : (int) ((time - fReferenceTime) >> fPower);
+ while (index < fTraceEvents.size()) {
+ TimeChartEvent event = fTraceEvents.get(index++);
+ if (event != null && (lastTime == -1 || event.getTime() > time)) {
+ if (event.getTime() + event.getDuration() >= fIteratorStartTime && event.getTime() <= fIteratorStopTime) {
+ if (event.getItemizedEntry() == null || event.getDuration() <= fIteratorMaxDuration) {
+ lastTime = event.getTime() + event.getDuration();
+ next = event;
+ return true;
+ }
+ nestedIterator = event.getItemizedEntry().getTimeEventsIterator(fIteratorStartTime, fIteratorStopTime, fIteratorMaxDuration);
+ return nestedIterator.hasNext();
+ }
+ }
+ }
+ return false;
+ }
+ }
+
+ @Override
+ public TimeChartEvent next() {
+ synchronized (fTraceEvents) {
+ if (nestedIterator != null) {
+ TimeChartEvent event = (TimeChartEvent) nestedIterator.next();
+ lastTime = event.getTime() + event.getDuration();
+ return event;
+ }
+ if (hasNext()) {
+ TimeChartEvent event = next;
+ next = null;
+ return event;
+ }
+ throw new NoSuchElementException();
+ }
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ /**
+ * Add a time event to the time chart entry
+ *
+ * @param timeEvent
+ * The event to add
+ */
+ public void addTraceEvent(ITimeEvent timeEvent) {
+ long time = timeEvent.getTime();
+ synchronized (fTraceEvents) {
+ long index = (fReferenceTime == -1) ? 0 : (time - fReferenceTime) >> fPower;
+ if (index < 0) {
+ if (fTraceEvents.capacity() - fTraceEvents.size() < -index) {
+ int powershift = (-index + fTraceEvents.size() <= 2 * fTraceEvents.capacity()) ? 1 :
+ (int) Math.ceil(Math.log((double) (-index + fTraceEvents.size()) / fTraceEvents.capacity()) / Math.log(2));
+ merge(powershift);
+ index = (int) ((time - fReferenceTime) >> fPower);
+ }
+ shift((int) -index);
+ index = 0;
+ fTraceEvents.set(0, (TimeChartEvent) timeEvent);
+ } else if (index < fTraceEvents.capacity()) {
+ if (index >= fTraceEvents.size()) {
+ fTraceEvents.setSize((int) index + 1);
+ }
+ } else {
+ int powershift = (index < 2 * fTraceEvents.capacity()) ? 1 :
+ (int) Math.ceil(Math.log((double) (index + 1) / fTraceEvents.capacity()) / Math.log(2));
+ merge(powershift);
+ index = (int) ((time - fReferenceTime) >> fPower);
+ fTraceEvents.setSize((int) index + 1);
+ }
+ TimeChartEvent event = fTraceEvents.get((int) index);
+ if (event == null) {
+ fTraceEvents.set((int) index, (TimeChartEvent) timeEvent);
+ } else {
+ if (event.getItemizedEntry() == null) {
+ event.merge((TimeChartEvent) timeEvent);
+ } else {
+ event.mergeDecorations((TimeChartEvent) timeEvent);
+ event.getItemizedEntry().addTraceEvent(timeEvent);
+ }
+ }
+ if (fReferenceTime == -1 || time < fReferenceTime) {
+ fReferenceTime = (time >> fPower) << fPower;
+ }
+ if (fStartTime == -1 || time < fStartTime) {
+ fStartTime = time;
+ }
+ if (fStopTime == -1 || time > fStopTime) {
+ fStopTime = time;
+ }
+ }
+ }
+
+ private void merge(int powershift) {
+ fPower += powershift;
+ fReferenceTime = (fReferenceTime >> fPower) << fPower;
+ int index = 0;
+ for (int i = 0; i < fTraceEvents.size(); i++) {
+ TimeChartEvent event = fTraceEvents.get(i);
+ if (event != null) {
+ index = (int) ((event.getTime() - fReferenceTime) >> fPower);
+ TimeChartEvent mergedEvent = fTraceEvents.get(index);
+ if (mergedEvent == null) {
+ fTraceEvents.set(index, event);
+ } else {
+ mergedEvent.merge(event);
+ }
+ if (i != index) {
+ fTraceEvents.set(i, null);
+ }
+ }
+ }
+ fTraceEvents.setSize(index + 1);
+ }
+
+ private void shift(int indexshift) {
+ int oldSize = fTraceEvents.size();
+ fTraceEvents.setSize(oldSize + indexshift);
+ for (int i = oldSize - 1; i >= 0; i--) {
+ fTraceEvents.set(i + indexshift, fTraceEvents.get(i));
+ }
+ for (int i = 0; i < indexshift; i++) {
+ fTraceEvents.set(i, null);
+ }
+ }
+
+ /**
+ * Retrieve the trace associated with this entry
+ *
+ * @return The trace object
+ */
+ public ITmfTrace getTrace() {
+ return fTrace;
+ }
+
+ /**
+ * Set the last rank of the entry
+ *
+ * @param rank
+ * The rank to set
+ */
+ public void setLastRank(long rank) {
+ fLastRank = rank;
+ }
+
+ /**
+ * Retrieve the last rank of the entry
+ *
+ * @return The last rank
+ */
+ public long getLastRank() {
+ return fLastRank;
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.timechart;\r
-\r
-import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSetting;\r
-import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.graphics.Color;\r
-import org.eclipse.swt.graphics.GC;\r
-import org.eclipse.swt.graphics.Rectangle;\r
-import org.eclipse.swt.widgets.Display;\r
-\r
-/**\r
- * Provider for a time chart analysis view\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TimeChartAnalysisProvider extends TimeGraphPresentationProvider {\r
-\r
- private static final Color BOOKMARK_INNER_COLOR = new Color(Display.getDefault(), 115, 165, 224);\r
- private static final Color BOOKMARK_OUTER_COLOR = new Color(Display.getDefault(), 2, 70, 140);\r
- private static final Color SEARCH_MATCH_COLOR = new Color(Display.getDefault(), 177, 118, 14);\r
-\r
- private int lastX = Integer.MIN_VALUE;\r
- private int currX = Integer.MIN_VALUE;\r
- private int lastPriority;\r
- private int lastBookmarkX = Integer.MIN_VALUE;\r
-\r
- @Override\r
- public StateItem[] getStateTable() {\r
-\r
- ColorSetting[] settings = ColorSettingsManager.getColorSettings();\r
- StateItem[] stateItems = new StateItem[settings.length];\r
- for (int i = 0; i < settings.length; i++) {\r
- stateItems[i] = new StateItem(settings[i].getTickColorRGB());\r
- }\r
- return stateItems;\r
- }\r
-\r
- @Override\r
- public int getStateTableIndex(ITimeEvent event) {\r
- int priority = ((TimeChartEvent) event).getColorSettingPriority();\r
- if (currX == lastX) {\r
- priority = Math.min(priority, lastPriority);\r
- }\r
- lastPriority = priority;\r
- return priority;\r
- }\r
-\r
- @Override\r
- public void postDrawEvent(ITimeEvent event, Rectangle rect, GC gc) {\r
- if (! ((TimeChartEvent) event).isVisible()) {\r
- return;\r
- }\r
- lastX = currX;\r
- currX = rect.x;\r
- if (lastBookmarkX == rect.x || ((TimeChartEvent) event).isBookmarked()) {\r
- drawBookmark(rect, gc);\r
- lastBookmarkX = rect.x;\r
- } else if (lastBookmarkX == rect.x - 1) {\r
- Rectangle r = new Rectangle(lastBookmarkX, rect.y, rect.width, rect.height);\r
- drawBookmark(r, gc);\r
- } else {\r
- lastBookmarkX = Integer.MIN_VALUE;\r
- }\r
- if (((TimeChartEvent) event).isSearchMatch()) {\r
- drawSearchMatch(rect, gc);\r
- }\r
- }\r
-\r
- private static void drawBookmark(Rectangle r, GC gc) {\r
- gc.setForeground(BOOKMARK_OUTER_COLOR);\r
- gc.drawLine(r.x - 1, r.y - 2, r.x - 1, r.y + 2);\r
- gc.drawLine(r.x + 1, r.y - 2, r.x + 1, r.y + 2);\r
- gc.drawPoint(r.x, r.y - 2);\r
- gc.setForeground(BOOKMARK_INNER_COLOR);\r
- gc.drawLine(r.x, r.y - 1, r.x, r.y + 1);\r
- gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));\r
- gc.drawPoint(r.x - 1, r.y + 3);\r
- gc.drawPoint(r.x, r.y + 2);\r
- gc.drawPoint(r.x + 1, r.y + 3);\r
- }\r
-\r
- private static void drawSearchMatch(Rectangle r, GC gc) {\r
- gc.setForeground(SEARCH_MATCH_COLOR);\r
- gc.drawPoint(r.x, r.y + r.height);\r
- gc.drawLine(r.x - 1, r.y + r.height + 1, r.x + 1, r.y + r.height + 1);\r
- gc.drawLine(r.x - 2, r.y + r.height + 2, r.x + 2, r.y + r.height + 2);\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.timechart;
+
+import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSetting;
+import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Provider for a time chart analysis view
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TimeChartAnalysisProvider extends TimeGraphPresentationProvider {
+
+ private static final Color BOOKMARK_INNER_COLOR = new Color(Display.getDefault(), 115, 165, 224);
+ private static final Color BOOKMARK_OUTER_COLOR = new Color(Display.getDefault(), 2, 70, 140);
+ private static final Color SEARCH_MATCH_COLOR = new Color(Display.getDefault(), 177, 118, 14);
+
+ private int lastX = Integer.MIN_VALUE;
+ private int currX = Integer.MIN_VALUE;
+ private int lastPriority;
+ private int lastBookmarkX = Integer.MIN_VALUE;
+
+ @Override
+ public StateItem[] getStateTable() {
+
+ ColorSetting[] settings = ColorSettingsManager.getColorSettings();
+ StateItem[] stateItems = new StateItem[settings.length];
+ for (int i = 0; i < settings.length; i++) {
+ stateItems[i] = new StateItem(settings[i].getTickColorRGB());
+ }
+ return stateItems;
+ }
+
+ @Override
+ public int getStateTableIndex(ITimeEvent event) {
+ int priority = ((TimeChartEvent) event).getColorSettingPriority();
+ if (currX == lastX) {
+ priority = Math.min(priority, lastPriority);
+ }
+ lastPriority = priority;
+ return priority;
+ }
+
+ @Override
+ public void postDrawEvent(ITimeEvent event, Rectangle rect, GC gc) {
+ if (! ((TimeChartEvent) event).isVisible()) {
+ return;
+ }
+ lastX = currX;
+ currX = rect.x;
+ if (lastBookmarkX == rect.x || ((TimeChartEvent) event).isBookmarked()) {
+ drawBookmark(rect, gc);
+ lastBookmarkX = rect.x;
+ } else if (lastBookmarkX == rect.x - 1) {
+ Rectangle r = new Rectangle(lastBookmarkX, rect.y, rect.width, rect.height);
+ drawBookmark(r, gc);
+ } else {
+ lastBookmarkX = Integer.MIN_VALUE;
+ }
+ if (((TimeChartEvent) event).isSearchMatch()) {
+ drawSearchMatch(rect, gc);
+ }
+ }
+
+ private static void drawBookmark(Rectangle r, GC gc) {
+ gc.setForeground(BOOKMARK_OUTER_COLOR);
+ gc.drawLine(r.x - 1, r.y - 2, r.x - 1, r.y + 2);
+ gc.drawLine(r.x + 1, r.y - 2, r.x + 1, r.y + 2);
+ gc.drawPoint(r.x, r.y - 2);
+ gc.setForeground(BOOKMARK_INNER_COLOR);
+ gc.drawLine(r.x, r.y - 1, r.x, r.y + 1);
+ gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
+ gc.drawPoint(r.x - 1, r.y + 3);
+ gc.drawPoint(r.x, r.y + 2);
+ gc.drawPoint(r.x + 1, r.y + 3);
+ }
+
+ private static void drawSearchMatch(Rectangle r, GC gc) {
+ gc.setForeground(SEARCH_MATCH_COLOR);
+ gc.drawPoint(r.x, r.y + r.height);
+ gc.drawLine(r.x - 1, r.y + r.height + 1, r.x + 1, r.y + r.height + 1);
+ gc.drawLine(r.x - 2, r.y + r.height + 2, r.x + 2, r.y + r.height + 2);
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.timechart;\r
-\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-import org.eclipse.core.resources.IFile;\r
-import org.eclipse.core.resources.IMarker;\r
-import org.eclipse.core.resources.IResource;\r
-import org.eclipse.core.runtime.CoreException;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;\r
-\r
-/**\r
- * Provider for decorations in the time chart view\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TimeChartDecorationProvider {\r
-\r
- private final IFile fBookmarksFile;\r
- private final Set<Long> fBookmarksSet = new HashSet<Long>();\r
- private ITmfFilter fFilterFilter;\r
- private ITmfFilter fSearchFilter;\r
-\r
- /**\r
- * Constructor\r
- *\r
- * @param bookmarksFile\r
- * Bookmark file associated with the trace\r
- */\r
- public TimeChartDecorationProvider(IFile bookmarksFile) {\r
- fBookmarksFile = bookmarksFile;\r
- refreshBookmarks();\r
- }\r
-\r
- /**\r
- * Retrieve the bookmark file that was assigned to this provider\r
- *\r
- * @return The bookmark file\r
- */\r
- public IFile getBookmarksFile() {\r
- return fBookmarksFile;\r
- }\r
-\r
- /**\r
- * Verify if the selected rank has a bookmark assigned to it.\r
- *\r
- * @param rank\r
- * The rank to check for\r
- * @return If there is a bookmark there\r
- */\r
- public boolean isBookmark(long rank) {\r
- return fBookmarksSet.contains(rank);\r
- }\r
-\r
- /**\r
- * Refresh the bookmark display.\r
- */\r
- public void refreshBookmarks() {\r
- try {\r
- fBookmarksSet.clear();\r
- for (IMarker bookmark : fBookmarksFile.findMarkers(\r
- IMarker.BOOKMARK, false, IResource.DEPTH_ZERO)) {\r
- int location = bookmark.getAttribute(IMarker.LOCATION, -1);\r
- if (location != -1) {\r
- Long rank = (long) location;\r
- fBookmarksSet.add(rank);\r
- }\r
- }\r
- } catch (CoreException e) {\r
- Activator.getDefault().logError("Error refreshing bookmarks", e); //$NON-NLS-1$\r
- }\r
- }\r
-\r
- /**\r
- * Notify that a filter is now applied on the view.\r
- *\r
- * @param filter\r
- * The filter that was applied\r
- */\r
- public void filterApplied(ITmfFilter filter) {\r
- fFilterFilter = filter;\r
- }\r
-\r
- /**\r
- * Check if an event is currently visible in the view or not.\r
- *\r
- * @param event\r
- * The event to check for\r
- * @return If the event is visible or not\r
- */\r
- public boolean isVisible(ITmfEvent event) {\r
- if (fFilterFilter != null) {\r
- return fFilterFilter.matches(event);\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Notify that a search is applied on the view.\r
- *\r
- * @param filter\r
- * The search filter that was applied\r
- */\r
- public void searchApplied(ITmfFilter filter) {\r
- fSearchFilter = filter;\r
- }\r
-\r
- /**\r
- * Verify if the currently active search filter applies to the given event\r
- * or not.\r
- *\r
- * @param event\r
- * The event to check for\r
- * @return If the event matches\r
- */\r
- public boolean isSearchMatch(ITmfEvent event) {\r
- if (fSearchFilter != null) {\r
- return fSearchFilter.matches(event);\r
- }\r
- return false;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.timechart;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
+
+/**
+ * Provider for decorations in the time chart view
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TimeChartDecorationProvider {
+
+ private final IFile fBookmarksFile;
+ private final Set<Long> fBookmarksSet = new HashSet<Long>();
+ private ITmfFilter fFilterFilter;
+ private ITmfFilter fSearchFilter;
+
+ /**
+ * Constructor
+ *
+ * @param bookmarksFile
+ * Bookmark file associated with the trace
+ */
+ public TimeChartDecorationProvider(IFile bookmarksFile) {
+ fBookmarksFile = bookmarksFile;
+ refreshBookmarks();
+ }
+
+ /**
+ * Retrieve the bookmark file that was assigned to this provider
+ *
+ * @return The bookmark file
+ */
+ public IFile getBookmarksFile() {
+ return fBookmarksFile;
+ }
+
+ /**
+ * Verify if the selected rank has a bookmark assigned to it.
+ *
+ * @param rank
+ * The rank to check for
+ * @return If there is a bookmark there
+ */
+ public boolean isBookmark(long rank) {
+ return fBookmarksSet.contains(rank);
+ }
+
+ /**
+ * Refresh the bookmark display.
+ */
+ public void refreshBookmarks() {
+ try {
+ fBookmarksSet.clear();
+ for (IMarker bookmark : fBookmarksFile.findMarkers(
+ IMarker.BOOKMARK, false, IResource.DEPTH_ZERO)) {
+ int location = bookmark.getAttribute(IMarker.LOCATION, -1);
+ if (location != -1) {
+ Long rank = (long) location;
+ fBookmarksSet.add(rank);
+ }
+ }
+ } catch (CoreException e) {
+ Activator.getDefault().logError("Error refreshing bookmarks", e); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Notify that a filter is now applied on the view.
+ *
+ * @param filter
+ * The filter that was applied
+ */
+ public void filterApplied(ITmfFilter filter) {
+ fFilterFilter = filter;
+ }
+
+ /**
+ * Check if an event is currently visible in the view or not.
+ *
+ * @param event
+ * The event to check for
+ * @return If the event is visible or not
+ */
+ public boolean isVisible(ITmfEvent event) {
+ if (fFilterFilter != null) {
+ return fFilterFilter.matches(event);
+ }
+ return true;
+ }
+
+ /**
+ * Notify that a search is applied on the view.
+ *
+ * @param filter
+ * The search filter that was applied
+ */
+ public void searchApplied(ITmfFilter filter) {
+ fSearchFilter = filter;
+ }
+
+ /**
+ * Verify if the currently active search filter applies to the given event
+ * or not.
+ *
+ * @param event
+ * The event to check for
+ * @return If the event matches
+ */
+ public boolean isSearchMatch(ITmfEvent event) {
+ if (fSearchFilter != null) {
+ return fSearchFilter.matches(event);
+ }
+ return false;
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.timechart;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-\r
-/**\r
- * Event in the time chart view\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TimeChartEvent implements ITimeEvent {\r
-\r
- private static final byte TIMESTAMP_SCALE = -9;\r
-\r
- private final TimeChartAnalysisEntry fParentEntry;\r
- private long fTime;\r
- private long fDuration;\r
- private long fFirstRank;\r
- private long fLastRank;\r
- private final RankRangeList fRankRangeList;\r
- private long fNbEvents;\r
- private int fColorSettingPriority;\r
- private boolean fIsBookmark;\r
- private boolean fIsVisible;\r
- private boolean fIsSearchMatch;\r
- private TimeChartAnalysisEntry fItemizedEntry;\r
- private boolean fItemizing;\r
-\r
- /**\r
- * Standard constructor\r
- *\r
- * @param parentEntry\r
- * The parent entry\r
- * @param event\r
- * The event from which this time chart event originates\r
- * @param rank\r
- * The rank of the event in the trace\r
- * @param decorationProvider\r
- * The decoration provider to use\r
- */\r
- public TimeChartEvent(TimeChartAnalysisEntry parentEntry, ITmfEvent event,\r
- long rank, TimeChartDecorationProvider decorationProvider) {\r
- fParentEntry = parentEntry;\r
- fTime = event.getTimestamp().normalize(0, TIMESTAMP_SCALE).getValue();\r
- fDuration = 0;\r
- fFirstRank = fLastRank = rank;\r
- fRankRangeList = new RankRangeList(rank);\r
- fNbEvents = 1;\r
- fColorSettingPriority = ColorSettingsManager.getColorSettingPriority(event);\r
- fIsBookmark = decorationProvider.isBookmark(rank);\r
- fIsVisible = decorationProvider.isVisible(event);\r
- fIsSearchMatch = decorationProvider.isSearchMatch(event);\r
- }\r
-\r
- @Override\r
- public ITimeGraphEntry getEntry() {\r
- return fParentEntry;\r
- }\r
-\r
- @Override\r
- public long getTime() {\r
- return fTime;\r
- }\r
-\r
- @Override\r
- public long getDuration() {\r
- return fDuration;\r
- }\r
-\r
- /**\r
- * Retrieve the rank of the trace event which started this time event.\r
- *\r
- * @return The rank of the beginning\r
- */\r
- public long getFirstRank() {\r
- return fFirstRank;\r
- }\r
-\r
- /**\r
- * Retrieve the rank of the trace event which *finished* this time event.\r
- *\r
- * @return The rank of the end\r
- */\r
- public long getLastRank() {\r
- return fLastRank;\r
- }\r
-\r
- /**\r
- * Get the list of rank ranges corresponding to this time event.\r
- *\r
- * @return The rank range list\r
- */\r
- public RankRangeList getRankRangeList() {\r
- return fRankRangeList;\r
- }\r
-\r
- /**\r
- * Merge another time event with this one.\r
- *\r
- * @param event\r
- * The other event\r
- */\r
- public void merge(TimeChartEvent event) {\r
- mergeDecorations(event);\r
- if (fTime == event.getTime() && fDuration == event.getDuration()) {\r
- return;\r
- }\r
- long endTime = Math.max(fTime + fDuration, event.getTime() + event.getDuration());\r
- fTime = Math.min(fTime, event.getTime());\r
- fDuration = endTime - fTime;\r
- fFirstRank = Math.min(fFirstRank, event.fFirstRank);\r
- fLastRank = Math.max(fLastRank, event.fLastRank);\r
- fNbEvents += event.fNbEvents;\r
- fItemizedEntry = null;\r
- synchronized (fRankRangeList) {\r
- fRankRangeList.merge(event.getRankRangeList());\r
- }\r
- }\r
-\r
- /**\r
- * Merge the decorations of another time event with the decorations of this\r
- * one.\r
- *\r
- * @param event\r
- * The other event\r
- */\r
- public void mergeDecorations(TimeChartEvent event) {\r
- fColorSettingPriority = Math.min(fColorSettingPriority, event.getColorSettingPriority());\r
- fIsBookmark |= event.fIsBookmark;\r
- fIsVisible |= event.fIsVisible;\r
- fIsSearchMatch |= event.fIsSearchMatch;\r
- }\r
-\r
- /**\r
- * Get the number of time events that have been merged with this one (starts\r
- * counting at 1 if no merge happened).\r
- *\r
- * @return The current number of events in the bath\r
- */\r
- public long getNbEvents() {\r
- return fNbEvents;\r
- }\r
-\r
- /**\r
- * Retrieve the color setting priority.\r
- *\r
- * @return The priority\r
- */\r
- public int getColorSettingPriority() {\r
- return fColorSettingPriority;\r
- }\r
-\r
- /**\r
- * Set the color setting priority.\r
- *\r
- * @param priority\r
- * The priority to set\r
- */\r
- public void setColorSettingPriority(int priority) {\r
- fColorSettingPriority = priority;\r
- }\r
-\r
- /**\r
- * Check if this time event is bookmarked\r
- *\r
- * @return Y/N\r
- */\r
- public boolean isBookmarked() {\r
- return fIsBookmark;\r
- }\r
-\r
- /**\r
- * Set this time event to be bookmarked or not.\r
- *\r
- * @param isBookmarked\r
- * Should time time event become a bookmark, or not\r
- */\r
- public void setIsBookmarked(boolean isBookmarked) {\r
- fIsBookmark = isBookmarked;\r
- }\r
-\r
- /**\r
- * Check if this time is currently visible or not.\r
- *\r
- * @return If the event is visible\r
- */\r
- public boolean isVisible() {\r
- return fIsVisible;\r
- }\r
-\r
- /**\r
- * Set this time event to visible (or to non-visible).\r
- *\r
- * @param isVisible The new status\r
- */\r
- public void setIsVisible(boolean isVisible) {\r
- fIsVisible = isVisible;\r
- }\r
-\r
- /**\r
- * Check if the time event matches the current search.\r
- *\r
- * @return If it matches, Y/N\r
- */\r
- public boolean isSearchMatch() {\r
- return fIsSearchMatch;\r
- }\r
-\r
- /**\r
- * Mark this event as matching (or non-matching) the current search.\r
- *\r
- * @param isSearchMatch\r
- * The new matching status\r
- */\r
- public void setIsSearchMatch(boolean isSearchMatch) {\r
- fIsSearchMatch = isSearchMatch;\r
- }\r
-\r
- /**\r
- * Set this event's itemized entry.\r
- *\r
- * @param timeAnalysisEntry\r
- * The entry to set\r
- */\r
- public void setItemizedEntry(TimeChartAnalysisEntry timeAnalysisEntry) {\r
- fItemizedEntry = timeAnalysisEntry;\r
- }\r
-\r
- /**\r
- * Retrieve this event's itemized entry.\r
- *\r
- * @return The itemized entry that was previously set\r
- */\r
- public TimeChartAnalysisEntry getItemizedEntry() {\r
- return fItemizedEntry;\r
- }\r
-\r
- /**\r
- * @return Has this time event been set to itemizing?\r
- */\r
- public boolean isItemizing() {\r
- return fItemizing;\r
- }\r
-\r
- /**\r
- * Set this event's itemizing flag to true or false.\r
- *\r
- * @param itemizing\r
- * The new value\r
- */\r
- public void setItemizing(boolean itemizing) {\r
- fItemizing = itemizing;\r
- }\r
-\r
- /**\r
- * Inner class to define a range in terms of ranks in the trace.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
- public class RankRange {\r
- private long firstRank;\r
- private long lastRank;\r
-\r
- /**\r
- * Standard constructor\r
- *\r
- * @param firstRank\r
- * The first (earliest) rank of the range\r
- * @param lastRank\r
- * The last (latest) rank of the range\r
- */\r
- public RankRange(long firstRank, long lastRank) {\r
- this.firstRank = firstRank;\r
- this.lastRank = lastRank;\r
- }\r
-\r
- /**\r
- * Retrieve the start rank of this range.\r
- *\r
- * @return The first rank\r
- */\r
- public long getFirstRank() {\r
- return firstRank;\r
- }\r
-\r
- /**\r
- * Retrieve the end rank of this range\r
- *\r
- * @return The end rank\r
- */\r
- public long getLastRank() {\r
- return lastRank;\r
- }\r
-\r
- /**\r
- * Calculate the minimal distance between two RankRange's\r
- *\r
- * @param range\r
- * The other range\r
- * @return The distance, in "number of events" between the two ranges\r
- */\r
- public long distanceFrom(RankRange range) {\r
- if (range.lastRank < fFirstRank) {\r
- return fFirstRank - range.lastRank;\r
- } else if (range.firstRank > fLastRank) {\r
- return range.firstRank - fLastRank;\r
- } else {\r
- return 0;\r
- }\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return "["+firstRank+","+lastRank+"]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- }\r
- }\r
-\r
- private class RankRangeList extends ArrayList<RankRange> {\r
-\r
- private static final long serialVersionUID = 6060485531208535986L;\r
-\r
- public RankRangeList(long rank) {\r
- super(1);\r
- add(new RankRange(rank, rank));\r
- }\r
-\r
- public void merge(RankRangeList rankRangeList) {\r
- long threshold = fParentEntry.getTrace().getCacheSize();\r
- for (RankRange newRange : rankRangeList) {\r
- boolean merged = false;\r
- for (RankRange oldRange : fRankRangeList) {\r
- if (newRange.distanceFrom(oldRange) <= threshold) {\r
- oldRange.firstRank = Math.min(oldRange.firstRank, newRange.firstRank);\r
- oldRange.lastRank = Math.max(oldRange.lastRank, newRange.lastRank);\r
- merged = true;\r
- break;\r
- }\r
- }\r
- if (!merged) {\r
- add(newRange);\r
- }\r
- }\r
- Iterator<RankRange> iterator = fRankRangeList.iterator();\r
- RankRange previous = null;\r
- while (iterator.hasNext()) {\r
- RankRange range = iterator.next();\r
- if (previous != null && range.distanceFrom(previous) <= threshold) {\r
- previous.firstRank = Math.min(previous.firstRank, range.firstRank);\r
- previous.lastRank = Math.max(previous.lastRank, range.lastRank);\r
- iterator.remove();\r
- }\r
- previous = range;\r
- }\r
- }\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.timechart;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+
+/**
+ * Event in the time chart view
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TimeChartEvent implements ITimeEvent {
+
+ private static final byte TIMESTAMP_SCALE = -9;
+
+ private final TimeChartAnalysisEntry fParentEntry;
+ private long fTime;
+ private long fDuration;
+ private long fFirstRank;
+ private long fLastRank;
+ private final RankRangeList fRankRangeList;
+ private long fNbEvents;
+ private int fColorSettingPriority;
+ private boolean fIsBookmark;
+ private boolean fIsVisible;
+ private boolean fIsSearchMatch;
+ private TimeChartAnalysisEntry fItemizedEntry;
+ private boolean fItemizing;
+
+ /**
+ * Standard constructor
+ *
+ * @param parentEntry
+ * The parent entry
+ * @param event
+ * The event from which this time chart event originates
+ * @param rank
+ * The rank of the event in the trace
+ * @param decorationProvider
+ * The decoration provider to use
+ */
+ public TimeChartEvent(TimeChartAnalysisEntry parentEntry, ITmfEvent event,
+ long rank, TimeChartDecorationProvider decorationProvider) {
+ fParentEntry = parentEntry;
+ fTime = event.getTimestamp().normalize(0, TIMESTAMP_SCALE).getValue();
+ fDuration = 0;
+ fFirstRank = fLastRank = rank;
+ fRankRangeList = new RankRangeList(rank);
+ fNbEvents = 1;
+ fColorSettingPriority = ColorSettingsManager.getColorSettingPriority(event);
+ fIsBookmark = decorationProvider.isBookmark(rank);
+ fIsVisible = decorationProvider.isVisible(event);
+ fIsSearchMatch = decorationProvider.isSearchMatch(event);
+ }
+
+ @Override
+ public ITimeGraphEntry getEntry() {
+ return fParentEntry;
+ }
+
+ @Override
+ public long getTime() {
+ return fTime;
+ }
+
+ @Override
+ public long getDuration() {
+ return fDuration;
+ }
+
+ /**
+ * Retrieve the rank of the trace event which started this time event.
+ *
+ * @return The rank of the beginning
+ */
+ public long getFirstRank() {
+ return fFirstRank;
+ }
+
+ /**
+ * Retrieve the rank of the trace event which *finished* this time event.
+ *
+ * @return The rank of the end
+ */
+ public long getLastRank() {
+ return fLastRank;
+ }
+
+ /**
+ * Get the list of rank ranges corresponding to this time event.
+ *
+ * @return The rank range list
+ */
+ public RankRangeList getRankRangeList() {
+ return fRankRangeList;
+ }
+
+ /**
+ * Merge another time event with this one.
+ *
+ * @param event
+ * The other event
+ */
+ public void merge(TimeChartEvent event) {
+ mergeDecorations(event);
+ if (fTime == event.getTime() && fDuration == event.getDuration()) {
+ return;
+ }
+ long endTime = Math.max(fTime + fDuration, event.getTime() + event.getDuration());
+ fTime = Math.min(fTime, event.getTime());
+ fDuration = endTime - fTime;
+ fFirstRank = Math.min(fFirstRank, event.fFirstRank);
+ fLastRank = Math.max(fLastRank, event.fLastRank);
+ fNbEvents += event.fNbEvents;
+ fItemizedEntry = null;
+ synchronized (fRankRangeList) {
+ fRankRangeList.merge(event.getRankRangeList());
+ }
+ }
+
+ /**
+ * Merge the decorations of another time event with the decorations of this
+ * one.
+ *
+ * @param event
+ * The other event
+ */
+ public void mergeDecorations(TimeChartEvent event) {
+ fColorSettingPriority = Math.min(fColorSettingPriority, event.getColorSettingPriority());
+ fIsBookmark |= event.fIsBookmark;
+ fIsVisible |= event.fIsVisible;
+ fIsSearchMatch |= event.fIsSearchMatch;
+ }
+
+ /**
+ * Get the number of time events that have been merged with this one (starts
+ * counting at 1 if no merge happened).
+ *
+ * @return The current number of events in the bath
+ */
+ public long getNbEvents() {
+ return fNbEvents;
+ }
+
+ /**
+ * Retrieve the color setting priority.
+ *
+ * @return The priority
+ */
+ public int getColorSettingPriority() {
+ return fColorSettingPriority;
+ }
+
+ /**
+ * Set the color setting priority.
+ *
+ * @param priority
+ * The priority to set
+ */
+ public void setColorSettingPriority(int priority) {
+ fColorSettingPriority = priority;
+ }
+
+ /**
+ * Check if this time event is bookmarked
+ *
+ * @return Y/N
+ */
+ public boolean isBookmarked() {
+ return fIsBookmark;
+ }
+
+ /**
+ * Set this time event to be bookmarked or not.
+ *
+ * @param isBookmarked
+ * Should time time event become a bookmark, or not
+ */
+ public void setIsBookmarked(boolean isBookmarked) {
+ fIsBookmark = isBookmarked;
+ }
+
+ /**
+ * Check if this time is currently visible or not.
+ *
+ * @return If the event is visible
+ */
+ public boolean isVisible() {
+ return fIsVisible;
+ }
+
+ /**
+ * Set this time event to visible (or to non-visible).
+ *
+ * @param isVisible The new status
+ */
+ public void setIsVisible(boolean isVisible) {
+ fIsVisible = isVisible;
+ }
+
+ /**
+ * Check if the time event matches the current search.
+ *
+ * @return If it matches, Y/N
+ */
+ public boolean isSearchMatch() {
+ return fIsSearchMatch;
+ }
+
+ /**
+ * Mark this event as matching (or non-matching) the current search.
+ *
+ * @param isSearchMatch
+ * The new matching status
+ */
+ public void setIsSearchMatch(boolean isSearchMatch) {
+ fIsSearchMatch = isSearchMatch;
+ }
+
+ /**
+ * Set this event's itemized entry.
+ *
+ * @param timeAnalysisEntry
+ * The entry to set
+ */
+ public void setItemizedEntry(TimeChartAnalysisEntry timeAnalysisEntry) {
+ fItemizedEntry = timeAnalysisEntry;
+ }
+
+ /**
+ * Retrieve this event's itemized entry.
+ *
+ * @return The itemized entry that was previously set
+ */
+ public TimeChartAnalysisEntry getItemizedEntry() {
+ return fItemizedEntry;
+ }
+
+ /**
+ * @return Has this time event been set to itemizing?
+ */
+ public boolean isItemizing() {
+ return fItemizing;
+ }
+
+ /**
+ * Set this event's itemizing flag to true or false.
+ *
+ * @param itemizing
+ * The new value
+ */
+ public void setItemizing(boolean itemizing) {
+ fItemizing = itemizing;
+ }
+
+ /**
+ * Inner class to define a range in terms of ranks in the trace.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+ public class RankRange {
+ private long firstRank;
+ private long lastRank;
+
+ /**
+ * Standard constructor
+ *
+ * @param firstRank
+ * The first (earliest) rank of the range
+ * @param lastRank
+ * The last (latest) rank of the range
+ */
+ public RankRange(long firstRank, long lastRank) {
+ this.firstRank = firstRank;
+ this.lastRank = lastRank;
+ }
+
+ /**
+ * Retrieve the start rank of this range.
+ *
+ * @return The first rank
+ */
+ public long getFirstRank() {
+ return firstRank;
+ }
+
+ /**
+ * Retrieve the end rank of this range
+ *
+ * @return The end rank
+ */
+ public long getLastRank() {
+ return lastRank;
+ }
+
+ /**
+ * Calculate the minimal distance between two RankRange's
+ *
+ * @param range
+ * The other range
+ * @return The distance, in "number of events" between the two ranges
+ */
+ public long distanceFrom(RankRange range) {
+ if (range.lastRank < fFirstRank) {
+ return fFirstRank - range.lastRank;
+ } else if (range.firstRank > fLastRank) {
+ return range.firstRank - fLastRank;
+ } else {
+ return 0;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "["+firstRank+","+lastRank+"]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
+
+ private class RankRangeList extends ArrayList<RankRange> {
+
+ private static final long serialVersionUID = 6060485531208535986L;
+
+ public RankRangeList(long rank) {
+ super(1);
+ add(new RankRange(rank, rank));
+ }
+
+ public void merge(RankRangeList rankRangeList) {
+ long threshold = fParentEntry.getTrace().getCacheSize();
+ for (RankRange newRange : rankRangeList) {
+ boolean merged = false;
+ for (RankRange oldRange : fRankRangeList) {
+ if (newRange.distanceFrom(oldRange) <= threshold) {
+ oldRange.firstRank = Math.min(oldRange.firstRank, newRange.firstRank);
+ oldRange.lastRank = Math.max(oldRange.lastRank, newRange.lastRank);
+ merged = true;
+ break;
+ }
+ }
+ if (!merged) {
+ add(newRange);
+ }
+ }
+ Iterator<RankRange> iterator = fRankRangeList.iterator();
+ RankRange previous = null;
+ while (iterator.hasNext()) {
+ RankRange range = iterator.next();
+ if (previous != null && range.distanceFrom(previous) <= threshold) {
+ previous.firstRank = Math.min(previous.firstRank, range.firstRank);
+ previous.lastRank = Math.max(previous.lastRank, range.lastRank);
+ iterator.remove();
+ }
+ previous = range;
+ }
+ }
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.timechart;\r
-\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.Map;\r
-\r
-import org.eclipse.core.resources.IFile;\r
-import org.eclipse.core.resources.IMarker;\r
-import org.eclipse.core.resources.IMarkerDelta;\r
-import org.eclipse.core.resources.IResourceChangeEvent;\r
-import org.eclipse.core.resources.IResourceChangeListener;\r
-import org.eclipse.core.resources.IResourceDelta;\r
-import org.eclipse.core.resources.ResourcesPlugin;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r
-import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-import org.eclipse.linuxtools.tmf.ui.editors.ITmfTraceEditor;\r
-import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceClosedSignal;\r
-import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceOpenedSignal;\r
-import org.eclipse.linuxtools.tmf.ui.viewers.events.ITmfEventsFilterListener;\r
-import org.eclipse.linuxtools.tmf.ui.viewers.events.ITmfEventsFilterProvider;\r
-import org.eclipse.linuxtools.tmf.ui.views.TmfView;\r
-import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSetting;\r
-import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;\r
-import org.eclipse.linuxtools.tmf.ui.views.colors.IColorSettingsListener;\r
-import org.eclipse.linuxtools.tmf.ui.views.timechart.TimeChartEvent.RankRange;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphSelectionListener;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphSelectionEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphViewer;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.ui.IEditorPart;\r
-import org.eclipse.ui.IEditorReference;\r
-\r
-/**\r
- * Generic Time Chart view, which is similar to a Gantt chart for trace analysis\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TimeChartView extends TmfView implements ITimeGraphRangeListener,\r
- ITimeGraphSelectionListener, ITimeGraphTimeListener,\r
- IColorSettingsListener, IResourceChangeListener,\r
- ITmfEventsFilterListener {\r
-\r
- /** TimeChartView's ID */\r
- public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.timechart"; //$NON-NLS-1$\r
-\r
- private static final int TIMESTAMP_SCALE = -9;\r
-\r
- private final int fDisplayWidth;\r
- private TimeGraphViewer fViewer;\r
- private final ArrayList<TimeChartAnalysisEntry> fTimeAnalysisEntries = new ArrayList<TimeChartAnalysisEntry>();\r
- private final Map<ITmfTrace, TimeChartDecorationProvider> fDecorationProviders = new HashMap<ITmfTrace, TimeChartDecorationProvider>();\r
- private ArrayList<DecorateThread> fDecorateThreads;\r
- private long fStartTime = 0;\r
- private long fStopTime = Long.MAX_VALUE;\r
- private boolean fRefreshBusy = false;\r
- private boolean fRefreshPending = false;\r
- private boolean fRedrawBusy = false;\r
- private boolean fRedrawPending = false;\r
- private final Object fSyncObj = new Object();\r
- private ITimeGraphPresentationProvider fPresentationProvider;\r
-\r
- /**\r
- * Default constructor\r
- */\r
- public TimeChartView() {\r
- super("Time Chart"); //$NON-NLS-1$\r
- fDisplayWidth = Display.getDefault().getBounds().width;\r
- }\r
-\r
- @Override\r
- public void createPartControl(Composite parent) {\r
- fViewer = new TimeGraphViewer(parent, SWT.NONE);\r
- fPresentationProvider = new TimeChartAnalysisProvider();\r
- fViewer.setTimeGraphProvider(fPresentationProvider);\r
- fViewer.setTimeCalendarFormat(true);\r
- fViewer.addTimeListener(this);\r
- fViewer.addRangeListener(this);\r
- fViewer.addSelectionListener(this);\r
- fViewer.setMinimumItemWidth(1);\r
-\r
- IEditorReference[] editorReferences = getSite().getPage().getEditorReferences();\r
- for (IEditorReference editorReference : editorReferences) {\r
- IEditorPart editor = editorReference.getEditor(false);\r
- if (editor instanceof ITmfTraceEditor) {\r
- ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();\r
- if (trace != null) {\r
- IFile bookmarksFile = ((ITmfTraceEditor) editor).getBookmarksFile();\r
- TimeChartAnalysisEntry timeAnalysisEntry = new TimeChartAnalysisEntry(trace, fDisplayWidth * 2);\r
- fTimeAnalysisEntries.add(timeAnalysisEntry);\r
- fDecorationProviders.put(trace, new TimeChartDecorationProvider(bookmarksFile));\r
- Thread thread = new ProcessTraceThread(timeAnalysisEntry);\r
- thread.start();\r
- }\r
- }\r
- }\r
- fViewer.setInput(fTimeAnalysisEntries.toArray(new TimeChartAnalysisEntry[0]));\r
-\r
- fDecorateThreads = new ArrayList<DecorateThread>();\r
- ColorSettingsManager.addColorSettingsListener(this);\r
- ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);\r
- for (DecorateThread thread : fDecorateThreads) {\r
- thread.cancel();\r
- }\r
- ColorSettingsManager.removeColorSettingsListener(this);\r
- super.dispose();\r
- }\r
-\r
- @Override\r
- public void setFocus() {\r
- fViewer.setFocus();\r
- }\r
-\r
- private class ProcessTraceThread extends Thread {\r
-\r
- private final TimeChartAnalysisEntry fTimeAnalysisEntry;\r
-\r
- public ProcessTraceThread(TimeChartAnalysisEntry timeAnalysisEntry) {\r
- super("ProcessTraceJob:" + timeAnalysisEntry.getName()); //$NON-NLS-1$\r
- fTimeAnalysisEntry = timeAnalysisEntry;\r
- }\r
-\r
- @Override\r
- public void run() {\r
- updateTraceEntry(fTimeAnalysisEntry, Long.MAX_VALUE, 0, Long.MAX_VALUE);\r
- }\r
- }\r
-\r
- private void updateTraceEntry(TimeChartAnalysisEntry timeAnalysisEntry, long stopRank, long startTime, long stopTime) {\r
- ITmfTrace trace = timeAnalysisEntry.getTrace();\r
- TimeChartDecorationProvider decorationProvider = fDecorationProviders.get(trace);\r
- if (decorationProvider == null) {\r
- return; // the trace has been closed\r
- }\r
- ITmfContext context = null;\r
- // TmfTimestamp lastTimestamp = null;\r
- boolean done = false;\r
- while (!done) {\r
- synchronized (timeAnalysisEntry) {\r
- if (timeAnalysisEntry.getLastRank() >= trace.getNbEvents()) {\r
- done = true;\r
- break;\r
- }\r
- if (context == null || context.getRank() != timeAnalysisEntry.getLastRank()) {\r
- if (context != null) {\r
- context.dispose();\r
- }\r
- if (timeAnalysisEntry.getLastRank() != -1) {\r
- context = trace.seekEvent(timeAnalysisEntry.getLastRank());\r
- } else {\r
- // context = trace.seekLocation(null);\r
- context = trace.seekEvent(0);\r
- }\r
- }\r
- while (true) {\r
- long rank = context.getRank();\r
- ITmfEvent event = trace.getNext(context);\r
- if (event == null) {\r
- done = true;\r
- break;\r
- }\r
- // if (!event.getTimestamp().equals(lastTimestamp)) {\r
- TimeChartEvent timeEvent = new TimeChartEvent(timeAnalysisEntry, event, rank, decorationProvider);\r
- if (timeEvent.getTime() >= startTime && timeEvent.getTime() <= stopTime) {\r
- timeAnalysisEntry.addTraceEvent(timeEvent);\r
- }\r
- // lastTimestamp = event.getTimestamp();\r
- // } *** commented out so that color setting priority gets\r
- // set even if the event has same time\r
- if (context.getRank() == trace.getNbEvents() || context.getRank() == stopRank) {\r
- done = true;\r
- break;\r
- }\r
- if (context.getRank() % trace.getCacheSize() == 1) {\r
- // break for UI refresh\r
- break;\r
- }\r
- }\r
- // timeAnalysisEntry.setLastRank(Math.min(trace.getNbEvents(),\r
- // stopRank));\r
- timeAnalysisEntry.setLastRank(context.getRank());\r
- }\r
- redrawViewer(true);\r
- }\r
- if (context != null) {\r
- context.dispose();\r
- }\r
- }\r
-\r
- private void refreshViewer() {\r
- synchronized (fSyncObj) {\r
- if (fRefreshBusy) {\r
- fRefreshPending = true;\r
- return;\r
- }\r
- fRefreshBusy = true;\r
- }\r
- // Perform the refresh on the UI thread\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- if (fViewer.getControl().isDisposed()) {\r
- return;\r
- }\r
- fViewer.setInput(fTimeAnalysisEntries.toArray(new TimeChartAnalysisEntry[0]));\r
- fViewer.resetStartFinishTime();\r
- synchronized (fSyncObj) {\r
- fRefreshBusy = false;\r
- if (fRefreshPending) {\r
- fRefreshPending = false;\r
- refreshViewer();\r
- }\r
- }\r
- }\r
- });\r
- }\r
-\r
- private void redrawViewer(boolean resetTimeIntervals) {\r
- synchronized (fSyncObj) {\r
- if (fRedrawBusy) {\r
- fRedrawPending = true;\r
- return;\r
- }\r
- fRedrawBusy = true;\r
- }\r
- final boolean reset = resetTimeIntervals;\r
- // Perform the refresh on the UI thread\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- if (fViewer.getControl().isDisposed()) {\r
- return;\r
- }\r
- if (reset) {\r
- fViewer.setTimeRange(fTimeAnalysisEntries.toArray(new TimeChartAnalysisEntry[0]));\r
- fViewer.setTimeBounds();\r
- }\r
- fViewer.getControl().redraw();\r
- fViewer.getControl().update();\r
- synchronized (fSyncObj) {\r
- fRedrawBusy = false;\r
- if (fRedrawPending) {\r
- fRedrawPending = false;\r
- redrawViewer(reset);\r
- }\r
- }\r
- }\r
- });\r
- }\r
-\r
- private void itemize(long startTime, long stopTime) {\r
- for (int i = 0; i < fTimeAnalysisEntries.size(); i++) {\r
- Thread thread = new ItemizeThread(fTimeAnalysisEntries.get(i), startTime, stopTime);\r
- thread.start();\r
- }\r
- }\r
-\r
- private class ItemizeThread extends Thread {\r
-\r
- private final TimeChartAnalysisEntry fTimeAnalysisEntry;\r
- private final long fStartTime;\r
- private final long fStopTime;\r
- private final long fMaxDuration;\r
-\r
- private ItemizeThread(TimeChartAnalysisEntry timeAnalysisEntry, long startTime, long stopTime) {\r
- super("Itemize Thread:" + timeAnalysisEntry.getName()); //$NON-NLS-1$\r
- fTimeAnalysisEntry = timeAnalysisEntry;\r
- fStartTime = startTime;\r
- fStopTime = stopTime;\r
- fMaxDuration = 3 * (fStopTime - fStartTime) / fDisplayWidth;\r
- }\r
-\r
- @Override\r
- public void run() {\r
- itemizeTraceEntry(fTimeAnalysisEntry);\r
- }\r
-\r
- public void itemizeTraceEntry(TimeChartAnalysisEntry timeAnalysisEntry) {\r
- Iterator<ITimeEvent> iterator = timeAnalysisEntry.getTimeEventsIterator();\r
- TimeChartEvent event = null;\r
- boolean hasNext = true;\r
- while (hasNext) {\r
- synchronized (timeAnalysisEntry) {\r
- while (hasNext = iterator.hasNext()) {\r
- event = (TimeChartEvent) iterator.next();\r
- if (event.getTime() + event.getDuration() > fStartTime && event.getTime() < fStopTime && event.getDuration() > fMaxDuration\r
- && event.getNbEvents() > 1) {\r
- break;\r
- }\r
- }\r
- }\r
- if (hasNext) {\r
- if (event.getItemizedEntry() == null) {\r
- itemizeEvent(event);\r
- } else {\r
- itemizeTraceEntry(event.getItemizedEntry());\r
- }\r
- }\r
- }\r
- }\r
-\r
- public void itemizeEvent(TimeChartEvent event) {\r
- synchronized (event) {\r
- if (event.isItemizing()) {\r
- return;\r
- }\r
- event.setItemizing(true);\r
- }\r
- TimeChartAnalysisEntry timeAnalysisEntry = new TimeChartAnalysisEntry(fTimeAnalysisEntry.getTrace(), (int) Math.min(\r
- event.getNbEvents() + 1, fDisplayWidth * 2));\r
- synchronized (event.getRankRangeList()) {\r
- for (RankRange range : event.getRankRangeList()) {\r
- timeAnalysisEntry.setLastRank(range.getFirstRank());\r
- updateTraceEntry(timeAnalysisEntry, range.getLastRank() + 1, event.getTime(), event.getTime() + event.getDuration());\r
- }\r
- }\r
- event.setItemizedEntry(timeAnalysisEntry);\r
- redrawViewer(false);\r
- itemizeTraceEntry(timeAnalysisEntry);\r
- synchronized (event) {\r
- event.setItemizing(false);\r
- }\r
- }\r
- }\r
-\r
- private void redecorate() {\r
- synchronized (fDecorateThreads) {\r
- for (DecorateThread thread : fDecorateThreads) {\r
- thread.cancel();\r
- }\r
- fDecorateThreads.clear();\r
- for (int i = 0; i < fTimeAnalysisEntries.size(); i++) {\r
- DecorateThread thread = new DecorateThread(fTimeAnalysisEntries.get(i));\r
- thread.start();\r
- fDecorateThreads.add(thread);\r
- }\r
- }\r
- }\r
-\r
- private class DecorateThread extends Thread {\r
- private volatile boolean interrupted = false;\r
- private final TimeChartAnalysisEntry fTimeAnalysisEntry;\r
- private final TimeChartDecorationProvider fDecorationProvider;\r
- private ITmfContext fContext;\r
- private int fCount = 0;\r
-\r
- private DecorateThread(TimeChartAnalysisEntry timeAnalysisEntry) {\r
- super("Decorate Thread:" + timeAnalysisEntry.getName()); //$NON-NLS-1$\r
- fTimeAnalysisEntry = timeAnalysisEntry;\r
- fDecorationProvider = fDecorationProviders.get(timeAnalysisEntry.getTrace());\r
- }\r
-\r
- @Override\r
- public void run() {\r
- resetTraceEntry(fTimeAnalysisEntry);\r
- redrawViewer(false);\r
- decorateTraceEntry(fTimeAnalysisEntry, null);\r
- redrawViewer(false);\r
- synchronized (fDecorateThreads) {\r
- fDecorateThreads.remove(this);\r
- }\r
- if (fContext != null) {\r
- fContext.dispose();\r
- }\r
- }\r
-\r
- public void resetTraceEntry(TimeChartAnalysisEntry timeAnalysisEntry) {\r
- Iterator<ITimeEvent> iterator = timeAnalysisEntry.getTimeEventsIterator();\r
- TimeChartEvent event = null;\r
- boolean hasNext = true;\r
- while (!interrupted && hasNext) {\r
- synchronized (timeAnalysisEntry) {\r
- while (hasNext = iterator.hasNext()) {\r
- event = (TimeChartEvent) iterator.next();\r
- break;\r
- }\r
- }\r
- if (hasNext) {\r
- // TODO possible concurrency problem here with ItemizeJob\r
- event.setColorSettingPriority(ColorSettingsManager.PRIORITY_NONE);\r
- if (event.getItemizedEntry() != null) {\r
- resetTraceEntry(event.getItemizedEntry());\r
- }\r
- }\r
- }\r
- }\r
-\r
- public void decorateTraceEntry(TimeChartAnalysisEntry timeAnalysisEntry, TimeChartEvent parentEvent) {\r
- // Set max duration high to ensure iterator does not consider\r
- // itemized events\r
- Iterator<ITimeEvent> iterator = timeAnalysisEntry.getTimeEventsIterator(0, Long.MAX_VALUE, Long.MAX_VALUE);\r
- TimeChartEvent event = null;\r
- int entryPriority = ColorSettingsManager.PRIORITY_NONE;\r
- boolean entryIsBookmarked = false;\r
- boolean entryIsVisible = false;\r
- boolean entryIsSearchMatch = false;\r
- boolean hasNext = true;\r
- while (!interrupted && hasNext) {\r
- synchronized (timeAnalysisEntry) {\r
- while (hasNext = iterator.hasNext()) {\r
- event = (TimeChartEvent) iterator.next();\r
- break;\r
- }\r
- }\r
- if (hasNext) {\r
- // TODO possible concurrency problem here with ItemizeJob\r
- if (event.getItemizedEntry() == null) {\r
- decorateEvent(event);\r
- } else {\r
- decorateTraceEntry(event.getItemizedEntry(), event);\r
- }\r
- entryPriority = Math.min(entryPriority, event.getColorSettingPriority());\r
- entryIsBookmarked |= event.isBookmarked();\r
- entryIsVisible |= event.isVisible();\r
- entryIsSearchMatch |= event.isSearchMatch();\r
- if (++fCount % timeAnalysisEntry.getTrace().getCacheSize() == 0) {\r
- redrawViewer(false);\r
- }\r
- }\r
- }\r
- if (parentEvent != null) {\r
- parentEvent.setColorSettingPriority(entryPriority);\r
- parentEvent.setIsBookmarked(entryIsBookmarked);\r
- parentEvent.setIsVisible(entryIsVisible);\r
- parentEvent.setIsSearchMatch(entryIsSearchMatch);\r
- }\r
- }\r
-\r
- public void decorateEvent(TimeChartEvent timeChartEvent) {\r
- // TODO possible concurrency problem here with ItemizeJob\r
- TimeChartAnalysisEntry timeAnalysisEntry = (TimeChartAnalysisEntry) timeChartEvent.getEntry();\r
- ITmfTrace trace = timeAnalysisEntry.getTrace();\r
- int priority = ColorSettingsManager.PRIORITY_NONE;\r
- boolean isBookmarked = false;\r
- boolean isVisible = false;\r
- boolean isSearchMatch = false;\r
- synchronized (timeChartEvent.getRankRangeList()) {\r
- for (RankRange range : timeChartEvent.getRankRangeList()) {\r
- if (interrupted) {\r
- return;\r
- }\r
- if (fContext == null || fContext.getRank() != range.getFirstRank()) {\r
- if (fContext != null) {\r
- fContext.dispose();\r
- }\r
- fContext = trace.seekEvent(range.getFirstRank());\r
- fContext.setRank(range.getFirstRank());\r
- }\r
- while (true) {\r
- if (interrupted) {\r
- return;\r
- }\r
- long rank = fContext.getRank();\r
- ITmfEvent event = trace.getNext(fContext);\r
- if (event == null) {\r
- break;\r
- }\r
- long eventTime = event.getTimestamp().normalize(0, -9).getValue();\r
- if (eventTime >= timeChartEvent.getTime() && eventTime <= timeChartEvent.getTime() + timeChartEvent.getDuration()) {\r
- priority = Math.min(priority, ColorSettingsManager.getColorSettingPriority(event));\r
- }\r
- isBookmarked |= fDecorationProvider.isBookmark(rank);\r
- isVisible |= fDecorationProvider.isVisible(event);\r
- isSearchMatch |= fDecorationProvider.isSearchMatch(event);\r
- if (fContext.getRank() > range.getLastRank()) {\r
- break;\r
- }\r
- }\r
- }\r
- }\r
- timeChartEvent.setColorSettingPriority(priority);\r
- timeChartEvent.setIsBookmarked(isBookmarked);\r
- timeChartEvent.setIsVisible(isVisible);\r
- timeChartEvent.setIsSearchMatch(isSearchMatch);\r
- }\r
-\r
- public void cancel() {\r
- interrupted = true;\r
- }\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Listeners\r
- // ------------------------------------------------------------------------\r
-\r
- @Override\r
- public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) {\r
- fStartTime = event.getStartTime();\r
- fStopTime = event.getEndTime();\r
- itemize(fStartTime, fStopTime);\r
- }\r
-\r
- @Override\r
- public void selectionChanged(TimeGraphSelectionEvent event) {\r
- ITimeGraphEntry timeAnalysisEntry = null;\r
- if (event.getSelection() instanceof TimeChartAnalysisEntry) {\r
- timeAnalysisEntry = event.getSelection();\r
- } else if (event.getSelection() instanceof TimeChartEvent) {\r
- timeAnalysisEntry = ((TimeChartEvent) event.getSelection()).getEntry();\r
- }\r
- if (timeAnalysisEntry instanceof TimeChartAnalysisEntry) {\r
- broadcast(new TmfTraceSelectedSignal(this, ((TimeChartAnalysisEntry) timeAnalysisEntry).getTrace()));\r
- }\r
- }\r
-\r
- @Override\r
- public void timeSelected(TimeGraphTimeEvent event) {\r
- broadcast(new TmfTimeSynchSignal(this, new TmfTimestamp(event.getTime(), TIMESTAMP_SCALE)));\r
- }\r
-\r
- @Override\r
- public void colorSettingsChanged(ColorSetting[] colorSettings) {\r
- // Set presentation provider again to trigger re-creation of new color settings which are stored\r
- // in the TimeGraphControl class\r
- fViewer.setTimeGraphProvider(fPresentationProvider);\r
- redecorate();\r
- }\r
-\r
- @Override\r
- public void resourceChanged(IResourceChangeEvent event) {\r
- for (IMarkerDelta delta : event.findMarkerDeltas(IMarker.BOOKMARK, false)) {\r
- for (TimeChartDecorationProvider provider : fDecorationProviders.values()) {\r
- if (delta.getResource().equals(provider.getBookmarksFile())) {\r
- if (delta.getKind() == IResourceDelta.CHANGED && delta.getMarker().getAttribute(IMarker.LOCATION, -1) != -1) {\r
- provider.refreshBookmarks();\r
- } else if (delta.getKind() == IResourceDelta.REMOVED) {\r
- provider.refreshBookmarks();\r
- }\r
- }\r
- }\r
- }\r
- redecorate();\r
- }\r
-\r
- @Override\r
- public void filterApplied(ITmfFilter filter, ITmfTrace trace) {\r
- TimeChartDecorationProvider decorationProvider = fDecorationProviders.get(trace);\r
- decorationProvider.filterApplied(filter);\r
- redecorate();\r
- }\r
-\r
- @Override\r
- public void searchApplied(ITmfFilter filter, ITmfTrace trace) {\r
- TimeChartDecorationProvider decorationProvider = fDecorationProviders.get(trace);\r
- decorationProvider.searchApplied(filter);\r
- redecorate();\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Signal handlers\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Handler for the Trace Opened signal\r
- *\r
- * @param signal\r
- * The incoming signal\r
- */\r
- @TmfSignalHandler\r
- public void traceOpened(TmfTraceOpenedSignal signal) {\r
- if (fTimeAnalysisEntries == null) {\r
- return;\r
- }\r
- final ITmfTrace trace = signal.getTrace();\r
- final IFile bookmarksFile = signal.getBookmarksFile();\r
- final ITmfEventsFilterProvider eventsFilterProvider = signal.getEventsFilterProvider();\r
- TimeChartAnalysisEntry timeAnalysisEntry = null;\r
- for (int i = 0; i < fTimeAnalysisEntries.size(); i++) {\r
- if (fTimeAnalysisEntries.get(i).getTrace().equals(trace)) {\r
- timeAnalysisEntry = fTimeAnalysisEntries.get(i);\r
- break;\r
- }\r
- }\r
- if (timeAnalysisEntry == null) {\r
- timeAnalysisEntry = new TimeChartAnalysisEntry(trace, fDisplayWidth * 2);\r
- fTimeAnalysisEntries.add(timeAnalysisEntry);\r
- fDecorationProviders.put(trace, new TimeChartDecorationProvider(bookmarksFile));\r
- Thread thread = new ProcessTraceThread(timeAnalysisEntry);\r
- thread.start();\r
- }\r
- refreshViewer();\r
- if (eventsFilterProvider != null) {\r
- eventsFilterProvider.addEventsFilterListener(this);\r
- }\r
- }\r
-\r
- /**\r
- * Handler for the Trace Closed signal\r
- *\r
- * @param signal\r
- * The incoming signal\r
- */\r
- @TmfSignalHandler\r
- public void traceClosed(TmfTraceClosedSignal signal) {\r
- if (fTimeAnalysisEntries == null) {\r
- return;\r
- }\r
- final ITmfTrace trace = signal.getTrace();\r
- for (int i = 0; i < fTimeAnalysisEntries.size(); i++) {\r
- if (fTimeAnalysisEntries.get(i).getTrace().equals(trace)) {\r
- fTimeAnalysisEntries.remove(i);\r
- fDecorationProviders.remove(trace);\r
- refreshViewer();\r
- break;\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Handler for the Trace Selected signal\r
- *\r
- * @param signal\r
- * The incoming signal\r
- */\r
- @TmfSignalHandler\r
- public void traceSelected(TmfTraceSelectedSignal signal) {\r
- if (signal.getSource() != this && fTimeAnalysisEntries != null) {\r
- ITmfTrace trace = signal.getTrace();\r
- for (int i = 0; i < fTimeAnalysisEntries.size(); i++) {\r
- if (fTimeAnalysisEntries.get(i).getTrace().equals(trace)) {\r
- fViewer.setSelection(fTimeAnalysisEntries.get(i));\r
- break;\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Handler for the Trace Updated signal\r
- *\r
- * @param signal\r
- * The incoming signal\r
- */\r
- @TmfSignalHandler\r
- public void traceUpdated(TmfTraceUpdatedSignal signal) {\r
- if (fTimeAnalysisEntries == null) {\r
- return;\r
- }\r
- final ITmfTrace trace = signal.getTrace();\r
- for (int i = 0; i < fTimeAnalysisEntries.size(); i++) {\r
- TimeChartAnalysisEntry timeAnalysisEntry = fTimeAnalysisEntries.get(i);\r
- if (timeAnalysisEntry.getTrace().equals(trace)) {\r
- updateTraceEntry(timeAnalysisEntry, Long.MAX_VALUE, 0, Long.MAX_VALUE);\r
- break;\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Handler for the Time Synch signal\r
- *\r
- * @param signal\r
- * The incoming signal\r
- */\r
- @TmfSignalHandler\r
- public void currentTimeUpdated(TmfTimeSynchSignal signal) {\r
- final long time = signal.getCurrentTime().normalize(0, TIMESTAMP_SCALE).getValue();\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- fViewer.setSelectedTime(time, true);\r
- }\r
- });\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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.timechart;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IMarkerDelta;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.ui.editors.ITmfTraceEditor;
+import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceClosedSignal;
+import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceOpenedSignal;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.ITmfEventsFilterListener;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.ITmfEventsFilterProvider;
+import org.eclipse.linuxtools.tmf.ui.views.TmfView;
+import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSetting;
+import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;
+import org.eclipse.linuxtools.tmf.ui.views.colors.IColorSettingsListener;
+import org.eclipse.linuxtools.tmf.ui.views.timechart.TimeChartEvent.RankRange;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphSelectionListener;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphSelectionEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphViewer;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+
+/**
+ * Generic Time Chart view, which is similar to a Gantt chart for trace analysis
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TimeChartView extends TmfView implements ITimeGraphRangeListener,
+ ITimeGraphSelectionListener, ITimeGraphTimeListener,
+ IColorSettingsListener, IResourceChangeListener,
+ ITmfEventsFilterListener {
+
+ /** TimeChartView's ID */
+ public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.timechart"; //$NON-NLS-1$
+
+ private static final int TIMESTAMP_SCALE = -9;
+
+ private final int fDisplayWidth;
+ private TimeGraphViewer fViewer;
+ private final ArrayList<TimeChartAnalysisEntry> fTimeAnalysisEntries = new ArrayList<TimeChartAnalysisEntry>();
+ private final Map<ITmfTrace, TimeChartDecorationProvider> fDecorationProviders = new HashMap<ITmfTrace, TimeChartDecorationProvider>();
+ private ArrayList<DecorateThread> fDecorateThreads;
+ private long fStartTime = 0;
+ private long fStopTime = Long.MAX_VALUE;
+ private boolean fRefreshBusy = false;
+ private boolean fRefreshPending = false;
+ private boolean fRedrawBusy = false;
+ private boolean fRedrawPending = false;
+ private final Object fSyncObj = new Object();
+ private ITimeGraphPresentationProvider fPresentationProvider;
+
+ /**
+ * Default constructor
+ */
+ public TimeChartView() {
+ super("Time Chart"); //$NON-NLS-1$
+ fDisplayWidth = Display.getDefault().getBounds().width;
+ }
+
+ @Override
+ public void createPartControl(Composite parent) {
+ fViewer = new TimeGraphViewer(parent, SWT.NONE);
+ fPresentationProvider = new TimeChartAnalysisProvider();
+ fViewer.setTimeGraphProvider(fPresentationProvider);
+ fViewer.setTimeCalendarFormat(true);
+ fViewer.addTimeListener(this);
+ fViewer.addRangeListener(this);
+ fViewer.addSelectionListener(this);
+ fViewer.setMinimumItemWidth(1);
+
+ IEditorReference[] editorReferences = getSite().getPage().getEditorReferences();
+ for (IEditorReference editorReference : editorReferences) {
+ IEditorPart editor = editorReference.getEditor(false);
+ if (editor instanceof ITmfTraceEditor) {
+ ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();
+ if (trace != null) {
+ IFile bookmarksFile = ((ITmfTraceEditor) editor).getBookmarksFile();
+ TimeChartAnalysisEntry timeAnalysisEntry = new TimeChartAnalysisEntry(trace, fDisplayWidth * 2);
+ fTimeAnalysisEntries.add(timeAnalysisEntry);
+ fDecorationProviders.put(trace, new TimeChartDecorationProvider(bookmarksFile));
+ Thread thread = new ProcessTraceThread(timeAnalysisEntry);
+ thread.start();
+ }
+ }
+ }
+ fViewer.setInput(fTimeAnalysisEntries.toArray(new TimeChartAnalysisEntry[0]));
+
+ fDecorateThreads = new ArrayList<DecorateThread>();
+ ColorSettingsManager.addColorSettingsListener(this);
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
+ }
+
+ @Override
+ public void dispose() {
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+ for (DecorateThread thread : fDecorateThreads) {
+ thread.cancel();
+ }
+ ColorSettingsManager.removeColorSettingsListener(this);
+ super.dispose();
+ }
+
+ @Override
+ public void setFocus() {
+ fViewer.setFocus();
+ }
+
+ private class ProcessTraceThread extends Thread {
+
+ private final TimeChartAnalysisEntry fTimeAnalysisEntry;
+
+ public ProcessTraceThread(TimeChartAnalysisEntry timeAnalysisEntry) {
+ super("ProcessTraceJob:" + timeAnalysisEntry.getName()); //$NON-NLS-1$
+ fTimeAnalysisEntry = timeAnalysisEntry;
+ }
+
+ @Override
+ public void run() {
+ updateTraceEntry(fTimeAnalysisEntry, Long.MAX_VALUE, 0, Long.MAX_VALUE);
+ }
+ }
+
+ private void updateTraceEntry(TimeChartAnalysisEntry timeAnalysisEntry, long stopRank, long startTime, long stopTime) {
+ ITmfTrace trace = timeAnalysisEntry.getTrace();
+ TimeChartDecorationProvider decorationProvider = fDecorationProviders.get(trace);
+ if (decorationProvider == null) {
+ return; // the trace has been closed
+ }
+ ITmfContext context = null;
+ // TmfTimestamp lastTimestamp = null;
+ boolean done = false;
+ while (!done) {
+ synchronized (timeAnalysisEntry) {
+ if (timeAnalysisEntry.getLastRank() >= trace.getNbEvents()) {
+ done = true;
+ break;
+ }
+ if (context == null || context.getRank() != timeAnalysisEntry.getLastRank()) {
+ if (context != null) {
+ context.dispose();
+ }
+ if (timeAnalysisEntry.getLastRank() != -1) {
+ context = trace.seekEvent(timeAnalysisEntry.getLastRank());
+ } else {
+ // context = trace.seekLocation(null);
+ context = trace.seekEvent(0);
+ }
+ }
+ while (true) {
+ long rank = context.getRank();
+ ITmfEvent event = trace.getNext(context);
+ if (event == null) {
+ done = true;
+ break;
+ }
+ // if (!event.getTimestamp().equals(lastTimestamp)) {
+ TimeChartEvent timeEvent = new TimeChartEvent(timeAnalysisEntry, event, rank, decorationProvider);
+ if (timeEvent.getTime() >= startTime && timeEvent.getTime() <= stopTime) {
+ timeAnalysisEntry.addTraceEvent(timeEvent);
+ }
+ // lastTimestamp = event.getTimestamp();
+ // } *** commented out so that color setting priority gets
+ // set even if the event has same time
+ if (context.getRank() == trace.getNbEvents() || context.getRank() == stopRank) {
+ done = true;
+ break;
+ }
+ if (context.getRank() % trace.getCacheSize() == 1) {
+ // break for UI refresh
+ break;
+ }
+ }
+ // timeAnalysisEntry.setLastRank(Math.min(trace.getNbEvents(),
+ // stopRank));
+ timeAnalysisEntry.setLastRank(context.getRank());
+ }
+ redrawViewer(true);
+ }
+ if (context != null) {
+ context.dispose();
+ }
+ }
+
+ private void refreshViewer() {
+ synchronized (fSyncObj) {
+ if (fRefreshBusy) {
+ fRefreshPending = true;
+ return;
+ }
+ fRefreshBusy = true;
+ }
+ // Perform the refresh on the UI thread
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (fViewer.getControl().isDisposed()) {
+ return;
+ }
+ fViewer.setInput(fTimeAnalysisEntries.toArray(new TimeChartAnalysisEntry[0]));
+ fViewer.resetStartFinishTime();
+ synchronized (fSyncObj) {
+ fRefreshBusy = false;
+ if (fRefreshPending) {
+ fRefreshPending = false;
+ refreshViewer();
+ }
+ }
+ }
+ });
+ }
+
+ private void redrawViewer(boolean resetTimeIntervals) {
+ synchronized (fSyncObj) {
+ if (fRedrawBusy) {
+ fRedrawPending = true;
+ return;
+ }
+ fRedrawBusy = true;
+ }
+ final boolean reset = resetTimeIntervals;
+ // Perform the refresh on the UI thread
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (fViewer.getControl().isDisposed()) {
+ return;
+ }
+ if (reset) {
+ fViewer.setTimeRange(fTimeAnalysisEntries.toArray(new TimeChartAnalysisEntry[0]));
+ fViewer.setTimeBounds();
+ }
+ fViewer.getControl().redraw();
+ fViewer.getControl().update();
+ synchronized (fSyncObj) {
+ fRedrawBusy = false;
+ if (fRedrawPending) {
+ fRedrawPending = false;
+ redrawViewer(reset);
+ }
+ }
+ }
+ });
+ }
+
+ private void itemize(long startTime, long stopTime) {
+ for (int i = 0; i < fTimeAnalysisEntries.size(); i++) {
+ Thread thread = new ItemizeThread(fTimeAnalysisEntries.get(i), startTime, stopTime);
+ thread.start();
+ }
+ }
+
+ private class ItemizeThread extends Thread {
+
+ private final TimeChartAnalysisEntry fTimeAnalysisEntry;
+ private final long fStartTime;
+ private final long fStopTime;
+ private final long fMaxDuration;
+
+ private ItemizeThread(TimeChartAnalysisEntry timeAnalysisEntry, long startTime, long stopTime) {
+ super("Itemize Thread:" + timeAnalysisEntry.getName()); //$NON-NLS-1$
+ fTimeAnalysisEntry = timeAnalysisEntry;
+ fStartTime = startTime;
+ fStopTime = stopTime;
+ fMaxDuration = 3 * (fStopTime - fStartTime) / fDisplayWidth;
+ }
+
+ @Override
+ public void run() {
+ itemizeTraceEntry(fTimeAnalysisEntry);
+ }
+
+ public void itemizeTraceEntry(TimeChartAnalysisEntry timeAnalysisEntry) {
+ Iterator<ITimeEvent> iterator = timeAnalysisEntry.getTimeEventsIterator();
+ TimeChartEvent event = null;
+ boolean hasNext = true;
+ while (hasNext) {
+ synchronized (timeAnalysisEntry) {
+ while (hasNext = iterator.hasNext()) {
+ event = (TimeChartEvent) iterator.next();
+ if (event.getTime() + event.getDuration() > fStartTime && event.getTime() < fStopTime && event.getDuration() > fMaxDuration
+ && event.getNbEvents() > 1) {
+ break;
+ }
+ }
+ }
+ if (hasNext) {
+ if (event.getItemizedEntry() == null) {
+ itemizeEvent(event);
+ } else {
+ itemizeTraceEntry(event.getItemizedEntry());
+ }
+ }
+ }
+ }
+
+ public void itemizeEvent(TimeChartEvent event) {
+ synchronized (event) {
+ if (event.isItemizing()) {
+ return;
+ }
+ event.setItemizing(true);
+ }
+ TimeChartAnalysisEntry timeAnalysisEntry = new TimeChartAnalysisEntry(fTimeAnalysisEntry.getTrace(), (int) Math.min(
+ event.getNbEvents() + 1, fDisplayWidth * 2));
+ synchronized (event.getRankRangeList()) {
+ for (RankRange range : event.getRankRangeList()) {
+ timeAnalysisEntry.setLastRank(range.getFirstRank());
+ updateTraceEntry(timeAnalysisEntry, range.getLastRank() + 1, event.getTime(), event.getTime() + event.getDuration());
+ }
+ }
+ event.setItemizedEntry(timeAnalysisEntry);
+ redrawViewer(false);
+ itemizeTraceEntry(timeAnalysisEntry);
+ synchronized (event) {
+ event.setItemizing(false);
+ }
+ }
+ }
+
+ private void redecorate() {
+ synchronized (fDecorateThreads) {
+ for (DecorateThread thread : fDecorateThreads) {
+ thread.cancel();
+ }
+ fDecorateThreads.clear();
+ for (int i = 0; i < fTimeAnalysisEntries.size(); i++) {
+ DecorateThread thread = new DecorateThread(fTimeAnalysisEntries.get(i));
+ thread.start();
+ fDecorateThreads.add(thread);
+ }
+ }
+ }
+
+ private class DecorateThread extends Thread {
+ private volatile boolean interrupted = false;
+ private final TimeChartAnalysisEntry fTimeAnalysisEntry;
+ private final TimeChartDecorationProvider fDecorationProvider;
+ private ITmfContext fContext;
+ private int fCount = 0;
+
+ private DecorateThread(TimeChartAnalysisEntry timeAnalysisEntry) {
+ super("Decorate Thread:" + timeAnalysisEntry.getName()); //$NON-NLS-1$
+ fTimeAnalysisEntry = timeAnalysisEntry;
+ fDecorationProvider = fDecorationProviders.get(timeAnalysisEntry.getTrace());
+ }
+
+ @Override
+ public void run() {
+ resetTraceEntry(fTimeAnalysisEntry);
+ redrawViewer(false);
+ decorateTraceEntry(fTimeAnalysisEntry, null);
+ redrawViewer(false);
+ synchronized (fDecorateThreads) {
+ fDecorateThreads.remove(this);
+ }
+ if (fContext != null) {
+ fContext.dispose();
+ }
+ }
+
+ public void resetTraceEntry(TimeChartAnalysisEntry timeAnalysisEntry) {
+ Iterator<ITimeEvent> iterator = timeAnalysisEntry.getTimeEventsIterator();
+ TimeChartEvent event = null;
+ boolean hasNext = true;
+ while (!interrupted && hasNext) {
+ synchronized (timeAnalysisEntry) {
+ while (hasNext = iterator.hasNext()) {
+ event = (TimeChartEvent) iterator.next();
+ break;
+ }
+ }
+ if (hasNext) {
+ // TODO possible concurrency problem here with ItemizeJob
+ event.setColorSettingPriority(ColorSettingsManager.PRIORITY_NONE);
+ if (event.getItemizedEntry() != null) {
+ resetTraceEntry(event.getItemizedEntry());
+ }
+ }
+ }
+ }
+
+ public void decorateTraceEntry(TimeChartAnalysisEntry timeAnalysisEntry, TimeChartEvent parentEvent) {
+ // Set max duration high to ensure iterator does not consider
+ // itemized events
+ Iterator<ITimeEvent> iterator = timeAnalysisEntry.getTimeEventsIterator(0, Long.MAX_VALUE, Long.MAX_VALUE);
+ TimeChartEvent event = null;
+ int entryPriority = ColorSettingsManager.PRIORITY_NONE;
+ boolean entryIsBookmarked = false;
+ boolean entryIsVisible = false;
+ boolean entryIsSearchMatch = false;
+ boolean hasNext = true;
+ while (!interrupted && hasNext) {
+ synchronized (timeAnalysisEntry) {
+ while (hasNext = iterator.hasNext()) {
+ event = (TimeChartEvent) iterator.next();
+ break;
+ }
+ }
+ if (hasNext) {
+ // TODO possible concurrency problem here with ItemizeJob
+ if (event.getItemizedEntry() == null) {
+ decorateEvent(event);
+ } else {
+ decorateTraceEntry(event.getItemizedEntry(), event);
+ }
+ entryPriority = Math.min(entryPriority, event.getColorSettingPriority());
+ entryIsBookmarked |= event.isBookmarked();
+ entryIsVisible |= event.isVisible();
+ entryIsSearchMatch |= event.isSearchMatch();
+ if (++fCount % timeAnalysisEntry.getTrace().getCacheSize() == 0) {
+ redrawViewer(false);
+ }
+ }
+ }
+ if (parentEvent != null) {
+ parentEvent.setColorSettingPriority(entryPriority);
+ parentEvent.setIsBookmarked(entryIsBookmarked);
+ parentEvent.setIsVisible(entryIsVisible);
+ parentEvent.setIsSearchMatch(entryIsSearchMatch);
+ }
+ }
+
+ public void decorateEvent(TimeChartEvent timeChartEvent) {
+ // TODO possible concurrency problem here with ItemizeJob
+ TimeChartAnalysisEntry timeAnalysisEntry = (TimeChartAnalysisEntry) timeChartEvent.getEntry();
+ ITmfTrace trace = timeAnalysisEntry.getTrace();
+ int priority = ColorSettingsManager.PRIORITY_NONE;
+ boolean isBookmarked = false;
+ boolean isVisible = false;
+ boolean isSearchMatch = false;
+ synchronized (timeChartEvent.getRankRangeList()) {
+ for (RankRange range : timeChartEvent.getRankRangeList()) {
+ if (interrupted) {
+ return;
+ }
+ if (fContext == null || fContext.getRank() != range.getFirstRank()) {
+ if (fContext != null) {
+ fContext.dispose();
+ }
+ fContext = trace.seekEvent(range.getFirstRank());
+ fContext.setRank(range.getFirstRank());
+ }
+ while (true) {
+ if (interrupted) {
+ return;
+ }
+ long rank = fContext.getRank();
+ ITmfEvent event = trace.getNext(fContext);
+ if (event == null) {
+ break;
+ }
+ long eventTime = event.getTimestamp().normalize(0, -9).getValue();
+ if (eventTime >= timeChartEvent.getTime() && eventTime <= timeChartEvent.getTime() + timeChartEvent.getDuration()) {
+ priority = Math.min(priority, ColorSettingsManager.getColorSettingPriority(event));
+ }
+ isBookmarked |= fDecorationProvider.isBookmark(rank);
+ isVisible |= fDecorationProvider.isVisible(event);
+ isSearchMatch |= fDecorationProvider.isSearchMatch(event);
+ if (fContext.getRank() > range.getLastRank()) {
+ break;
+ }
+ }
+ }
+ }
+ timeChartEvent.setColorSettingPriority(priority);
+ timeChartEvent.setIsBookmarked(isBookmarked);
+ timeChartEvent.setIsVisible(isVisible);
+ timeChartEvent.setIsSearchMatch(isSearchMatch);
+ }
+
+ public void cancel() {
+ interrupted = true;
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Listeners
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) {
+ fStartTime = event.getStartTime();
+ fStopTime = event.getEndTime();
+ itemize(fStartTime, fStopTime);
+ }
+
+ @Override
+ public void selectionChanged(TimeGraphSelectionEvent event) {
+ ITimeGraphEntry timeAnalysisEntry = null;
+ if (event.getSelection() instanceof TimeChartAnalysisEntry) {
+ timeAnalysisEntry = event.getSelection();
+ } else if (event.getSelection() instanceof TimeChartEvent) {
+ timeAnalysisEntry = ((TimeChartEvent) event.getSelection()).getEntry();
+ }
+ if (timeAnalysisEntry instanceof TimeChartAnalysisEntry) {
+ broadcast(new TmfTraceSelectedSignal(this, ((TimeChartAnalysisEntry) timeAnalysisEntry).getTrace()));
+ }
+ }
+
+ @Override
+ public void timeSelected(TimeGraphTimeEvent event) {
+ broadcast(new TmfTimeSynchSignal(this, new TmfTimestamp(event.getTime(), TIMESTAMP_SCALE)));
+ }
+
+ @Override
+ public void colorSettingsChanged(ColorSetting[] colorSettings) {
+ // Set presentation provider again to trigger re-creation of new color settings which are stored
+ // in the TimeGraphControl class
+ fViewer.setTimeGraphProvider(fPresentationProvider);
+ redecorate();
+ }
+
+ @Override
+ public void resourceChanged(IResourceChangeEvent event) {
+ for (IMarkerDelta delta : event.findMarkerDeltas(IMarker.BOOKMARK, false)) {
+ for (TimeChartDecorationProvider provider : fDecorationProviders.values()) {
+ if (delta.getResource().equals(provider.getBookmarksFile())) {
+ if (delta.getKind() == IResourceDelta.CHANGED && delta.getMarker().getAttribute(IMarker.LOCATION, -1) != -1) {
+ provider.refreshBookmarks();
+ } else if (delta.getKind() == IResourceDelta.REMOVED) {
+ provider.refreshBookmarks();
+ }
+ }
+ }
+ }
+ redecorate();
+ }
+
+ @Override
+ public void filterApplied(ITmfFilter filter, ITmfTrace trace) {
+ TimeChartDecorationProvider decorationProvider = fDecorationProviders.get(trace);
+ decorationProvider.filterApplied(filter);
+ redecorate();
+ }
+
+ @Override
+ public void searchApplied(ITmfFilter filter, ITmfTrace trace) {
+ TimeChartDecorationProvider decorationProvider = fDecorationProviders.get(trace);
+ decorationProvider.searchApplied(filter);
+ redecorate();
+ }
+
+ // ------------------------------------------------------------------------
+ // Signal handlers
+ // ------------------------------------------------------------------------
+
+ /**
+ * Handler for the Trace Opened signal
+ *
+ * @param signal
+ * The incoming signal
+ */
+ @TmfSignalHandler
+ public void traceOpened(TmfTraceOpenedSignal signal) {
+ if (fTimeAnalysisEntries == null) {
+ return;
+ }
+ final ITmfTrace trace = signal.getTrace();
+ final IFile bookmarksFile = signal.getBookmarksFile();
+ final ITmfEventsFilterProvider eventsFilterProvider = signal.getEventsFilterProvider();
+ TimeChartAnalysisEntry timeAnalysisEntry = null;
+ for (int i = 0; i < fTimeAnalysisEntries.size(); i++) {
+ if (fTimeAnalysisEntries.get(i).getTrace().equals(trace)) {
+ timeAnalysisEntry = fTimeAnalysisEntries.get(i);
+ break;
+ }
+ }
+ if (timeAnalysisEntry == null) {
+ timeAnalysisEntry = new TimeChartAnalysisEntry(trace, fDisplayWidth * 2);
+ fTimeAnalysisEntries.add(timeAnalysisEntry);
+ fDecorationProviders.put(trace, new TimeChartDecorationProvider(bookmarksFile));
+ Thread thread = new ProcessTraceThread(timeAnalysisEntry);
+ thread.start();
+ }
+ refreshViewer();
+ if (eventsFilterProvider != null) {
+ eventsFilterProvider.addEventsFilterListener(this);
+ }
+ }
+
+ /**
+ * Handler for the Trace Closed signal
+ *
+ * @param signal
+ * The incoming signal
+ */
+ @TmfSignalHandler
+ public void traceClosed(TmfTraceClosedSignal signal) {
+ if (fTimeAnalysisEntries == null) {
+ return;
+ }
+ final ITmfTrace trace = signal.getTrace();
+ for (int i = 0; i < fTimeAnalysisEntries.size(); i++) {
+ if (fTimeAnalysisEntries.get(i).getTrace().equals(trace)) {
+ fTimeAnalysisEntries.remove(i);
+ fDecorationProviders.remove(trace);
+ refreshViewer();
+ break;
+ }
+ }
+ }
+
+ /**
+ * Handler for the Trace Selected signal
+ *
+ * @param signal
+ * The incoming signal
+ */
+ @TmfSignalHandler
+ public void traceSelected(TmfTraceSelectedSignal signal) {
+ if (signal.getSource() != this && fTimeAnalysisEntries != null) {
+ ITmfTrace trace = signal.getTrace();
+ for (int i = 0; i < fTimeAnalysisEntries.size(); i++) {
+ if (fTimeAnalysisEntries.get(i).getTrace().equals(trace)) {
+ fViewer.setSelection(fTimeAnalysisEntries.get(i));
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Handler for the Trace Updated signal
+ *
+ * @param signal
+ * The incoming signal
+ */
+ @TmfSignalHandler
+ public void traceUpdated(TmfTraceUpdatedSignal signal) {
+ if (fTimeAnalysisEntries == null) {
+ return;
+ }
+ final ITmfTrace trace = signal.getTrace();
+ for (int i = 0; i < fTimeAnalysisEntries.size(); i++) {
+ TimeChartAnalysisEntry timeAnalysisEntry = fTimeAnalysisEntries.get(i);
+ if (timeAnalysisEntry.getTrace().equals(trace)) {
+ updateTraceEntry(timeAnalysisEntry, Long.MAX_VALUE, 0, Long.MAX_VALUE);
+ break;
+ }
+ }
+ }
+
+ /**
+ * Handler for the Time Synch signal
+ *
+ * @param signal
+ * The incoming signal
+ */
+ @TmfSignalHandler
+ public void currentTimeUpdated(TmfTimeSynchSignal signal) {
+ final long time = signal.getCurrentTime().normalize(0, TIMESTAMP_SCALE).getValue();
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ fViewer.setSelectedTime(time, true);
+ }
+ });
+ }
+
+}
/**********************************************************************
* Copyright (c) 2011, 2012 Ericsson
- *
+ *
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
+ *
+ * Contributors:
* Bernd Hufmann - Initial API and implementation
**********************************************************************/
package org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.IHandlerActivation;
import org.eclipse.ui.handlers.IHandlerService;
/**
* <p>
- * Singleton class that manages key-bindings for certain commands across multiple sequence
+ * Singleton class that manages key-bindings for certain commands across multiple sequence
* diagram view instances.
* </p>
- *
+ *
* @version 1.0
* @author Bernd Hufmann
- *
+ *
*/
public class KeyBindingsManager {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
-
+
/**
- * The singleton instance.
+ * The singleton instance.
*/
private static KeyBindingsManager fInstance = null;
/**
- * The list of view names.
+ * The list of view names.
*/
- private Set<String> fViews = new HashSet<String>();
+ private Set<String> fViews = new HashSet<String>();
/**
* The list of activations Activations to store
*/
private List<IHandlerActivation> fHandlerActivations = new ArrayList<IHandlerActivation>();
/**
- * The action reference for moving to a message in view.
+ * The action reference for moving to a message in view.
*/
private MoveToMessage fGoToMessageForKeyBinding;
/**
- * The action reference for opening the find dialog.
+ * The action reference for opening the find dialog.
*/
private OpenSDFindDialog fFindForKeyBinding;
/**
- * The action reference for moving up in view.
+ * The action reference for moving up in view.
*/
private MoveSDUp fMoveUpForKeyBinding;
/**
- * The action reference for moving down in view.
+ * The action reference for moving down in view.
*/
private MoveSDDown fMoveDownForKeyBinding;
/**
- * The action reference for moving left in view.
+ * The action reference for moving left in view.
*/
private MoveSDLeft fMoveLeftForKeyBinding;
/**
- * The action reference for moving right in view.
+ * The action reference for moving right in view.
*/
private MoveSDRight fMoveRightForKeyBinding;
/**
- * The action reference for showing node start.
+ * The action reference for showing node start.
*/
private ShowNodeStart fShowNodeStartForKeyBinding;
/**
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
-
+
/**
- * Constructor
+ * Constructor
*/
protected KeyBindingsManager() {
}
// ------------------------------------------------------------------------
/**
* Returns the KeyBindingsManager singleton instance.
- *
+ *
* @return the KeyBindingsManager singleton instance
*/
public synchronized static KeyBindingsManager getInstance() {
}
return fInstance;
}
-
+
/**
- * Adds a view list of managed view list.
- *
+ * Adds a view list of managed view list.
+ *
* @param viewId Id of SD view to add and to manage
*/
public void add(String viewId) {
-
+
if (fViews.isEmpty()) {
initialize();
}
-
+
if(!fViews.contains(viewId)) {
fViews.add(viewId);
}
}
-
+
/**
* Removes a view from managed view list
- *
+ *
* @param viewId Id of SD view to remove
*/
public void remove(String viewId) {
dispose();
}
}
-
+
/*
* Initialized the KeyBindingsManager.
*/
fHandlerActivations.add(activation);
}
-
+
/*
* Disposes the KeyBindingsManager
*/
private void dispose() {
- IHandlerService service = (IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(IHandlerService.class);
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window == null) {
+ //During Eclipse shutdown the active workbench window is null
+ return;
+ }
+ IHandlerService service = (IHandlerService) window.getService(IHandlerService.class);
for(IHandlerActivation activation : fHandlerActivations) {
service.deactivateHandler(activation);
}
-
+
fGoToMessageForKeyBinding = null;
fFindForKeyBinding = null;
fMoveUpForKeyBinding = null;
}
/**
- * Set the view in all supported actions
- *
+ * Set the view in all supported actions
+ *
* @param view to set in global actions
*/
public void setSdView(SDView view) {
/**
* Enable / disable find action
- *
- * @param enabled <code>true</code> for enabling else <code>false</code>
+ *
+ * @param enabled <code>true</code> for enabling else <code>false</code>
*/
public void setFindEnabled(boolean enabled) {
if (fFindForKeyBinding != null) {
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.IProgressConstants;
super.dispose();
fLock.lock();
try {
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().removePostSelectionListener(this);
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ // During Eclipse shutdown the active workbench window is null
+ if (window != null) {
+ window.getSelectionService().removePostSelectionListener(this);
+ }
fView.setSDFindProvider(null);
fView.setSDPagingProvider(null);
fView.setSDFilterProvider(null);
-/*******************************************************************************\r
- * Copyright (c) 2010, 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- ******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.rawviewer;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.CaretEvent;\r
-import org.eclipse.swt.custom.CaretListener;\r
-import org.eclipse.swt.custom.ScrolledComposite;\r
-import org.eclipse.swt.custom.StyledText;\r
-import org.eclipse.swt.events.ControlEvent;\r
-import org.eclipse.swt.events.ControlListener;\r
-import org.eclipse.swt.events.KeyEvent;\r
-import org.eclipse.swt.events.KeyListener;\r
-import org.eclipse.swt.events.MouseAdapter;\r
-import org.eclipse.swt.events.MouseEvent;\r
-import org.eclipse.swt.events.MouseMoveListener;\r
-import org.eclipse.swt.events.MouseTrackListener;\r
-import org.eclipse.swt.events.MouseWheelListener;\r
-import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.events.SelectionListener;\r
-import org.eclipse.swt.graphics.Color;\r
-import org.eclipse.swt.graphics.Font;\r
-import org.eclipse.swt.graphics.FontData;\r
-import org.eclipse.swt.graphics.Point;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.Event;\r
-import org.eclipse.swt.widgets.Listener;\r
-import org.eclipse.swt.widgets.Menu;\r
-import org.eclipse.swt.widgets.Slider;\r
-\r
-/**\r
- * TmfRawEventViewer allows for the display of the raw data for an arbitrarily\r
- * large number of TMF events.\r
- *\r
- * It is essentially a Composite of a StyledText area and a Slider, where the number\r
- * of visible lines in the StyledText control is set to fill the viewer display area.\r
- * An underlying data model is used to store a cache of event raw text line data.\r
- * The slider is ratio-based.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TmfRawEventViewer extends Composite implements ControlListener, SelectionListener,\r
- KeyListener, CaretListener, MouseMoveListener, MouseTrackListener, MouseWheelListener {\r
-\r
- private static final Color COLOR_BACKGROUND_ODD = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);\r
- private static final Color COLOR_BACKGROUND_EVEN = new Color(Display.getDefault(), 242, 242, 242);\r
- private static final Color COLOR_BACKGROUND_SELECTED = new Color(Display.getDefault(), 231, 246, 254);\r
- private static final Color COLOR_BACKGROUND_HIGHLIGHTED = new Color(Display.getDefault(), 246, 252, 255);\r
- private static final int MAX_LINE_DATA_SIZE = 1000;\r
- private static final int SLIDER_MAX = 1000000;\r
-\r
- private ITmfTrace fTrace;\r
- private ITmfContext fBottomContext;\r
-\r
- private ScrolledComposite fScrolledComposite;\r
- private Composite fTextArea;\r
- private StyledText fStyledText;\r
- private Font fFixedFont;\r
- private Slider fSlider;\r
-\r
- private final List<LineData> fLines = new ArrayList<LineData>();\r
- private boolean fActualRanks = false;\r
- private int fTopLineIndex;\r
- private int fLastTopLineIndex;\r
- private final CaretPosition[] fStoredCaretPosition = new CaretPosition[]\r
- { new CaretPosition(0, 0), new CaretPosition(0,0)};\r
- private int fNumVisibleLines;\r
- private ITmfLocation fSelectedLocation = null;\r
- private long fHighlightedRank = Long.MIN_VALUE;\r
- private int fCursorYCoordinate = -1;\r
- private int fHoldSelection = 0;\r
-\r
- private static class LineData {\r
- long rank;\r
- ITmfLocation location;\r
- String string;\r
- public LineData(long rank, ITmfLocation location, String string) {\r
- this.rank = rank;\r
- this.location = location;\r
- if (string.length() == 0) {\r
- this.string = " "; // workaround for setLineBackground has no effect on empty line //$NON-NLS-1$\r
- } else {\r
- this.string = string;\r
- }\r
- }\r
- @Override\r
- public String toString() {\r
- return rank + " [" + location + "]: " + string; //$NON-NLS-1$ //$NON-NLS-2$\r
- }\r
- }\r
-\r
- private static class CaretPosition {\r
- int time;\r
- int caretOffset;\r
- public CaretPosition(int time, int caretOffset) {\r
- this.time = time;\r
- this.caretOffset = caretOffset;\r
- }\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Constructor\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Constructor\r
- * @param parent The parent composite\r
- * @param style The style bits\r
- */\r
- public TmfRawEventViewer(Composite parent, int style) {\r
- super(parent, style & (~SWT.H_SCROLL) & (~SWT.V_SCROLL));\r
-\r
- // Set the layout\r
- GridLayout gridLayout = new GridLayout();\r
- gridLayout.numColumns = 2;\r
- gridLayout.horizontalSpacing = 0;\r
- gridLayout.verticalSpacing = 0;\r
- gridLayout.marginWidth = 0;\r
- gridLayout.marginHeight = 0;\r
- setLayout(gridLayout);\r
-\r
- // Create the controls\r
- createTextArea(style & SWT.H_SCROLL);\r
- createSlider(style & SWT.V_SCROLL);\r
-\r
- // Prevent the slider from being traversed\r
- setTabList(new Control[] { fScrolledComposite });\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- if (fFixedFont != null) {\r
- fFixedFont.dispose();\r
- fFixedFont = null;\r
- }\r
- super.dispose();\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Text area handling\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Create the text area and add listeners\r
- */\r
- private void createTextArea(int style) {\r
- fScrolledComposite = new ScrolledComposite(this, style);\r
- fScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- fTextArea = new Composite(fScrolledComposite, SWT.NONE);\r
- fTextArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
- fScrolledComposite.setContent(fTextArea);\r
- fScrolledComposite.setExpandHorizontal(true);\r
- fScrolledComposite.setExpandVertical(true);\r
- fScrolledComposite.setAlwaysShowScrollBars(true);\r
- fScrolledComposite.setMinSize(fTextArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));\r
- fScrolledComposite.addControlListener(this);\r
-\r
- GridLayout textAreaGridLayout = new GridLayout();\r
- textAreaGridLayout.marginHeight = 0;\r
- textAreaGridLayout.marginWidth = 0;\r
- fTextArea.setLayout(textAreaGridLayout);\r
-\r
- if (fFixedFont == null) {\r
- if (System.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$\r
- fFixedFont = new Font(Display.getCurrent(), new FontData("Courier New", 10, SWT.NORMAL)); //$NON-NLS-1$\r
- } else {\r
- fFixedFont = new Font(Display.getCurrent(), new FontData("Monospace", 10, SWT.NORMAL)); //$NON-NLS-1$\r
- }\r
- }\r
-\r
- fStyledText = new StyledText(fTextArea, SWT.READ_ONLY);\r
- fStyledText.setFont(fFixedFont);\r
- fStyledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));\r
-\r
- fStyledText.addCaretListener(this);\r
- fStyledText.addMouseMoveListener(this);\r
- fStyledText.addMouseTrackListener(this);\r
- fStyledText.addMouseWheelListener(this);\r
- fStyledText.addListener(SWT.MouseWheel, new Listener() { // disable mouse scroll of horizontal scroll bar\r
- @Override\r
- public void handleEvent(Event event) { event.doit = false; }});\r
- fStyledText.addKeyListener(this);\r
-\r
- fTextArea.setBackground(fStyledText.getBackground());\r
- fTextArea.addMouseListener(new MouseAdapter() {\r
- @Override\r
- public void mouseDown(MouseEvent e) {\r
- fTextArea.setFocus();\r
- }});\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Slider handling\r
- // ------------------------------------------------------------------------\r
-\r
- private void createSlider(int style) {\r
- fSlider = new Slider(this, SWT.VERTICAL);\r
- fSlider.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));\r
- fSlider.setValues(0, 0, SLIDER_MAX, SLIDER_MAX, 1, 1);\r
- fSlider.addSelectionListener(this);\r
- if ((style & SWT.V_SCROLL) == 0) {\r
- fSlider.setVisible(false);\r
- }\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Controls interactions\r
- // ------------------------------------------------------------------------\r
-\r
- @Override\r
- public boolean setFocus() {\r
- boolean isVisible = isVisible();\r
- if (isVisible) {\r
- fTextArea.setFocus();\r
- }\r
- return isVisible;\r
- }\r
-\r
- @Override\r
- public void setMenu(Menu menu) {\r
- fStyledText.setMenu(menu);\r
- }\r
-\r
- /**\r
- * Sets the trace and updates the content\r
- * @param trace The trace to set\r
- */\r
- public void setTrace(ITmfTrace trace) {\r
- fTrace = trace;\r
- fTopLineIndex = 0;\r
- fLines.clear();\r
- refreshEventCount();\r
- }\r
-\r
- /**\r
- * Refreshes the event count, updates the slider thumb and loads display\r
- */\r
- public void refreshEventCount() {\r
- if (fTrace != null) {\r
- if (fTrace.getNbEvents() > 0) {\r
- fSlider.setThumb((int) Math.max(SLIDER_MAX / fTrace.getNbEvents(), 1));\r
- } else {\r
- fSlider.setThumb(SLIDER_MAX);\r
- }\r
-\r
- if (!isVisible()) {\r
- return;\r
- }\r
-\r
- if (fLines.size() == 0) {\r
- setTopRank(0);\r
- } else if (fLines.size() < fNumVisibleLines) {\r
- fBottomContext = null;\r
- loadLineData();\r
- fillTextArea();\r
- //fSlider.setSelection((int) (SLIDER_MAX * ((double) fLines.get(fTopLineIndex).rank / fTrace.getNbEvents())));\r
- fSlider.setSelection((int) (SLIDER_MAX * fTrace.getLocationRatio(fLines.get(fTopLineIndex).location)));\r
- }\r
- } else {\r
- fBottomContext = null;\r
- fillTextArea();\r
- fSlider.setThumb(SLIDER_MAX);\r
- fSlider.setSelection(0);\r
- }\r
- }\r
-\r
- /**\r
- * Selects the event of given rank and makes it visible.\r
- * @param rank The rank of event\r
- */\r
- public void selectAndReveal(long rank) {\r
- if (fTrace == null || !isVisible()) {\r
- return;\r
- }\r
- if (fActualRanks && fTopLineIndex < fLines.size() && rank >= fLines.get(fTopLineIndex).rank) {\r
- int lastVisibleIndex = Math.min(fTopLineIndex + fNumVisibleLines, fLines.size()) - 1;\r
- if (rank <= fLines.get(lastVisibleIndex).rank) {\r
- for (int i = fTopLineIndex; i < fLines.size(); i++) {\r
- if (fLines.get(i).rank == rank) {\r
- fSelectedLocation = fLines.get(i).location;\r
- break;\r
- }\r
- }\r
- refreshLineBackgrounds();\r
- return;\r
- }\r
- }\r
- setTopRank(rank);\r
- if (fLines.size() > 0 && fHoldSelection == 0) {\r
- fSelectedLocation = fLines.get(0).location;\r
- refreshLineBackgrounds();\r
- }\r
- }\r
-\r
- /**\r
- * Add a selection listener\r
- * @param listener A listener to add\r
- */\r
- public void addSelectionListener(Listener listener) {\r
- checkWidget();\r
- if (listener == null) {\r
- SWT.error (SWT.ERROR_NULL_ARGUMENT);\r
- }\r
- addListener (SWT.Selection, listener);\r
- }\r
-\r
- /**\r
- * Remove selection listener\r
- * @param listener A listener to remove\r
- */\r
- public void removeSelectionListener(Listener listener) {\r
- checkWidget();\r
- if (listener == null) {\r
- SWT.error (SWT.ERROR_NULL_ARGUMENT);\r
- }\r
- removeListener(SWT.Selection, listener);\r
- }\r
-\r
- private void sendSelectionEvent(LineData lineData) {\r
- Event event = new Event();\r
- if (fActualRanks) {\r
- event.data = Long.valueOf(lineData.rank);\r
- } else {\r
- event.data = lineData.location;\r
- }\r
- notifyListeners(SWT.Selection, event);\r
- }\r
-\r
- private void setTopRank(long rank) {\r
- fBottomContext = fTrace.seekEvent(rank);\r
- if (fBottomContext == null) {\r
- return;\r
- }\r
- fLines.clear();\r
- fActualRanks = true;\r
- fTopLineIndex = 0;\r
- loadLineData();\r
- refreshTextArea();\r
- if (fLines.size() == 0) {\r
- fSlider.setSelection(0);\r
- } else {\r
- //fSlider.setSelection((int) (SLIDER_MAX * ((double) fLines.get(fTopLineIndex).rank / fTrace.getNbEvents())));\r
- fSlider.setSelection((int) (SLIDER_MAX * fTrace.getLocationRatio(fLines.get(fTopLineIndex).location)));\r
- }\r
- }\r
-\r
- private void setTopPosition(double ratio) {\r
- fBottomContext = fTrace.seekEvent(ratio);\r
- if (fBottomContext == null) {\r
- return;\r
- }\r
- fBottomContext.setRank(0);\r
- fLines.clear();\r
- fActualRanks = false;\r
- fTopLineIndex = 0;\r
- loadLineData();\r
- refreshTextArea();\r
- }\r
-\r
- private void loadLineData() {\r
- if (fTopLineIndex < 0) {\r
- //if (fLines.size() > 0 && fLines.get(0).rank > 0) {\r
- //long endRank = fLines.get(0).rank;\r
- //long startRank = Math.max(0, endRank - fNumVisibleLines);\r
- //TmfContext context = fTrace.seekEvent(startRank);\r
- //int index = 0;\r
- //while (context.getRank() < endRank) {\r
- //long rank = context.getRank();\r
- //ITmfLocation<?> location = context.getLocation();\r
- //TmfEvent event = fTrace.getNextEvent(context);\r
- //String[] lines = event.getRawText().split("\r?\n");\r
- //for (int i = 0; i < lines.length; i++) {\r
- //String line = lines[i];\r
- //LineData lineData = new LineData(rank, location, line);\r
- //fLines.add(index++, lineData);\r
- //fTopLineIndex++;\r
- //fLastTopLineIndex++;\r
- //}\r
- //}\r
- //}\r
- if (fLines.size() > 0 && fTrace.getLocationRatio(fLines.get(0).location) > 0) {\r
- double lastRatio = fTrace.getLocationRatio(fLines.get(fLines.size() - 1).location);\r
- double firstRatio = fTrace.getLocationRatio(fLines.get(0).location);\r
- double delta;\r
- boolean singleEvent = false;\r
- if (firstRatio != lastRatio) {\r
- // approximate ratio of at least 20 items\r
- delta = Math.max(20, fNumVisibleLines) * (lastRatio - firstRatio) / (fLines.size() - 1);\r
- } else {\r
- delta = Math.pow(10, -15);\r
- singleEvent = true;\r
- }\r
- while (fTopLineIndex < 0) {\r
- ITmfLocation endLocation = fLines.get(0).location;\r
- firstRatio = Math.max(0, firstRatio - delta);\r
- ITmfContext context = fTrace.seekEvent(firstRatio);\r
- ITmfLocation location;\r
- int index = 0;\r
- long rank = 0;\r
- while (!context.getLocation().equals(endLocation)) {\r
- location = context.getLocation().clone();\r
- ITmfEvent event = fTrace.getNext(context);\r
- if (event == null) {\r
- break;\r
- }\r
- if (event.getContent() != null && event.getContent().getValue() != null) {\r
- String[] lines = event.getContent().getValue().toString().split("\r?\n"); //$NON-NLS-1$\r
- for (int i = 0; i < lines.length; i++) {\r
- String line = lines[i];\r
- LineData lineData = new LineData(rank, location, line);\r
- fLines.add(index++, lineData);\r
- fTopLineIndex++;\r
- fLastTopLineIndex++;\r
- }\r
- } else {\r
- LineData lineData = new LineData(rank, location, ""); //$NON-NLS-1$\r
- fLines.add(index++, lineData);\r
- fTopLineIndex++;\r
- fLastTopLineIndex++;\r
- }\r
- rank++;\r
- }\r
- long rankOffset = fLines.get(index).rank - rank;\r
- for (int i = 0; i < index; i++) {\r
- fLines.get(i).rank += rankOffset;\r
- }\r
- if (firstRatio == 0) {\r
- break;\r
- }\r
- if (singleEvent) {\r
- delta = Math.min(delta * 10, 0.1);\r
- }\r
- }\r
- }\r
- if (fTopLineIndex < 0) {\r
- fTopLineIndex = 0;\r
- }\r
- }\r
-\r
- while (fLines.size() - fTopLineIndex < fNumVisibleLines) {\r
- if (fBottomContext == null) {\r
- if (fLines.size() == 0) {\r
- fBottomContext = fTrace.seekEvent(0);\r
- } else {\r
- //fBottomContext = fTrace.seekEvent(fLines.get(fLines.size() - 1).rank + 1);\r
- fBottomContext = fTrace.seekEvent(fLines.get(fLines.size() - 1).location);\r
- fTrace.getNext(fBottomContext);\r
- }\r
- if (fBottomContext == null) {\r
- break;\r
- }\r
- }\r
- long rank = fBottomContext.getRank();\r
- ITmfLocation location = fBottomContext.getLocation() != null ? fBottomContext.getLocation().clone() : null;\r
- ITmfEvent event = fTrace.getNext(fBottomContext);\r
- if (event == null) {\r
- break;\r
- }\r
- if (event.getContent() != null && event.getContent().getValue() != null) {\r
- for (String line : event.getContent().getValue().toString().split("\r?\n")) { //$NON-NLS-1$\r
- int crPos;\r
- if ((crPos = line.indexOf('\r')) != -1) {\r
- line = line.substring(0, crPos);\r
- }\r
- LineData lineData = new LineData(rank, location, line);\r
- fLines.add(lineData);\r
- }\r
- } else {\r
- LineData lineData = new LineData(rank, location, ""); //$NON-NLS-1$\r
- fLines.add(lineData);\r
- }\r
- }\r
- fTopLineIndex = Math.max(0, Math.min(fTopLineIndex, fLines.size() - 1));\r
-\r
- if (fLines.size() > MAX_LINE_DATA_SIZE) {\r
- if (fTopLineIndex < MAX_LINE_DATA_SIZE / 2) {\r
- long rank = fLines.get(MAX_LINE_DATA_SIZE - 1).rank;\r
- for (int i = MAX_LINE_DATA_SIZE; i < fLines.size(); i++) {\r
- if (fLines.get(i).rank > rank) {\r
- fLines.subList(i, fLines.size()).clear();\r
- fBottomContext = null;\r
- break;\r
- }\r
- }\r
- } else {\r
- long rank = fLines.get(fLines.size() - MAX_LINE_DATA_SIZE).rank;\r
- for (int i = fLines.size() - MAX_LINE_DATA_SIZE - 1; i >= 0; i--) {\r
- if (fLines.get(i).rank < rank) {\r
- fLines.subList(0, i + 1).clear();\r
- fTopLineIndex -= (i + 1);\r
- fLastTopLineIndex -= (i + 1);\r
- break;\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- private void refreshTextArea() {\r
- fStyledText.setText(""); //$NON-NLS-1$\r
- for (int i = 0; i < fLines.size() - fTopLineIndex && i < fNumVisibleLines; i++) {\r
- if (i > 0)\r
- {\r
- fStyledText.append("\n"); //$NON-NLS-1$\r
- }\r
- LineData lineData = fLines.get(fTopLineIndex + i);\r
- fStyledText.append(lineData.string);\r
- setLineBackground(i, lineData);\r
- }\r
- fTextArea.layout();\r
- fScrolledComposite.setMinSize(fTextArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));\r
- fLastTopLineIndex = fTopLineIndex;\r
- }\r
-\r
- private void fillTextArea() {\r
- int nextLine = fStyledText.getCharCount() == 0 ? 0 : fStyledText.getLineCount();\r
- for (int i = nextLine; i < fLines.size() - fTopLineIndex && i < fNumVisibleLines; i++) {\r
- if (i > 0)\r
- {\r
- fStyledText.append("\n"); //$NON-NLS-1$\r
- }\r
- LineData lineData = fLines.get(fTopLineIndex + i);\r
- fStyledText.append(lineData.string);\r
- setLineBackground(i, lineData);\r
- }\r
- int endLine = Math.min(fNumVisibleLines, fLines.size());\r
- if (endLine < fStyledText.getLineCount()) {\r
- int endOffset = fStyledText.getOffsetAtLine(endLine) - 1;\r
- if (endOffset > fStyledText.getCharCount()) {\r
- fHoldSelection++;\r
- fStyledText.replaceTextRange(endOffset, fStyledText.getCharCount() - endOffset, ""); //$NON-NLS-1$\r
- fHoldSelection--;\r
- }\r
- }\r
- fTextArea.layout();\r
- fScrolledComposite.setMinSize(fTextArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));\r
- }\r
-\r
- private void updateTextArea() {\r
- if (fTopLineIndex < fLastTopLineIndex) {\r
- StringBuffer insertedText = new StringBuffer();\r
- for (int i = fTopLineIndex; i < fLastTopLineIndex; i++) {\r
- insertedText.append(fLines.get(i).string + "\n"); //$NON-NLS-1$\r
- }\r
- fStyledText.replaceTextRange(0, 0, insertedText.toString());\r
- for (int i = 0; i < fLastTopLineIndex - fTopLineIndex; i++) {\r
- LineData lineData = fLines.get(fTopLineIndex + i);\r
- setLineBackground(i, lineData);\r
- }\r
- fLastTopLineIndex = fTopLineIndex;\r
- } else if (fTopLineIndex > fLastTopLineIndex) {\r
- int length = 0;\r
- for (int i = 0; i < fTopLineIndex - fLastTopLineIndex && i < fNumVisibleLines; i++) {\r
- length += fLines.get(i + fLastTopLineIndex).string.length();\r
- if (i < fStyledText.getLineCount()) {\r
- length += 1;\r
- }\r
- }\r
- fStyledText.replaceTextRange(0, length, ""); //$NON-NLS-1$\r
- fLastTopLineIndex = fTopLineIndex;\r
- fillTextArea();\r
- }\r
- int endLine = Math.min(fNumVisibleLines, fLines.size());\r
- if (endLine < fStyledText.getLineCount()) {\r
- int endOffset = fStyledText.getOffsetAtLine(endLine) - 1;\r
- if (endOffset > fStyledText.getCharCount()) {\r
- fStyledText.replaceTextRange(endOffset, fStyledText.getCharCount() - endOffset, ""); //$NON-NLS-1$\r
- }\r
- }\r
- fTextArea.layout();\r
- fScrolledComposite.setMinSize(fTextArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));\r
- }\r
-\r
- private void refreshLineBackgrounds() {\r
- for (int i = 0; (i < fStyledText.getLineCount()) && (i < fNumVisibleLines) && (i < fLines.size() - fTopLineIndex); i++) {\r
- LineData lineData = fLines.get(fTopLineIndex + i);\r
- setLineBackground(i, lineData);\r
- }\r
- }\r
-\r
- private void setLineBackground(int index, LineData lineData) {\r
- if (lineData.location.equals(fSelectedLocation)) {\r
- fStyledText.setLineBackground(index, 1, COLOR_BACKGROUND_SELECTED);\r
- } else if (lineData.rank == fHighlightedRank) {\r
- fStyledText.setLineBackground(index, 1, COLOR_BACKGROUND_HIGHLIGHTED);\r
- } else if (lineData.rank % 2 == 0) {\r
- fStyledText.setLineBackground(index, 1, COLOR_BACKGROUND_EVEN);\r
- } else {\r
- fStyledText.setLineBackground(index, 1, COLOR_BACKGROUND_ODD);\r
- }\r
- }\r
-\r
- private void storeCaretPosition(int time, int caretOffset) {\r
- if (fStoredCaretPosition[0].time == time) {\r
- fStoredCaretPosition[0].caretOffset = caretOffset;\r
- } else {\r
- fStoredCaretPosition[1] = fStoredCaretPosition[0];\r
- fStoredCaretPosition[0] = new CaretPosition(time, caretOffset);\r
- }\r
- }\r
-\r
- private int getPreviousCaretOffset(int time) {\r
- if (fStoredCaretPosition[0].time == time) {\r
- return fStoredCaretPosition[1].caretOffset;\r
- }\r
- return fStoredCaretPosition[0].caretOffset;\r
- }\r
-\r
- private void updateHighlightedRank() {\r
- if (fCursorYCoordinate < 0 || fCursorYCoordinate > fStyledText.getSize().y) {\r
- if (fHighlightedRank != Long.MIN_VALUE) {\r
- fHighlightedRank = Long.MIN_VALUE;\r
- refreshLineBackgrounds();\r
- }\r
- return;\r
- }\r
- int offset = fStyledText.getOffsetAtLocation(new Point(0, fCursorYCoordinate));\r
- int line = fStyledText.getLineAtOffset(offset);\r
- if (line < fLines.size() - fTopLineIndex) {\r
- LineData lineData = fLines.get(fTopLineIndex + line);\r
- if (fHighlightedRank != lineData.rank) {\r
- fHighlightedRank = lineData.rank;\r
- refreshLineBackgrounds();\r
- }\r
- } else {\r
- if (fHighlightedRank != Long.MIN_VALUE) {\r
- fHighlightedRank = Long.MIN_VALUE;\r
- refreshLineBackgrounds();\r
- }\r
- }\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // ControlListener (ScrolledComposite)\r
- // ------------------------------------------------------------------------\r
-\r
- @Override\r
- public void controlResized(ControlEvent event) {\r
- int areaHeight = fScrolledComposite.getSize().y;\r
- if (fScrolledComposite.getHorizontalBar() != null) {\r
- areaHeight -= fScrolledComposite.getHorizontalBar().getSize().y;\r
- }\r
- int lineHeight = fStyledText.getLineHeight();\r
- fNumVisibleLines = Math.max((areaHeight + lineHeight - 1) / lineHeight, 1);\r
-\r
- if (fBottomContext != null) {\r
- loadLineData();\r
- fillTextArea();\r
- }\r
- }\r
-\r
- @Override\r
- public void controlMoved(ControlEvent e) {\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // SelectionListener (Slider)\r
- // ------------------------------------------------------------------------\r
-\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- fTextArea.setFocus();\r
- if (fLines.size() == 0) {\r
- return;\r
- }\r
- if (e.detail == SWT.DRAG) {\r
- return;\r
- }\r
- fHoldSelection++;\r
- switch (e.detail) {\r
- case SWT.NONE: {\r
- //long rank = (long) (fTrace.getNbEvents() * ((double) fSlider.getSelection() / SLIDER_MAX));\r
- //setTopRank(rank);\r
- if (fSlider.getSelection() == 0 || fSlider.getThumb() == SLIDER_MAX) {\r
- fLines.clear();\r
- setTopPosition(0.0);\r
- break;\r
- }\r
- double ratio = (double) fSlider.getSelection() / (SLIDER_MAX - fSlider.getThumb());\r
- double delta = Math.pow(10, -15);\r
- fLines.clear();\r
- while (fLines.size() == 0) {\r
- setTopPosition(ratio);\r
- if (ratio == 0.0) {\r
- break;\r
- }\r
- delta = Math.min(delta * 10, 0.1);\r
- ratio = Math.max(ratio - delta, 0.0);\r
- }\r
- break;\r
- }\r
- case SWT.ARROW_DOWN: {\r
- if (fTopLineIndex >= fLines.size()) {\r
- break;\r
- }\r
- fTopLineIndex++;\r
- loadLineData();\r
- updateTextArea();\r
- break;\r
- }\r
- case SWT.PAGE_DOWN: {\r
- fTopLineIndex += Math.max(fNumVisibleLines - 1, 1);\r
- loadLineData();\r
- updateTextArea();\r
- break;\r
- }\r
- case SWT.ARROW_UP: {\r
- //if (fLines.size() == 0 || (fTopLineIndex == 0 && fLines.get(0).rank == 0)) {\r
- if (fLines.size() == 0) {// || (fTopLineIndex == 0 && fLines.get(0).rank == 0)) {\r
- break;\r
- }\r
- fTopLineIndex--;\r
- loadLineData();\r
- updateTextArea();\r
- break;\r
- }\r
- case SWT.PAGE_UP: {\r
- fTopLineIndex -= Math.max(fNumVisibleLines - 1, 1);\r
- loadLineData();\r
- updateTextArea();\r
- break;\r
- }\r
- case SWT.HOME: {\r
- //selectAndReveal(0);\r
- setTopPosition(0.0);\r
- break;\r
- }\r
- case SWT.END: {\r
- //if (fTrace.getNbEvents() > 0) {\r
- //selectAndReveal(fTrace.getNbEvents() - 1);\r
- //}\r
- double ratio = 1.0;\r
- double delta = Math.pow(10, -15);\r
- fLines.clear();\r
- while (fLines.size() == 0) {\r
- setTopPosition(ratio);\r
- if (ratio == 0.0) {\r
- break;\r
- }\r
- delta = Math.min(delta * 10, 0.1);\r
- ratio = Math.max(ratio - delta, 0.0);\r
- }\r
- break;\r
- }\r
- default:\r
- break;\r
- }\r
- //fSlider.setSelection((int) (SLIDER_MAX * ((double) fLines.get(fTopLineIndex).rank / fTrace.getNbEvents())));\r
- if (e.detail != SWT.NONE) {\r
- fSlider.setSelection((int) (SLIDER_MAX * fTrace.getLocationRatio(fLines.get(fTopLineIndex).location)));\r
- }\r
-\r
- fHoldSelection = 0;\r
- }\r
-\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // KeyListener (StyledText)\r
- // ------------------------------------------------------------------------\r
-\r
- @Override\r
- public void keyPressed(KeyEvent e) {\r
- if (fLines.size() == 0) {\r
- return;\r
- }\r
- int caretOffset = fStyledText.getCaretOffset();\r
- int previousCaretOffset = getPreviousCaretOffset(e.time);\r
- int previousLineAtCaretPosition = fStyledText.getLineAtOffset(previousCaretOffset);\r
- int previousColumnAtCaretPosition = getPreviousCaretOffset(e.time) - fStyledText.getOffsetAtLine(previousLineAtCaretPosition);\r
- switch (e.keyCode) {\r
- case SWT.ARROW_DOWN: {\r
- if (previousLineAtCaretPosition < (fNumVisibleLines - 2)) {\r
- break;\r
- }\r
- fHoldSelection++;\r
- fTopLineIndex++;\r
- loadLineData();\r
- updateTextArea();\r
- fHoldSelection--;\r
- LineData lineData = fLines.get(fTopLineIndex + fStyledText.getLineAtOffset(fStyledText.getCaretOffset()));\r
- if (!lineData.location.equals(fSelectedLocation)) {\r
- fSelectedLocation = lineData.location;\r
- refreshLineBackgrounds();\r
- sendSelectionEvent(lineData);\r
- }\r
- break;\r
- }\r
- case SWT.PAGE_DOWN: {\r
- if (previousLineAtCaretPosition >= (fNumVisibleLines - 1)) {\r
- fHoldSelection++;\r
- if (fLines.get(fTopLineIndex + previousLineAtCaretPosition).rank % 2 == 0) {\r
- fStyledText.setLineBackground(previousLineAtCaretPosition, 1, COLOR_BACKGROUND_EVEN);\r
- } else {\r
- fStyledText.setLineBackground(previousLineAtCaretPosition, 1, COLOR_BACKGROUND_ODD);\r
- }\r
- fSelectedLocation = null;\r
- fTopLineIndex += Math.max(fNumVisibleLines - 1, 1);\r
- loadLineData();\r
- updateTextArea();\r
- fHoldSelection--;\r
- }\r
- int line = Math.min(fNumVisibleLines - 1, fStyledText.getLineCount() - 1);\r
- int offset = fStyledText.getOffsetAtLine(line);\r
- fStyledText.setSelection(offset + Math.min(previousColumnAtCaretPosition, fLines.get(fTopLineIndex + line).string.length()));\r
- break;\r
- }\r
- case SWT.ARROW_RIGHT: {\r
- if (previousCaretOffset < fStyledText.getCharCount() || previousLineAtCaretPosition < (fNumVisibleLines - 2)) {\r
- break;\r
- }\r
- fHoldSelection++;\r
- fTopLineIndex++;\r
- loadLineData();\r
- updateTextArea();\r
- fHoldSelection--;\r
- fStyledText.setSelection(fStyledText.getCaretOffset() + 1);\r
- break;\r
- }\r
- case SWT.ARROW_UP: {\r
- if (previousLineAtCaretPosition > 0) {\r
- break;\r
- }\r
- if (fLines.size() == 0) {// || (fTopLineIndex == 0 && fLines.get(0).rank == 0)) {\r
- break;\r
- }\r
- fHoldSelection++;\r
- fTopLineIndex--;\r
- loadLineData();\r
- updateTextArea();\r
- fHoldSelection--;\r
- LineData lineData = fLines.get(fTopLineIndex);\r
- if (!lineData.location.equals(fSelectedLocation)) {\r
- fSelectedLocation = lineData.location;\r
- refreshLineBackgrounds();\r
- sendSelectionEvent(lineData);\r
- }\r
- fStyledText.setSelection(caretOffset);\r
- break;\r
- }\r
- case SWT.PAGE_UP: {\r
- if (previousLineAtCaretPosition > 0) {\r
- break;\r
- }\r
- fHoldSelection++;\r
- fTopLineIndex -= Math.max(fNumVisibleLines - 1, 1);\r
- loadLineData();\r
- updateTextArea();\r
- fHoldSelection--;\r
- LineData lineData = fLines.get(fTopLineIndex);\r
- if (!lineData.location.equals(fSelectedLocation)) {\r
- fSelectedLocation = lineData.location;\r
- refreshLineBackgrounds();\r
- sendSelectionEvent(lineData);\r
- }\r
- fStyledText.setSelection(caretOffset);\r
- break;\r
- }\r
- case SWT.ARROW_LEFT: {\r
- if (previousCaretOffset > 0) {\r
- break;\r
- }\r
- if (fLines.size() == 0) {// || (fTopLineIndex == 0 && fLines.get(0).rank == 0)) {\r
- break;\r
- }\r
- long topRank = fLines.get(fTopLineIndex).rank;\r
- fHoldSelection++;\r
- fTopLineIndex--;\r
- loadLineData();\r
- updateTextArea();\r
- fHoldSelection--;\r
- LineData lineData = fLines.get(fTopLineIndex);\r
- if (!lineData.location.equals(fSelectedLocation)) {\r
- fSelectedLocation = lineData.location;\r
- refreshLineBackgrounds();\r
- sendSelectionEvent(lineData);\r
- }\r
- if (topRank != fLines.get(fTopLineIndex).rank) {\r
- fStyledText.setSelection(fLines.get(fTopLineIndex).string.length());\r
- }\r
- break;\r
- }\r
- case SWT.HOME: {\r
- if ((e.stateMask & SWT.CTRL) == 0) {\r
- break;\r
- }\r
- //selectAndReveal(0);\r
- setTopPosition(0.0);\r
- LineData lineData = fLines.get(fTopLineIndex);\r
- if (!lineData.location.equals(fSelectedLocation)) {\r
- fSelectedLocation = lineData.location;\r
- refreshLineBackgrounds();\r
- sendSelectionEvent(lineData);\r
- }\r
- break;\r
- }\r
- case SWT.END: {\r
- if ((e.stateMask & SWT.CTRL) == 0) {\r
- break;\r
- }\r
- //if (fTrace.getNbEvents() > 0) {\r
- //selectAndReveal(fTrace.getNbEvents() - 1);\r
- //}\r
- double ratio = 1.0;\r
- double delta = Math.pow(10, -15);\r
- fLines.clear();\r
- while (fLines.size() == 0) {\r
- setTopPosition(ratio);\r
- if (ratio == 0.0) {\r
- break;\r
- }\r
- delta = Math.min(delta * 10, 0.1);\r
- ratio = Math.max(ratio - delta, 0.0);\r
- }\r
- LineData lineData = fLines.get(fTopLineIndex);\r
- if (!lineData.location.equals(fSelectedLocation)) {\r
- fSelectedLocation = lineData.location;\r
- refreshLineBackgrounds();\r
- sendSelectionEvent(lineData);\r
- }\r
- break;\r
- }\r
- default:\r
- break;\r
- }\r
- //fSlider.setSelection((int) (SLIDER_MAX * ((double) fLines.get(fTopLineIndex).rank / fTrace.getNbEvents())));\r
- updateHighlightedRank();\r
- fSlider.setSelection((int) (SLIDER_MAX * fTrace.getLocationRatio(fLines.get(fTopLineIndex).location)));\r
- }\r
-\r
- @Override\r
- public void keyReleased(KeyEvent e) {\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // CaretListener (StyledText)\r
- // ------------------------------------------------------------------------\r
-\r
- @Override\r
- public void caretMoved(CaretEvent event) {\r
- if (fHoldSelection == 0) {\r
- int line = fStyledText.getLineAtOffset(event.caretOffset);\r
- if (fTopLineIndex + line < fLines.size()) {\r
- LineData lineData = fLines.get(fTopLineIndex + line);\r
- if (!lineData.location.equals(fSelectedLocation)) {\r
- fSelectedLocation = lineData.location;\r
- refreshLineBackgrounds();\r
- sendSelectionEvent(lineData);\r
- }\r
- }\r
- }\r
- storeCaretPosition(event.time, event.caretOffset);\r
- if (fHoldSelection == 0) {\r
- Point caret = fStyledText.getLocationAtOffset(fStyledText.getCaretOffset());\r
- Point origin = fScrolledComposite.getOrigin();\r
- if (origin.x > caret.x) {\r
- origin.x = caret.x;\r
- } else if (caret.x - origin.x > fScrolledComposite.getSize().x) {\r
- origin.x = caret.x - fScrolledComposite.getSize().x + 1;\r
- }\r
- fScrolledComposite.setOrigin(origin);\r
- }\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // MouseMoveListener (StyledText)\r
- // ------------------------------------------------------------------------\r
-\r
- @Override\r
- public void mouseMove(MouseEvent e) {\r
- fCursorYCoordinate = e.y;\r
- if (e.y < 0 || e.y > fStyledText.getSize().y) {\r
- if (fHighlightedRank != Long.MIN_VALUE) {\r
- fHighlightedRank = Long.MIN_VALUE;\r
- refreshLineBackgrounds();\r
- }\r
- return;\r
- }\r
- int offset = fStyledText.getOffsetAtLocation(new Point(0, e.y));\r
- int line = fStyledText.getLineAtOffset(offset);\r
- if (line < fLines.size() - fTopLineIndex) {\r
- LineData lineData = fLines.get(fTopLineIndex + line);\r
- if (fHighlightedRank != lineData.rank) {\r
- fHighlightedRank = lineData.rank;\r
- refreshLineBackgrounds();\r
- }\r
- } else {\r
- if (fHighlightedRank != Long.MIN_VALUE) {\r
- fHighlightedRank = Long.MIN_VALUE;\r
- refreshLineBackgrounds();\r
- }\r
- }\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // MouseTrackListener (StyledText)\r
- // ------------------------------------------------------------------------\r
-\r
- @Override\r
- public void mouseExit(MouseEvent e) {\r
- fCursorYCoordinate = -1;\r
- if (fHighlightedRank != Long.MIN_VALUE) {\r
- fHighlightedRank = Long.MIN_VALUE;\r
- refreshLineBackgrounds();\r
- }\r
- }\r
-\r
- @Override\r
- public void mouseEnter(MouseEvent e) {\r
- fCursorYCoordinate = e.y;\r
- }\r
-\r
- @Override\r
- public void mouseHover(MouseEvent e) {\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // MouseWheelListener (StyledText)\r
- // ------------------------------------------------------------------------\r
-\r
- @Override\r
- public void mouseScrolled(MouseEvent e) {\r
- if (fLines.size() == 0) {\r
- return;\r
- }\r
- fHoldSelection++;\r
- fTopLineIndex -= e.count;\r
- loadLineData();\r
- updateTextArea();\r
- fHoldSelection = 0;\r
- //fSlider.setSelection((int) (SLIDER_MAX * ((double) fLines.get(fTopLineIndex).rank / fTrace.getNbEvents())));\r
- updateHighlightedRank();\r
- fSlider.setSelection((int) (SLIDER_MAX * fTrace.getLocationRatio(fLines.get(fTopLineIndex).location)));\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2010, 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.rawviewer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CaretEvent;
+import org.eclipse.swt.custom.CaretListener;
+import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.ControlListener;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseMoveListener;
+import org.eclipse.swt.events.MouseTrackListener;
+import org.eclipse.swt.events.MouseWheelListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Slider;
+
+/**
+ * TmfRawEventViewer allows for the display of the raw data for an arbitrarily
+ * large number of TMF events.
+ *
+ * It is essentially a Composite of a StyledText area and a Slider, where the number
+ * of visible lines in the StyledText control is set to fill the viewer display area.
+ * An underlying data model is used to store a cache of event raw text line data.
+ * The slider is ratio-based.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TmfRawEventViewer extends Composite implements ControlListener, SelectionListener,
+ KeyListener, CaretListener, MouseMoveListener, MouseTrackListener, MouseWheelListener {
+
+ private static final Color COLOR_BACKGROUND_ODD = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
+ private static final Color COLOR_BACKGROUND_EVEN = new Color(Display.getDefault(), 242, 242, 242);
+ private static final Color COLOR_BACKGROUND_SELECTED = new Color(Display.getDefault(), 231, 246, 254);
+ private static final Color COLOR_BACKGROUND_HIGHLIGHTED = new Color(Display.getDefault(), 246, 252, 255);
+ private static final int MAX_LINE_DATA_SIZE = 1000;
+ private static final int SLIDER_MAX = 1000000;
+
+ private ITmfTrace fTrace;
+ private ITmfContext fBottomContext;
+
+ private ScrolledComposite fScrolledComposite;
+ private Composite fTextArea;
+ private StyledText fStyledText;
+ private Font fFixedFont;
+ private Slider fSlider;
+
+ private final List<LineData> fLines = new ArrayList<LineData>();
+ private boolean fActualRanks = false;
+ private int fTopLineIndex;
+ private int fLastTopLineIndex;
+ private final CaretPosition[] fStoredCaretPosition = new CaretPosition[]
+ { new CaretPosition(0, 0), new CaretPosition(0,0)};
+ private int fNumVisibleLines;
+ private ITmfLocation fSelectedLocation = null;
+ private long fHighlightedRank = Long.MIN_VALUE;
+ private int fCursorYCoordinate = -1;
+ private int fHoldSelection = 0;
+
+ private static class LineData {
+ long rank;
+ ITmfLocation location;
+ String string;
+ public LineData(long rank, ITmfLocation location, String string) {
+ this.rank = rank;
+ this.location = location;
+ if (string.length() == 0) {
+ this.string = " "; // workaround for setLineBackground has no effect on empty line //$NON-NLS-1$
+ } else {
+ this.string = string;
+ }
+ }
+ @Override
+ public String toString() {
+ return rank + " [" + location + "]: " + string; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ private static class CaretPosition {
+ int time;
+ int caretOffset;
+ public CaretPosition(int time, int caretOffset) {
+ this.time = time;
+ this.caretOffset = caretOffset;
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Constructor
+ // ------------------------------------------------------------------------
+
+ /**
+ * Constructor
+ * @param parent The parent composite
+ * @param style The style bits
+ */
+ public TmfRawEventViewer(Composite parent, int style) {
+ super(parent, style & (~SWT.H_SCROLL) & (~SWT.V_SCROLL));
+
+ // Set the layout
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 2;
+ gridLayout.horizontalSpacing = 0;
+ gridLayout.verticalSpacing = 0;
+ gridLayout.marginWidth = 0;
+ gridLayout.marginHeight = 0;
+ setLayout(gridLayout);
+
+ // Create the controls
+ createTextArea(style & SWT.H_SCROLL);
+ createSlider(style & SWT.V_SCROLL);
+
+ // Prevent the slider from being traversed
+ setTabList(new Control[] { fScrolledComposite });
+ }
+
+ @Override
+ public void dispose() {
+ if (fFixedFont != null) {
+ fFixedFont.dispose();
+ fFixedFont = null;
+ }
+ super.dispose();
+ }
+
+ // ------------------------------------------------------------------------
+ // Text area handling
+ // ------------------------------------------------------------------------
+
+ /**
+ * Create the text area and add listeners
+ */
+ private void createTextArea(int style) {
+ fScrolledComposite = new ScrolledComposite(this, style);
+ fScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ fTextArea = new Composite(fScrolledComposite, SWT.NONE);
+ fTextArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ fScrolledComposite.setContent(fTextArea);
+ fScrolledComposite.setExpandHorizontal(true);
+ fScrolledComposite.setExpandVertical(true);
+ fScrolledComposite.setAlwaysShowScrollBars(true);
+ fScrolledComposite.setMinSize(fTextArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ fScrolledComposite.addControlListener(this);
+
+ GridLayout textAreaGridLayout = new GridLayout();
+ textAreaGridLayout.marginHeight = 0;
+ textAreaGridLayout.marginWidth = 0;
+ fTextArea.setLayout(textAreaGridLayout);
+
+ if (fFixedFont == null) {
+ if (System.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
+ fFixedFont = new Font(Display.getCurrent(), new FontData("Courier New", 10, SWT.NORMAL)); //$NON-NLS-1$
+ } else {
+ fFixedFont = new Font(Display.getCurrent(), new FontData("Monospace", 10, SWT.NORMAL)); //$NON-NLS-1$
+ }
+ }
+
+ fStyledText = new StyledText(fTextArea, SWT.READ_ONLY);
+ fStyledText.setFont(fFixedFont);
+ fStyledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+
+ fStyledText.addCaretListener(this);
+ fStyledText.addMouseMoveListener(this);
+ fStyledText.addMouseTrackListener(this);
+ fStyledText.addMouseWheelListener(this);
+ fStyledText.addListener(SWT.MouseWheel, new Listener() { // disable mouse scroll of horizontal scroll bar
+ @Override
+ public void handleEvent(Event event) { event.doit = false; }});
+ fStyledText.addKeyListener(this);
+
+ fTextArea.setBackground(fStyledText.getBackground());
+ fTextArea.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseDown(MouseEvent e) {
+ fTextArea.setFocus();
+ }});
+ }
+
+ // ------------------------------------------------------------------------
+ // Slider handling
+ // ------------------------------------------------------------------------
+
+ private void createSlider(int style) {
+ fSlider = new Slider(this, SWT.VERTICAL);
+ fSlider.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
+ fSlider.setValues(0, 0, SLIDER_MAX, SLIDER_MAX, 1, 1);
+ fSlider.addSelectionListener(this);
+ if ((style & SWT.V_SCROLL) == 0) {
+ fSlider.setVisible(false);
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Controls interactions
+ // ------------------------------------------------------------------------
+
+ @Override
+ public boolean setFocus() {
+ boolean isVisible = isVisible();
+ if (isVisible) {
+ fTextArea.setFocus();
+ }
+ return isVisible;
+ }
+
+ @Override
+ public void setMenu(Menu menu) {
+ fStyledText.setMenu(menu);
+ }
+
+ /**
+ * Sets the trace and updates the content
+ * @param trace The trace to set
+ */
+ public void setTrace(ITmfTrace trace) {
+ fTrace = trace;
+ fTopLineIndex = 0;
+ fLines.clear();
+ refreshEventCount();
+ }
+
+ /**
+ * Refreshes the event count, updates the slider thumb and loads display
+ */
+ public void refreshEventCount() {
+ if (fTrace != null) {
+ if (fTrace.getNbEvents() > 0) {
+ fSlider.setThumb((int) Math.max(SLIDER_MAX / fTrace.getNbEvents(), 1));
+ } else {
+ fSlider.setThumb(SLIDER_MAX);
+ }
+
+ if (!isVisible()) {
+ return;
+ }
+
+ if (fLines.size() == 0) {
+ setTopRank(0);
+ } else if (fLines.size() < fNumVisibleLines) {
+ fBottomContext = null;
+ loadLineData();
+ fillTextArea();
+ //fSlider.setSelection((int) (SLIDER_MAX * ((double) fLines.get(fTopLineIndex).rank / fTrace.getNbEvents())));
+ fSlider.setSelection((int) (SLIDER_MAX * fTrace.getLocationRatio(fLines.get(fTopLineIndex).location)));
+ }
+ } else {
+ fBottomContext = null;
+ fillTextArea();
+ fSlider.setThumb(SLIDER_MAX);
+ fSlider.setSelection(0);
+ }
+ }
+
+ /**
+ * Selects the event of given rank and makes it visible.
+ * @param rank The rank of event
+ */
+ public void selectAndReveal(long rank) {
+ if (fTrace == null || !isVisible()) {
+ return;
+ }
+ if (fActualRanks && fTopLineIndex < fLines.size() && rank >= fLines.get(fTopLineIndex).rank) {
+ int lastVisibleIndex = Math.min(fTopLineIndex + fNumVisibleLines, fLines.size()) - 1;
+ if (rank <= fLines.get(lastVisibleIndex).rank) {
+ for (int i = fTopLineIndex; i < fLines.size(); i++) {
+ if (fLines.get(i).rank == rank) {
+ fSelectedLocation = fLines.get(i).location;
+ break;
+ }
+ }
+ refreshLineBackgrounds();
+ return;
+ }
+ }
+ setTopRank(rank);
+ if (fLines.size() > 0 && fHoldSelection == 0) {
+ fSelectedLocation = fLines.get(0).location;
+ refreshLineBackgrounds();
+ }
+ }
+
+ /**
+ * Add a selection listener
+ * @param listener A listener to add
+ */
+ public void addSelectionListener(Listener listener) {
+ checkWidget();
+ if (listener == null) {
+ SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ }
+ addListener (SWT.Selection, listener);
+ }
+
+ /**
+ * Remove selection listener
+ * @param listener A listener to remove
+ */
+ public void removeSelectionListener(Listener listener) {
+ checkWidget();
+ if (listener == null) {
+ SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ }
+ removeListener(SWT.Selection, listener);
+ }
+
+ private void sendSelectionEvent(LineData lineData) {
+ Event event = new Event();
+ if (fActualRanks) {
+ event.data = Long.valueOf(lineData.rank);
+ } else {
+ event.data = lineData.location;
+ }
+ notifyListeners(SWT.Selection, event);
+ }
+
+ private void setTopRank(long rank) {
+ fBottomContext = fTrace.seekEvent(rank);
+ if (fBottomContext == null) {
+ return;
+ }
+ fLines.clear();
+ fActualRanks = true;
+ fTopLineIndex = 0;
+ loadLineData();
+ refreshTextArea();
+ if (fLines.size() == 0) {
+ fSlider.setSelection(0);
+ } else {
+ //fSlider.setSelection((int) (SLIDER_MAX * ((double) fLines.get(fTopLineIndex).rank / fTrace.getNbEvents())));
+ fSlider.setSelection((int) (SLIDER_MAX * fTrace.getLocationRatio(fLines.get(fTopLineIndex).location)));
+ }
+ }
+
+ private void setTopPosition(double ratio) {
+ fBottomContext = fTrace.seekEvent(ratio);
+ if (fBottomContext == null) {
+ return;
+ }
+ fBottomContext.setRank(0);
+ fLines.clear();
+ fActualRanks = false;
+ fTopLineIndex = 0;
+ loadLineData();
+ refreshTextArea();
+ }
+
+ private void loadLineData() {
+ if (fTopLineIndex < 0) {
+ //if (fLines.size() > 0 && fLines.get(0).rank > 0) {
+ //long endRank = fLines.get(0).rank;
+ //long startRank = Math.max(0, endRank - fNumVisibleLines);
+ //TmfContext context = fTrace.seekEvent(startRank);
+ //int index = 0;
+ //while (context.getRank() < endRank) {
+ //long rank = context.getRank();
+ //ITmfLocation<?> location = context.getLocation();
+ //TmfEvent event = fTrace.getNextEvent(context);
+ //String[] lines = event.getRawText().split("\r?\n");
+ //for (int i = 0; i < lines.length; i++) {
+ //String line = lines[i];
+ //LineData lineData = new LineData(rank, location, line);
+ //fLines.add(index++, lineData);
+ //fTopLineIndex++;
+ //fLastTopLineIndex++;
+ //}
+ //}
+ //}
+ if (fLines.size() > 0 && fTrace.getLocationRatio(fLines.get(0).location) > 0) {
+ double lastRatio = fTrace.getLocationRatio(fLines.get(fLines.size() - 1).location);
+ double firstRatio = fTrace.getLocationRatio(fLines.get(0).location);
+ double delta;
+ boolean singleEvent = false;
+ if (firstRatio != lastRatio) {
+ // approximate ratio of at least 20 items
+ delta = Math.max(20, fNumVisibleLines) * (lastRatio - firstRatio) / (fLines.size() - 1);
+ } else {
+ delta = Math.pow(10, -15);
+ singleEvent = true;
+ }
+ while (fTopLineIndex < 0) {
+ ITmfLocation endLocation = fLines.get(0).location;
+ firstRatio = Math.max(0, firstRatio - delta);
+ ITmfContext context = fTrace.seekEvent(firstRatio);
+ ITmfLocation location;
+ int index = 0;
+ long rank = 0;
+ while (!context.getLocation().equals(endLocation)) {
+ location = context.getLocation().clone();
+ ITmfEvent event = fTrace.getNext(context);
+ if (event == null) {
+ break;
+ }
+ if (event.getContent() != null && event.getContent().getValue() != null) {
+ String[] lines = event.getContent().getValue().toString().split("\r?\n"); //$NON-NLS-1$
+ for (int i = 0; i < lines.length; i++) {
+ String line = lines[i];
+ LineData lineData = new LineData(rank, location, line);
+ fLines.add(index++, lineData);
+ fTopLineIndex++;
+ fLastTopLineIndex++;
+ }
+ } else {
+ LineData lineData = new LineData(rank, location, ""); //$NON-NLS-1$
+ fLines.add(index++, lineData);
+ fTopLineIndex++;
+ fLastTopLineIndex++;
+ }
+ rank++;
+ }
+ long rankOffset = fLines.get(index).rank - rank;
+ for (int i = 0; i < index; i++) {
+ fLines.get(i).rank += rankOffset;
+ }
+ if (firstRatio == 0) {
+ break;
+ }
+ if (singleEvent) {
+ delta = Math.min(delta * 10, 0.1);
+ }
+ }
+ }
+ if (fTopLineIndex < 0) {
+ fTopLineIndex = 0;
+ }
+ }
+
+ while (fLines.size() - fTopLineIndex < fNumVisibleLines) {
+ if (fBottomContext == null) {
+ if (fLines.size() == 0) {
+ fBottomContext = fTrace.seekEvent(0);
+ } else {
+ //fBottomContext = fTrace.seekEvent(fLines.get(fLines.size() - 1).rank + 1);
+ fBottomContext = fTrace.seekEvent(fLines.get(fLines.size() - 1).location);
+ fTrace.getNext(fBottomContext);
+ }
+ if (fBottomContext == null) {
+ break;
+ }
+ }
+ long rank = fBottomContext.getRank();
+ ITmfLocation location = fBottomContext.getLocation() != null ? fBottomContext.getLocation().clone() : null;
+ ITmfEvent event = fTrace.getNext(fBottomContext);
+ if (event == null) {
+ break;
+ }
+ if (event.getContent() != null && event.getContent().getValue() != null) {
+ for (String line : event.getContent().getValue().toString().split("\r?\n")) { //$NON-NLS-1$
+ int crPos;
+ if ((crPos = line.indexOf('\r')) != -1) {
+ line = line.substring(0, crPos);
+ }
+ LineData lineData = new LineData(rank, location, line);
+ fLines.add(lineData);
+ }
+ } else {
+ LineData lineData = new LineData(rank, location, ""); //$NON-NLS-1$
+ fLines.add(lineData);
+ }
+ }
+ fTopLineIndex = Math.max(0, Math.min(fTopLineIndex, fLines.size() - 1));
+
+ if (fLines.size() > MAX_LINE_DATA_SIZE) {
+ if (fTopLineIndex < MAX_LINE_DATA_SIZE / 2) {
+ long rank = fLines.get(MAX_LINE_DATA_SIZE - 1).rank;
+ for (int i = MAX_LINE_DATA_SIZE; i < fLines.size(); i++) {
+ if (fLines.get(i).rank > rank) {
+ fLines.subList(i, fLines.size()).clear();
+ fBottomContext = null;
+ break;
+ }
+ }
+ } else {
+ long rank = fLines.get(fLines.size() - MAX_LINE_DATA_SIZE).rank;
+ for (int i = fLines.size() - MAX_LINE_DATA_SIZE - 1; i >= 0; i--) {
+ if (fLines.get(i).rank < rank) {
+ fLines.subList(0, i + 1).clear();
+ fTopLineIndex -= (i + 1);
+ fLastTopLineIndex -= (i + 1);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ private void refreshTextArea() {
+ fStyledText.setText(""); //$NON-NLS-1$
+ for (int i = 0; i < fLines.size() - fTopLineIndex && i < fNumVisibleLines; i++) {
+ if (i > 0)
+ {
+ fStyledText.append("\n"); //$NON-NLS-1$
+ }
+ LineData lineData = fLines.get(fTopLineIndex + i);
+ fStyledText.append(lineData.string);
+ setLineBackground(i, lineData);
+ }
+ fTextArea.layout();
+ fScrolledComposite.setMinSize(fTextArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ fLastTopLineIndex = fTopLineIndex;
+ }
+
+ private void fillTextArea() {
+ int nextLine = fStyledText.getCharCount() == 0 ? 0 : fStyledText.getLineCount();
+ for (int i = nextLine; i < fLines.size() - fTopLineIndex && i < fNumVisibleLines; i++) {
+ if (i > 0)
+ {
+ fStyledText.append("\n"); //$NON-NLS-1$
+ }
+ LineData lineData = fLines.get(fTopLineIndex + i);
+ fStyledText.append(lineData.string);
+ setLineBackground(i, lineData);
+ }
+ int endLine = Math.min(fNumVisibleLines, fLines.size());
+ if (endLine < fStyledText.getLineCount()) {
+ int endOffset = fStyledText.getOffsetAtLine(endLine) - 1;
+ if (endOffset > fStyledText.getCharCount()) {
+ fHoldSelection++;
+ fStyledText.replaceTextRange(endOffset, fStyledText.getCharCount() - endOffset, ""); //$NON-NLS-1$
+ fHoldSelection--;
+ }
+ }
+ fTextArea.layout();
+ fScrolledComposite.setMinSize(fTextArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ }
+
+ private void updateTextArea() {
+ if (fTopLineIndex < fLastTopLineIndex) {
+ StringBuffer insertedText = new StringBuffer();
+ for (int i = fTopLineIndex; i < fLastTopLineIndex; i++) {
+ insertedText.append(fLines.get(i).string + "\n"); //$NON-NLS-1$
+ }
+ fStyledText.replaceTextRange(0, 0, insertedText.toString());
+ for (int i = 0; i < fLastTopLineIndex - fTopLineIndex; i++) {
+ LineData lineData = fLines.get(fTopLineIndex + i);
+ setLineBackground(i, lineData);
+ }
+ fLastTopLineIndex = fTopLineIndex;
+ } else if (fTopLineIndex > fLastTopLineIndex) {
+ int length = 0;
+ for (int i = 0; i < fTopLineIndex - fLastTopLineIndex && i < fNumVisibleLines; i++) {
+ length += fLines.get(i + fLastTopLineIndex).string.length();
+ if (i < fStyledText.getLineCount()) {
+ length += 1;
+ }
+ }
+ fStyledText.replaceTextRange(0, length, ""); //$NON-NLS-1$
+ fLastTopLineIndex = fTopLineIndex;
+ fillTextArea();
+ }
+ int endLine = Math.min(fNumVisibleLines, fLines.size());
+ if (endLine < fStyledText.getLineCount()) {
+ int endOffset = fStyledText.getOffsetAtLine(endLine) - 1;
+ if (endOffset > fStyledText.getCharCount()) {
+ fStyledText.replaceTextRange(endOffset, fStyledText.getCharCount() - endOffset, ""); //$NON-NLS-1$
+ }
+ }
+ fTextArea.layout();
+ fScrolledComposite.setMinSize(fTextArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ }
+
+ private void refreshLineBackgrounds() {
+ for (int i = 0; (i < fStyledText.getLineCount()) && (i < fNumVisibleLines) && (i < fLines.size() - fTopLineIndex); i++) {
+ LineData lineData = fLines.get(fTopLineIndex + i);
+ setLineBackground(i, lineData);
+ }
+ }
+
+ private void setLineBackground(int index, LineData lineData) {
+ if (lineData.location.equals(fSelectedLocation)) {
+ fStyledText.setLineBackground(index, 1, COLOR_BACKGROUND_SELECTED);
+ } else if (lineData.rank == fHighlightedRank) {
+ fStyledText.setLineBackground(index, 1, COLOR_BACKGROUND_HIGHLIGHTED);
+ } else if (lineData.rank % 2 == 0) {
+ fStyledText.setLineBackground(index, 1, COLOR_BACKGROUND_EVEN);
+ } else {
+ fStyledText.setLineBackground(index, 1, COLOR_BACKGROUND_ODD);
+ }
+ }
+
+ private void storeCaretPosition(int time, int caretOffset) {
+ if (fStoredCaretPosition[0].time == time) {
+ fStoredCaretPosition[0].caretOffset = caretOffset;
+ } else {
+ fStoredCaretPosition[1] = fStoredCaretPosition[0];
+ fStoredCaretPosition[0] = new CaretPosition(time, caretOffset);
+ }
+ }
+
+ private int getPreviousCaretOffset(int time) {
+ if (fStoredCaretPosition[0].time == time) {
+ return fStoredCaretPosition[1].caretOffset;
+ }
+ return fStoredCaretPosition[0].caretOffset;
+ }
+
+ private void updateHighlightedRank() {
+ if (fCursorYCoordinate < 0 || fCursorYCoordinate > fStyledText.getSize().y) {
+ if (fHighlightedRank != Long.MIN_VALUE) {
+ fHighlightedRank = Long.MIN_VALUE;
+ refreshLineBackgrounds();
+ }
+ return;
+ }
+ int offset = fStyledText.getOffsetAtLocation(new Point(0, fCursorYCoordinate));
+ int line = fStyledText.getLineAtOffset(offset);
+ if (line < fLines.size() - fTopLineIndex) {
+ LineData lineData = fLines.get(fTopLineIndex + line);
+ if (fHighlightedRank != lineData.rank) {
+ fHighlightedRank = lineData.rank;
+ refreshLineBackgrounds();
+ }
+ } else {
+ if (fHighlightedRank != Long.MIN_VALUE) {
+ fHighlightedRank = Long.MIN_VALUE;
+ refreshLineBackgrounds();
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // ControlListener (ScrolledComposite)
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void controlResized(ControlEvent event) {
+ int areaHeight = fScrolledComposite.getSize().y;
+ if (fScrolledComposite.getHorizontalBar() != null) {
+ areaHeight -= fScrolledComposite.getHorizontalBar().getSize().y;
+ }
+ int lineHeight = fStyledText.getLineHeight();
+ fNumVisibleLines = Math.max((areaHeight + lineHeight - 1) / lineHeight, 1);
+
+ if (fBottomContext != null) {
+ loadLineData();
+ fillTextArea();
+ }
+ }
+
+ @Override
+ public void controlMoved(ControlEvent e) {
+ }
+
+ // ------------------------------------------------------------------------
+ // SelectionListener (Slider)
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ fTextArea.setFocus();
+ if (fLines.size() == 0) {
+ return;
+ }
+ if (e.detail == SWT.DRAG) {
+ return;
+ }
+ fHoldSelection++;
+ switch (e.detail) {
+ case SWT.NONE: {
+ //long rank = (long) (fTrace.getNbEvents() * ((double) fSlider.getSelection() / SLIDER_MAX));
+ //setTopRank(rank);
+ if (fSlider.getSelection() == 0 || fSlider.getThumb() == SLIDER_MAX) {
+ fLines.clear();
+ setTopPosition(0.0);
+ break;
+ }
+ double ratio = (double) fSlider.getSelection() / (SLIDER_MAX - fSlider.getThumb());
+ double delta = Math.pow(10, -15);
+ fLines.clear();
+ while (fLines.size() == 0) {
+ setTopPosition(ratio);
+ if (ratio == 0.0) {
+ break;
+ }
+ delta = Math.min(delta * 10, 0.1);
+ ratio = Math.max(ratio - delta, 0.0);
+ }
+ break;
+ }
+ case SWT.ARROW_DOWN: {
+ if (fTopLineIndex >= fLines.size()) {
+ break;
+ }
+ fTopLineIndex++;
+ loadLineData();
+ updateTextArea();
+ break;
+ }
+ case SWT.PAGE_DOWN: {
+ fTopLineIndex += Math.max(fNumVisibleLines - 1, 1);
+ loadLineData();
+ updateTextArea();
+ break;
+ }
+ case SWT.ARROW_UP: {
+ //if (fLines.size() == 0 || (fTopLineIndex == 0 && fLines.get(0).rank == 0)) {
+ if (fLines.size() == 0) {// || (fTopLineIndex == 0 && fLines.get(0).rank == 0)) {
+ break;
+ }
+ fTopLineIndex--;
+ loadLineData();
+ updateTextArea();
+ break;
+ }
+ case SWT.PAGE_UP: {
+ fTopLineIndex -= Math.max(fNumVisibleLines - 1, 1);
+ loadLineData();
+ updateTextArea();
+ break;
+ }
+ case SWT.HOME: {
+ //selectAndReveal(0);
+ setTopPosition(0.0);
+ break;
+ }
+ case SWT.END: {
+ //if (fTrace.getNbEvents() > 0) {
+ //selectAndReveal(fTrace.getNbEvents() - 1);
+ //}
+ double ratio = 1.0;
+ double delta = Math.pow(10, -15);
+ fLines.clear();
+ while (fLines.size() == 0) {
+ setTopPosition(ratio);
+ if (ratio == 0.0) {
+ break;
+ }
+ delta = Math.min(delta * 10, 0.1);
+ ratio = Math.max(ratio - delta, 0.0);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ //fSlider.setSelection((int) (SLIDER_MAX * ((double) fLines.get(fTopLineIndex).rank / fTrace.getNbEvents())));
+ if (e.detail != SWT.NONE) {
+ fSlider.setSelection((int) (SLIDER_MAX * fTrace.getLocationRatio(fLines.get(fTopLineIndex).location)));
+ }
+
+ fHoldSelection = 0;
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ // ------------------------------------------------------------------------
+ // KeyListener (StyledText)
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ if (fLines.size() == 0) {
+ return;
+ }
+ int caretOffset = fStyledText.getCaretOffset();
+ int previousCaretOffset = getPreviousCaretOffset(e.time);
+ int previousLineAtCaretPosition = fStyledText.getLineAtOffset(previousCaretOffset);
+ int previousColumnAtCaretPosition = getPreviousCaretOffset(e.time) - fStyledText.getOffsetAtLine(previousLineAtCaretPosition);
+ switch (e.keyCode) {
+ case SWT.ARROW_DOWN: {
+ if (previousLineAtCaretPosition < (fNumVisibleLines - 2)) {
+ break;
+ }
+ fHoldSelection++;
+ fTopLineIndex++;
+ loadLineData();
+ updateTextArea();
+ fHoldSelection--;
+ LineData lineData = fLines.get(fTopLineIndex + fStyledText.getLineAtOffset(fStyledText.getCaretOffset()));
+ if (!lineData.location.equals(fSelectedLocation)) {
+ fSelectedLocation = lineData.location;
+ refreshLineBackgrounds();
+ sendSelectionEvent(lineData);
+ }
+ break;
+ }
+ case SWT.PAGE_DOWN: {
+ if (previousLineAtCaretPosition >= (fNumVisibleLines - 1)) {
+ fHoldSelection++;
+ if (fLines.get(fTopLineIndex + previousLineAtCaretPosition).rank % 2 == 0) {
+ fStyledText.setLineBackground(previousLineAtCaretPosition, 1, COLOR_BACKGROUND_EVEN);
+ } else {
+ fStyledText.setLineBackground(previousLineAtCaretPosition, 1, COLOR_BACKGROUND_ODD);
+ }
+ fSelectedLocation = null;
+ fTopLineIndex += Math.max(fNumVisibleLines - 1, 1);
+ loadLineData();
+ updateTextArea();
+ fHoldSelection--;
+ }
+ int line = Math.min(fNumVisibleLines - 1, fStyledText.getLineCount() - 1);
+ int offset = fStyledText.getOffsetAtLine(line);
+ fStyledText.setSelection(offset + Math.min(previousColumnAtCaretPosition, fLines.get(fTopLineIndex + line).string.length()));
+ break;
+ }
+ case SWT.ARROW_RIGHT: {
+ if (previousCaretOffset < fStyledText.getCharCount() || previousLineAtCaretPosition < (fNumVisibleLines - 2)) {
+ break;
+ }
+ fHoldSelection++;
+ fTopLineIndex++;
+ loadLineData();
+ updateTextArea();
+ fHoldSelection--;
+ fStyledText.setSelection(fStyledText.getCaretOffset() + 1);
+ break;
+ }
+ case SWT.ARROW_UP: {
+ if (previousLineAtCaretPosition > 0) {
+ break;
+ }
+ if (fLines.size() == 0) {// || (fTopLineIndex == 0 && fLines.get(0).rank == 0)) {
+ break;
+ }
+ fHoldSelection++;
+ fTopLineIndex--;
+ loadLineData();
+ updateTextArea();
+ fHoldSelection--;
+ LineData lineData = fLines.get(fTopLineIndex);
+ if (!lineData.location.equals(fSelectedLocation)) {
+ fSelectedLocation = lineData.location;
+ refreshLineBackgrounds();
+ sendSelectionEvent(lineData);
+ }
+ fStyledText.setSelection(caretOffset);
+ break;
+ }
+ case SWT.PAGE_UP: {
+ if (previousLineAtCaretPosition > 0) {
+ break;
+ }
+ fHoldSelection++;
+ fTopLineIndex -= Math.max(fNumVisibleLines - 1, 1);
+ loadLineData();
+ updateTextArea();
+ fHoldSelection--;
+ LineData lineData = fLines.get(fTopLineIndex);
+ if (!lineData.location.equals(fSelectedLocation)) {
+ fSelectedLocation = lineData.location;
+ refreshLineBackgrounds();
+ sendSelectionEvent(lineData);
+ }
+ fStyledText.setSelection(caretOffset);
+ break;
+ }
+ case SWT.ARROW_LEFT: {
+ if (previousCaretOffset > 0) {
+ break;
+ }
+ if (fLines.size() == 0) {// || (fTopLineIndex == 0 && fLines.get(0).rank == 0)) {
+ break;
+ }
+ long topRank = fLines.get(fTopLineIndex).rank;
+ fHoldSelection++;
+ fTopLineIndex--;
+ loadLineData();
+ updateTextArea();
+ fHoldSelection--;
+ LineData lineData = fLines.get(fTopLineIndex);
+ if (!lineData.location.equals(fSelectedLocation)) {
+ fSelectedLocation = lineData.location;
+ refreshLineBackgrounds();
+ sendSelectionEvent(lineData);
+ }
+ if (topRank != fLines.get(fTopLineIndex).rank) {
+ fStyledText.setSelection(fLines.get(fTopLineIndex).string.length());
+ }
+ break;
+ }
+ case SWT.HOME: {
+ if ((e.stateMask & SWT.CTRL) == 0) {
+ break;
+ }
+ //selectAndReveal(0);
+ setTopPosition(0.0);
+ LineData lineData = fLines.get(fTopLineIndex);
+ if (!lineData.location.equals(fSelectedLocation)) {
+ fSelectedLocation = lineData.location;
+ refreshLineBackgrounds();
+ sendSelectionEvent(lineData);
+ }
+ break;
+ }
+ case SWT.END: {
+ if ((e.stateMask & SWT.CTRL) == 0) {
+ break;
+ }
+ //if (fTrace.getNbEvents() > 0) {
+ //selectAndReveal(fTrace.getNbEvents() - 1);
+ //}
+ double ratio = 1.0;
+ double delta = Math.pow(10, -15);
+ fLines.clear();
+ while (fLines.size() == 0) {
+ setTopPosition(ratio);
+ if (ratio == 0.0) {
+ break;
+ }
+ delta = Math.min(delta * 10, 0.1);
+ ratio = Math.max(ratio - delta, 0.0);
+ }
+ LineData lineData = fLines.get(fTopLineIndex);
+ if (!lineData.location.equals(fSelectedLocation)) {
+ fSelectedLocation = lineData.location;
+ refreshLineBackgrounds();
+ sendSelectionEvent(lineData);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ //fSlider.setSelection((int) (SLIDER_MAX * ((double) fLines.get(fTopLineIndex).rank / fTrace.getNbEvents())));
+ updateHighlightedRank();
+ fSlider.setSelection((int) (SLIDER_MAX * fTrace.getLocationRatio(fLines.get(fTopLineIndex).location)));
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ }
+
+ // ------------------------------------------------------------------------
+ // CaretListener (StyledText)
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void caretMoved(CaretEvent event) {
+ if (fHoldSelection == 0) {
+ int line = fStyledText.getLineAtOffset(event.caretOffset);
+ if (fTopLineIndex + line < fLines.size()) {
+ LineData lineData = fLines.get(fTopLineIndex + line);
+ if (!lineData.location.equals(fSelectedLocation)) {
+ fSelectedLocation = lineData.location;
+ refreshLineBackgrounds();
+ sendSelectionEvent(lineData);
+ }
+ }
+ }
+ storeCaretPosition(event.time, event.caretOffset);
+ if (fHoldSelection == 0) {
+ Point caret = fStyledText.getLocationAtOffset(fStyledText.getCaretOffset());
+ Point origin = fScrolledComposite.getOrigin();
+ if (origin.x > caret.x) {
+ origin.x = caret.x;
+ } else if (caret.x - origin.x > fScrolledComposite.getSize().x) {
+ origin.x = caret.x - fScrolledComposite.getSize().x + 1;
+ }
+ fScrolledComposite.setOrigin(origin);
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // MouseMoveListener (StyledText)
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void mouseMove(MouseEvent e) {
+ fCursorYCoordinate = e.y;
+ if (e.y < 0 || e.y > fStyledText.getSize().y) {
+ if (fHighlightedRank != Long.MIN_VALUE) {
+ fHighlightedRank = Long.MIN_VALUE;
+ refreshLineBackgrounds();
+ }
+ return;
+ }
+ int offset = fStyledText.getOffsetAtLocation(new Point(0, e.y));
+ int line = fStyledText.getLineAtOffset(offset);
+ if (line < fLines.size() - fTopLineIndex) {
+ LineData lineData = fLines.get(fTopLineIndex + line);
+ if (fHighlightedRank != lineData.rank) {
+ fHighlightedRank = lineData.rank;
+ refreshLineBackgrounds();
+ }
+ } else {
+ if (fHighlightedRank != Long.MIN_VALUE) {
+ fHighlightedRank = Long.MIN_VALUE;
+ refreshLineBackgrounds();
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // MouseTrackListener (StyledText)
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void mouseExit(MouseEvent e) {
+ fCursorYCoordinate = -1;
+ if (fHighlightedRank != Long.MIN_VALUE) {
+ fHighlightedRank = Long.MIN_VALUE;
+ refreshLineBackgrounds();
+ }
+ }
+
+ @Override
+ public void mouseEnter(MouseEvent e) {
+ fCursorYCoordinate = e.y;
+ }
+
+ @Override
+ public void mouseHover(MouseEvent e) {
+ }
+
+ // ------------------------------------------------------------------------
+ // MouseWheelListener (StyledText)
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void mouseScrolled(MouseEvent e) {
+ if (fLines.size() == 0) {
+ return;
+ }
+ fHoldSelection++;
+ fTopLineIndex -= e.count;
+ loadLineData();
+ updateTextArea();
+ fHoldSelection = 0;
+ //fSlider.setSelection((int) (SLIDER_MAX * ((double) fLines.get(fTopLineIndex).rank / fTrace.getNbEvents())));
+ updateHighlightedRank();
+ fSlider.setSelection((int) (SLIDER_MAX * fTrace.getLocationRatio(fLines.get(fTopLineIndex).location)));
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;\r
-\r
-import java.util.EventListener;\r
-\r
-/**\r
- * A listener which is notified when a timegraph changes its visible time range.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public interface ITimeGraphRangeListener extends EventListener {\r
-\r
- /**\r
- * Notifies that the timegraph range has changed.\r
- *\r
- * @param event event object describing details\r
- */\r
- public void timeRangeUpdated(TimeGraphRangeUpdateEvent event);\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;
+
+import java.util.EventListener;
+
+/**
+ * A listener which is notified when a timegraph changes its visible time range.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public interface ITimeGraphRangeListener extends EventListener {
+
+ /**
+ * Notifies that the timegraph range has changed.
+ *
+ * @param event event object describing details
+ */
+ public void timeRangeUpdated(TimeGraphRangeUpdateEvent event);
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;\r
-\r
-import java.util.EventListener;\r
-\r
-/**\r
- * A listener which is notified when a timegraph changes its selected time.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public interface ITimeGraphSelectionListener extends EventListener {\r
-\r
- /**\r
- * Notifies that the timegraph selected entry has changed.\r
- *\r
- * @param event event object describing details\r
- */\r
- public void selectionChanged(TimeGraphSelectionEvent event);\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;
+
+import java.util.EventListener;
+
+/**
+ * A listener which is notified when a timegraph changes its selected time.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public interface ITimeGraphSelectionListener extends EventListener {
+
+ /**
+ * Notifies that the timegraph selected entry has changed.
+ *
+ * @param event event object describing details
+ */
+ public void selectionChanged(TimeGraphSelectionEvent event);
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;\r
-\r
-import java.util.EventListener;\r
-\r
-/**\r
- * A listener which is notified when a timegraph changes its selected time.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public interface ITimeGraphTimeListener extends EventListener {\r
-\r
- /**\r
- * Notifies that the timegraph selected time has changed.\r
- *\r
- * @param event event object describing details\r
- */\r
- public void timeSelected(TimeGraphTimeEvent event);\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;
+
+import java.util.EventListener;
+
+/**
+ * A listener which is notified when a timegraph changes its selected time.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public interface ITimeGraphTimeListener extends EventListener {
+
+ /**
+ * Notifies that the timegraph selected time has changed.
+ *
+ * @param event event object describing details
+ */
+ public void timeSelected(TimeGraphTimeEvent event);
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;\r
-\r
-/**\r
- * A listener which is notified when a timegraph expands or collapses an entry.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public interface ITimeGraphTreeListener {\r
-\r
- /**\r
- * Notifies that an entry in the timegraph has been collapsed.\r
- *\r
- * @param event event object describing details\r
- */\r
- public void treeCollapsed(TimeGraphTreeExpansionEvent event);\r
-\r
- /**\r
- * Notifies that an entry in the timegraph has been expanded.\r
- *\r
- * @param event event object describing details\r
- */\r
- public void treeExpanded(TimeGraphTreeExpansionEvent event);\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;
+
+/**
+ * A listener which is notified when a timegraph expands or collapses an entry.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public interface ITimeGraphTreeListener {
+
+ /**
+ * Notifies that an entry in the timegraph has been collapsed.
+ *
+ * @param event event object describing details
+ */
+ public void treeCollapsed(TimeGraphTreeExpansionEvent event);
+
+ /**
+ * Notifies that an entry in the timegraph has been expanded.
+ *
+ * @param event event object describing details
+ */
+ public void treeExpanded(TimeGraphTreeExpansionEvent event);
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;\r
-\r
-import java.util.EventObject;\r
-\r
-/**\r
- * Notifier for the time graph that the time range has been updated.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TimeGraphRangeUpdateEvent extends EventObject {\r
-\r
- /**\r
- * Default serial version UID for this class.\r
- * @since 1.0\r
- */\r
- private static final long serialVersionUID = 1L;\r
-\r
- /**\r
- * The start time.\r
- */\r
- private final long fStartTime;\r
-\r
- /**\r
- * The end time.\r
- */\r
- private final long fEndTime;\r
-\r
- /**\r
- * Standard constructor\r
- *\r
- * @param source\r
- * The source of this event\r
- * @param startTime\r
- * The start time\r
- * @param endTime\r
- * The end time\r
- */\r
- public TimeGraphRangeUpdateEvent(Object source, long startTime, long endTime) {\r
- super(source);\r
- fStartTime = startTime;\r
- fEndTime = endTime;\r
- }\r
-\r
- /**\r
- * @return the start time\r
- */\r
- public long getStartTime() {\r
- return fStartTime;\r
- }\r
-\r
- /**\r
- * @return the end time\r
- */\r
- public long getEndTime() {\r
- return fEndTime;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;
+
+import java.util.EventObject;
+
+/**
+ * Notifier for the time graph that the time range has been updated.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TimeGraphRangeUpdateEvent extends EventObject {
+
+ /**
+ * Default serial version UID for this class.
+ * @since 1.0
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The start time.
+ */
+ private final long fStartTime;
+
+ /**
+ * The end time.
+ */
+ private final long fEndTime;
+
+ /**
+ * Standard constructor
+ *
+ * @param source
+ * The source of this event
+ * @param startTime
+ * The start time
+ * @param endTime
+ * The end time
+ */
+ public TimeGraphRangeUpdateEvent(Object source, long startTime, long endTime) {
+ super(source);
+ fStartTime = startTime;
+ fEndTime = endTime;
+ }
+
+ /**
+ * @return the start time
+ */
+ public long getStartTime() {
+ return fStartTime;
+ }
+
+ /**
+ * @return the end time
+ */
+ public long getEndTime() {
+ return fEndTime;
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;\r
-\r
-import java.util.EventObject;\r
-\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-\r
-/**\r
- * Notifier for the time graph that an object in the views has been selected.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TimeGraphSelectionEvent extends EventObject {\r
-\r
- /**\r
- * Default serial version UID for this class.\r
- * @since 1.0\r
- */\r
- private static final long serialVersionUID = 1L;\r
-\r
- /**\r
- * The selected entry.\r
- */\r
- private final ITimeGraphEntry fSelection;\r
-\r
- /**\r
- * Standard constructor\r
- *\r
- * @param source\r
- * The source of this event\r
- * @param selection\r
- * The entry that was selected\r
- */\r
- public TimeGraphSelectionEvent(Object source, ITimeGraphEntry selection) {\r
- super(source);\r
- fSelection = selection;\r
- }\r
-\r
- /**\r
- * @return the selected entry or null if the selection is empty.\r
- */\r
- public ITimeGraphEntry getSelection() {\r
- return fSelection;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;
+
+import java.util.EventObject;
+
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+
+/**
+ * Notifier for the time graph that an object in the views has been selected.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TimeGraphSelectionEvent extends EventObject {
+
+ /**
+ * Default serial version UID for this class.
+ * @since 1.0
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The selected entry.
+ */
+ private final ITimeGraphEntry fSelection;
+
+ /**
+ * Standard constructor
+ *
+ * @param source
+ * The source of this event
+ * @param selection
+ * The entry that was selected
+ */
+ public TimeGraphSelectionEvent(Object source, ITimeGraphEntry selection) {
+ super(source);
+ fSelection = selection;
+ }
+
+ /**
+ * @return the selected entry or null if the selection is empty.
+ */
+ public ITimeGraphEntry getSelection() {
+ return fSelection;
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;\r
-\r
-import java.util.EventObject;\r
-\r
-/**\r
- * Event for the time graph view\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TimeGraphTimeEvent extends EventObject {\r
-\r
- /**\r
- * Default serial version UID for this class.\r
- * @since 1.0\r
- */\r
- private static final long serialVersionUID = 1L;\r
-\r
- /**\r
- * The selected time.\r
- */\r
- private final long fTime;\r
-\r
- /**\r
- * Standard constructor\r
- *\r
- * @param source\r
- * The source of this event\r
- * @param time\r
- * The time that was requested\r
- */\r
- public TimeGraphTimeEvent(Object source, long time) {\r
- super(source);\r
- fTime = time;\r
- }\r
-\r
- /**\r
- * @return the selected time\r
- */\r
- public long getTime() {\r
- return fTime;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;
+
+import java.util.EventObject;
+
+/**
+ * Event for the time graph view
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TimeGraphTimeEvent extends EventObject {
+
+ /**
+ * Default serial version UID for this class.
+ * @since 1.0
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The selected time.
+ */
+ private final long fTime;
+
+ /**
+ * Standard constructor
+ *
+ * @param source
+ * The source of this event
+ * @param time
+ * The time that was requested
+ */
+ public TimeGraphTimeEvent(Object source, long time) {
+ super(source);
+ fTime = time;
+ }
+
+ /**
+ * @return the selected time
+ */
+ public long getTime() {
+ return fTime;
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;\r
-\r
-import java.util.EventObject;\r
-\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-\r
-/**\r
- * Notifier for the time graph view that a tree has been expanded.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TimeGraphTreeExpansionEvent extends EventObject {\r
-\r
- /**\r
- * Default serial version UID for this class.\r
- * @since 1.0\r
- */\r
- private static final long serialVersionUID = 1L;\r
-\r
- /**\r
- * The entry that was expanded or collapsed.\r
- */\r
- private final ITimeGraphEntry fEntry;\r
-\r
- /**\r
- * Creates a new event for the given source and entry.\r
- *\r
- * @param source the tree viewer\r
- * @param entry the entry\r
- */\r
- public TimeGraphTreeExpansionEvent(Object source, ITimeGraphEntry entry) {\r
- super(source);\r
- fEntry = entry;\r
- }\r
-\r
- /**\r
- * Returns the entry that got expanded or collapsed.\r
- *\r
- * @return the entry\r
- */\r
- public ITimeGraphEntry getEntry() {\r
- return fEntry;\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;
+
+import java.util.EventObject;
+
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+
+/**
+ * Notifier for the time graph view that a tree has been expanded.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TimeGraphTreeExpansionEvent extends EventObject {
+
+ /**
+ * Default serial version UID for this class.
+ * @since 1.0
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The entry that was expanded or collapsed.
+ */
+ private final ITimeGraphEntry fEntry;
+
+ /**
+ * Creates a new event for the given source and entry.
+ *
+ * @param source the tree viewer
+ * @param entry the entry
+ */
+ public TimeGraphTreeExpansionEvent(Object source, ITimeGraphEntry entry) {
+ super(source);
+ fEntry = entry;
+ }
+
+ /**
+ * Returns the entry that got expanded or collapsed.
+ *
+ * @return the entry
+ */
+ public ITimeGraphEntry getEntry() {
+ return fEntry;
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2009, 2012 Ericsson.\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Alvaro Sanchez-Leon - Initial API and implementation\r
- * Patrick Tasse - Refactoring\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs;\r
-\r
-import org.eclipse.jface.dialogs.IDialogConstants;\r
-import org.eclipse.jface.dialogs.TitleAreaDialog;\r
-import org.eclipse.jface.resource.JFaceResources;\r
-import org.eclipse.jface.resource.LocalResourceManager;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.graphics.Color;\r
-import org.eclipse.swt.graphics.GC;\r
-import org.eclipse.swt.graphics.RGB;\r
-import org.eclipse.swt.graphics.Rectangle;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Canvas;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.Event;\r
-import org.eclipse.swt.widgets.Group;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Listener;\r
-import org.eclipse.swt.widgets.Shell;\r
-\r
-/**\r
- * Legend for the colors used in the time graph view\r
- *\r
- * @version 1.0\r
- * @author Alvaro Sanchez-Leon\r
- * @author Patrick Tasse\r
- */\r
-public class TimeGraphLegend extends TitleAreaDialog {\r
-\r
- private final ITimeGraphPresentationProvider provider;\r
- private final LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources());\r
-\r
- /**\r
- * Open the time graph legend window\r
- *\r
- * @param parent\r
- * The parent shell\r
- * @param provider\r
- * The presentation provider\r
- */\r
- public static void open(Shell parent, ITimeGraphPresentationProvider provider) {\r
- (new TimeGraphLegend(parent, provider)).open();\r
- }\r
-\r
- /**\r
- * Standard constructor\r
- *\r
- * @param parent\r
- * The parent shell\r
- * @param provider\r
- * The presentation provider\r
- */\r
- public TimeGraphLegend(Shell parent, ITimeGraphPresentationProvider provider) {\r
- super(parent);\r
- this.provider = provider;\r
- this.setShellStyle(getShellStyle());\r
- }\r
-\r
- @Override\r
- protected Control createDialogArea(Composite parent) {\r
- Composite dlgArea = (Composite) super.createDialogArea(parent);\r
- Composite composite = new Composite(dlgArea, SWT.NONE);\r
-\r
- GridLayout layout = new GridLayout();\r
- layout.numColumns = 2;\r
- composite.setLayout(layout);\r
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);\r
- composite.setLayoutData(gd);\r
-\r
- createStatesGroup(composite);\r
-\r
- setTitle(Messages.TmfTimeLegend_LEGEND);\r
- setDialogHelpAvailable(false);\r
- setHelpAvailable(false);\r
-\r
- return composite;\r
- }\r
-\r
- private void createStatesGroup(Composite composite) {\r
- Group gs = new Group(composite, SWT.NONE);\r
- String stateTypeName = provider.getStateTypeName();\r
- StringBuffer buffer = new StringBuffer();\r
- if (!stateTypeName.isEmpty()) {\r
- buffer.append(stateTypeName);\r
- buffer.append(" "); //$NON-NLS-1$\r
- }\r
- buffer.append(Messages.TmfTimeLegend_StateTypeName);\r
- gs.setText(buffer.toString());\r
-\r
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);\r
- gs.setLayoutData(gd);\r
-\r
- GridLayout layout = new GridLayout();\r
- layout.numColumns = 2;\r
- layout.marginWidth = 20;\r
- layout.marginBottom = 10;\r
- gs.setLayout(layout);\r
-\r
- // Go through all the defined pairs of state color and state name and display them.\r
- StateItem[] stateItems = provider.getStateTable();\r
- for (int i = 0; i < stateItems.length; i++) {\r
- //Get the color related to the index\r
- RGB rgb = stateItems[i].getStateColor();\r
-\r
- //Get the given name, provided by the interface to the application\r
- String stateName = stateItems[i].getStateString();\r
-\r
- // draw color with name\r
- Bar bar = new Bar(gs, rgb);\r
- gd = new GridData();\r
- gd.widthHint = 40;\r
- gd.heightHint = 20;\r
- gd.verticalIndent = 8;\r
- bar.setLayoutData(gd);\r
- Label name = new Label(gs, SWT.NONE);\r
- name.setText(stateName);\r
- gd = new GridData();\r
- gd.horizontalIndent = 10;\r
- gd.verticalIndent = 8;\r
- name.setLayoutData(gd);\r
- }\r
- }\r
-\r
- @Override\r
- protected void configureShell(Shell shell) {\r
- super.configureShell(shell);\r
- shell.setText(Messages.TmfTimeLegend_TRACE_STATES_TITLE);\r
- }\r
-\r
- @Override\r
- protected void createButtonsForButtonBar(Composite parent) {\r
- createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,\r
- true);\r
- }\r
-\r
- class Bar extends Canvas {\r
- private final Color color;\r
-\r
- public Bar(Composite parent, RGB rgb) {\r
- super(parent, SWT.NONE);\r
-\r
- color = fResourceManager.createColor(rgb);\r
- addListener(SWT.Paint, new Listener() {\r
- @Override\r
- public void handleEvent(Event event) {\r
- draw(event.gc);\r
- }\r
- });\r
- }\r
-\r
- private void draw(GC gc) {\r
- Rectangle r = getClientArea();\r
- gc.setBackground(color);\r
- gc.fillRectangle(r);\r
- gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));\r
- gc.drawRectangle(0, 0, r.width - 1, r.height - 1);\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- super.dispose();\r
- color.dispose();\r
- }\r
-\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2009, 2012 Ericsson.
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alvaro Sanchez-Leon - Initial API and implementation
+ * Patrick Tasse - Refactoring
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Legend for the colors used in the time graph view
+ *
+ * @version 1.0
+ * @author Alvaro Sanchez-Leon
+ * @author Patrick Tasse
+ */
+public class TimeGraphLegend extends TitleAreaDialog {
+
+ private final ITimeGraphPresentationProvider provider;
+ private final LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources());
+
+ /**
+ * Open the time graph legend window
+ *
+ * @param parent
+ * The parent shell
+ * @param provider
+ * The presentation provider
+ */
+ public static void open(Shell parent, ITimeGraphPresentationProvider provider) {
+ (new TimeGraphLegend(parent, provider)).open();
+ }
+
+ /**
+ * Standard constructor
+ *
+ * @param parent
+ * The parent shell
+ * @param provider
+ * The presentation provider
+ */
+ public TimeGraphLegend(Shell parent, ITimeGraphPresentationProvider provider) {
+ super(parent);
+ this.provider = provider;
+ this.setShellStyle(getShellStyle());
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite dlgArea = (Composite) super.createDialogArea(parent);
+ Composite composite = new Composite(dlgArea, SWT.NONE);
+
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ composite.setLayout(layout);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ composite.setLayoutData(gd);
+
+ createStatesGroup(composite);
+
+ setTitle(Messages.TmfTimeLegend_LEGEND);
+ setDialogHelpAvailable(false);
+ setHelpAvailable(false);
+
+ return composite;
+ }
+
+ private void createStatesGroup(Composite composite) {
+ Group gs = new Group(composite, SWT.NONE);
+ String stateTypeName = provider.getStateTypeName();
+ StringBuffer buffer = new StringBuffer();
+ if (!stateTypeName.isEmpty()) {
+ buffer.append(stateTypeName);
+ buffer.append(" "); //$NON-NLS-1$
+ }
+ buffer.append(Messages.TmfTimeLegend_StateTypeName);
+ gs.setText(buffer.toString());
+
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gs.setLayoutData(gd);
+
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginWidth = 20;
+ layout.marginBottom = 10;
+ gs.setLayout(layout);
+
+ // Go through all the defined pairs of state color and state name and display them.
+ StateItem[] stateItems = provider.getStateTable();
+ for (int i = 0; i < stateItems.length; i++) {
+ //Get the color related to the index
+ RGB rgb = stateItems[i].getStateColor();
+
+ //Get the given name, provided by the interface to the application
+ String stateName = stateItems[i].getStateString();
+
+ // draw color with name
+ Bar bar = new Bar(gs, rgb);
+ gd = new GridData();
+ gd.widthHint = 40;
+ gd.heightHint = 20;
+ gd.verticalIndent = 8;
+ bar.setLayoutData(gd);
+ Label name = new Label(gs, SWT.NONE);
+ name.setText(stateName);
+ gd = new GridData();
+ gd.horizontalIndent = 10;
+ gd.verticalIndent = 8;
+ name.setLayoutData(gd);
+ }
+ }
+
+ @Override
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setText(Messages.TmfTimeLegend_TRACE_STATES_TITLE);
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
+ true);
+ }
+
+ class Bar extends Canvas {
+ private final Color color;
+
+ public Bar(Composite parent, RGB rgb) {
+ super(parent, SWT.NONE);
+
+ color = fResourceManager.createColor(rgb);
+ addListener(SWT.Paint, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ draw(event.gc);
+ }
+ });
+ }
+
+ private void draw(GC gc) {
+ Rectangle r = getClientArea();
+ gc.setBackground(color);
+ gc.fillRectangle(r);
+ gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
+ gc.drawRectangle(0, 0, r.width - 1, r.height - 1);
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ color.dispose();
+ }
+
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2009, 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Alvaro Sanchez-Leon - Initial API and implementation\r
- * Patrick Tasse - Refactoring\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model;\r
-\r
-/**\r
- * Interface for time events, for use in the timegraph view\r
- *\r
- * @version 1.0\r
- * @author Alvaro Sanchez-Leon\r
- * @author Patrick Tasse\r
- */\r
-public interface ITimeEvent {\r
-\r
- /**\r
- * Get the entry matching this time event.\r
- *\r
- * @return The time graph entry\r
- */\r
- public ITimeGraphEntry getEntry();\r
-\r
- /**\r
- * Get the timestamp of this event.\r
- *\r
- * @return The event's time\r
- */\r
- public long getTime();\r
-\r
- /**\r
- * @return\r
- * <list>\r
- * <li>-1: Considers duration to be from current event till the next</li>\r
- * <li>0: Duration is not relevant e.g. a Burst / no state associated</li>\r
- * <li>>0: Valid duration value specified</li>\r
- * </list>\r
- * <p>\r
- */\r
- public long getDuration();\r
-\r
+/*******************************************************************************
+ * Copyright (c) 2009, 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alvaro Sanchez-Leon - Initial API and implementation
+ * Patrick Tasse - Refactoring
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model;
+
+/**
+ * Interface for time events, for use in the timegraph view
+ *
+ * @version 1.0
+ * @author Alvaro Sanchez-Leon
+ * @author Patrick Tasse
+ */
+public interface ITimeEvent {
+
+ /**
+ * Get the entry matching this time event.
+ *
+ * @return The time graph entry
+ */
+ public ITimeGraphEntry getEntry();
+
+ /**
+ * Get the timestamp of this event.
+ *
+ * @return The event's time
+ */
+ public long getTime();
+
+ /**
+ * @return
+ * <list>
+ * <li>-1: Considers duration to be from current event till the next</li>
+ * <li>0: Duration is not relevant e.g. a Burst / no state associated</li>
+ * <li>>0: Valid duration value specified</li>
+ * </list>
+ * <p>
+ */
+ public long getDuration();
+
}
\ No newline at end of file
-/*******************************************************************************\r
- * Copyright (c) 2009, 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Alvaro Sanchez-Leon - Initial API and implementation\r
- * Patrick Tasse - Refactoring\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model;\r
-\r
-import java.util.Iterator;\r
-\r
-/**\r
- * Interface for an entry (row) in the time graph view\r
- *\r
- * @version 1.0\r
- * @author Alvaro Sanchez-Leon\r
- * @author Patrick Tasse\r
- */\r
-public interface ITimeGraphEntry {\r
-\r
- /**\r
- * Returns the parent of this entry, or <code>null</code> if it has none.\r
- *\r
- * @return the parent element, or <code>null</code> if it has none\r
- */\r
- public ITimeGraphEntry getParent();\r
-\r
- /**\r
- * Returns whether this entry has children.\r
- *\r
- * @return <code>true</code> if the given element has children,\r
- * and <code>false</code> if it has no children\r
- */\r
- public boolean hasChildren();\r
-\r
- /**\r
- * Returns the child elements of this entry.\r
- *\r
- * @return an array of child elements\r
- */\r
- public ITimeGraphEntry[] getChildren();\r
-\r
- /**\r
- * Returns the name of this entry.\r
- *\r
- * @return the entry name\r
- */\r
- public String getName();\r
-\r
- /**\r
- * Returns the start time of this entry in nanoseconds.\r
- *\r
- * @return the start time\r
- */\r
- public long getStartTime();\r
-\r
- /**\r
- * Returns the end time of this entry in nanoseconds.\r
- *\r
- * @return the end time\r
- */\r
- public long getEndTime();\r
-\r
- /**\r
- * Returns whether this entry has time events.\r
- * If true, the time events iterator should not be null.\r
- *\r
- * @return true if the entry has time events\r
- *\r
- * @see #getTimeEventsIterator\r
- * @see #getTimeEventsIterator(long, long, long)\r
- */\r
- public boolean hasTimeEvents();\r
-\r
- /**\r
- * Get an iterator which returns all time events.\r
- *\r
- * @return the iterator\r
- */\r
- public <T extends ITimeEvent> Iterator<T> getTimeEventsIterator();\r
-\r
- /**\r
- * Get an iterator which only returns events that fall within the start time and the stop time.\r
- * The visible duration is the event duration below which further detail is not discernible.\r
- * If no such iterator is implemented, provide a basic iterator which returns all events.\r
- *\r
- * @param startTime start time in nanoseconds\r
- * @param stopTime stop time in nanoseconds\r
- * @param visibleDuration duration of one pixel in nanoseconds\r
- *\r
- * @return the iterator\r
- */\r
- public <T extends ITimeEvent> Iterator<T> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration);\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2009, 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alvaro Sanchez-Leon - Initial API and implementation
+ * Patrick Tasse - Refactoring
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model;
+
+import java.util.Iterator;
+
+/**
+ * Interface for an entry (row) in the time graph view
+ *
+ * @version 1.0
+ * @author Alvaro Sanchez-Leon
+ * @author Patrick Tasse
+ */
+public interface ITimeGraphEntry {
+
+ /**
+ * Returns the parent of this entry, or <code>null</code> if it has none.
+ *
+ * @return the parent element, or <code>null</code> if it has none
+ */
+ public ITimeGraphEntry getParent();
+
+ /**
+ * Returns whether this entry has children.
+ *
+ * @return <code>true</code> if the given element has children,
+ * and <code>false</code> if it has no children
+ */
+ public boolean hasChildren();
+
+ /**
+ * Returns the child elements of this entry.
+ *
+ * @return an array of child elements
+ */
+ public ITimeGraphEntry[] getChildren();
+
+ /**
+ * Returns the name of this entry.
+ *
+ * @return the entry name
+ */
+ public String getName();
+
+ /**
+ * Returns the start time of this entry in nanoseconds.
+ *
+ * @return the start time
+ */
+ public long getStartTime();
+
+ /**
+ * Returns the end time of this entry in nanoseconds.
+ *
+ * @return the end time
+ */
+ public long getEndTime();
+
+ /**
+ * Returns whether this entry has time events.
+ * If true, the time events iterator should not be null.
+ *
+ * @return true if the entry has time events
+ *
+ * @see #getTimeEventsIterator
+ * @see #getTimeEventsIterator(long, long, long)
+ */
+ public boolean hasTimeEvents();
+
+ /**
+ * Get an iterator which returns all time events.
+ *
+ * @return the iterator
+ */
+ public <T extends ITimeEvent> Iterator<T> getTimeEventsIterator();
+
+ /**
+ * Get an iterator which only returns events that fall within the start time and the stop time.
+ * The visible duration is the event duration below which further detail is not discernible.
+ * If no such iterator is implemented, provide a basic iterator which returns all events.
+ *
+ * @param startTime start time in nanoseconds
+ * @param stopTime stop time in nanoseconds
+ * @param visibleDuration duration of one pixel in nanoseconds
+ *
+ * @return the iterator
+ */
+ public <T extends ITimeEvent> Iterator<T> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration);
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model;\r
-\r
-/**\r
- * Generic TimeEvent implementation\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TimeEvent implements ITimeEvent {\r
- protected ITimeGraphEntry fEntry;\r
- protected long fTime;\r
- protected long fDuration;\r
-\r
- /**\r
- * Standard constructor\r
- *\r
- * @param entry\r
- * The entry matching this event\r
- * @param time\r
- * The timestamp of this event\r
- * @param duration\r
- * The duration of the event\r
- */\r
- public TimeEvent(ITimeGraphEntry entry, long time, long duration) {\r
- fEntry = entry;\r
- fTime = time;\r
- fDuration = duration;\r
- }\r
-\r
- @Override\r
- public ITimeGraphEntry getEntry() {\r
- return fEntry;\r
- }\r
-\r
- @Override\r
- public long getTime() {\r
- return fTime;\r
- }\r
-\r
- @Override\r
- public long getDuration() {\r
- return fDuration;\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model;
+
+/**
+ * Generic TimeEvent implementation
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TimeEvent implements ITimeEvent {
+ protected ITimeGraphEntry fEntry;
+ protected long fTime;
+ protected long fDuration;
+
+ /**
+ * Standard constructor
+ *
+ * @param entry
+ * The entry matching this event
+ * @param time
+ * The timestamp of this event
+ * @param duration
+ * The duration of the event
+ */
+ public TimeEvent(ITimeGraphEntry entry, long time, long duration) {
+ fEntry = entry;
+ fTime = time;
+ fDuration = duration;
+ }
+
+ @Override
+ public ITimeGraphEntry getEntry() {
+ return fEntry;
+ }
+
+ @Override
+ public long getTime() {
+ return fTime;
+ }
+
+ @Override
+ public long getDuration() {
+ return fDuration;
+ }
+}
-/*****************************************************************************\r
- * Copyright (c) 2007 Intel Corporation, 2010, 2012 Ericsson.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Intel Corporation - Initial API and implementation\r
- * Ruslan A. Scherbakov, Intel - Initial API and implementation\r
- * Alvaro Sanchez-Leon - Updated for TMF\r
- * Patrick Tasse - Refactoring\r
- *\r
- *****************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;\r
-\r
-/**\r
- * Time data provider interface, for use in the timegraph widget.\r
- *\r
- * @version 1.0\r
- * @author Alvaro Sanchez-Leon\r
- * @author Patrick Tasse\r
- */\r
-public interface ITimeDataProvider {\r
-\r
- /**\r
- * @return The selected time\r
- */\r
- long getSelectedTime();\r
-\r
- /**\r
- * @return The beginning time\r
- */\r
- long getBeginTime();\r
-\r
- /**\r
- * @return The end time\r
- */\r
- long getEndTime();\r
-\r
- /**\r
- * @return The minimum time\r
- */\r
- long getMinTime();\r
-\r
- /**\r
- * @return The maximum time\r
- */\r
- long getMaxTime();\r
-\r
- /**\r
- * @return The start time of the current selection window\r
- */\r
- long getTime0();\r
-\r
- /**\r
- * @return The end time of the current selection window\r
- */\r
- long getTime1();\r
-\r
- /**\r
- * @return The minimal time interval\r
- */\r
- long getMinTimeInterval();\r
-\r
- /**\r
- * Updates the time range and notify registered listeners\r
- *\r
- * @param time0\r
- * @param time1\r
- */\r
- void setStartFinishTimeNotify(long time0, long time1);\r
-\r
- /**\r
- * Update the time range but do not trigger event notification\r
- *\r
- * @param time0\r
- * @param time1\r
- */\r
- void setStartFinishTime(long time0, long time1);\r
-\r
- /**\r
- * Notify registered listeners without updating the time range\r
- */\r
- void notifyStartFinishTime();\r
-\r
- /**\r
- * Updates the selected time, adjusts the time range if necessary and\r
- * notifies any registered listeners about the new selected time and new\r
- * range (if necessary)\r
- *\r
- * @param time\r
- * A Time to set\r
- * @param ensureVisible\r
- * Ensure visibility of new time (will adjust time range if\r
- * necessary)\r
- */\r
- public void setSelectedTimeNotify(long time, boolean ensureVisible);\r
-\r
- /**\r
- * Updates the selected time and adjusts the time range if necessary without\r
- * notifying registered listeners.\r
- *\r
- * @param time\r
- * A Time to set\r
- * @param ensureVisible\r
- * Ensure visibility of new time (will adjust time range if\r
- * necessary)\r
- */\r
- public void setSelectedTime(long time, boolean ensureVisible);\r
-\r
- /**\r
- * Reset the start and end times\r
- */\r
- void resetStartFinishTime();\r
-\r
- /**\r
- * @return The names' width\r
- */\r
- int getNameSpace();\r
-\r
- /**\r
- * Set the names' width\r
- *\r
- * @param width\r
- */\r
- void setNameSpace(int width);\r
-\r
- /**\r
- * @return The width for timestamps\r
- */\r
- int getTimeSpace();\r
-\r
- /**\r
- * @return If the calendar format is absolute (true) or relative (false)\r
- */\r
- boolean isCalendarFormat();\r
-}\r
+/*****************************************************************************
+ * Copyright (c) 2007 Intel Corporation, 2010, 2012 Ericsson.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ * Ruslan A. Scherbakov, Intel - Initial API and implementation
+ * Alvaro Sanchez-Leon - Updated for TMF
+ * Patrick Tasse - Refactoring
+ *
+ *****************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;
+
+/**
+ * Time data provider interface, for use in the timegraph widget.
+ *
+ * @version 1.0
+ * @author Alvaro Sanchez-Leon
+ * @author Patrick Tasse
+ */
+public interface ITimeDataProvider {
+
+ /**
+ * @return The selected time
+ */
+ long getSelectedTime();
+
+ /**
+ * @return The beginning time
+ */
+ long getBeginTime();
+
+ /**
+ * @return The end time
+ */
+ long getEndTime();
+
+ /**
+ * @return The minimum time
+ */
+ long getMinTime();
+
+ /**
+ * @return The maximum time
+ */
+ long getMaxTime();
+
+ /**
+ * @return The start time of the current selection window
+ */
+ long getTime0();
+
+ /**
+ * @return The end time of the current selection window
+ */
+ long getTime1();
+
+ /**
+ * @return The minimal time interval
+ */
+ long getMinTimeInterval();
+
+ /**
+ * Updates the time range and notify registered listeners
+ *
+ * @param time0
+ * @param time1
+ */
+ void setStartFinishTimeNotify(long time0, long time1);
+
+ /**
+ * Update the time range but do not trigger event notification
+ *
+ * @param time0
+ * @param time1
+ */
+ void setStartFinishTime(long time0, long time1);
+
+ /**
+ * Notify registered listeners without updating the time range
+ */
+ void notifyStartFinishTime();
+
+ /**
+ * Updates the selected time, adjusts the time range if necessary and
+ * notifies any registered listeners about the new selected time and new
+ * range (if necessary)
+ *
+ * @param time
+ * A Time to set
+ * @param ensureVisible
+ * Ensure visibility of new time (will adjust time range if
+ * necessary)
+ */
+ public void setSelectedTimeNotify(long time, boolean ensureVisible);
+
+ /**
+ * Updates the selected time and adjusts the time range if necessary without
+ * notifying registered listeners.
+ *
+ * @param time
+ * A Time to set
+ * @param ensureVisible
+ * Ensure visibility of new time (will adjust time range if
+ * necessary)
+ */
+ public void setSelectedTime(long time, boolean ensureVisible);
+
+ /**
+ * Reset the start and end times
+ */
+ void resetStartFinishTime();
+
+ /**
+ * @return The names' width
+ */
+ int getNameSpace();
+
+ /**
+ * Set the names' width
+ *
+ * @param width
+ */
+ void setNameSpace(int width);
+
+ /**
+ * @return The width for timestamps
+ */
+ int getTimeSpace();
+
+ /**
+ * @return If the calendar format is absolute (true) or relative (false)
+ */
+ boolean isCalendarFormat();
+}
-/*****************************************************************************\r
- * Copyright (c) 2007 Intel Corporation, 2009, 2012 Ericsson.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Intel Corporation - Initial API and implementation\r
- * Ruslan A. Scherbakov, Intel - Initial API and implementation\r
- * Alvaro Sanchez-Leon - Updated for TMF\r
- * Patrick Tasse - Refactoring\r
- *\r
- *****************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;\r
-\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.PaintEvent;\r
-import org.eclipse.swt.events.PaintListener;\r
-import org.eclipse.swt.graphics.Color;\r
-import org.eclipse.swt.graphics.Rectangle;\r
-import org.eclipse.swt.widgets.Canvas;\r
-import org.eclipse.swt.widgets.Composite;\r
-\r
-/**\r
- * Base control abstract class for the time graph widget\r
- *\r
- * @version 1.0\r
- * @author Alvaro Sanchez-Leon\r
- * @author Patrick Tasse\r
- */\r
-public abstract class TimeGraphBaseControl extends Canvas implements PaintListener {\r
-\r
- /** Default left margin size */\r
- static public final int MARGIN = 4;\r
-\r
- /** Default expanded size */\r
- static public final int EXPAND_SIZE = 9; // the [+] or [-] control size\r
-\r
- /** Default size of the right margin */\r
- static public final int RIGHT_MARGIN = 1; // 1 pixels less to make sure end time is visible\r
-\r
- /** Default size for small icons */\r
- static public final int SMALL_ICON_SIZE = 16;\r
-\r
- protected TimeGraphColorScheme _colors;\r
- protected int _fontHeight = 0;\r
-\r
- /**\r
- * Basic constructor. Uses a default style value\r
- *\r
- * @param parent\r
- * The parent composite object\r
- * @param colors\r
- * The color scheme to use\r
- */\r
- public TimeGraphBaseControl(Composite parent, TimeGraphColorScheme colors) {\r
- this(parent, colors, SWT.NO_BACKGROUND | SWT.NO_FOCUS);\r
- }\r
-\r
- /**\r
- * Standard constructor\r
- *\r
- * @param parent\r
- * The parent composite object\r
- * @param colors\r
- * The color scheme to use\r
- * @param style\r
- * The index of the style to use\r
- */\r
- public TimeGraphBaseControl(Composite parent, TimeGraphColorScheme colors, int style) {\r
- super(parent, style);\r
- _colors = colors;\r
- addPaintListener(this);\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- super.dispose();\r
- }\r
-\r
- @Override\r
- public void paintControl(PaintEvent e) {\r
- if (e.widget != this) {\r
- return;\r
- }\r
- _fontHeight = e.gc.getFontMetrics().getHeight();\r
- Rectangle bound = getClientArea();\r
- if (!bound.isEmpty()) {\r
- Color colBackup = e.gc.getBackground();\r
- paint(bound, e);\r
- e.gc.setBackground(colBackup);\r
- }\r
- }\r
-\r
- /**\r
- * Retrieve the current font's height\r
- *\r
- * @return The height\r
- */\r
- public int getFontHeight() {\r
- return _fontHeight;\r
- }\r
-\r
- abstract void paint(Rectangle bound, PaintEvent e);\r
-}\r
+/*****************************************************************************
+ * Copyright (c) 2007 Intel Corporation, 2009, 2012 Ericsson.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ * Ruslan A. Scherbakov, Intel - Initial API and implementation
+ * Alvaro Sanchez-Leon - Updated for TMF
+ * Patrick Tasse - Refactoring
+ *
+ *****************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Base control abstract class for the time graph widget
+ *
+ * @version 1.0
+ * @author Alvaro Sanchez-Leon
+ * @author Patrick Tasse
+ */
+public abstract class TimeGraphBaseControl extends Canvas implements PaintListener {
+
+ /** Default left margin size */
+ static public final int MARGIN = 4;
+
+ /** Default expanded size */
+ static public final int EXPAND_SIZE = 9; // the [+] or [-] control size
+
+ /** Default size of the right margin */
+ static public final int RIGHT_MARGIN = 1; // 1 pixels less to make sure end time is visible
+
+ /** Default size for small icons */
+ static public final int SMALL_ICON_SIZE = 16;
+
+ protected TimeGraphColorScheme _colors;
+ protected int _fontHeight = 0;
+
+ /**
+ * Basic constructor. Uses a default style value
+ *
+ * @param parent
+ * The parent composite object
+ * @param colors
+ * The color scheme to use
+ */
+ public TimeGraphBaseControl(Composite parent, TimeGraphColorScheme colors) {
+ this(parent, colors, SWT.NO_BACKGROUND | SWT.NO_FOCUS);
+ }
+
+ /**
+ * Standard constructor
+ *
+ * @param parent
+ * The parent composite object
+ * @param colors
+ * The color scheme to use
+ * @param style
+ * The index of the style to use
+ */
+ public TimeGraphBaseControl(Composite parent, TimeGraphColorScheme colors, int style) {
+ super(parent, style);
+ _colors = colors;
+ addPaintListener(this);
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ }
+
+ @Override
+ public void paintControl(PaintEvent e) {
+ if (e.widget != this) {
+ return;
+ }
+ _fontHeight = e.gc.getFontMetrics().getHeight();
+ Rectangle bound = getClientArea();
+ if (!bound.isEmpty()) {
+ Color colBackup = e.gc.getBackground();
+ paint(bound, e);
+ e.gc.setBackground(colBackup);
+ }
+ }
+
+ /**
+ * Retrieve the current font's height
+ *
+ * @return The height
+ */
+ public int getFontHeight() {
+ return _fontHeight;
+ }
+
+ abstract void paint(Rectangle bound, PaintEvent e);
+}
-/*****************************************************************************\r
- * Copyright (c) 2008 Intel Corporation, 2009, 2012 Ericsson.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Intel Corporation - Initial API and implementation\r
- * Ruslan A. Scherbakov, Intel - Initial API and implementation\r
- * Alvaro Sanchez-Leon - Updated for TMF\r
- * Patrick Tasse - Refactoring\r
- *\r
- *****************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;\r
-\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.graphics.Color;\r
-\r
-/**\r
- * Color theme used by the timegraph view\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-@SuppressWarnings("javadoc")\r
-public class TimeGraphColorScheme {\r
-\r
- // elements color indices\r
- static public final int BLACK_STATE = 0;\r
- static public final int GREEN_STATE = 1;\r
- static public final int DARK_BLUE_STATE = 2;\r
- static public final int ORANGE_STATE = 3;\r
- static public final int GOLD_STATE = 4;\r
- static public final int RED_STATE = 5;\r
- static public final int GRAY_STATE = 6;\r
- static public final int DARK_GREEN_STATE = 7;\r
- static public final int DARK_YELLOW_STATE = 8;\r
- static public final int MAGENTA3_STATE = 9;\r
- static public final int PURPLE1_STATE = 10;\r
- static public final int PINK1_STATE = 11;\r
- static public final int AQUAMARINE_STATE = 12;\r
- static public final int LIGHT_BLUE_STATE = 13;\r
- static public final int CADET_BLUE_STATE = 14;\r
- static public final int OLIVE_STATE = 15;\r
-\r
- static public final int STATES0 = 0;\r
- static public final int STATES1 = 15;\r
-\r
- // selected state elements color indices\r
- static public final int BLACK_STATE_SEL = 16;\r
- static public final int GREEN_STATE_SEL = 17;\r
- static public final int DARK_BLUE_STATE_SEL = 18;\r
- static public final int ORANGE_STATE_SEL = 19;\r
- static public final int GOLD_STATE_SEL = 20;\r
- static public final int RED_STATE_SEL = 21;\r
- static public final int GRAY_STATE_SEL = 22;\r
- static public final int DARK_GREEN_STATE_SEL = 23;\r
- static public final int DARK_YELLOW_STATE_SEL = 24;\r
- static public final int MAGENTA3_STATE_SEL = 25;\r
- static public final int PURPLE1_STATE_SEL = 26;\r
- static public final int PINK1_STATE_SEL = 27;\r
- static public final int AQUAMARINE_STATE_SEL = 28;\r
- static public final int LIGHT_BLUE_STATE_SEL = 29;\r
- static public final int CADET_BLUE_STATE_SEL = 30;\r
- static public final int OLIVE_STATE_SEL = 31;\r
-\r
- static public final int STATES_SEL0 = 16;\r
- static public final int STATES_SEL1 = 31;\r
-\r
- // colors indices for viewer controls\r
- static public final int BACKGROUND = 32;\r
- static public final int FOREGROUND = 33;\r
- static public final int BACKGROUND_SEL = 34;\r
- static public final int FOREGROUND_SEL = 35;\r
- static public final int BACKGROUND_SEL_NOFOCUS = 36;\r
- static public final int FOREGROUND_SEL_NOFOCUS = 37;\r
- static public final int TOOL_BACKGROUND = 38;\r
- static public final int TOOL_FOREGROUND = 39;\r
-\r
- // misc colors\r
- static public final int FIX_COLOR = 40;\r
- static public final int WHITE = 41;\r
- static public final int GRAY = 42;\r
- static public final int BLACK = 43;\r
- static public final int DARK_GRAY = 44;\r
-\r
- // selected border color indices\r
- static public final int BLACK_BORDER = 45;\r
- static public final int GREEN_BORDER = 46;\r
- static public final int DARK_BLUE_BORDER = 47;\r
- static public final int ORANGE_BORDER = 48;\r
- static public final int GOLD_BORDER = 49;\r
- static public final int RED_BORDER = 50;\r
- static public final int GRAY_BORDER = 51;\r
- static public final int DARK_GREEN_BORDER1 = 52;\r
- static public final int DARK_YELLOW_BORDER1 = 53;\r
- static public final int MAGENTA3_BORDER1 = 54;\r
- static public final int PURPLE1_BORDER1 = 55;\r
- static public final int PINK1_BORDER1 = 56;\r
- static public final int AQUAMARINE_BORDER1 = 57;\r
- static public final int LIGHT_BLUE_BORDER1 = 58;\r
- static public final int CADET_BLUE_STATE_BORDER = 59;\r
- static public final int OLIVE_BORDER2 = 60;\r
-\r
- static public final int STATES_BORDER0 = 45;\r
- static public final int STATES_BORDER1 = 60;\r
-\r
- static public final int MID_LINE = 61;\r
- static public final int RED = 62;\r
- static public final int GREEN = 63;\r
- static public final int BLUE = 64;\r
- static public final int YELLOW = 65;\r
- static public final int CYAN = 66;\r
- static public final int MAGENTA = 67;\r
-\r
- static public final int SELECTED_TIME = 68;\r
- static public final int LEGEND_BACKGROUND = 69;\r
- static public final int LEGEND_FOREGROUND = 70;\r
-\r
- // group items' colors\r
- static public final int GR_BACKGROUND = 71;\r
- static public final int GR_FOREGROUND = 72;\r
- static public final int GR_BACKGROUND_SEL = 73;\r
- static public final int GR_FOREGROUND_SEL = 74;\r
- static public final int GR_BACKGROUND_SEL_NOFOCUS = 75;\r
- static public final int GR_FOREGROUND_SEL_NOFOCUS = 76;\r
-\r
- static public final int LIGHT_LINE = 77;\r
- static public final int BACKGROUND_NAME = 78;\r
- static public final int BACKGROUND_NAME_SEL = 79;\r
- static public final int BACKGROUND_NAME_SEL_NOFOCUS = 80;\r
-\r
- // Interraction's colors\r
- static public final int TI_START_THREAD = BLACK;\r
- static public final int TI_HANDOFF_LOCK = BLUE;\r
- static public final int TI_NOTIFY_ALL = GREEN;\r
- static public final int TI_NOTIFY = GREEN;\r
- static public final int TI_NOTIFY_JOINED = DARK_GRAY;\r
- static public final int TI_INTERRUPT = RED;\r
- static public final int TI_WAIT_EXCEEDED = BLUE;\r
-\r
- static interface IColorProvider {\r
- public Color get();\r
- }\r
-\r
- static class SysCol implements IColorProvider {\r
- int syscol;\r
-\r
- SysCol(int syscol) {\r
- this.syscol = syscol;\r
- }\r
-\r
- @Override\r
- public Color get() {\r
- return Utils.getSysColor(syscol);\r
- }\r
- }\r
-\r
- static class RGB implements IColorProvider {\r
- int r;\r
- int g;\r
- int b;\r
-\r
- RGB(int r, int g, int b) {\r
- this.r = r;\r
- this.g = g;\r
- this.b = b;\r
- }\r
-\r
- @Override\r
- public Color get() {\r
- return new Color(null, r, g, b);\r
- }\r
- }\r
-\r
- static class Mix implements IColorProvider {\r
- IColorProvider cp1;\r
- IColorProvider cp2;\r
- int w1;\r
- int w2;\r
-\r
- Mix(IColorProvider cp1, IColorProvider cp2, int w1, int w2) {\r
- this.cp1 = cp1;\r
- this.cp2 = cp2;\r
- this.w1 = w1;\r
- this.w2 = w2;\r
- }\r
-\r
- Mix(IColorProvider cp1, IColorProvider cp2) {\r
- this.cp1 = cp1;\r
- this.cp2 = cp2;\r
- this.w1 = 1;\r
- this.w2 = 1;\r
- }\r
-\r
- @Override\r
- public Color get() {\r
- Color col1 = cp1.get();\r
- Color col2 = cp2.get();\r
- Color col = Utils.mixColors(col1, col2, w1, w2);\r
- return col;\r
- }\r
- }\r
-\r
- static private final IColorProvider _providersMap[] = {\r
- //\r
- new RGB(100, 100, 100), // UNKNOWN\r
- new RGB(174, 200, 124), // RUNNING\r
- new Mix(new SysCol(SWT.COLOR_BLUE), new SysCol(SWT.COLOR_GRAY), 1, 3), // SLEEPING\r
- new RGB(210, 150, 60), // WAITING\r
- new RGB(242, 225, 168), // BLOCKED\r
- new Mix(new SysCol(SWT.COLOR_RED), new SysCol(SWT.COLOR_GRAY), 1, 3), // DEADLOCK\r
- new RGB(200, 200, 200), // STOPPED\r
- new RGB(35, 107, 42), // STEEL BLUE\r
- new RGB(205,205,0), // DARK YELLOW\r
- new RGB(205, 0, 205), // MAGENTA\r
- new RGB(171, 130, 255), // PURPLE\r
- new RGB(255, 181, 197), // PINK\r
- new RGB(112, 219, 147), // AQUAMARINE\r
- new RGB(198, 226, 255), // SLATEGRAY\r
- new RGB(95, 158, 160), // CADET BLUE\r
- new RGB(107, 142, 35), // OLIVE\r
-\r
-\r
- //TODO: Does not seem to be used, check during clean-up\r
- new SysCol(SWT.COLOR_WHITE), // UNKNOWN_SEL\r
- new SysCol(SWT.COLOR_GREEN), // RUNNING_SEL\r
- new SysCol(SWT.COLOR_BLUE), // SLEEPING_SEL\r
- new SysCol(SWT.COLOR_CYAN), // WAITING_SEL\r
- new SysCol(SWT.COLOR_YELLOW), // BLOCKED_SEL\r
- new SysCol(SWT.COLOR_RED), // DEADLOCK_SEL\r
- new SysCol(SWT.COLOR_DARK_GRAY), // STOPPED_SEL\r
- new SysCol(SWT.COLOR_WHITE),\r
- new SysCol(SWT.COLOR_GREEN),\r
- new SysCol(SWT.COLOR_BLUE),\r
- new SysCol(SWT.COLOR_CYAN),\r
- new SysCol(SWT.COLOR_YELLOW),\r
- new SysCol(SWT.COLOR_RED),\r
- new SysCol(SWT.COLOR_DARK_GRAY),\r
- new SysCol(SWT.COLOR_WHITE),\r
- new SysCol(SWT.COLOR_GREEN),\r
-\r
-\r
- new SysCol(SWT.COLOR_LIST_BACKGROUND), // BACKGROUND\r
- new SysCol(SWT.COLOR_LIST_FOREGROUND), // FOREGROUND\r
- new RGB(232, 242, 254), // BACKGROUND_SEL\r
- new SysCol(SWT.COLOR_LIST_FOREGROUND), // FOREGROUND_SEL\r
- new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // BACKGROUND_SEL_NOFOCUS\r
- new SysCol(SWT.COLOR_WIDGET_FOREGROUND), // FOREGROUND_SEL_NOFOCUS\r
- new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // TOOL_BACKGROUND\r
- new SysCol(SWT.COLOR_WIDGET_DARK_SHADOW), // TOOL_FOREGROUND\r
-\r
- new SysCol(SWT.COLOR_GRAY), // FIX_COLOR\r
- new SysCol(SWT.COLOR_WHITE), // WHITE\r
- new SysCol(SWT.COLOR_GRAY), // GRAY\r
- new SysCol(SWT.COLOR_BLACK), // BLACK\r
- new SysCol(SWT.COLOR_DARK_GRAY), // DARK_GRAY\r
-\r
- new SysCol(SWT.COLOR_DARK_GRAY), // BLACK_BORDER\r
- new RGB(75, 115, 120), // GREEN_BORDER\r
- new SysCol(SWT.COLOR_DARK_BLUE), // DARK_BLUE_BORDER\r
- new RGB(242, 225, 168), // ORANGE_BORDER\r
- new RGB(210, 150, 60), // GOLD_BORDER\r
- new SysCol(SWT.COLOR_DARK_RED), // RED_BORDER\r
- new SysCol(SWT.COLOR_BLACK), // GRAY_BORDER\r
- new SysCol(SWT.COLOR_DARK_GRAY), // DARK_GREEN_BORDER\r
- new RGB(75, 115, 120), // DARK_YELLOW_BORDER\r
- new SysCol(SWT.COLOR_DARK_BLUE), // MAGENTA3_BORDER\r
- new RGB(242, 225, 168), // PURPLE1_BORDER\r
- new RGB(210, 150, 60), // PINK1_BORDER\r
- new SysCol(SWT.COLOR_DARK_RED), // AQUAMARINE_BORDER\r
- new SysCol(SWT.COLOR_BLACK), // LIGHT_BLUE_BORDER\r
- new SysCol(SWT.COLOR_DARK_GRAY), // BLUE_BORDER\r
- new RGB(75, 115, 120), // OLIVE_BORDER\r
-\r
-\r
- new SysCol(SWT.COLOR_GRAY), // MID_LINE\r
- new SysCol(SWT.COLOR_RED), // RED\r
- new SysCol(SWT.COLOR_GREEN), // GREEN\r
- new SysCol(SWT.COLOR_BLUE), // BLUE\r
- new SysCol(SWT.COLOR_YELLOW), // YELLOW\r
- new SysCol(SWT.COLOR_CYAN), // CYAN\r
- new SysCol(SWT.COLOR_MAGENTA), // MAGENTA\r
-\r
- new SysCol(SWT.COLOR_BLUE), // SELECTED_TIME\r
- new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // LEGEND_BACKGROUND\r
- new SysCol(SWT.COLOR_WIDGET_DARK_SHADOW), // LEGEND_FOREGROUND\r
-\r
- new Mix(new RGB(150, 200, 240), new SysCol(SWT.COLOR_LIST_BACKGROUND)), // GR_BACKGROUND\r
- new RGB(0, 0, 50), // GR_FOREGROUND\r
- new Mix(new RGB(150, 200, 240), new SysCol(SWT.COLOR_WHITE), 6, 1), // GR_BACKGROUND_SEL\r
- new RGB(0, 0, 50), // GR_FOREGROUND_SEL\r
- new Mix(new RGB(150, 200, 240), new SysCol(SWT.COLOR_WHITE), 6, 1), // GR_BACKGROUND_SEL_NOFOCUS\r
- new RGB(0, 0, 50), // GR_FOREGROUND_SEL_NOFOCUS\r
-\r
- new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_LIST_BACKGROUND), 1, 3), // LIGHT_LINE\r
-\r
- new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_LIST_BACKGROUND), 1, 6), // BACKGROUND_NAME\r
- new Mix(new SysCol(SWT.COLOR_GRAY), new RGB(232, 242, 254), 1, 6), // BACKGROUND_NAME_SEL\r
- new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_WIDGET_BACKGROUND), 1, 6), // BACKGROUND_NAME_SEL_NOFOCUS\r
- };\r
-\r
- private final Color _colors[];\r
-\r
- /**\r
- * Default constructor\r
- */\r
- public TimeGraphColorScheme() {\r
- _colors = new Color[_providersMap.length];\r
- }\r
-\r
- /**\r
- * Dispose this color scheme\r
- */\r
- public void dispose() {\r
- for (int i = 0; i < _colors.length; i++) {\r
- Utils.dispose(_colors[i]);\r
- _colors[i] = null;\r
- }\r
- }\r
-\r
- /**\r
- * Get the color matching the given index\r
- *\r
- * @param idx\r
- * The index\r
- * @return The matching color\r
- */\r
- public Color getColor(int idx) {\r
- if (null == _colors[idx]) {\r
- if (idx >= STATES_SEL0 && idx <= STATES_SEL1) {\r
- Color col1 = getColor(idx - STATES_SEL0);\r
- Color col2 = getColor(BACKGROUND_SEL);\r
- _colors[idx] = Utils.mixColors(col1, col2, 3, 1);\r
- } else {\r
- _colors[idx] = _providersMap[idx].get();\r
- }\r
- }\r
- return _colors[idx];\r
- }\r
-\r
- /**\r
- * Get an entry's background color based on its status.\r
- *\r
- * @param selected\r
- * If the entry is selected\r
- * @param focused\r
- * If the entry is focused\r
- * @param name\r
- * Get the color of the name column (false for other columns)\r
- * @return The matching color\r
- */\r
- public Color getBkColor(boolean selected, boolean focused, boolean name) {\r
- if (name) {\r
- if (selected && focused) {\r
- return getColor(BACKGROUND_NAME_SEL);\r
- }\r
- if (selected) {\r
- return getColor(BACKGROUND_NAME_SEL_NOFOCUS);\r
- }\r
- return getColor(BACKGROUND_NAME);\r
- }\r
- if (selected && focused) {\r
- return getColor(BACKGROUND_SEL);\r
- }\r
- if (selected) {\r
- return getColor(BACKGROUND_SEL_NOFOCUS);\r
- }\r
- return getColor(BACKGROUND);\r
- }\r
-\r
- /**\r
- * Get the correct foreground color\r
- *\r
- * @param selected\r
- * Is the entry selected\r
- * @param focused\r
- * Is the entry focused\r
- * @return The matching color\r
- */\r
- public Color getFgColor(boolean selected, boolean focused) {\r
- if (selected && focused) {\r
- return getColor(FOREGROUND_SEL);\r
- }\r
- if (selected) {\r
- return getColor(FOREGROUND_SEL_NOFOCUS);\r
- }\r
- return getColor(FOREGROUND);\r
- }\r
-\r
- /**\r
- * Get the correct background color group\r
- *\r
- * @param selected\r
- * Is the entry selected\r
- * @param focused\r
- * Is the entry focused\r
- * @return The matching color\r
- */\r
- public Color getBkColorGroup(boolean selected, boolean focused) {\r
- if (selected && focused) {\r
- return getColor(GR_BACKGROUND_SEL);\r
- }\r
- if (selected) {\r
- return getColor(GR_BACKGROUND_SEL_NOFOCUS);\r
- }\r
- return getColor(GR_BACKGROUND);\r
- }\r
-\r
- /**\r
- * Get the correct foreground color group\r
- *\r
- * @param selected\r
- * Is the entry selected\r
- * @param focused\r
- * Is the entry focused\r
- * @return The matching color\r
- */\r
- public Color getFgColorGroup(boolean selected, boolean focused) {\r
- if (selected && focused) {\r
- return getColor(GR_FOREGROUND_SEL);\r
- }\r
- if (selected) {\r
- return getColor(GR_FOREGROUND_SEL_NOFOCUS);\r
- }\r
- return getColor(GR_FOREGROUND);\r
- }\r
-}\r
+/*****************************************************************************
+ * Copyright (c) 2008 Intel Corporation, 2009, 2012 Ericsson.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ * Ruslan A. Scherbakov, Intel - Initial API and implementation
+ * Alvaro Sanchez-Leon - Updated for TMF
+ * Patrick Tasse - Refactoring
+ *
+ *****************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * Color theme used by the timegraph view
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+public class TimeGraphColorScheme {
+
+ // elements color indices
+ static public final int BLACK_STATE = 0;
+ static public final int GREEN_STATE = 1;
+ static public final int DARK_BLUE_STATE = 2;
+ static public final int ORANGE_STATE = 3;
+ static public final int GOLD_STATE = 4;
+ static public final int RED_STATE = 5;
+ static public final int GRAY_STATE = 6;
+ static public final int DARK_GREEN_STATE = 7;
+ static public final int DARK_YELLOW_STATE = 8;
+ static public final int MAGENTA3_STATE = 9;
+ static public final int PURPLE1_STATE = 10;
+ static public final int PINK1_STATE = 11;
+ static public final int AQUAMARINE_STATE = 12;
+ static public final int LIGHT_BLUE_STATE = 13;
+ static public final int CADET_BLUE_STATE = 14;
+ static public final int OLIVE_STATE = 15;
+
+ static public final int STATES0 = 0;
+ static public final int STATES1 = 15;
+
+ // selected state elements color indices
+ static public final int BLACK_STATE_SEL = 16;
+ static public final int GREEN_STATE_SEL = 17;
+ static public final int DARK_BLUE_STATE_SEL = 18;
+ static public final int ORANGE_STATE_SEL = 19;
+ static public final int GOLD_STATE_SEL = 20;
+ static public final int RED_STATE_SEL = 21;
+ static public final int GRAY_STATE_SEL = 22;
+ static public final int DARK_GREEN_STATE_SEL = 23;
+ static public final int DARK_YELLOW_STATE_SEL = 24;
+ static public final int MAGENTA3_STATE_SEL = 25;
+ static public final int PURPLE1_STATE_SEL = 26;
+ static public final int PINK1_STATE_SEL = 27;
+ static public final int AQUAMARINE_STATE_SEL = 28;
+ static public final int LIGHT_BLUE_STATE_SEL = 29;
+ static public final int CADET_BLUE_STATE_SEL = 30;
+ static public final int OLIVE_STATE_SEL = 31;
+
+ static public final int STATES_SEL0 = 16;
+ static public final int STATES_SEL1 = 31;
+
+ // colors indices for viewer controls
+ static public final int BACKGROUND = 32;
+ static public final int FOREGROUND = 33;
+ static public final int BACKGROUND_SEL = 34;
+ static public final int FOREGROUND_SEL = 35;
+ static public final int BACKGROUND_SEL_NOFOCUS = 36;
+ static public final int FOREGROUND_SEL_NOFOCUS = 37;
+ static public final int TOOL_BACKGROUND = 38;
+ static public final int TOOL_FOREGROUND = 39;
+
+ // misc colors
+ static public final int FIX_COLOR = 40;
+ static public final int WHITE = 41;
+ static public final int GRAY = 42;
+ static public final int BLACK = 43;
+ static public final int DARK_GRAY = 44;
+
+ // selected border color indices
+ static public final int BLACK_BORDER = 45;
+ static public final int GREEN_BORDER = 46;
+ static public final int DARK_BLUE_BORDER = 47;
+ static public final int ORANGE_BORDER = 48;
+ static public final int GOLD_BORDER = 49;
+ static public final int RED_BORDER = 50;
+ static public final int GRAY_BORDER = 51;
+ static public final int DARK_GREEN_BORDER1 = 52;
+ static public final int DARK_YELLOW_BORDER1 = 53;
+ static public final int MAGENTA3_BORDER1 = 54;
+ static public final int PURPLE1_BORDER1 = 55;
+ static public final int PINK1_BORDER1 = 56;
+ static public final int AQUAMARINE_BORDER1 = 57;
+ static public final int LIGHT_BLUE_BORDER1 = 58;
+ static public final int CADET_BLUE_STATE_BORDER = 59;
+ static public final int OLIVE_BORDER2 = 60;
+
+ static public final int STATES_BORDER0 = 45;
+ static public final int STATES_BORDER1 = 60;
+
+ static public final int MID_LINE = 61;
+ static public final int RED = 62;
+ static public final int GREEN = 63;
+ static public final int BLUE = 64;
+ static public final int YELLOW = 65;
+ static public final int CYAN = 66;
+ static public final int MAGENTA = 67;
+
+ static public final int SELECTED_TIME = 68;
+ static public final int LEGEND_BACKGROUND = 69;
+ static public final int LEGEND_FOREGROUND = 70;
+
+ // group items' colors
+ static public final int GR_BACKGROUND = 71;
+ static public final int GR_FOREGROUND = 72;
+ static public final int GR_BACKGROUND_SEL = 73;
+ static public final int GR_FOREGROUND_SEL = 74;
+ static public final int GR_BACKGROUND_SEL_NOFOCUS = 75;
+ static public final int GR_FOREGROUND_SEL_NOFOCUS = 76;
+
+ static public final int LIGHT_LINE = 77;
+ static public final int BACKGROUND_NAME = 78;
+ static public final int BACKGROUND_NAME_SEL = 79;
+ static public final int BACKGROUND_NAME_SEL_NOFOCUS = 80;
+
+ // Interraction's colors
+ static public final int TI_START_THREAD = BLACK;
+ static public final int TI_HANDOFF_LOCK = BLUE;
+ static public final int TI_NOTIFY_ALL = GREEN;
+ static public final int TI_NOTIFY = GREEN;
+ static public final int TI_NOTIFY_JOINED = DARK_GRAY;
+ static public final int TI_INTERRUPT = RED;
+ static public final int TI_WAIT_EXCEEDED = BLUE;
+
+ static interface IColorProvider {
+ public Color get();
+ }
+
+ static class SysCol implements IColorProvider {
+ int syscol;
+
+ SysCol(int syscol) {
+ this.syscol = syscol;
+ }
+
+ @Override
+ public Color get() {
+ return Utils.getSysColor(syscol);
+ }
+ }
+
+ static class RGB implements IColorProvider {
+ int r;
+ int g;
+ int b;
+
+ RGB(int r, int g, int b) {
+ this.r = r;
+ this.g = g;
+ this.b = b;
+ }
+
+ @Override
+ public Color get() {
+ return new Color(null, r, g, b);
+ }
+ }
+
+ static class Mix implements IColorProvider {
+ IColorProvider cp1;
+ IColorProvider cp2;
+ int w1;
+ int w2;
+
+ Mix(IColorProvider cp1, IColorProvider cp2, int w1, int w2) {
+ this.cp1 = cp1;
+ this.cp2 = cp2;
+ this.w1 = w1;
+ this.w2 = w2;
+ }
+
+ Mix(IColorProvider cp1, IColorProvider cp2) {
+ this.cp1 = cp1;
+ this.cp2 = cp2;
+ this.w1 = 1;
+ this.w2 = 1;
+ }
+
+ @Override
+ public Color get() {
+ Color col1 = cp1.get();
+ Color col2 = cp2.get();
+ Color col = Utils.mixColors(col1, col2, w1, w2);
+ return col;
+ }
+ }
+
+ static private final IColorProvider _providersMap[] = {
+ //
+ new RGB(100, 100, 100), // UNKNOWN
+ new RGB(174, 200, 124), // RUNNING
+ new Mix(new SysCol(SWT.COLOR_BLUE), new SysCol(SWT.COLOR_GRAY), 1, 3), // SLEEPING
+ new RGB(210, 150, 60), // WAITING
+ new RGB(242, 225, 168), // BLOCKED
+ new Mix(new SysCol(SWT.COLOR_RED), new SysCol(SWT.COLOR_GRAY), 1, 3), // DEADLOCK
+ new RGB(200, 200, 200), // STOPPED
+ new RGB(35, 107, 42), // STEEL BLUE
+ new RGB(205,205,0), // DARK YELLOW
+ new RGB(205, 0, 205), // MAGENTA
+ new RGB(171, 130, 255), // PURPLE
+ new RGB(255, 181, 197), // PINK
+ new RGB(112, 219, 147), // AQUAMARINE
+ new RGB(198, 226, 255), // SLATEGRAY
+ new RGB(95, 158, 160), // CADET BLUE
+ new RGB(107, 142, 35), // OLIVE
+
+
+ //TODO: Does not seem to be used, check during clean-up
+ new SysCol(SWT.COLOR_WHITE), // UNKNOWN_SEL
+ new SysCol(SWT.COLOR_GREEN), // RUNNING_SEL
+ new SysCol(SWT.COLOR_BLUE), // SLEEPING_SEL
+ new SysCol(SWT.COLOR_CYAN), // WAITING_SEL
+ new SysCol(SWT.COLOR_YELLOW), // BLOCKED_SEL
+ new SysCol(SWT.COLOR_RED), // DEADLOCK_SEL
+ new SysCol(SWT.COLOR_DARK_GRAY), // STOPPED_SEL
+ new SysCol(SWT.COLOR_WHITE),
+ new SysCol(SWT.COLOR_GREEN),
+ new SysCol(SWT.COLOR_BLUE),
+ new SysCol(SWT.COLOR_CYAN),
+ new SysCol(SWT.COLOR_YELLOW),
+ new SysCol(SWT.COLOR_RED),
+ new SysCol(SWT.COLOR_DARK_GRAY),
+ new SysCol(SWT.COLOR_WHITE),
+ new SysCol(SWT.COLOR_GREEN),
+
+
+ new SysCol(SWT.COLOR_LIST_BACKGROUND), // BACKGROUND
+ new SysCol(SWT.COLOR_LIST_FOREGROUND), // FOREGROUND
+ new RGB(232, 242, 254), // BACKGROUND_SEL
+ new SysCol(SWT.COLOR_LIST_FOREGROUND), // FOREGROUND_SEL
+ new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // BACKGROUND_SEL_NOFOCUS
+ new SysCol(SWT.COLOR_WIDGET_FOREGROUND), // FOREGROUND_SEL_NOFOCUS
+ new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // TOOL_BACKGROUND
+ new SysCol(SWT.COLOR_WIDGET_DARK_SHADOW), // TOOL_FOREGROUND
+
+ new SysCol(SWT.COLOR_GRAY), // FIX_COLOR
+ new SysCol(SWT.COLOR_WHITE), // WHITE
+ new SysCol(SWT.COLOR_GRAY), // GRAY
+ new SysCol(SWT.COLOR_BLACK), // BLACK
+ new SysCol(SWT.COLOR_DARK_GRAY), // DARK_GRAY
+
+ new SysCol(SWT.COLOR_DARK_GRAY), // BLACK_BORDER
+ new RGB(75, 115, 120), // GREEN_BORDER
+ new SysCol(SWT.COLOR_DARK_BLUE), // DARK_BLUE_BORDER
+ new RGB(242, 225, 168), // ORANGE_BORDER
+ new RGB(210, 150, 60), // GOLD_BORDER
+ new SysCol(SWT.COLOR_DARK_RED), // RED_BORDER
+ new SysCol(SWT.COLOR_BLACK), // GRAY_BORDER
+ new SysCol(SWT.COLOR_DARK_GRAY), // DARK_GREEN_BORDER
+ new RGB(75, 115, 120), // DARK_YELLOW_BORDER
+ new SysCol(SWT.COLOR_DARK_BLUE), // MAGENTA3_BORDER
+ new RGB(242, 225, 168), // PURPLE1_BORDER
+ new RGB(210, 150, 60), // PINK1_BORDER
+ new SysCol(SWT.COLOR_DARK_RED), // AQUAMARINE_BORDER
+ new SysCol(SWT.COLOR_BLACK), // LIGHT_BLUE_BORDER
+ new SysCol(SWT.COLOR_DARK_GRAY), // BLUE_BORDER
+ new RGB(75, 115, 120), // OLIVE_BORDER
+
+
+ new SysCol(SWT.COLOR_GRAY), // MID_LINE
+ new SysCol(SWT.COLOR_RED), // RED
+ new SysCol(SWT.COLOR_GREEN), // GREEN
+ new SysCol(SWT.COLOR_BLUE), // BLUE
+ new SysCol(SWT.COLOR_YELLOW), // YELLOW
+ new SysCol(SWT.COLOR_CYAN), // CYAN
+ new SysCol(SWT.COLOR_MAGENTA), // MAGENTA
+
+ new SysCol(SWT.COLOR_BLUE), // SELECTED_TIME
+ new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // LEGEND_BACKGROUND
+ new SysCol(SWT.COLOR_WIDGET_DARK_SHADOW), // LEGEND_FOREGROUND
+
+ new Mix(new RGB(150, 200, 240), new SysCol(SWT.COLOR_LIST_BACKGROUND)), // GR_BACKGROUND
+ new RGB(0, 0, 50), // GR_FOREGROUND
+ new Mix(new RGB(150, 200, 240), new SysCol(SWT.COLOR_WHITE), 6, 1), // GR_BACKGROUND_SEL
+ new RGB(0, 0, 50), // GR_FOREGROUND_SEL
+ new Mix(new RGB(150, 200, 240), new SysCol(SWT.COLOR_WHITE), 6, 1), // GR_BACKGROUND_SEL_NOFOCUS
+ new RGB(0, 0, 50), // GR_FOREGROUND_SEL_NOFOCUS
+
+ new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_LIST_BACKGROUND), 1, 3), // LIGHT_LINE
+
+ new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_LIST_BACKGROUND), 1, 6), // BACKGROUND_NAME
+ new Mix(new SysCol(SWT.COLOR_GRAY), new RGB(232, 242, 254), 1, 6), // BACKGROUND_NAME_SEL
+ new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_WIDGET_BACKGROUND), 1, 6), // BACKGROUND_NAME_SEL_NOFOCUS
+ };
+
+ private final Color _colors[];
+
+ /**
+ * Default constructor
+ */
+ public TimeGraphColorScheme() {
+ _colors = new Color[_providersMap.length];
+ }
+
+ /**
+ * Dispose this color scheme
+ */
+ public void dispose() {
+ for (int i = 0; i < _colors.length; i++) {
+ Utils.dispose(_colors[i]);
+ _colors[i] = null;
+ }
+ }
+
+ /**
+ * Get the color matching the given index
+ *
+ * @param idx
+ * The index
+ * @return The matching color
+ */
+ public Color getColor(int idx) {
+ if (null == _colors[idx]) {
+ if (idx >= STATES_SEL0 && idx <= STATES_SEL1) {
+ Color col1 = getColor(idx - STATES_SEL0);
+ Color col2 = getColor(BACKGROUND_SEL);
+ _colors[idx] = Utils.mixColors(col1, col2, 3, 1);
+ } else {
+ _colors[idx] = _providersMap[idx].get();
+ }
+ }
+ return _colors[idx];
+ }
+
+ /**
+ * Get an entry's background color based on its status.
+ *
+ * @param selected
+ * If the entry is selected
+ * @param focused
+ * If the entry is focused
+ * @param name
+ * Get the color of the name column (false for other columns)
+ * @return The matching color
+ */
+ public Color getBkColor(boolean selected, boolean focused, boolean name) {
+ if (name) {
+ if (selected && focused) {
+ return getColor(BACKGROUND_NAME_SEL);
+ }
+ if (selected) {
+ return getColor(BACKGROUND_NAME_SEL_NOFOCUS);
+ }
+ return getColor(BACKGROUND_NAME);
+ }
+ if (selected && focused) {
+ return getColor(BACKGROUND_SEL);
+ }
+ if (selected) {
+ return getColor(BACKGROUND_SEL_NOFOCUS);
+ }
+ return getColor(BACKGROUND);
+ }
+
+ /**
+ * Get the correct foreground color
+ *
+ * @param selected
+ * Is the entry selected
+ * @param focused
+ * Is the entry focused
+ * @return The matching color
+ */
+ public Color getFgColor(boolean selected, boolean focused) {
+ if (selected && focused) {
+ return getColor(FOREGROUND_SEL);
+ }
+ if (selected) {
+ return getColor(FOREGROUND_SEL_NOFOCUS);
+ }
+ return getColor(FOREGROUND);
+ }
+
+ /**
+ * Get the correct background color group
+ *
+ * @param selected
+ * Is the entry selected
+ * @param focused
+ * Is the entry focused
+ * @return The matching color
+ */
+ public Color getBkColorGroup(boolean selected, boolean focused) {
+ if (selected && focused) {
+ return getColor(GR_BACKGROUND_SEL);
+ }
+ if (selected) {
+ return getColor(GR_BACKGROUND_SEL_NOFOCUS);
+ }
+ return getColor(GR_BACKGROUND);
+ }
+
+ /**
+ * Get the correct foreground color group
+ *
+ * @param selected
+ * Is the entry selected
+ * @param focused
+ * Is the entry focused
+ * @return The matching color
+ */
+ public Color getFgColorGroup(boolean selected, boolean focused) {
+ if (selected && focused) {
+ return getColor(GR_FOREGROUND_SEL);
+ }
+ if (selected) {
+ return getColor(GR_FOREGROUND_SEL_NOFOCUS);
+ }
+ return getColor(GR_FOREGROUND);
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-\r
-/**\r
- * Item in the generic time graph view\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-@SuppressWarnings("javadoc")\r
-public class TimeGraphItem {\r
- public boolean _expanded;\r
- public boolean _selected;\r
- public boolean _hasChildren;\r
- public int itemHeight;\r
- public int level;\r
- public List<TimeGraphItem> children;\r
- public String _name;\r
- public ITimeGraphEntry _trace;\r
-\r
- /**\r
- * Standard constructor\r
- *\r
- * @param trace\r
- * The entry matching to trace to which this item is associated\r
- * @param name\r
- * The name of the item\r
- * @param level\r
- * The tree level of this entry (0 = top level)\r
- */\r
- public TimeGraphItem(ITimeGraphEntry trace, String name, int level) {\r
- this._trace = trace;\r
- this._name = name;\r
- this.level = level;\r
- this.children = new ArrayList<TimeGraphItem>();\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return _name;\r
- }\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+
+/**
+ * Item in the generic time graph view
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+public class TimeGraphItem {
+ public boolean _expanded;
+ public boolean _selected;
+ public boolean _hasChildren;
+ public int itemHeight;
+ public int level;
+ public List<TimeGraphItem> children;
+ public String _name;
+ public ITimeGraphEntry _trace;
+
+ /**
+ * Standard constructor
+ *
+ * @param trace
+ * The entry matching to trace to which this item is associated
+ * @param name
+ * The name of the item
+ * @param level
+ * The tree level of this entry (0 = top level)
+ */
+ public TimeGraphItem(ITimeGraphEntry trace, String name, int level) {
+ this._trace = trace;
+ this._name = name;
+ this.level = level;
+ this.children = new ArrayList<TimeGraphItem>();
+ }
+
+ @Override
+ public String toString() {
+ return _name;
+ }
}
\ No newline at end of file
-/*****************************************************************************\r
- * Copyright (c) 2007 Intel Corporation, 2009, 2012 Ericsson.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Intel Corporation - Initial API and implementation\r
- * Ruslan A. Scherbakov, Intel - Initial API and implementation\r
- * Alvaro Sanchez-Leon - Updated for TMF\r
- * Patrick Tasse - Refactoring\r
- *\r
- *****************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-\r
-import org.eclipse.jface.viewers.IStructuredSelection;\r
-\r
-/**\r
- * Selection object for the time graph scale\r
- *\r
- * @version 1.0\r
- * @author Alvaro Sanchez-Leon\r
- * @author Patrick Tasse\r
- */\r
-public class TimeGraphSelection implements IStructuredSelection {\r
-\r
- List<Object> list = new ArrayList<Object>();\r
-\r
- /**\r
- * Default constructor\r
- */\r
- public TimeGraphSelection() {\r
- }\r
-\r
- /**\r
- * "Wrapper" constructor. Instantiate a new selection object with only one\r
- * existing selection.\r
- *\r
- * @param sel\r
- * The initial selection to add to this one\r
- */\r
- public TimeGraphSelection(Object sel) {\r
- add(sel);\r
- }\r
-\r
- /**\r
- * Add a selection to this one.\r
- *\r
- * @param sel\r
- * The selection to add\r
- */\r
- public void add(Object sel) {\r
- if (null != sel && !list.contains(sel)) {\r
- list.add(sel);\r
- }\r
- }\r
-\r
- @Override\r
- public Object getFirstElement() {\r
- if (!list.isEmpty()) {\r
- return list.get(0);\r
- }\r
- return null;\r
- }\r
-\r
- @Override\r
- public Iterator<Object> iterator() {\r
- return list.iterator();\r
- }\r
-\r
- @Override\r
- public int size() {\r
- return list.size();\r
- }\r
-\r
- @Override\r
- public Object[] toArray() {\r
- return list.toArray();\r
- }\r
-\r
- @Override\r
- public List<Object> toList() {\r
- return list;\r
- }\r
-\r
- @Override\r
- public boolean isEmpty() {\r
- return list.isEmpty();\r
- }\r
-}\r
+/*****************************************************************************
+ * Copyright (c) 2007 Intel Corporation, 2009, 2012 Ericsson.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ * Ruslan A. Scherbakov, Intel - Initial API and implementation
+ * Alvaro Sanchez-Leon - Updated for TMF
+ * Patrick Tasse - Refactoring
+ *
+ *****************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+
+/**
+ * Selection object for the time graph scale
+ *
+ * @version 1.0
+ * @author Alvaro Sanchez-Leon
+ * @author Patrick Tasse
+ */
+public class TimeGraphSelection implements IStructuredSelection {
+
+ List<Object> list = new ArrayList<Object>();
+
+ /**
+ * Default constructor
+ */
+ public TimeGraphSelection() {
+ }
+
+ /**
+ * "Wrapper" constructor. Instantiate a new selection object with only one
+ * existing selection.
+ *
+ * @param sel
+ * The initial selection to add to this one
+ */
+ public TimeGraphSelection(Object sel) {
+ add(sel);
+ }
+
+ /**
+ * Add a selection to this one.
+ *
+ * @param sel
+ * The selection to add
+ */
+ public void add(Object sel) {
+ if (null != sel && !list.contains(sel)) {
+ list.add(sel);
+ }
+ }
+
+ @Override
+ public Object getFirstElement() {
+ if (!list.isEmpty()) {
+ return list.get(0);
+ }
+ return null;
+ }
+
+ @Override
+ public Iterator<Object> iterator() {
+ return list.iterator();
+ }
+
+ @Override
+ public int size() {
+ return list.size();
+ }
+
+ @Override
+ public Object[] toArray() {
+ return list.toArray();
+ }
+
+ @Override
+ public List<Object> toList() {
+ return list;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return list.isEmpty();
+ }
+}
-/*****************************************************************************\r
- * Copyright (c) 2007, 2008 Intel Corporation, 2009, 2012 Ericsson.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Intel Corporation - Initial API and implementation\r
- * Ruslan A. Scherbakov, Intel - Initial API and implementation\r
- * Alvaro Sanchez-Leon - Udpated for TMF\r
- * Patrick Tasse - Refactoring\r
- *\r
- *****************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;\r
-\r
-import java.text.SimpleDateFormat;\r
-import java.util.Date;\r
-import java.util.Iterator;\r
-\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-import org.eclipse.swt.graphics.Color;\r
-import org.eclipse.swt.graphics.Device;\r
-import org.eclipse.swt.graphics.GC;\r
-import org.eclipse.swt.graphics.Point;\r
-import org.eclipse.swt.graphics.Rectangle;\r
-import org.eclipse.swt.widgets.Display;\r
-\r
-/**\r
- * General utilities and definitions used by the time graph widget\r
- *\r
- * @version 1.0\r
- * @author Alvaro Sanchez-Leon\r
- * @author Patrick Tasse\r
- */\r
-public class Utils {\r
-\r
- /** Time format for dates and timestamp */\r
- public enum TimeFormat {\r
- /** Relative to the start of the trace */\r
- RELATIVE,\r
- /** Absolute timestamp (ie, relative to the Unix epoch) */\r
- ABSOLUTE\r
- }\r
-\r
- static public final int IMG_THREAD_RUNNING = 0;\r
- static public final int IMG_THREAD_SUSPENDED = 1;\r
- static public final int IMG_THREAD_STOPPED = 2;\r
- static public final int IMG_METHOD_RUNNING = 3;\r
- static public final int IMG_METHOD = 4;\r
- static public final int IMG_NUM = 5;\r
-\r
- static public final Object[] _empty = new Object[0];\r
-\r
- public static enum Resolution {\r
- SECONDS, MILLISEC, MICROSEC, NANOSEC\r
- }\r
-\r
- static private final SimpleDateFormat stimeformat = new SimpleDateFormat("HH:mm:ss"); //$NON-NLS-1$\r
- static private final SimpleDateFormat sdateformat = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$\r
-\r
- static Rectangle clone(Rectangle source) {\r
- return new Rectangle(source.x, source.y, source.width, source.height);\r
- }\r
-\r
- /**\r
- * Initialize a Rectangle object to default values (all equal to 0)\r
- *\r
- * @param rect\r
- * The Rectangle to initialize\r
- */\r
- static public void init(Rectangle rect) {\r
- rect.x = 0;\r
- rect.y = 0;\r
- rect.width = 0;\r
- rect.height = 0;\r
- }\r
-\r
- /**\r
- * Initialize a Rectangle object with all the given values\r
- *\r
- * @param rect\r
- * The Rectangle object to initialize\r
- * @param x\r
- * The X coordinate\r
- * @param y\r
- * The Y coordinate\r
- * @param width\r
- * The width of the rectangle\r
- * @param height\r
- * The height of the rectangle\r
- */\r
- static public void init(Rectangle rect, int x, int y, int width, int height) {\r
- rect.x = x;\r
- rect.y = y;\r
- rect.width = width;\r
- rect.height = height;\r
- }\r
-\r
- /**\r
- * Initialize a Rectangle object to another existing Rectangle's values.\r
- *\r
- * @param rect\r
- * The Rectangle to initialize\r
- * @param source\r
- * The reference Rectangle to copy\r
- */\r
- static public void init(Rectangle rect, Rectangle source) {\r
- rect.x = source.x;\r
- rect.y = source.y;\r
- rect.width = source.width;\r
- rect.height = source.height;\r
- }\r
-\r
- /**\r
- * Reduce the size of a given rectangle by the given amounts.\r
- *\r
- * @param rect\r
- * The rectangle to modify\r
- * @param x\r
- * The reduction in width\r
- * @param y\r
- * The reduction in height\r
- */\r
- static public void deflate(Rectangle rect, int x, int y) {\r
- rect.x += x;\r
- rect.y += y;\r
- rect.width -= x + x;\r
- rect.height -= y + y;\r
- }\r
-\r
- /**\r
- * Increase the size of a given rectangle by the given amounts.\r
- *\r
- * @param rect\r
- * The rectangle to modify\r
- * @param x\r
- * The augmentation in width\r
- * @param y\r
- * The augmentation in height\r
- */\r
- static public void inflate(Rectangle rect, int x, int y) {\r
- rect.x -= x;\r
- rect.y -= y;\r
- rect.width += x + x;\r
- rect.height += y + y;\r
- }\r
-\r
- static void dispose(Color col) {\r
- if (null != col) {\r
- col.dispose();\r
- }\r
- }\r
-\r
- /**\r
- * Get the resulting color from a mix of two existing ones for a given\r
- * display.\r
- *\r
- * @param display\r
- * The display device (which might affect the color conversion)\r
- * @param c1\r
- * The first color\r
- * @param c2\r
- * The second color\r
- * @param w1\r
- * The gamma level for color 1\r
- * @param w2\r
- * The gamma level for color 2\r
- * @return The resulting color\r
- */\r
- static public Color mixColors(Device display, Color c1, Color c2, int w1,\r
- int w2) {\r
- return new Color(display, (w1 * c1.getRed() + w2 * c2.getRed())\r
- / (w1 + w2), (w1 * c1.getGreen() + w2 * c2.getGreen())\r
- / (w1 + w2), (w1 * c1.getBlue() + w2 * c2.getBlue())\r
- / (w1 + w2));\r
- }\r
-\r
- /**\r
- * Get the system color with the given ID.\r
- *\r
- * @param id\r
- * The color ID\r
- * @return The resulting color\r
- */\r
- static public Color getSysColor(int id) {\r
- Color col = Display.getCurrent().getSystemColor(id);\r
- return new Color(col.getDevice(), col.getRGB());\r
- }\r
-\r
- /**\r
- * Get the resulting color from a mix of two existing ones for the current\r
- * display.\r
- *\r
- * @param col1\r
- * The first color\r
- * @param col2\r
- * The second color\r
- * @param w1\r
- * The gamma level for color 1\r
- * @param w2\r
- * The gamma level for color 2\r
- * @return The resulting color\r
- */\r
- static public Color mixColors(Color col1, Color col2, int w1, int w2) {\r
- return mixColors(Display.getCurrent(), col1, col2, w1, w2);\r
- }\r
-\r
- /**\r
- * Draw text in a rectangle.\r
- *\r
- * @param gc\r
- * The SWT GC object\r
- * @param text\r
- * The text to draw\r
- * @param rect\r
- * The rectangle object which is being drawn\r
- * @param transp\r
- * Should we transpose the color\r
- * @return The X coordinate where we have written\r
- */\r
- static public int drawText(GC gc, String text, Rectangle rect, boolean transp) {\r
- Point size = gc.stringExtent(text);\r
- gc.drawText(text, rect.x, rect.y, transp);\r
- return size.x;\r
- }\r
-\r
- /**\r
- * Draw text at a given location.\r
- *\r
- * @param gc\r
- * The SWT GC object\r
- * @param text\r
- * The text to draw\r
- * @param x\r
- * The X coordinate of the starting point\r
- * @param y\r
- * the Y coordinate of the starting point\r
- * @param transp\r
- * Should we transpose the color\r
- * @return The X coordinate where we have written\r
- */\r
- static public int drawText(GC gc, String text, int x, int y, boolean transp) {\r
- Point size = gc.stringExtent(text);\r
- gc.drawText(text, x, y, transp);\r
- return size.x;\r
- }\r
-\r
- /**\r
- * Formats time in format: MM:SS:NNN\r
- *\r
- * @param time time\r
- * @param format 0: MMMM:ss:nnnnnnnnn, 1: HH:MM:ss MMM.mmmm.nnn\r
- * @param resolution the resolution\r
- * @return the formatted time\r
- */\r
- static public String formatTime(long time, TimeFormat format, Resolution resolution) {\r
- // if format is absolute (Calendar)\r
- if (format == TimeFormat.ABSOLUTE) {\r
- return formatTimeAbs(time, resolution);\r
- }\r
-\r
- StringBuffer str = new StringBuffer();\r
- boolean neg = time < 0;\r
- if (neg) {\r
- time = -time;\r
- str.append('-');\r
- }\r
-\r
- long sec = (long) (time * 1E-9);\r
- // TODO: Expand to make it possible to select the minute, second, nanosecond format\r
- //printing minutes is suppressed just sec and ns\r
- // if (sec / 60 < 10)\r
- // str.append('0');\r
- // str.append(sec / 60);\r
- // str.append(':');\r
- // sec %= 60;\r
- // if (sec < 10)\r
- // str.append('0');\r
- str.append(sec);\r
- String ns = formatNs(time, resolution);\r
- if (!ns.equals("")) { //$NON-NLS-1$\r
- str.append('.');\r
- str.append(ns);\r
- }\r
-\r
- return str.toString();\r
- }\r
-\r
- /**\r
- * From input time in nanoseconds, convert to Date format YYYY-MM-dd\r
- *\r
- * @param absTime\r
- * The source time, in ns\r
- * @return the formatted date\r
- */\r
- public static String formatDate(long absTime) {\r
- String sdate = sdateformat.format(new Date((long) (absTime * 1E-6)));\r
- return sdate;\r
- }\r
-\r
- /**\r
- * Formats time in ns to Calendar format: HH:MM:SS MMM.mmm.nnn\r
- *\r
- * @param time\r
- * The source time, in ns\r
- * @param res\r
- * The resolution to use\r
- * @return the formatted time\r
- */\r
- static public String formatTimeAbs(long time, Resolution res) {\r
- StringBuffer str = new StringBuffer();\r
-\r
- // format time from nanoseconds to calendar time HH:MM:SS\r
- String stime = stimeformat.format(new Date((long) (time * 1E-6)));\r
- str.append(stime);\r
- str.append('.');\r
- // append the Milliseconds, MicroSeconds and NanoSeconds as specified in\r
- // the Resolution\r
- str.append(formatNs(time, res));\r
- return str.toString();\r
- }\r
-\r
- /**\r
- * Obtains the remainder fraction on unit Seconds of the entered value in\r
- * nanoseconds. e.g. input: 1241207054171080214 ns The number of fraction\r
- * seconds can be obtained by removing the last 9 digits: 1241207054 the\r
- * fractional portion of seconds, expressed in ns is: 171080214\r
- *\r
- * @param time\r
- * The source time in ns\r
- * @param res\r
- * The Resolution to use\r
- * @return the formatted nanosec\r
- */\r
- public static String formatNs(long time, Resolution res) {\r
- StringBuffer str = new StringBuffer();\r
- boolean neg = time < 0;\r
- if (neg) {\r
- time = -time;\r
- }\r
-\r
- // The following approach could be used although performance\r
- // decreases in half.\r
- // String strVal = String.format("%09d", time);\r
- // String tmp = strVal.substring(strVal.length() - 9);\r
-\r
- long ns = time;\r
- ns %= 1000000000;\r
- if (ns < 10) {\r
- str.append("00000000"); //$NON-NLS-1$\r
- } else if (ns < 100) {\r
- str.append("0000000"); //$NON-NLS-1$\r
- } else if (ns < 1000) {\r
- str.append("000000"); //$NON-NLS-1$\r
- } else if (ns < 10000) {\r
- str.append("00000"); //$NON-NLS-1$\r
- } else if (ns < 100000) {\r
- str.append("0000"); //$NON-NLS-1$\r
- } else if (ns < 1000000) {\r
- str.append("000"); //$NON-NLS-1$\r
- } else if (ns < 10000000) {\r
- str.append("00"); //$NON-NLS-1$\r
- } else if (ns < 100000000) {\r
- str.append("0"); //$NON-NLS-1$\r
- }\r
- str.append(ns);\r
-\r
- if (res == Resolution.MILLISEC) {\r
- return str.substring(0, 3);\r
- } else if (res == Resolution.MICROSEC) {\r
- return str.substring(0, 6);\r
- } else if (res == Resolution.NANOSEC) {\r
- return str.substring(0, 9);\r
- }\r
- return ""; //$NON-NLS-1$\r
- }\r
-\r
- /**\r
- * FIXME Currently does nothing.\r
- *\r
- * @param opt\r
- * The option name\r
- * @param def\r
- * The option value\r
- * @param min\r
- * The minimal accepted value\r
- * @param max\r
- * The maximal accepted value\r
- * @return The value that was read\r
- */\r
- static public int loadIntOption(String opt, int def, int min, int max) {\r
- // int val =\r
- // TraceUIPlugin.getDefault().getPreferenceStore().getInt(opt);\r
- // if (0 == val)\r
- // val = def;\r
- // if (val < min)\r
- // val = min;\r
- // if (val > max)\r
- // val = max;\r
- return def;\r
- }\r
-\r
- /**\r
- * FIXME currently does nothing\r
- *\r
- * @param opt\r
- * The option name\r
- * @param val\r
- * The option value\r
- */\r
- static public void saveIntOption(String opt, int val) {\r
- // TraceUIPlugin.getDefault().getPreferenceStore().setValue(opt, val);\r
- }\r
-\r
- static ITimeEvent getFirstEvent(ITimeGraphEntry entry) {\r
- if (null == entry || ! entry.hasTimeEvents()) {\r
- return null;\r
- }\r
- Iterator<ITimeEvent> iterator = entry.getTimeEventsIterator();\r
- if (iterator != null && iterator.hasNext()) {\r
- return iterator.next();\r
- }\r
- return null;\r
- }\r
-\r
- /**\r
- * N means: <list> <li>-1: Previous Event</li> <li>0: Current Event</li> <li>\r
- * 1: Next Event</li> <li>2: Previous Event when located in a non Event Area\r
- * </list>\r
- *\r
- * @param entry\r
- * @param time\r
- * @param n\r
- * @return\r
- */\r
- static ITimeEvent findEvent(ITimeGraphEntry entry, long time, int n) {\r
- if (null == entry || ! entry.hasTimeEvents()) {\r
- return null;\r
- }\r
- Iterator<ITimeEvent> iterator = entry.getTimeEventsIterator();\r
- if (iterator == null) {\r
- return null;\r
- }\r
- ITimeEvent nextEvent = null;\r
- ITimeEvent currEvent = null;\r
- ITimeEvent prevEvent = null;\r
-\r
- while (iterator.hasNext()) {\r
- nextEvent = iterator.next();\r
- long nextStartTime = nextEvent.getTime();\r
-\r
- if (nextStartTime > time) {\r
- break;\r
- }\r
-\r
- if (currEvent == null || currEvent.getTime() != nextStartTime) {\r
- prevEvent = currEvent;\r
- currEvent = nextEvent;\r
- }\r
- }\r
-\r
- if (n == -1) { //previous\r
- if (currEvent != null && currEvent.getTime() + currEvent.getDuration() >= time) {\r
- return prevEvent;\r
- }\r
- return currEvent;\r
- } else if (n == 0) { //current\r
- if (currEvent != null && currEvent.getTime() + currEvent.getDuration() >= time) {\r
- return currEvent;\r
- }\r
- return null;\r
- } else if (n == 1) { //next\r
- if (nextEvent != null && nextEvent.getTime() > time) {\r
- return nextEvent;\r
- }\r
- return null;\r
- } else if (n == 2) { //current or previous when in empty space\r
- return currEvent;\r
- }\r
-\r
- return null;\r
- }\r
-\r
- /**\r
- * Pretty-print a method signature.\r
- *\r
- * @param sig\r
- * The original signature\r
- * @return The pretty signature\r
- */\r
- static public String fixMethodSignature(String sig) {\r
- int pos = sig.indexOf('(');\r
- if (pos >= 0) {\r
- String ret = sig.substring(0, pos);\r
- sig = sig.substring(pos);\r
- sig = sig + " " + ret; //$NON-NLS-1$\r
- }\r
- return sig;\r
- }\r
-\r
- /**\r
- * Restore an original method signature from a pretty-printed one.\r
- *\r
- * @param sig\r
- * The pretty-printed signature\r
- * @return The original method signature\r
- */\r
- static public String restoreMethodSignature(String sig) {\r
- String ret = ""; //$NON-NLS-1$\r
- int pos = sig.indexOf('(');\r
- if (pos >= 0) {\r
- ret = sig.substring(0, pos);\r
- sig = sig.substring(pos + 1);\r
- }\r
- pos = sig.indexOf(')');\r
- if (pos >= 0) {\r
- sig = sig.substring(0, pos);\r
- }\r
- String args[] = sig.split(","); //$NON-NLS-1$\r
- StringBuffer result = new StringBuffer("("); //$NON-NLS-1$\r
- for (int i = 0; i < args.length; i++) {\r
- String arg = args[i].trim();\r
- if (arg.length() == 0 && args.length == 1) {\r
- break;\r
- }\r
- result.append(getTypeSignature(arg));\r
- }\r
- result.append(")").append(getTypeSignature(ret)); //$NON-NLS-1$\r
- return result.toString();\r
- }\r
-\r
- /**\r
- * Get the mangled type information from an array of types.\r
- *\r
- * @param type\r
- * The types to convert. See method implementation for what it\r
- * expects.\r
- * @return The mangled string of types\r
- */\r
- static public String getTypeSignature(String type) {\r
- int dim = 0;\r
- for (int j = 0; j < type.length(); j++) {\r
- if (type.charAt(j) == '[') {\r
- dim++;\r
- }\r
- }\r
- int pos = type.indexOf('[');\r
- if (pos >= 0) {\r
- type = type.substring(0, pos);\r
- }\r
- StringBuffer sig = new StringBuffer(""); //$NON-NLS-1$\r
- for (int j = 0; j < dim; j++)\r
- {\r
- sig.append("["); //$NON-NLS-1$\r
- }\r
- if (type.equals("boolean")) { //$NON-NLS-1$\r
- sig.append('Z');\r
- } else if (type.equals("byte")) { //$NON-NLS-1$\r
- sig.append('B');\r
- } else if (type.equals("char")) { //$NON-NLS-1$\r
- sig.append('C');\r
- } else if (type.equals("short")) { //$NON-NLS-1$\r
- sig.append('S');\r
- } else if (type.equals("int")) { //$NON-NLS-1$\r
- sig.append('I');\r
- } else if (type.equals("long")) { //$NON-NLS-1$\r
- sig.append('J');\r
- } else if (type.equals("float")) { //$NON-NLS-1$\r
- sig.append('F');\r
- } else if (type.equals("double")) { //$NON-NLS-1$\r
- sig.append('D');\r
- } else if (type.equals("void")) { //$NON-NLS-1$\r
- sig.append('V');\r
- }\r
- else {\r
- sig.append('L').append(type.replace('.', '/')).append(';');\r
- }\r
- return sig.toString();\r
- }\r
-\r
- /**\r
- * Compare two doubles together.\r
- *\r
- * @param d1\r
- * First double\r
- * @param d2\r
- * Second double\r
- * @return 1 if they are different, and 0 if they are *exactly* the same.\r
- * Because of the way doubles are stored, it's possible for the\r
- * same number obtained in two different ways to actually look\r
- * different.\r
- */\r
- static public int compare(double d1, double d2) {\r
- if (d1 > d2) {\r
- return 1;\r
- }\r
- if (d1 < d2) {\r
- return 1;\r
- }\r
- return 0;\r
- }\r
-\r
- /**\r
- * Compare two character strings alphabetically. This is simply a wrapper\r
- * around String.compareToIgnoreCase but that will handle cases where\r
- * strings can be null\r
- *\r
- * @param s1\r
- * The first string\r
- * @param s2\r
- * The second string\r
- * @return A number below, equal, or greater than zero if the first string\r
- * is smaller, equal, or bigger (alphabetically) than the second\r
- * one.\r
- */\r
- static public int compare(String s1, String s2) {\r
- if (s1 != null && s2 != null) {\r
- return s1.compareToIgnoreCase(s2);\r
- }\r
- if (s1 != null) {\r
- return 1;\r
- }\r
- if (s2 != null) {\r
- return -1;\r
- }\r
- return 0;\r
- }\r
-}\r
+/*****************************************************************************
+ * Copyright (c) 2007, 2008 Intel Corporation, 2009, 2012 Ericsson.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ * Ruslan A. Scherbakov, Intel - Initial API and implementation
+ * Alvaro Sanchez-Leon - Udpated for TMF
+ * Patrick Tasse - Refactoring
+ *
+ *****************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Iterator;
+
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Device;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * General utilities and definitions used by the time graph widget
+ *
+ * @version 1.0
+ * @author Alvaro Sanchez-Leon
+ * @author Patrick Tasse
+ */
+public class Utils {
+
+ /** Time format for dates and timestamp */
+ public enum TimeFormat {
+ /** Relative to the start of the trace */
+ RELATIVE,
+ /** Absolute timestamp (ie, relative to the Unix epoch) */
+ ABSOLUTE
+ }
+
+ static public final int IMG_THREAD_RUNNING = 0;
+ static public final int IMG_THREAD_SUSPENDED = 1;
+ static public final int IMG_THREAD_STOPPED = 2;
+ static public final int IMG_METHOD_RUNNING = 3;
+ static public final int IMG_METHOD = 4;
+ static public final int IMG_NUM = 5;
+
+ static public final Object[] _empty = new Object[0];
+
+ public static enum Resolution {
+ SECONDS, MILLISEC, MICROSEC, NANOSEC
+ }
+
+ static private final SimpleDateFormat stimeformat = new SimpleDateFormat("HH:mm:ss"); //$NON-NLS-1$
+ static private final SimpleDateFormat sdateformat = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$
+
+ static Rectangle clone(Rectangle source) {
+ return new Rectangle(source.x, source.y, source.width, source.height);
+ }
+
+ /**
+ * Initialize a Rectangle object to default values (all equal to 0)
+ *
+ * @param rect
+ * The Rectangle to initialize
+ */
+ static public void init(Rectangle rect) {
+ rect.x = 0;
+ rect.y = 0;
+ rect.width = 0;
+ rect.height = 0;
+ }
+
+ /**
+ * Initialize a Rectangle object with all the given values
+ *
+ * @param rect
+ * The Rectangle object to initialize
+ * @param x
+ * The X coordinate
+ * @param y
+ * The Y coordinate
+ * @param width
+ * The width of the rectangle
+ * @param height
+ * The height of the rectangle
+ */
+ static public void init(Rectangle rect, int x, int y, int width, int height) {
+ rect.x = x;
+ rect.y = y;
+ rect.width = width;
+ rect.height = height;
+ }
+
+ /**
+ * Initialize a Rectangle object to another existing Rectangle's values.
+ *
+ * @param rect
+ * The Rectangle to initialize
+ * @param source
+ * The reference Rectangle to copy
+ */
+ static public void init(Rectangle rect, Rectangle source) {
+ rect.x = source.x;
+ rect.y = source.y;
+ rect.width = source.width;
+ rect.height = source.height;
+ }
+
+ /**
+ * Reduce the size of a given rectangle by the given amounts.
+ *
+ * @param rect
+ * The rectangle to modify
+ * @param x
+ * The reduction in width
+ * @param y
+ * The reduction in height
+ */
+ static public void deflate(Rectangle rect, int x, int y) {
+ rect.x += x;
+ rect.y += y;
+ rect.width -= x + x;
+ rect.height -= y + y;
+ }
+
+ /**
+ * Increase the size of a given rectangle by the given amounts.
+ *
+ * @param rect
+ * The rectangle to modify
+ * @param x
+ * The augmentation in width
+ * @param y
+ * The augmentation in height
+ */
+ static public void inflate(Rectangle rect, int x, int y) {
+ rect.x -= x;
+ rect.y -= y;
+ rect.width += x + x;
+ rect.height += y + y;
+ }
+
+ static void dispose(Color col) {
+ if (null != col) {
+ col.dispose();
+ }
+ }
+
+ /**
+ * Get the resulting color from a mix of two existing ones for a given
+ * display.
+ *
+ * @param display
+ * The display device (which might affect the color conversion)
+ * @param c1
+ * The first color
+ * @param c2
+ * The second color
+ * @param w1
+ * The gamma level for color 1
+ * @param w2
+ * The gamma level for color 2
+ * @return The resulting color
+ */
+ static public Color mixColors(Device display, Color c1, Color c2, int w1,
+ int w2) {
+ return new Color(display, (w1 * c1.getRed() + w2 * c2.getRed())
+ / (w1 + w2), (w1 * c1.getGreen() + w2 * c2.getGreen())
+ / (w1 + w2), (w1 * c1.getBlue() + w2 * c2.getBlue())
+ / (w1 + w2));
+ }
+
+ /**
+ * Get the system color with the given ID.
+ *
+ * @param id
+ * The color ID
+ * @return The resulting color
+ */
+ static public Color getSysColor(int id) {
+ Color col = Display.getCurrent().getSystemColor(id);
+ return new Color(col.getDevice(), col.getRGB());
+ }
+
+ /**
+ * Get the resulting color from a mix of two existing ones for the current
+ * display.
+ *
+ * @param col1
+ * The first color
+ * @param col2
+ * The second color
+ * @param w1
+ * The gamma level for color 1
+ * @param w2
+ * The gamma level for color 2
+ * @return The resulting color
+ */
+ static public Color mixColors(Color col1, Color col2, int w1, int w2) {
+ return mixColors(Display.getCurrent(), col1, col2, w1, w2);
+ }
+
+ /**
+ * Draw text in a rectangle.
+ *
+ * @param gc
+ * The SWT GC object
+ * @param text
+ * The text to draw
+ * @param rect
+ * The rectangle object which is being drawn
+ * @param transp
+ * Should we transpose the color
+ * @return The X coordinate where we have written
+ */
+ static public int drawText(GC gc, String text, Rectangle rect, boolean transp) {
+ Point size = gc.stringExtent(text);
+ gc.drawText(text, rect.x, rect.y, transp);
+ return size.x;
+ }
+
+ /**
+ * Draw text at a given location.
+ *
+ * @param gc
+ * The SWT GC object
+ * @param text
+ * The text to draw
+ * @param x
+ * The X coordinate of the starting point
+ * @param y
+ * the Y coordinate of the starting point
+ * @param transp
+ * Should we transpose the color
+ * @return The X coordinate where we have written
+ */
+ static public int drawText(GC gc, String text, int x, int y, boolean transp) {
+ Point size = gc.stringExtent(text);
+ gc.drawText(text, x, y, transp);
+ return size.x;
+ }
+
+ /**
+ * Formats time in format: MM:SS:NNN
+ *
+ * @param time time
+ * @param format 0: MMMM:ss:nnnnnnnnn, 1: HH:MM:ss MMM.mmmm.nnn
+ * @param resolution the resolution
+ * @return the formatted time
+ */
+ static public String formatTime(long time, TimeFormat format, Resolution resolution) {
+ // if format is absolute (Calendar)
+ if (format == TimeFormat.ABSOLUTE) {
+ return formatTimeAbs(time, resolution);
+ }
+
+ StringBuffer str = new StringBuffer();
+ boolean neg = time < 0;
+ if (neg) {
+ time = -time;
+ str.append('-');
+ }
+
+ long sec = (long) (time * 1E-9);
+ // TODO: Expand to make it possible to select the minute, second, nanosecond format
+ //printing minutes is suppressed just sec and ns
+ // if (sec / 60 < 10)
+ // str.append('0');
+ // str.append(sec / 60);
+ // str.append(':');
+ // sec %= 60;
+ // if (sec < 10)
+ // str.append('0');
+ str.append(sec);
+ String ns = formatNs(time, resolution);
+ if (!ns.equals("")) { //$NON-NLS-1$
+ str.append('.');
+ str.append(ns);
+ }
+
+ return str.toString();
+ }
+
+ /**
+ * From input time in nanoseconds, convert to Date format YYYY-MM-dd
+ *
+ * @param absTime
+ * The source time, in ns
+ * @return the formatted date
+ */
+ public static String formatDate(long absTime) {
+ String sdate = sdateformat.format(new Date((long) (absTime * 1E-6)));
+ return sdate;
+ }
+
+ /**
+ * Formats time in ns to Calendar format: HH:MM:SS MMM.mmm.nnn
+ *
+ * @param time
+ * The source time, in ns
+ * @param res
+ * The resolution to use
+ * @return the formatted time
+ */
+ static public String formatTimeAbs(long time, Resolution res) {
+ StringBuffer str = new StringBuffer();
+
+ // format time from nanoseconds to calendar time HH:MM:SS
+ String stime = stimeformat.format(new Date((long) (time * 1E-6)));
+ str.append(stime);
+ str.append('.');
+ // append the Milliseconds, MicroSeconds and NanoSeconds as specified in
+ // the Resolution
+ str.append(formatNs(time, res));
+ return str.toString();
+ }
+
+ /**
+ * Obtains the remainder fraction on unit Seconds of the entered value in
+ * nanoseconds. e.g. input: 1241207054171080214 ns The number of fraction
+ * seconds can be obtained by removing the last 9 digits: 1241207054 the
+ * fractional portion of seconds, expressed in ns is: 171080214
+ *
+ * @param time
+ * The source time in ns
+ * @param res
+ * The Resolution to use
+ * @return the formatted nanosec
+ */
+ public static String formatNs(long time, Resolution res) {
+ StringBuffer str = new StringBuffer();
+ boolean neg = time < 0;
+ if (neg) {
+ time = -time;
+ }
+
+ // The following approach could be used although performance
+ // decreases in half.
+ // String strVal = String.format("%09d", time);
+ // String tmp = strVal.substring(strVal.length() - 9);
+
+ long ns = time;
+ ns %= 1000000000;
+ if (ns < 10) {
+ str.append("00000000"); //$NON-NLS-1$
+ } else if (ns < 100) {
+ str.append("0000000"); //$NON-NLS-1$
+ } else if (ns < 1000) {
+ str.append("000000"); //$NON-NLS-1$
+ } else if (ns < 10000) {
+ str.append("00000"); //$NON-NLS-1$
+ } else if (ns < 100000) {
+ str.append("0000"); //$NON-NLS-1$
+ } else if (ns < 1000000) {
+ str.append("000"); //$NON-NLS-1$
+ } else if (ns < 10000000) {
+ str.append("00"); //$NON-NLS-1$
+ } else if (ns < 100000000) {
+ str.append("0"); //$NON-NLS-1$
+ }
+ str.append(ns);
+
+ if (res == Resolution.MILLISEC) {
+ return str.substring(0, 3);
+ } else if (res == Resolution.MICROSEC) {
+ return str.substring(0, 6);
+ } else if (res == Resolution.NANOSEC) {
+ return str.substring(0, 9);
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ /**
+ * FIXME Currently does nothing.
+ *
+ * @param opt
+ * The option name
+ * @param def
+ * The option value
+ * @param min
+ * The minimal accepted value
+ * @param max
+ * The maximal accepted value
+ * @return The value that was read
+ */
+ static public int loadIntOption(String opt, int def, int min, int max) {
+ // int val =
+ // TraceUIPlugin.getDefault().getPreferenceStore().getInt(opt);
+ // if (0 == val)
+ // val = def;
+ // if (val < min)
+ // val = min;
+ // if (val > max)
+ // val = max;
+ return def;
+ }
+
+ /**
+ * FIXME currently does nothing
+ *
+ * @param opt
+ * The option name
+ * @param val
+ * The option value
+ */
+ static public void saveIntOption(String opt, int val) {
+ // TraceUIPlugin.getDefault().getPreferenceStore().setValue(opt, val);
+ }
+
+ static ITimeEvent getFirstEvent(ITimeGraphEntry entry) {
+ if (null == entry || ! entry.hasTimeEvents()) {
+ return null;
+ }
+ Iterator<ITimeEvent> iterator = entry.getTimeEventsIterator();
+ if (iterator != null && iterator.hasNext()) {
+ return iterator.next();
+ }
+ return null;
+ }
+
+ /**
+ * N means: <list> <li>-1: Previous Event</li> <li>0: Current Event</li> <li>
+ * 1: Next Event</li> <li>2: Previous Event when located in a non Event Area
+ * </list>
+ *
+ * @param entry
+ * @param time
+ * @param n
+ * @return
+ */
+ static ITimeEvent findEvent(ITimeGraphEntry entry, long time, int n) {
+ if (null == entry || ! entry.hasTimeEvents()) {
+ return null;
+ }
+ Iterator<ITimeEvent> iterator = entry.getTimeEventsIterator();
+ if (iterator == null) {
+ return null;
+ }
+ ITimeEvent nextEvent = null;
+ ITimeEvent currEvent = null;
+ ITimeEvent prevEvent = null;
+
+ while (iterator.hasNext()) {
+ nextEvent = iterator.next();
+ long nextStartTime = nextEvent.getTime();
+
+ if (nextStartTime > time) {
+ break;
+ }
+
+ if (currEvent == null || currEvent.getTime() != nextStartTime) {
+ prevEvent = currEvent;
+ currEvent = nextEvent;
+ }
+ }
+
+ if (n == -1) { //previous
+ if (currEvent != null && currEvent.getTime() + currEvent.getDuration() >= time) {
+ return prevEvent;
+ }
+ return currEvent;
+ } else if (n == 0) { //current
+ if (currEvent != null && currEvent.getTime() + currEvent.getDuration() >= time) {
+ return currEvent;
+ }
+ return null;
+ } else if (n == 1) { //next
+ if (nextEvent != null && nextEvent.getTime() > time) {
+ return nextEvent;
+ }
+ return null;
+ } else if (n == 2) { //current or previous when in empty space
+ return currEvent;
+ }
+
+ return null;
+ }
+
+ /**
+ * Pretty-print a method signature.
+ *
+ * @param sig
+ * The original signature
+ * @return The pretty signature
+ */
+ static public String fixMethodSignature(String sig) {
+ int pos = sig.indexOf('(');
+ if (pos >= 0) {
+ String ret = sig.substring(0, pos);
+ sig = sig.substring(pos);
+ sig = sig + " " + ret; //$NON-NLS-1$
+ }
+ return sig;
+ }
+
+ /**
+ * Restore an original method signature from a pretty-printed one.
+ *
+ * @param sig
+ * The pretty-printed signature
+ * @return The original method signature
+ */
+ static public String restoreMethodSignature(String sig) {
+ String ret = ""; //$NON-NLS-1$
+ int pos = sig.indexOf('(');
+ if (pos >= 0) {
+ ret = sig.substring(0, pos);
+ sig = sig.substring(pos + 1);
+ }
+ pos = sig.indexOf(')');
+ if (pos >= 0) {
+ sig = sig.substring(0, pos);
+ }
+ String args[] = sig.split(","); //$NON-NLS-1$
+ StringBuffer result = new StringBuffer("("); //$NON-NLS-1$
+ for (int i = 0; i < args.length; i++) {
+ String arg = args[i].trim();
+ if (arg.length() == 0 && args.length == 1) {
+ break;
+ }
+ result.append(getTypeSignature(arg));
+ }
+ result.append(")").append(getTypeSignature(ret)); //$NON-NLS-1$
+ return result.toString();
+ }
+
+ /**
+ * Get the mangled type information from an array of types.
+ *
+ * @param type
+ * The types to convert. See method implementation for what it
+ * expects.
+ * @return The mangled string of types
+ */
+ static public String getTypeSignature(String type) {
+ int dim = 0;
+ for (int j = 0; j < type.length(); j++) {
+ if (type.charAt(j) == '[') {
+ dim++;
+ }
+ }
+ int pos = type.indexOf('[');
+ if (pos >= 0) {
+ type = type.substring(0, pos);
+ }
+ StringBuffer sig = new StringBuffer(""); //$NON-NLS-1$
+ for (int j = 0; j < dim; j++)
+ {
+ sig.append("["); //$NON-NLS-1$
+ }
+ if (type.equals("boolean")) { //$NON-NLS-1$
+ sig.append('Z');
+ } else if (type.equals("byte")) { //$NON-NLS-1$
+ sig.append('B');
+ } else if (type.equals("char")) { //$NON-NLS-1$
+ sig.append('C');
+ } else if (type.equals("short")) { //$NON-NLS-1$
+ sig.append('S');
+ } else if (type.equals("int")) { //$NON-NLS-1$
+ sig.append('I');
+ } else if (type.equals("long")) { //$NON-NLS-1$
+ sig.append('J');
+ } else if (type.equals("float")) { //$NON-NLS-1$
+ sig.append('F');
+ } else if (type.equals("double")) { //$NON-NLS-1$
+ sig.append('D');
+ } else if (type.equals("void")) { //$NON-NLS-1$
+ sig.append('V');
+ }
+ else {
+ sig.append('L').append(type.replace('.', '/')).append(';');
+ }
+ return sig.toString();
+ }
+
+ /**
+ * Compare two doubles together.
+ *
+ * @param d1
+ * First double
+ * @param d2
+ * Second double
+ * @return 1 if they are different, and 0 if they are *exactly* the same.
+ * Because of the way doubles are stored, it's possible for the
+ * same number obtained in two different ways to actually look
+ * different.
+ */
+ static public int compare(double d1, double d2) {
+ if (d1 > d2) {
+ return 1;
+ }
+ if (d1 < d2) {
+ return 1;
+ }
+ return 0;
+ }
+
+ /**
+ * Compare two character strings alphabetically. This is simply a wrapper
+ * around String.compareToIgnoreCase but that will handle cases where
+ * strings can be null
+ *
+ * @param s1
+ * The first string
+ * @param s2
+ * The second string
+ * @return A number below, equal, or greater than zero if the first string
+ * is smaller, equal, or bigger (alphabetically) than the second
+ * one.
+ */
+ static public int compare(String s1, String s2) {
+ if (s1 != null && s2 != null) {
+ return s1.compareToIgnoreCase(s2);
+ }
+ if (s1 != null) {
+ return 1;
+ }
+ if (s2 != null) {
+ return -1;
+ }
+ return 0;
+ }
+}
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Matthew Khouzam - Extracted from TmfEventsView\r
- ******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.virtualtable;\r
-/**\r
- * ColumnData\r
- * @author Matthew Khouzam\r
- * @version 1.0\r
- *\r
- */\r
-public class ColumnData {\r
- /**\r
- * The title of the column\r
- */\r
- public final String header;\r
- /**\r
- * the width of the column in pixels\r
- */\r
- public final int width;\r
- /**\r
- * the alignment of the column\r
- */\r
- public final int alignment;\r
-\r
- /**\r
- * Constructor\r
- * @param h header (title)\r
- * @param w width\r
- * @param a alignment\r
- */\r
- public ColumnData(String h, int w, int a) {\r
- header = h;\r
- width = w;\r
- alignment = a;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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:
+ * Matthew Khouzam - Extracted from TmfEventsView
+ ******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.virtualtable;
+/**
+ * ColumnData
+ * @author Matthew Khouzam
+ * @version 1.0
+ *
+ */
+public class ColumnData {
+ /**
+ * The title of the column
+ */
+ public final String header;
+ /**
+ * the width of the column in pixels
+ */
+ public final int width;
+ /**
+ * the alignment of the column
+ */
+ public final int alignment;
+
+ /**
+ * Constructor
+ * @param h header (title)
+ * @param w width
+ * @param a alignment
+ */
+ public ColumnData(String h, int w, int a) {
+ header = h;
+ width = w;
+ alignment = a;
+ }
+
+}