*******************************************************************************/
package org.eclipse.tracecompass.tmf.ui.tests.views.uml2sd.loader;
+import static org.junit.Assert.assertNotNull;
+
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.swt.widgets.Display;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
import org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub;
+import org.eclipse.tracecompass.tmf.ui.tests.shared.JobUtils;
import org.eclipse.tracecompass.tmf.ui.tests.uml2sd.trace.TmfUml2SDTestTrace;
import org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView;
import org.eclipse.tracecompass.tmf.ui.views.uml2sd.dialogs.Criteria;
*/
public class Uml2SDTestFacility {
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+ private static final String SD_VIEW_ID = "org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView";
+
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
private Uml2SDTestFacility() {
+ fParser = new TmfUml2SDTestTrace();
+ fTrace = setupTrace(fParser);
+ fParser.setTrace(fTrace);
}
// ------------------------------------------------------------------------
public synchronized static Uml2SDTestFacility getInstance() {
if (fInstance == null) {
fInstance = new Uml2SDTestFacility();
- fInstance.init();
}
return fInstance;
}
public void init() {
if (!fIsInitialized) {
-
- fParser = new TmfUml2SDTestTrace();
- fTrace = setupTrace(fParser);
- fParser.setTrace(fTrace);
-
IViewPart view;
try {
// Remove welcome view to avoid interference during test execution
- 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("org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView");
-
+ hideView("org.eclipse.ui.internal.introview");
+ view = showView(SD_VIEW_ID);
} catch (final PartInitException e) {
throw new RuntimeException(e);
}
fLoader = (TmfUml2SDSyncLoader) LoadersManager.getInstance().createLoader(
"org.eclipse.tracecompass.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader", fSdView);
- delay(3000);
fIsInitialized = true;
}
}
-
private TmfTraceStub setupTrace(final ITmfEventParser parser) {
try {
*/
public void dispose() {
if (fIsInitialized) {
- ITmfTrace trace = fTrace;
- TmfExperiment experiment = fExperiment;
- if (trace == null || experiment == null) {
- throw new IllegalStateException();
- }
-
- trace.broadcast(new TmfTraceClosedSignal(this, experiment));
- experiment.dispose();
-
// Wait for all Eclipse jobs to finish
waitForJobs();
-
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fSdView);
+ hideView(SD_VIEW_ID);
+ delay(200);
fIsInitialized = false;
}
}
}
}
+ /**
+ * Waits for a view to be closed
+ *
+ * @param viewId
+ * a view id
+ */
+ public void waitForViewClosed(String viewId) {
+ for (int i = 1; i < 5000 && (getViewPart(viewId) != null); i *= 2) {
+ delay(i);
+ }
+ }
+
+ /**
+ * Waits for a view to be opened
+ *
+ * @param viewId
+ * a view id
+ */
+ public void waitForViewOpened(String viewId) {
+ for (int i = 1; i < 5000 && (getViewPart(viewId) == null); i *= 2) {
+ delay(i);
+ }
+ }
+
+ private IViewPart showView(String viewId) throws PartInitException {
+ IViewPart view = getViewPart(viewId);
+
+ if (view == null) {
+ view = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow()
+ .getActivePage().showView(viewId);
+
+ waitForViewOpened(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);
+ }
+
/**
* Waits for all Eclipse jobs to finish
*/
public void waitForJobs() {
- while (!Job.getJobManager().isIdle()) {
- delay(IUml2SDTestConstants.WAIT_FOR_JOBS_DELAY);
- }
+ JobUtils.waitForJobs();
}
/**