Search in sources :

Example 1 with SDView

use of org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView in project tracecompass by tracecompass.

the class SDViewTest method testSDView.

/**
 * Test Sequence diagram view, counting the columns
 */
@Test
public void testSDView() {
    SWTBotView viewBot = fBot.viewById(UML2DVIEW_ID);
    SWTBotCanvas timeCompressionBar = viewBot.bot().canvas(0);
    SWTBotCanvas sdWidget = viewBot.bot().canvas(1);
    assertNotNull(viewBot);
    viewBot.setFocus();
    WaitUtils.waitForJobs();
    List<SWTBotToolbarButton> viewButtons = viewBot.getToolbarButtons();
    List<String> titles = new ArrayList<>();
    for (SWTBotToolbarButton buttonBot : viewButtons) {
        titles.add(buttonBot.getToolTipText());
    }
    final char commandKeyChar = (char) 0x2318;
    final String findShortcut = (Platform.getOS().equals(Platform.OS_MACOSX) ? commandKeyChar : "Ctrl+") + "F";
    String[] expected = { "Reset zoom factor", "Select", "Zoom in the diagram", "Zoom out the diagram", "Go to next page", "Go to previous page", "Go to first page", "Go to last page", "Find... (" + findShortcut + ")" };
    assertArrayEquals("Buttons", expected, titles.toArray(new String[0]));
    SDView view = (SDView) viewBot.getViewReference().getPart(false);
    ISDAdvancedPagingProvider pagingProvider = (ISDAdvancedPagingProvider) view.getSDPagingProvider();
    Frame frame = view.getFrame();
    assertEquals(2, frame.lifeLinesCount());
    timeCompressionBar.click();
    // Zoom in page using toolbar buttons
    viewBot.toolbarButton("Select").click();
    sdWidget.click(0, 0);
    viewBot.toolbarButton("Zoom in the diagram").click();
    sdWidget.click();
    sdWidget.click();
    viewBot.toolbarButton("Zoom out the diagram").click();
    sdWidget.click();
    viewBot.toolbarButton("Reset zoom factor").click();
    sdWidget.click();
    // Zoom in page using view menu
    viewBot.viewMenu("Select").click();
    sdWidget.click(0, 0);
    viewBot.viewMenu("Zoom in").click();
    sdWidget.click();
    sdWidget.click();
    viewBot.viewMenu("Zoom out").click();
    sdWidget.click();
    viewBot.viewMenu("Reset zoom factor").click();
    sdWidget.click();
    assertEquals(0, pagingProvider.currentPage());
    viewBot.toolbarButton("Find... (" + findShortcut + ")").click();
    SWTBot findDialogBot = fBot.shell("Sequence Diagram Find").bot();
    findDialogBot.comboBox().setText("peer2");
    findDialogBot.checkBox("Lifeline").select();
    findDialogBot.checkBox("Interaction").deselect();
    findDialogBot.button("Find").click();
    findDialogBot.button("Close").click();
    SWTBotUtils.waitUntil(f -> f.getLifeline(1).isSelected(), frame, "Did not find lifeline");
    assertEquals(0, pagingProvider.currentPage());
    // Shell focus required to enable tool item shortcut
    viewBot.setFocus();
    viewBot.toolbarButton("Find... (" + findShortcut + ")").click();
    findDialogBot = fBot.shell("Sequence Diagram Find").bot();
    findDialogBot.comboBox().setText("1001");
    findDialogBot.checkBox("Lifeline").deselect();
    findDialogBot.checkBox("Interaction").select();
    findDialogBot.button("Find").click();
    findDialogBot.button("Close").click();
    SWTBotUtils.waitUntil(f -> f.getSyncMessage(1).isSelected(), frame, "Did not find interaction");
    viewBot.viewMenu("Hide Patterns...").click();
    SWTBot hideDialogBot = fBot.shell("Sequence Diagram Hide Patterns").bot();
    hideDialogBot.button("Add...").click();
    SWTBot definitionBot = fBot.shell("Definition of Hide Pattern").bot();
    definitionBot.comboBox().setText("peer2");
    definitionBot.checkBox("Lifeline").select();
    definitionBot.checkBox("Interaction").deselect();
    definitionBot.button("Create").click();
    hideDialogBot.button("OK").click();
    SWTBotUtils.waitUntil(v -> v.getFrame().lifeLinesCount() == 1, view, "Did not hide lifeline");
    viewBot.viewMenu("Hide Patterns...").click();
    hideDialogBot = fBot.shell("Sequence Diagram Hide Patterns").bot();
    hideDialogBot.table().select("hide peer2 [Lifeline]");
    hideDialogBot.button("Remove").click();
    hideDialogBot.button("OK").click();
    SWTBotUtils.waitUntil(v -> v.getFrame().lifeLinesCount() == 2, view, "Did not show lifeline");
    viewBot.viewMenu("Configure Min Max...").click();
    SWTBot configurationBot = fBot.shell("TimeCompression bar configuration").bot();
    configurationBot.textWithLabel("Max time").setText("200");
    configurationBot.button("OK").click();
    viewBot.viewMenu("Configure Min Max...").click();
    configurationBot = fBot.shell("TimeCompression bar configuration").bot();
    configurationBot.button("Default").click();
    configurationBot.button("OK").click();
    // Navigate pages using toolbar buttons
    assertEquals(0, pagingProvider.currentPage());
    viewBot.toolbarButton("Go to next page").click();
    SWTBotUtils.waitUntil(pp -> pp.currentPage() == 1, pagingProvider, "Did not change page");
    viewBot.toolbarButton("Go to previous page").click();
    SWTBotUtils.waitUntil(pp -> pp.currentPage() == 0, pagingProvider, "Did not change page");
    viewBot.toolbarButton("Go to last page").click();
    SWTBotUtils.waitUntil(pp -> pp.currentPage() == 1, pagingProvider, "Did not change page");
    viewBot.toolbarButton("Go to first page").click();
    SWTBotUtils.waitUntil(pp -> pp.currentPage() == 0, pagingProvider, "Did not change page");
    // Navigate pages using view menu
    assertEquals(0, pagingProvider.currentPage());
    viewBot.viewMenu("Next page").click();
    SWTBotUtils.waitUntil(pp -> pp.currentPage() == 1, pagingProvider, "Did not change page");
    viewBot.viewMenu("Previous page").click();
    SWTBotUtils.waitUntil(pp -> pp.currentPage() == 0, pagingProvider, "Did not change page");
    viewBot.viewMenu("Last page").click();
    SWTBotUtils.waitUntil(pp -> pp.currentPage() == 1, pagingProvider, "Did not change page");
    viewBot.viewMenu("First page").click();
    SWTBotUtils.waitUntil(pp -> pp.currentPage() == 0, pagingProvider, "Did not change page");
    viewBot.viewMenu("Pages...").click();
    SWTBot pagesBot = fBot.shell("Sequence Diagram Pages").bot();
    pagesBot.text().setText("2");
    pagesBot.button("OK").click();
    SWTBotUtils.waitUntil(pp -> pp.currentPage() == 1, pagingProvider, "Did not change page");
}
Also used : Frame(org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.Frame) SWTBot(org.eclipse.swtbot.swt.finder.SWTBot) ArrayList(java.util.ArrayList) SWTBotCanvas(org.eclipse.swtbot.swt.finder.widgets.SWTBotCanvas) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) ISDAdvancedPagingProvider(org.eclipse.tracecompass.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider) SWTBotToolbarButton(org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton) SDView(org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView) Test(org.junit.Test)

Example 2 with SDView

use of org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView in project tracecompass by tracecompass.

the class TmfUml2SDSyncLoader method loadTrace.

/**
 * Method for loading the current selected trace into the view. Sub-class
 * need to override this method to add the view specific implementation.
 */
protected void loadTrace() {
    ITmfEventRequest indexRequest = null;
    fLock.lock();
    try {
        // $NON-NLS-1$ //$NON-NLS-2$
        final Job job = new IndexingJob("Indexing " + getName() + "...");
        job.setUser(false);
        job.schedule();
        indexRequest = fIndexRequest;
        cancelOngoingRequests();
        TmfTimeRange window = TmfTimeRange.ETERNITY;
        fIndexRequest = new TmfEventRequest(ITmfEvent.class, window, 0, ITmfEventRequest.ALL_DATA, ITmfEventRequest.ExecutionType.BACKGROUND) {

            private ITmfTimestamp fFirstTime = null;

            private ITmfTimestamp fLastTime = null;

            private int fNbSeqEvents = 0;

            private final List<ITmfSyncSequenceDiagramEvent> fSdEvents = new ArrayList<>(MAX_NUM_OF_MSG);

            @Override
            public void handleData(ITmfEvent event) {
                super.handleData(event);
                ITmfSyncSequenceDiagramEvent sdEvent = getSequenceDiagramEvent(event);
                ITmfTimestamp firstTime = fFirstTime;
                ITmfTimestamp lastTime = fLastTime;
                if (sdEvent != null) {
                    ++fNbSeqEvents;
                    if (firstTime == null) {
                        firstTime = event.getTimestamp();
                        fFirstTime = firstTime;
                    }
                    lastTime = event.getTimestamp();
                    fLastTime = lastTime;
                    if ((fNbSeqEvents % MAX_NUM_OF_MSG) == 0) {
                        fLock.lock();
                        try {
                            fCheckPoints.add(new TmfTimeRange(firstTime, lastTime));
                            if (fView != null) {
                                fView.updateCoolBar();
                            }
                        } finally {
                            fLock.unlock();
                        }
                        fFirstTime = null;
                    }
                    if (fNbSeqEvents > MAX_NUM_OF_MSG) {
                        // page is full
                        return;
                    }
                    fSdEvents.add(sdEvent);
                    if (fNbSeqEvents == MAX_NUM_OF_MSG) {
                        fillCurrentPage(fSdEvents);
                    }
                }
            }

            @Override
            public void handleSuccess() {
                final ITmfTimestamp firstTime = fFirstTime;
                final ITmfTimestamp lastTime = fLastTime;
                if ((firstTime != null) && (lastTime != null)) {
                    fLock.lock();
                    try {
                        fCheckPoints.add(new TmfTimeRange(firstTime, lastTime));
                        if (fView != null) {
                            fView.updateCoolBar();
                        }
                    } finally {
                        fLock.unlock();
                    }
                }
                if (fNbSeqEvents <= MAX_NUM_OF_MSG) {
                    fillCurrentPage(fSdEvents);
                }
                super.handleSuccess();
            }

            @Override
            public void handleCompleted() {
                if (fEvents.isEmpty()) {
                    fFrame = new Frame();
                    // make sure that view is not null when setting frame
                    SDView sdView;
                    fLock.lock();
                    try {
                        sdView = fView;
                    } finally {
                        fLock.unlock();
                    }
                    if (sdView != null) {
                        sdView.setFrameSync(fFrame);
                    }
                }
                super.handleCompleted();
                job.cancel();
            }
        };
    } finally {
        fLock.unlock();
    }
    if (indexRequest != null && !indexRequest.isCompleted()) {
        indexRequest.cancel();
    }
    resetLoader();
    fTrace.sendRequest(fIndexRequest);
}
Also used : Frame(org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.Frame) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) ITmfSyncSequenceDiagramEvent(org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) Job(org.eclipse.core.runtime.jobs.Job) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) SDView(org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView)

Example 3 with SDView

use of org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView in project tracecompass by tracecompass.

the class LoadersManagerTest method testLoaderManager.

/**
 * Tests of loader manager singleton class.
 */
@Test
public void testLoaderManager() {
    SDView view = null;
    try {
        /*
             * Test creation of a loader (one per SD view)
             */
        // Open view
        // Note this will create the default loader!
        view = (SDView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(SDVIEW_WITH_ONE_LOADER);
        IUml2SDLoader defaultLoader = LoadersManager.getInstance().getCurrentLoader(SDVIEW_WITH_ONE_LOADER, view);
        assertNotNull("testLoaderManager", defaultLoader);
        // Test createLoader where loader doesn't exist
        assertNull("testLoaderManager", LoadersManager.getInstance().createLoader("blabla", view));
        // Test createLoader
        IUml2SDLoader loader = LoadersManager.getInstance().createLoader(TEST_LOADER_CLASS_NAME, view);
        assertNotNull("testLoaderManager", loader);
        assertEquals("testLoaderManager", "Test Loader", loader.getTitleString());
        assertEquals("testLoaderManager", loader, LoadersManager.getInstance().getCurrentLoader(SDVIEW_WITH_ONE_LOADER));
        // compare loader and default loader. Even if they are the same class, they are different instances
        assertFalse("testLoaderManager", loader == defaultLoader);
        // test getCurrentLoader(viewId, view)
        IUml2SDLoader loader2 = LoadersManager.getInstance().getCurrentLoader(SDVIEW_WITH_ONE_LOADER, view);
        assertEquals("testLoaderManager", loader, loader2);
        // Hide the view
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(view);
        // test that view restores the previous associated loader
        view = (SDView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(SDVIEW_WITH_ONE_LOADER);
        // Well, this is the only way test which loader is set
        assertEquals("testLoaderManager", "Sequence Diagram - First Page", view.getFrame().getName());
        // Test view == null
        assertNull("testLoaderManager", LoadersManager.getInstance().createLoader(TEST_LOADER_CLASS_NAME, null));
        // Hide the view
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(view);
        /*
             * Test creation of loaders with re-uses the same SD view
             */
        // test that view restores the previous associated loader
        view = (SDView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(SDVIEW_WITH_MULTIPLE_LOADER);
        // Test that default loader is set. Note that 2 default loaders are define in the plugin.xml and the
        // the first one should be selected.
        // Well, this is the only way test which loader is set
        assertEquals("testLoaderManager", "Sequence Diagram - First Page", view.getFrame().getName());
        loader = LoadersManager.getInstance().getCurrentLoader(SDVIEW_WITH_MULTIPLE_LOADER, view);
        assertNotNull("testLoaderManager", loader);
        assertEquals("testLoaderManager", "Test Loader", loader.getTitleString());
        assertEquals("testLoaderManager", loader, LoadersManager.getInstance().getCurrentLoader(SDVIEW_WITH_MULTIPLE_LOADER));
        // Test createLoader for loader with class name TMF_UML2SD_LOADER_CLASS_NAME
        loader = LoadersManager.getInstance().createLoader(TMF_UML2SD_LOADER_CLASS_NAME, view);
        assertNotNull("testLoaderManager", loader);
        assertEquals("testLoaderManager", "Component Interactions", loader.getTitleString());
        assertEquals("testLoaderManager", loader, LoadersManager.getInstance().getCurrentLoader(SDVIEW_WITH_MULTIPLE_LOADER));
        // Verify if the correct loader is stored in the preferences as the current loader for this view
        assertEquals("testLoaderManager", TMF_UML2SD_LOADER_CLASS_NAME, getSavedLoader(SDVIEW_WITH_MULTIPLE_LOADER));
        // Test createLoader for loader with class name TEST_LOADER_CLASS_NAME
        loader = LoadersManager.getInstance().createLoader(TEST_LOADER_CLASS_NAME, view);
        assertNotNull("testLoaderManager", loader);
        assertEquals("testLoaderManager", "Test Loader", loader.getTitleString());
        assertEquals("testLoaderManager", loader, LoadersManager.getInstance().getCurrentLoader(SDVIEW_WITH_MULTIPLE_LOADER));
        // Verify if the correct loader is stored in the preferences as the current loader for this view
        assertEquals("testLoaderManager", TEST_LOADER_CLASS_NAME, getSavedLoader(SDVIEW_WITH_MULTIPLE_LOADER));
        assertEquals("testLoaderManager", TEST_LOADER_CLASS_NAME, LoadersManager.getInstance().getSavedLoader(SDVIEW_WITH_MULTIPLE_LOADER));
        // Hide the view
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(view);
        // Test reset loader
        LoadersManager.getInstance().resetLoader(SDVIEW_WITH_MULTIPLE_LOADER);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : IUml2SDLoader(org.eclipse.tracecompass.tmf.ui.views.uml2sd.load.IUml2SDLoader) SDView(org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView) Test(org.junit.Test)

Example 4 with SDView

use of org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView in project tracecompass by tracecompass.

the class LoadersManager method getCurrentLoader.

/**
 * Returns the loader in use in this Sequence Diagram View
 *
 * @param viewId The Sequence Diagram viewId
 * @param view The Sequence Diagram view (if known). Use null to reference the primary SD View.
 * @return the current loader if any - null otherwise
 */
public IUml2SDLoader getCurrentLoader(String viewId, SDView view) {
    if (viewId == null) {
        return null;
    }
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    // During Eclipse shutdown the active workbench window is null
    if (window == null) {
        return null;
    }
    IWorkbenchPage persp = window.getActivePage();
    SDView sdView = view;
    try {
        // Search the view corresponding to the viewId
        if (sdView == null) {
            IViewReference viewref = persp.findViewReference(viewId);
            if (viewref != null) {
                sdView = (SDView) viewref.getView(false);
            }
            if (sdView == null) {
                // no corresponding view exists -> return null for the loader
                return null;
            }
        }
        // Return the loader corresponding to that view (if any)
        IUml2SDLoader loader = fViewLoaderMap.get(viewId);
        if (loader == null) {
            createLastLoaderIfAny(viewId);
            loader = fViewLoaderMap.get(viewId);
        }
        return loader;
    } catch (Exception e) {
        // $NON-NLS-1$
        Activator.getDefault().logError("Error getting loader class", e);
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) CoreException(org.eclipse.core.runtime.CoreException) SDView(org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView)

Example 5 with SDView

use of org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView in project tracecompass by tracecompass.

the class LoadersManager method setCurrentLoader.

/**
 * Changes the current unique loader to the given secondary viewId.
 *
 * @param loader The current loader
 * @param id the view secondary id or null
 */
private void setCurrentLoader(IUml2SDLoader loader, String id) {
    if (id == null) {
        return;
    }
    // Get the loader in use
    IUml2SDLoader currentLoader = fViewLoaderMap.get(id);
    if ((currentLoader != null) && (currentLoader != loader)) {
        if (loader != null) {
            IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            // During Eclipse shutdown the active workbench window is null
            if (window == null) {
                return;
            }
            IWorkbenchPage persp = window.getActivePage();
            try {
                // Search view corresponding to the viewId
                SDView sdview = null;
                IViewReference viewref = persp.findViewReference(id);
                if (viewref != null) {
                    sdview = (SDView) viewref.getView(false);
                }
                // Make everything clean for the new loader
                if (sdview != null) {
                    sdview.resetProviders();
                }
            } catch (Exception e) {
                // $NON-NLS-1$
                Activator.getDefault().logError("Error setting current loader class", e);
            }
        }
        // The old loader is going to be kicked
        currentLoader.dispose();
    }
    // Replace the current loader by the new one in the map
    fViewLoaderMap.put(id, loader);
    // Store this loader in the preferences to be able to restore it when the workbench will be re-launched
    if (loader != null) {
        saveLastLoader(loader.getClass().getName(), id);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) CoreException(org.eclipse.core.runtime.CoreException) SDView(org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView)

Aggregations

SDView (org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView)5 ArrayList (java.util.ArrayList)2 CoreException (org.eclipse.core.runtime.CoreException)2 Frame (org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.Frame)2 IViewReference (org.eclipse.ui.IViewReference)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 Test (org.junit.Test)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Job (org.eclipse.core.runtime.jobs.Job)1 SWTBotView (org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView)1 SWTBot (org.eclipse.swtbot.swt.finder.SWTBot)1 SWTBotCanvas (org.eclipse.swtbot.swt.finder.widgets.SWTBotCanvas)1 SWTBotToolbarButton (org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton)1 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)1 ITmfEventRequest (org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)1 TmfEventRequest (org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)1 ITmfTimestamp (org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp)1 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)1 ITmfSyncSequenceDiagramEvent (org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent)1