package org.eclipse.tracecompass.lttng2.control.ui.tests.model.component;
+import static org.junit.Assert.assertNotNull;
+
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.common.NotDefinedException;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.swt.widgets.Display;
import org.eclipse.tracecompass.internal.lttng2.control.core.model.TargetNodeState;
import org.eclipse.tracecompass.internal.lttng2.control.ui.views.ControlView;
import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
+import org.eclipse.tracecompass.tmf.ui.tests.shared.JobUtils;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
// ------------------------------------------------------------------------
private static TraceControlTestFacility fInstance = null;
private ControlView fControlView = null;
- private boolean fIsInitialized = false;
+ private volatile boolean fIsInitialized = false;
// ------------------------------------------------------------------------
// Constructors
public void init() {
if (!fIsInitialized) {
-
IViewPart view;
try {
-
- view = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow()
- .getActivePage()
- .findView("org.eclipse.ui.internal.introview");
-
- if (view != null) {
- PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow()
- .getActivePage().hideView(view);
- }
-
- view = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow()
- .getActivePage()
- .showView(ControlView.ID);
-
+ hideView("org.eclipse.ui.internal.introview");
+ view = showView(ControlView.ID);
} catch (PartInitException e) {
throw new RuntimeException(e);
}
-
fControlView = (ControlView) view;
- delay(3000);
+ /*
+ * It is possible that the connections are saved due to the
+ * auto-save feature of the workbench which calls
+ * ControlView.saveState(IMemento). This can happen at any
+ * time (e.g. when calling delay()).
+ *
+ * When showing the view above ControlView.init(IMemento) is
+ * called which restores saved connections.
+ *
+ * The tests require that the ControlView is empty. So
+ * we remove all the connection nodes from the root.
+ */
+ fControlView.getTraceControlRoot().removeAllChildren();
+
fIsInitialized = true;
}
}
-
/**
* Disposes the facility (and GUI)
*/
public void dispose() {
if (fIsInitialized) {
waitForJobs();
-
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fControlView);
+ hideView(ControlView.ID);
+ delay(200);
fIsInitialized = false;
}
}
}
}
+ /**
+ * Waits for a view to be closed
+ */
+ public void waitForViewClosed(String viewId) {
+ for (int i = 1; i < 5000 && (getViewPart(viewId) != null); i *= 2) {
+ delay(i);
+ }
+ }
+
+ /**
+ * Waits for a view to be closed
+ */
+ public void waitForViewOpend(String viewId) {
+ for (int i = 1; i < 5000 && (getViewPart(viewId) == null); i *= 2) {
+ delay(i);
+ }
+ }
+
/**
* Waits for all Eclipse jobs to finish
*/
public void waitForJobs() {
- while (!Job.getJobManager().isIdle()) {
- delay(WAIT_FOR_JOBS_DELAY);
+ JobUtils.waitForJobs();
+ }
+
+ private IViewPart showView(String viewId) throws PartInitException {
+ IViewPart view = getViewPart(viewId);
+
+ if (view == null) {
+ view = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow()
+ .getActivePage().showView(viewId);
+
+ waitForViewOpend(viewId);
}
+ assertNotNull(view);
+ return view;
+ }
+
+ private void hideView(String viewId) {
+ IViewPart view = getViewPart(viewId);
+ if (view != null) {
+ PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow()
+ .getActivePage().hideView(view);
+ }
+ waitForViewClosed(viewId);
+ }
+
+ private static IViewPart getViewPart(String viewId) {
+ return PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow()
+ .getActivePage()
+ .findView(viewId);
}
/**