Search in sources :

Example 61 with IViewReference

use of org.eclipse.ui.IViewReference in project titan.EclipsePlug-ins by eclipse.

the class OpenMSCViewMenuAction method run.

public void run(final IStructuredSelection selection) {
    if (!isEnabled()) {
        return;
    }
    Object element = selection.getFirstElement();
    if (!(element instanceof TestCase)) {
        return;
    }
    final TestCase tc = (TestCase) element;
    final IFile logFile = tc.getLogFile();
    try {
        logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(LogFileCacheHandler.getPropertyFileForLogFile(logFile));
    } catch (IOException e1) {
        LogFileCacheHandler.handleLogFileChange(logFile);
        return;
    } catch (ClassNotFoundException e1) {
        LogFileCacheHandler.handleLogFileChange(logFile);
        return;
    }
    try {
        if (!PreferencesHandler.getInstance().getPreferences(this.logFileMetaData.getProjectName()).getVisualOrderComponents().isEmpty()) {
            // Get start time
            final long start = new Date().getTime();
            if (!logFile.exists()) {
                final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                IViewReference[] viewReferences = activePage.getViewReferences();
                ActionUtils.closeAssociatedViews(activePage, viewReferences, logFile);
                // $NON-NLS-1$
                TitanLogExceptionHandler.handleException(new UserException(Messages.getString("OpenMSCViewMenuAction.4")));
                return;
            }
            // Check if the file has been modified
            if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
                LogFileCacheHandler.handleLogFileChange(logFile);
                return;
            }
            // Get log record index file for selected log file - No need to check is exists due to
            // LogFileCacheHandler.hasLogFileChanged(logFile) returning false above
            File logRecordIndexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(logFile);
            final LogRecordIndex[] logRecordIndexes = LogFileCacheHandler.readLogRecordIndexFile(logRecordIndexFile, tc.getStartRecordNumber(), tc.getNumberOfRecords());
            final PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(this.logFileMetaData.getProjectName());
            WorkspaceJob job = new WorkspaceJob("Loading log information") {

                @Override
                public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
                    if (OpenMSCViewMenuAction.this.logFileMetaData == null || OpenMSCViewMenuAction.this.logFileMetaData.getExecutionMode() == null) {
                        return Status.CANCEL_STATUS;
                    }
                    final Parser parser;
                    final ExecutionModel model;
                    try {
                        parser = new Parser(OpenMSCViewMenuAction.this.logFileMetaData);
                        parser.setStart(start);
                        model = parser.preParse(tc, logRecordIndexes, preferences, null, monitor);
                    } catch (TechnicalException e) {
                        ErrorReporter.logExceptionStackTrace(e);
                        TitanLogExceptionHandler.handleException(new TechnicalException(// $NON-NLS-1$
                        Messages.getString("OpenMSCViewMenuAction.3") + e.getMessage()));
                        return Status.CANCEL_STATUS;
                    } catch (ParseException e) {
                        ErrorReporter.logExceptionStackTrace(e);
                        TitanLogExceptionHandler.handleException(new TechnicalException(// $NON-NLS-1$
                        Messages.getString("OpenMSCViewMenuAction.2") + e.getMessage()));
                        return Status.CANCEL_STATUS;
                    } catch (IOException e) {
                        ErrorReporter.logExceptionStackTrace("Error while parsing of the log file", e);
                        TitanLogExceptionHandler.handleException(new TechnicalException(e.getMessage()));
                        return Status.CANCEL_STATUS;
                    }
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            showView(model, parser, tc);
                            // Write data to the console
                            final long end = new Date().getTime();
                            parser.setEnd(end);
                            ConsoleWriter.getInstance().writeModelData(OpenMSCViewMenuAction.this.logFileMetaData.getProjectName(), parser, model, OpenMSCViewMenuAction.this.logFileMetaData.getFilePath().toString());
                        }
                    });
                    return Status.OK_STATUS;
                }
            };
            job.schedule();
        } else {
            // $NON-NLS-1$
            String userE = Messages.getString("OpenMSCViewMenuAction.1");
            TitanLogExceptionHandler.handleException(new UserException(userE));
        }
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace("Error while parsing of the log file", e);
        TitanLogExceptionHandler.handleException(new TechnicalException(e.getMessage()));
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) LogRecordIndex(org.eclipse.titan.log.viewer.models.LogRecordIndex) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IOException(java.io.IOException) Date(java.util.Date) Parser(org.eclipse.titan.log.viewer.parsers.Parser) ExecutionModel(org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel) PreferencesHolder(org.eclipse.titan.log.viewer.preferences.PreferencesHolder) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) ParseException(java.text.ParseException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 62 with IViewReference

use of org.eclipse.ui.IViewReference in project titan.EclipsePlug-ins by eclipse.

the class OpenStatisticalViewMenuAction method run.

public void run(final IStructuredSelection selection) {
    this.logFileMetaData = null;
    this.logFileIsSupported = true;
    if (this.selection == null) {
        return;
    }
    Set<IFile> logFiles = new HashSet<IFile>(selection.size());
    for (Iterator<?> iterator = selection.iterator(); iterator.hasNext(); ) {
        Object object = iterator.next();
        if (object instanceof IFile) {
            logFiles.add((IFile) object);
        } else if (object instanceof TestCase) {
            logFiles.add(((TestCase) object).getLogFile());
        }
    }
    if (logFiles.isEmpty()) {
        return;
    }
    List<StatisticalData> statisticalDataVector = createStatisticalData(logFiles);
    if (statisticalDataVector == null || statisticalDataVector.isEmpty()) {
        return;
    }
    String secondId = Constants.STATISTICAL_VIEW;
    if (statisticalDataVector.size() < 2) {
        secondId = File.separator + this.logFile.getProject().getName() + File.separator + this.logFile.getProjectRelativePath().toOSString();
    }
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IViewReference reference = activePage.findViewReference(Constants.STATISTICAL_VIEW_ID, secondId);
    // get the view
    if (reference != null) {
        StatisticalView part = (StatisticalView) reference.getView(false);
    }
    // create a new view
    try {
        StatisticalView part = (StatisticalView) activePage.showView(Constants.STATISTICAL_VIEW_ID, secondId, IWorkbenchPage.VIEW_ACTIVATE);
        part.setData(statisticalDataVector);
        part.setFocus();
    } catch (PartInitException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) StatisticalData(org.eclipse.titan.log.viewer.views.details.StatisticalData) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) StatisticalView(org.eclipse.titan.log.viewer.views.StatisticalView) PartInitException(org.eclipse.ui.PartInitException) HashSet(java.util.HashSet)

Example 63 with IViewReference

use of org.eclipse.ui.IViewReference in project titan.EclipsePlug-ins by eclipse.

the class TextTableViewHelper method updateSelectionInConnectedMscView.

static void updateSelectionInConnectedMscView(int selectedRecord, LogFileMetaData fileMetaData) {
    final IViewReference[] viewReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
    for (IViewReference viewReference : viewReferences) {
        final IViewPart viewPart = viewReference.getView(false);
        if (!(viewPart instanceof MSCView)) {
            continue;
        }
        final MSCView mscView = (MSCView) viewPart;
        if (mscView.getModel() == null || mscView.getModel().getTestCase() == null) {
            continue;
        }
        final TestCase testCase = mscView.getModel().getTestCase();
        if (fileMetaData.getFilePath().equals((mscView).getLogFileMetaData().getFilePath()) && testCase.getStartRecordNumber() <= selectedRecord && testCase.getEndRecordNumber() >= selectedRecord) {
            if (mscView.getSelectedRecordNumber() != selectedRecord) {
                mscView.setSelection(selectedRecord);
            }
            // Only one MSC view can be opened for one test case
            break;
        }
    }
}
Also used : IViewPart(org.eclipse.ui.IViewPart) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) IViewReference(org.eclipse.ui.IViewReference) MSCView(org.eclipse.titan.log.viewer.views.MSCView)

Example 64 with IViewReference

use of org.eclipse.ui.IViewReference in project titan.EclipsePlug-ins by eclipse.

the class ActionUtils method closeViewsForProject.

/**
 * Closes all connected views when closing/deleting a project
 * and clear the test case tabbed navigator if necessary
 * @param project  the selected project
 * @param activePage activePage page
 * @param viewReferences views
 */
private static void closeViewsForProject(final IProject project, final IWorkbenchPage activePage, final IViewReference[] viewReferences) {
    for (IViewReference reference : viewReferences) {
        IViewPart view = reference.getView(false);
        closeView(project, activePage, reference, view);
    }
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IViewReference(org.eclipse.ui.IViewReference)

Example 65 with IViewReference

use of org.eclipse.ui.IViewReference in project titan.EclipsePlug-ins by eclipse.

the class LogFileCacheHandler method handleLogFileChange.

/**
 * Should be called when a log file has changed. Closes the associated views. Shows a <code>MessageBox</code> where the user can decide if he/she wants to process
 * the log file or just close the views. If the user choose yes, the processing will start in a new <code>WorkspaceJob</code>.
 * @param logFile
 */
public static void handleLogFileChange(final IFile logFile) {
    final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final IViewReference[] viewReferences = activePage.getViewReferences();
    ActionUtils.closeAssociatedViews(activePage, viewReferences, logFile);
    clearCache(logFile);
    Display.getDefault().syncExec(new Runnable() {

        @Override
        public void run() {
            IViewPart view = activePage.findView("org.eclipse.ui.navigator.ProjectExplorer");
            if (view instanceof CommonNavigator) {
                CommonNavigator navigator = (CommonNavigator) view;
                navigator.getCommonViewer().collapseToLevel(logFile, AbstractTreeViewer.ALL_LEVELS);
            }
        }
    });
    MessageBox mb = new MessageBox(activePage.getActivePart().getSite().getShell(), SWT.ICON_ERROR | SWT.OK | SWT.CANCEL);
    mb.setText("The log file has been modified.");
    mb.setMessage("The log file has been modified. Click on OK to extract the test cases" + " or CANCEL to close the associated views.");
    if (mb.open() == SWT.OK) {
        WorkspaceJob job = new WorkspaceJob("Testcase extraction from log file: " + logFile.getName()) {

            @Override
            public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
                boolean completed = LogFileCacheHandler.processLogFile(logFile, monitor, false);
                return completed ? Status.OK_STATUS : Status.CANCEL_STATUS;
            }
        };
        job.setPriority(Job.LONG);
        job.setUser(true);
        job.setRule(logFile.getProject());
        job.schedule();
    }
}
Also used : CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) IViewPart(org.eclipse.ui.IViewPart) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IViewReference(org.eclipse.ui.IViewReference) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

IViewReference (org.eclipse.ui.IViewReference)66 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)48 IViewPart (org.eclipse.ui.IViewPart)37 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)23 PartInitException (org.eclipse.ui.PartInitException)23 IFile (org.eclipse.core.resources.IFile)10 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)8 ArrayList (java.util.ArrayList)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)8 CubridViewPart (com.cubrid.common.ui.spi.part.CubridViewPart)7 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)7 IOException (java.io.IOException)6 IEditorInput (org.eclipse.ui.IEditorInput)6 IEditorReference (org.eclipse.ui.IEditorReference)6 HostNode (com.cubrid.cubridmanager.ui.mondashboard.editor.model.HostNode)4 ParseException (java.text.ParseException)4 IProject (org.eclipse.core.resources.IProject)4 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)4 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4