import java.util.Arrays;
import java.util.List;
import java.util.Objects;
+import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType;
import org.eclipse.swtbot.swt.finder.results.ArrayResult;
import org.eclipse.swtbot.swt.finder.results.IntResult;
+import org.eclipse.swtbot.swt.finder.results.ListResult;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.utils.TableCollection;
import org.eclipse.swtbot.swt.finder.utils.TableRow;
import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
+import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
* if the entry was not found.
*/
public SWTBotTimeGraphEntry getEntry(String... names) throws WidgetNotFoundException {
- List<ITimeGraphEntry> entries = Arrays.asList(widget.getExpandedElements());
- ITableLabelProvider labelProvider = widget.getLabelProvider();
- ITimeGraphEntry parent = null;
- for (String name : names) {
- boolean found = false;
- for (ITimeGraphEntry entry : entries) {
- String label = labelProvider == null ? entry.getName() : labelProvider.getColumnText(entry, 0);
- if (Objects.equals(entry.getParent(), parent) && name.equals(label)) {
- parent = entry;
- found = true;
- break;
+ AtomicReference<ITimeGraphEntry> parent = new AtomicReference<>();
+ AtomicReference<String> missing = new AtomicReference<>();
+ WaitUtils.waitUntil(timegraph -> {
+ List<ITimeGraphEntry> entries = syncExec(new ListResult<ITimeGraphEntry>() {
+ @Override
+ public List<ITimeGraphEntry> run() {
+ return Arrays.asList(timegraph.getExpandedElements());
+ }
+ });
+ ITableLabelProvider labelProvider = timegraph.getLabelProvider();
+ for (String name : names) {
+ boolean found = false;
+ for (ITimeGraphEntry entry : entries) {
+ String label = labelProvider == null ? entry.getName() : labelProvider.getColumnText(entry, 0);
+ if (Objects.equals(entry.getParent(), parent.get()) && name.equals(label)) {
+ parent.set(entry);
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ missing.set(name);
+ return false;
}
}
- if (!found) {
- throw new WidgetNotFoundException("Timed out waiting for time graph entry " + name); //$NON-NLS-1$
- }
- }
- return new SWTBotTimeGraphEntry(widget, parent);
+ return true;
+ }, widget, "Timed out waiting for time graph entry " + missing.get());
+ return new SWTBotTimeGraphEntry(widget, parent.get());
}
/**
package org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.ArrayResult;
+import org.eclipse.swtbot.swt.finder.results.ListResult;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.waits.WaitForObjectCondition;
import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotRootMenu;
+import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
* @return the child entry
*/
public SWTBotTimeGraphEntry getEntry(String name) {
- return syncExec(new Result<SWTBotTimeGraphEntry>() {
- @Override
- public SWTBotTimeGraphEntry run() {
- ITableLabelProvider labelProvider = widget.getLabelProvider();
- for (ITimeGraphEntry entry : widget.getExpandedElements()) {
- if (fEntry.equals(entry.getParent())) {
- String label = labelProvider == null ? entry.getName() : labelProvider.getColumnText(entry, 0);
- if (name.equals(label)) {
- return new SWTBotTimeGraphEntry(widget, entry);
- }
+ AtomicReference<ITimeGraphEntry> found = new AtomicReference<>();
+ WaitUtils.waitUntil(timegraph -> {
+ List<ITimeGraphEntry> entries = syncExec(new ListResult<ITimeGraphEntry>() {
+ @Override
+ public List<ITimeGraphEntry> run() {
+ return Arrays.asList(timegraph.getExpandedElements());
+ }
+ });
+ ITableLabelProvider labelProvider = timegraph.getLabelProvider();
+ for (ITimeGraphEntry entry : entries) {
+ if (fEntry.equals(entry.getParent())) {
+ String label = labelProvider == null ? entry.getName() : labelProvider.getColumnText(entry, 0);
+ if (name.equals(label)) {
+ found.set(entry);
+ return true;
}
}
- throw new WidgetNotFoundException("Timed out waiting for time graph entry " + name); //$NON-NLS-1$
}
- });
+ return false;
+ }, widget, "Timed out waiting for time graph entry " + name);
+ return new SWTBotTimeGraphEntry(widget, found.get());
}
/**