Search in sources :

Example 1 with TTCN3Editor

use of org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor in project titan.EclipsePlug-ins by eclipse.

the class ContextLoggingActionFromBrowser method performContextLogging.

private void performContextLogging() {
    // find selection
    if (!(selection instanceof IStructuredSelection)) {
        return;
    }
    final IStructuredSelection structSelection = (IStructuredSelection) selection;
    final Set<IProject> projsToUpdate = Utils.findAllProjectsInSelection(structSelection);
    // update AST before refactoring
    Utils.updateASTBeforeRefactoring(projsToUpdate, "ContextLogging");
    Activator.getDefault().pauseHandlingResourceChanges();
    // create refactoring
    final ContextLoggingRefactoring refactoring = new ContextLoggingRefactoring(structSelection, null);
    // open wizard
    final ContextLoggingWizard wiz = new ContextLoggingWizard(refactoring);
    final RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(wiz);
    // getting the active editor
    final TTCN3Editor targetEditor = Utils.getActiveEditor();
    try {
        operation.run(targetEditor == null ? null : targetEditor.getEditorSite().getShell(), "");
    } catch (InterruptedException irex) {
    // operation was cancelled
    } catch (Exception e) {
        ErrorReporter.logError("ContextLoggingActionFromBrowser: Error while performing refactoring change! ");
        ErrorReporter.logExceptionStackTrace(e);
    }
    Activator.getDefault().resumeHandlingResourceChanges();
    // update AST after refactoring
    Utils.updateASTAfterRefactoring(wiz, refactoring.getAffectedObjects(), refactoring.getName());
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 2 with TTCN3Editor

use of org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor in project titan.EclipsePlug-ins by eclipse.

the class ContextLoggingActionFromEditor method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    // update AST
    Utils.updateASTForProjectActiveInEditor("ContextLogging");
    Activator.getDefault().pauseHandlingResourceChanges();
    // getting the active editor
    final TTCN3Editor targetEditor = Utils.getActiveEditor();
    if (targetEditor == null) {
        return null;
    }
    // getting status line manager
    statusLineManager = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
    // getting selected file
    final IFile selectedFile = Utils.getSelectedFileInEditor("MinimizeVisibility");
    if (selectedFile == null) {
        return null;
    }
    // getting selection
    final ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
    final ISelection sel = selectionService.getSelection();
    if (sel == null) {
        setStatusLineMsg(ERR_MSG_NO_SELECTION, statusLineManager);
        return null;
    } else if (!(sel instanceof TextSelection)) {
        ErrorReporter.logError("ContextLoggingActionFromEditor:" + " selection is not a TextSelection");
        return null;
    }
    selection = (TextSelection) sel;
    // 
    ContextLoggingRefactoring refactoring;
    if (selection.getLength() == 0) {
        final IStructuredSelection ssel = new StructuredSelection(new Object[] { selectedFile });
        refactoring = new ContextLoggingRefactoring(ssel, null);
    } else {
        refactoring = new ContextLoggingRefactoring(selectedFile, selection, null);
    }
    // open wizard
    final ContextLoggingWizard wiz = new ContextLoggingWizard(refactoring);
    final RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(wiz);
    try {
        operation.run(targetEditor.getEditorSite().getShell(), "");
    } catch (InterruptedException irex) {
    // operation was cancelled
    } catch (Exception e) {
        ErrorReporter.logError("ContextLoggingActionFromEditor: Error while performing refactoring change! ");
        ErrorReporter.logExceptionStackTrace(e);
    }
    // update AST again
    Activator.getDefault().resumeHandlingResourceChanges();
    final IProject project = selectedFile.getProject();
    GlobalParser.getProjectSourceParser(project).reportOutdating(selectedFile);
    GlobalParser.getProjectSourceParser(project).analyzeAll();
    return null;
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) TextSelection(org.eclipse.jface.text.TextSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExecutionException(org.eclipse.core.commands.ExecutionException) IProject(org.eclipse.core.resources.IProject) RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService)

Example 3 with TTCN3Editor

use of org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor in project titan.EclipsePlug-ins by eclipse.

the class MinimizeScopeActionFromBrowser method performMinimizeScope.

private void performMinimizeScope() {
    // getting the active editor
    final TTCN3Editor targetEditor = Utils.getActiveEditor();
    // find selection
    if (!(selection instanceof IStructuredSelection)) {
        return;
    }
    final IStructuredSelection structSelection = (IStructuredSelection) selection;
    final Set<IProject> projsToUpdate = Utils.findAllProjectsInSelection(structSelection);
    // update AST before refactoring
    Utils.updateASTBeforeRefactoring(projsToUpdate, "MinimizeScope");
    Activator.getDefault().pauseHandlingResourceChanges();
    // create refactoring
    final MinimizeScopeRefactoring refactoring = new MinimizeScopeRefactoring(structSelection, null);
    // open wizard
    final MinimizeScopeWizard wiz = new MinimizeScopeWizard(refactoring);
    final RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(wiz);
    try {
        operation.run(targetEditor == null ? null : targetEditor.getEditorSite().getShell(), "");
    } catch (InterruptedException irex) {
    // operation was cancelled
    } catch (Exception e) {
        ErrorReporter.logError("MinimizeScopeActionFromBrowser: Error while performing refactoring change! ");
        ErrorReporter.logExceptionStackTrace(e);
    }
    Activator.getDefault().resumeHandlingResourceChanges();
    // update AST after refactoring
    Utils.updateASTAfterRefactoring(wiz, refactoring.getAffectedObjects(), refactoring.getName());
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 4 with TTCN3Editor

use of org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor in project titan.EclipsePlug-ins by eclipse.

the class MinimizeScopeActionFromEditor method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    // update AST
    Utils.updateASTForProjectActiveInEditor("MinimizeScope");
    Activator.getDefault().pauseHandlingResourceChanges();
    // getting the active editor
    final TTCN3Editor targetEditor = Utils.getActiveEditor();
    if (targetEditor == null) {
        return null;
    }
    // get selected definition
    selection = findSelection();
    if (selection == null) {
        return null;
    }
    final IResource selectedRes = selection.getLocation().getFile();
    if (!(selectedRes instanceof IFile)) {
        ErrorReporter.logError("MinimizeScopeActionFromEditor.execute(): Selected resource `" + selectedRes.getName() + "' is not a file.");
        return null;
    }
    final IFile selectedFile = (IFile) selectedRes;
    // 
    final MinimizeScopeRefactoring refactoring = new MinimizeScopeRefactoring(selection, null);
    // open wizard
    final MinimizeScopeWizard wiz = new MinimizeScopeWizard(refactoring);
    final RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(wiz);
    try {
        operation.run(targetEditor.getEditorSite().getShell(), "");
    } catch (InterruptedException irex) {
    // operation was cancelled
    } catch (Exception e) {
        ErrorReporter.logError("MinimizeScopeActionFromEditor: Error while performing refactoring change! ");
        ErrorReporter.logExceptionStackTrace(e);
    }
    // update AST again
    Activator.getDefault().resumeHandlingResourceChanges();
    final IProject project = selectedFile.getProject();
    GlobalParser.getProjectSourceParser(project).reportOutdating(selectedFile);
    GlobalParser.getProjectSourceParser(project).analyzeAll();
    return null;
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) IResource(org.eclipse.core.resources.IResource) ExecutionException(org.eclipse.core.commands.ExecutionException) IProject(org.eclipse.core.resources.IProject)

Example 5 with TTCN3Editor

use of org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor in project titan.EclipsePlug-ins by eclipse.

the class MinimizeScopeActionFromEditor method findSelection.

private Definition findSelection() {
    // getting the active editor
    final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    TTCN3Editor targetEditor;
    if (editor == null || !(editor instanceof TTCN3Editor)) {
        return null;
    } else {
        targetEditor = (TTCN3Editor) editor;
    }
    final IStatusLineManager statusLineManager = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
    // getting current selection
    final ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
    final TextSelection textSelection = extractSelection(selectionService.getSelection());
    // iterating through part of the module
    final IResource selectedRes = extractResource(targetEditor);
    if (!(selectedRes instanceof IFile)) {
        ErrorReporter.logError("SelectionFinder.findSelection(): Selected resource `" + selectedRes.getName() + "' is not a file.");
        return null;
    }
    final IFile selectedFile = (IFile) selectedRes;
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(selectedFile.getProject());
    final Module selectedModule = projectSourceParser.containedModule(selectedFile);
    // getting current selection nodes
    final int selectionOffset = textSelection.getOffset() + textSelection.getLength();
    final SelectionFinderVisitor selVisitor = new SelectionFinderVisitor(selectionOffset);
    selectedModule.accept(selVisitor);
    final Definition selectedDef = selVisitor.getSelection();
    if (selectedDef == null) {
        ErrorReporter.logWarning("SelectionFinder.findSelection(): Visitor did not find a definition in the selection.");
        statusLineManager.setErrorMessage(ERR_MSG_NO_SELECTION);
        return null;
    }
    return selectedDef;
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) TextSelection(org.eclipse.jface.text.TextSelection) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ISelectionService(org.eclipse.ui.ISelectionService) IEditorPart(org.eclipse.ui.IEditorPart) Module(org.eclipse.titan.designer.AST.Module) IResource(org.eclipse.core.resources.IResource) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Aggregations

TTCN3Editor (org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor)24 IProject (org.eclipse.core.resources.IProject)15 IFile (org.eclipse.core.resources.IFile)14 ExecutionException (org.eclipse.core.commands.ExecutionException)13 RefactoringWizardOpenOperation (org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 TextSelection (org.eclipse.jface.text.TextSelection)7 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)7 IEditorPart (org.eclipse.ui.IEditorPart)5 IResource (org.eclipse.core.resources.IResource)4 Module (org.eclipse.titan.designer.AST.Module)4 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)4 ISelectionService (org.eclipse.ui.ISelectionService)4 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)3 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)3 CoreException (org.eclipse.core.runtime.CoreException)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 IStatusLineManager (org.eclipse.jface.action.IStatusLineManager)2 Reconciler (org.eclipse.titan.designer.editors.ttcn3editor.Reconciler)2 HashSet (java.util.HashSet)1