Search in sources :

Example 1 with MSCWidget

use of org.eclipse.titan.log.viewer.views.msc.ui.view.MSCWidget in project titan.EclipsePlug-ins by eclipse.

the class MSCView method createPartControl.

@Override
public void createPartControl(final Composite c) {
    // restores any saved state
    final WorkspaceJob job = restoreState();
    if (this.problemDuringRestore) {
        Label text = new Label(c, SWT.LEFT);
        // $NON-NLS-1$
        text.setText(Messages.getString("MSCView.0"));
        return;
    }
    Composite parent = new Composite(c, SWT.NONE);
    GridLayout parentLayout = new GridLayout();
    parentLayout.numColumns = 1;
    parentLayout.marginWidth = 0;
    parentLayout.marginHeight = 0;
    parent.setLayout(parentLayout);
    GridData seqDiagLayoutData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
    this.mscWidget = new MSCWidget(parent, SWT.NONE);
    this.mscWidget.setLayoutData(seqDiagLayoutData);
    this.mscWidget.setDragAutoScroll(false);
    this.mscWidget.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(final KeyEvent e) {
            if (e.keyCode != SWT.CR) {
                return;
            }
            PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(MSCView.this.logFileMetaData.getProjectName());
            int defaultBehaviour = preferences.getMscViewDefault();
            if (defaultBehaviour == PreferenceConstants.DEFAULT_TEXT) {
                MSCView.this.openTextTable.run();
            } else {
                MSCView.this.openValueView.run();
            }
        }
    });
    this.mscWidget.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(final MouseEvent e) {
            PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(MSCView.this.logFileMetaData.getProjectName());
            int defaultBehaviour = preferences.getMscViewDefault();
            if (defaultBehaviour == PreferenceConstants.DEFAULT_TEXT) {
                MSCView.this.openTextTable.run();
            } else {
                MSCView.this.openValueView.run();
            }
        }
    });
    this.mscWidget.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            if (!(event.getSelection() instanceof IStructuredSelection)) {
                return;
            }
            if (MSCView.this.model == null) {
                return;
            }
            final IFile logFile = MSCView.this.model.getTestCase().getLogFile();
            if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
                LogFileCacheHandler.handleLogFileChange(logFile);
                return;
            }
            final IStructuredSelection structuredSelection = (IStructuredSelection) event.getSelection();
            final IViewReference[] viewReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
            if (MSCView.this.logFileMetaData == null) {
                return;
            }
            for (IViewReference viewReference : viewReferences) {
                final IViewPart viewPart = viewReference.getView(false);
                if (viewPart instanceof TextTableView && ((TextTableView) viewPart).getLogFileMetaData() != null && MSCView.this.logFileMetaData.getFilePath().equals(((TextTableView) viewPart).getLogFileMetaData().getFilePath())) {
                    final Integer selectedLine = (Integer) structuredSelection.getFirstElement();
                    final int recordNumber = MSCView.this.model.getEvent(selectedLine - 2).getRecordNumber();
                    TextTableView textTableView = (TextTableView) viewPart;
                    if (textTableView.getSelectedRecord() != null && textTableView.getSelectedRecord().getRecordNumber() != recordNumber) {
                        textTableView.setSelectedRecord(recordNumber);
                    }
                    break;
                }
            }
            silentOpenSource.delayedRun(event.getSelection());
            silentOpenValueView.delayedRun(event.getSelection());
        }
    });
    createCoolbarContent();
    hookContextMenu();
    parent.layout(true);
    WorkspaceJob job2 = new WorkspaceJob("Displaying loaded log information") {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
            if (job == null) {
                return Status.OK_STATUS;
            }
            try {
                job.join();
            } catch (InterruptedException e) {
                return Status.CANCEL_STATUS;
            }
            // Check if model was restored
            if ((MSCView.this.logFileMetaData != null) && (MSCView.this.model != null)) {
                // always open restore at top
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        setModel(MSCView.this.model, MSCView.this.restoredSelection);
                    }
                });
            }
            return Status.OK_STATUS;
        }
    };
    job2.setSystem(true);
    job2.schedule();
}
Also used : IViewPart(org.eclipse.ui.IViewPart) MouseEvent(org.eclipse.swt.events.MouseEvent) IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) MSCWidget(org.eclipse.titan.log.viewer.views.msc.ui.view.MSCWidget) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) KeyEvent(org.eclipse.swt.events.KeyEvent) PreferencesHolder(org.eclipse.titan.log.viewer.preferences.PreferencesHolder) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IViewReference(org.eclipse.ui.IViewReference) GridData(org.eclipse.swt.layout.GridData) TextTableView(org.eclipse.titan.log.viewer.views.text.table.TextTableView)

Aggregations

IFile (org.eclipse.core.resources.IFile)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 KeyAdapter (org.eclipse.swt.events.KeyAdapter)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 PreferencesHolder (org.eclipse.titan.log.viewer.preferences.PreferencesHolder)1 MSCWidget (org.eclipse.titan.log.viewer.views.msc.ui.view.MSCWidget)1 TextTableView (org.eclipse.titan.log.viewer.views.text.table.TextTableView)1 IViewPart (org.eclipse.ui.IViewPart)1 IViewReference (org.eclipse.ui.IViewReference)1