Search in sources :

Example 16 with CommonNavigator

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

the class ExtractTestCasesAction method run.

@Override
public void run(final IProgressMonitor pMonitor) throws InvocationTargetException, InterruptedException {
    this.monitor = pMonitor == null ? new NullProgressMonitor() : pMonitor;
    // First of all, verify that the file is a TITAN supported log file
    try {
        this.logFileMetaData = this.logFileHandler.autoDetect();
    } catch (TechnicalException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new UserException(e.getMessage()));
        return;
    }
    try {
        Object temp = logFile.getSessionProperty(Constants.EXTRACTION_RUNNING);
        if (temp != null && (Boolean) temp) {
            monitor.done();
            return;
        }
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new UserException(e.getMessage()));
    }
    try {
        // $NON-NLS-1$
        this.monitor.beginTask(Messages.getString("ExtractTestCasesAction.0"), 100);
        // Check if a property file exists for the log file (if log file has changed or not)
        boolean logFileHasChanged = LogFileCacheHandler.hasLogFileChanged(this.logFile);
        // Get the property file
        File propertyFile = LogFileCacheHandler.getPropertyFileForLogFile(this.logFile);
        if (logFileHasChanged) {
            if (updateLogFileIndex()) {
                return;
            }
        } else {
            if (Constants.DEBUG) {
                // $NON-NLS-1$
                TITANDebugConsole.getConsole().newMessageStream().println("Log file has NOT changed -> extracting from index file!");
            }
            // Get log file meta data
            this.logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(propertyFile);
            // Extract test cases from the index file
            this.testCaseExtractor.extractTestCasesFromIndexedLogFile(this.logFile);
        }
    } catch (final IOException e) {
        handleExtractingError(e);
    } catch (final ClassNotFoundException e) {
        handleExtractingError(e);
    } catch (final CoreException e) {
        handleExtractingError(e);
    }
    setExtractionRunningProperty(false);
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            IViewPart view = activePage.findView(PROJECT_EXPLORER_VIEW_ID);
            if (view instanceof CommonNavigator) {
                CommonViewer viewer = ((CommonNavigator) view).getCommonViewer();
                viewer.refresh(logFile, true);
                viewer.expandToLevel(logFile, AbstractTreeViewer.ALL_LEVELS);
            }
        }
    });
    this.testCaseEventDispatcher.deleteObserver(this);
    this.testCaseExtractor.deleteObserver(this.testCaseEventDispatcher);
    this.monitor.done();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) IViewPart(org.eclipse.ui.IViewPart) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) CommonViewer(org.eclipse.ui.navigator.CommonViewer) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 17 with CommonNavigator

use of org.eclipse.ui.navigator.CommonNavigator 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)

Example 18 with CommonNavigator

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

the class LogFileCacheHandler method processLogFile.

/**
 * Processes the given LogFile if it has changed. The property file, index file, and log record index file will be created.
 * Does nothing if the log file has not changed, or test case extraction is already running on the file.
 * @param logFile The log file
 * @param pMonitor Progress monitor.
 * @param quietMode If false, the error messages will be displayed to the user.
 * @return true if the processing was successful, false otherwise
 */
public static boolean processLogFile(final IFile logFile, final IProgressMonitor pMonitor, final boolean quietMode) {
    IProgressMonitor monitor = pMonitor == null ? new NullProgressMonitor() : pMonitor;
    if (!logFile.exists()) {
        if (!quietMode) {
            // $NON-NLS-1$
            TitanLogExceptionHandler.handleException(new UserException("The log file does not exist: " + logFile.getName()));
        }
        return false;
    }
    try {
        Object temp = logFile.getSessionProperty(Constants.EXTRACTION_RUNNING);
        if (temp != null && (Boolean) temp) {
            if (!quietMode) {
                // $NON-NLS-1$
                TitanLogExceptionHandler.handleException(new TechnicalException("Test case extraction is running on the given logfile: " + logFile.getName()));
            }
            return false;
        }
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new UserException(e.getMessage()));
        return false;
    }
    if (!LogFileCacheHandler.hasLogFileChanged(logFile)) {
        return true;
    }
    try {
        logFile.setSessionProperty(Constants.EXTRACTION_RUNNING, true);
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        return false;
    }
    final LogFileHandler logFileHandler = new LogFileHandler(logFile);
    try {
        LogFileMetaData logFileMetaData = logFileHandler.autoDetect();
        final TestCaseExtractor testCaseExtractor = new TestCaseExtractor();
        testCaseExtractor.extractTestCasesFromLogFile(logFileMetaData, monitor);
        if (monitor.isCanceled()) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                    IViewPart view = activePage.findView("org.eclipse.ui.navigator.ProjectExplorer");
                    if (view instanceof CommonNavigator) {
                        CommonNavigator navigator = (CommonNavigator) view;
                        navigator.getCommonViewer().update(logFile, null);
                        navigator.getCommonViewer().collapseToLevel(logFile, AbstractTreeViewer.ALL_LEVELS);
                    }
                }
            });
            return false;
        }
        fillCache(logFile, logFileMetaData, testCaseExtractor.getTestCases(), testCaseExtractor.getLogRecordIndexes());
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                IViewPart view = activePage.findView("org.eclipse.ui.navigator.ProjectExplorer");
                if (view instanceof CommonNavigator) {
                    CommonNavigator navigator = (CommonNavigator) view;
                    navigator.getCommonViewer().refresh(logFile, true);
                    navigator.getCommonViewer().expandToLevel(logFile, AbstractTreeViewer.ALL_LEVELS);
                }
            }
        });
        if (testCaseExtractor.failedDuringExtraction()) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    MessageDialog.openInformation(null, Messages.getString("OpenTextTableProjectsViewMenuAction.8"), Messages.getString("OpenTextTableProjectsViewMenuAction.9"));
                }
            });
            return false;
        }
    } catch (IOException e) {
        if (!quietMode) {
            ErrorReporter.logExceptionStackTrace(e);
            TitanLogExceptionHandler.handleException(// $NON-NLS-1$
            new TechnicalException(Messages.getString("OpenTextTableProjectsViewMenuAction.2") + e.getMessage()));
        }
        return false;
    } catch (TechnicalException e) {
        // invalid file format
        if (!quietMode) {
            MessageDialog.openError(Display.getDefault().getActiveShell(), "Invalid log file", e.getMessage());
        }
        return false;
    } finally {
        try {
            logFile.setSessionProperty(Constants.EXTRACTION_RUNNING, false);
        } catch (CoreException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) IViewPart(org.eclipse.ui.IViewPart) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) TestCaseExtractor(org.eclipse.titan.log.viewer.extractors.TestCaseExtractor) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) LogFileMetaData(org.eclipse.titan.log.viewer.models.LogFileMetaData) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UserException(org.eclipse.titan.log.viewer.exceptions.UserException)

Example 19 with CommonNavigator

use of org.eclipse.ui.navigator.CommonNavigator in project erlide_eclipse by erlang.

the class ShowCustomOutlineFiltersDialogHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final Object activePart = HandlerUtil.getVariable(event, "activePart");
    final String targetId;
    final Shell shell;
    PatternFilter patternFilter;
    StructuredViewer viewer;
    if (activePart instanceof ContentOutline) {
        final ContentOutline outline = (ContentOutline) activePart;
        final ErlangOutlinePage erlangOutlinePage = outline.getAdapter(ErlangOutlinePage.class);
        if (erlangOutlinePage == null) {
            return null;
        }
        shell = outline.getSite().getShell();
        targetId = "org.eclipse.ui.views.ContentOutline";
        patternFilter = erlangOutlinePage.getPatternFilter();
        viewer = erlangOutlinePage.getTreeViewer();
    } else if (activePart instanceof CommonNavigator) {
        final CommonNavigator commonNavigator = (CommonNavigator) activePart;
        targetId = "commonNavigator";
        shell = commonNavigator.getSite().getShell();
        patternFilter = null;
        viewer = null;
    } else {
        return null;
    }
    List<String> oldUserDefinedPatterns = Lists.newArrayList();
    final Set<String> oldEnabledFilterIDs = Sets.newHashSet();
    final boolean oldAreUserDefinedPatternsEnabled = OutlineFilterUtils.loadViewDefaults(oldUserDefinedPatterns, oldEnabledFilterIDs);
    final CustomOutlineFiltersDialog dialog = new CustomOutlineFiltersDialog(shell, targetId, oldAreUserDefinedPatternsEnabled, oldUserDefinedPatterns, oldEnabledFilterIDs);
    if (!oldAreUserDefinedPatternsEnabled) {
        oldUserDefinedPatterns = Lists.newArrayList();
    }
    if (dialog.open() == Window.OK) {
        final boolean areUserDefinedPatternsEnabled = dialog.areUserDefinedPatternsEnabled();
        List<String> userDefinedPatterns = dialog.getUserDefinedPatterns();
        final Set<String> enabledFilterIDs = dialog.getEnabledFilterIds();
        // TODO should we support filter LRU history (as in JDT)?
        // setRecentlyChangedFilters(dialog.getFilterDescriptorChangeHistory());
        OutlineFilterUtils.storeViewDefaults(areUserDefinedPatternsEnabled, userDefinedPatterns, enabledFilterIDs);
        if (!areUserDefinedPatternsEnabled) {
            userDefinedPatterns = Lists.newArrayList();
        }
        OutlineFilterUtils.updateViewerFilters(viewer, oldUserDefinedPatterns, oldEnabledFilterIDs, userDefinedPatterns, enabledFilterIDs, patternFilter);
    }
    return null;
}
Also used : CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) Shell(org.eclipse.swt.widgets.Shell) PatternFilter(org.erlide.ui.editors.erl.outline.filters.PatternFilter) CustomOutlineFiltersDialog(org.erlide.ui.editors.erl.outline.filters.CustomOutlineFiltersDialog) ContentOutline(org.eclipse.ui.views.contentoutline.ContentOutline) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer)

Example 20 with CommonNavigator

use of org.eclipse.ui.navigator.CommonNavigator in project jbosstools-openshift by jbosstools.

the class ServerAdapterHandler method openServersView.

private void openServersView(final IServer openShiftServer, final IWorkbenchWindow workbenchWindow) {
    try {
        final CommonNavigator serversViewPart = (CommonNavigator) workbenchWindow.getActivePage().showView(SERVERS_VIEW_ID);
        serversViewPart.setFocus();
        serversViewPart.getCommonViewer().refresh();
        serversViewPart.getCommonViewer().setSelection(new StructuredSelection(openShiftServer));
    } catch (PartInitException e) {
        OpenShiftUIActivator.getDefault().getLogger().logError("Failed to open Servers View", e);
    }
}
Also used : CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

CommonNavigator (org.eclipse.ui.navigator.CommonNavigator)20 IViewPart (org.eclipse.ui.IViewPart)9 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)9 CommonViewer (org.eclipse.ui.navigator.CommonViewer)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)4 CoreException (org.eclipse.core.runtime.CoreException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)3 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)3 IOException (java.io.IOException)2 IFile (org.eclipse.core.resources.IFile)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)2 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)2 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)2