Search in sources :

Example 16 with TTCN3Editor

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

the class OrganizeImportsFromEditor method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    // update AST
    Utils.updateASTForProjectActiveInEditor("OrganizeImports");
    Activator.getDefault().pauseHandlingResourceChanges();
    // getting the active editor
    final TTCN3Editor targetEditor = Utils.getActiveEditor();
    if (targetEditor == null) {
        return null;
    }
    // getting selected file
    final IFile selectedFile = Utils.getSelectedFileInEditor("OrganizeImports");
    if (selectedFile == null) {
        return null;
    }
    final IStructuredSelection structSelection = new StructuredSelection(selectedFile);
    final OrganizeImportsRefactoring refactoring = new OrganizeImportsRefactoring(structSelection);
    // open wizard
    final OrganizeImportsWizard wiz = new OrganizeImportsWizard(refactoring);
    final RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(wiz);
    try {
        operation.run(targetEditor.getEditorSite().getShell(), "");
    } catch (InterruptedException irex) {
    // operation was cancelled
    } catch (Exception e) {
        ErrorReporter.logError("OrganizeImportsFromEditor: 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) 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)

Example 17 with TTCN3Editor

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

the class ExtractModuleParActionFromEditor method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    // getting the active editor
    final TTCN3Editor targetEditor = Utils.getActiveEditor();
    if (targetEditor == null) {
        return null;
    }
    final IFile selectedFile = Utils.getSelectedFileInEditor("ExtractModulePar");
    if (selectedFile == null) {
        return null;
    }
    // getting current project
    sourceProj = selectedFile.getProject();
    if (sourceProj == null) {
        ErrorReporter.logError("ExtractModuleParActionFromEditor: Source project is null. ");
        return null;
    }
    // update AST
    final Set<IProject> projsToUpdate = new HashSet<IProject>();
    projsToUpdate.add(sourceProj);
    Utils.updateASTBeforeRefactoring(projsToUpdate, "ExtractModulePar");
    // create refactoring
    final ExtractModuleParRefactoring refactoring = new ExtractModuleParRefactoring(sourceProj);
    final ExtractModuleParWizard wiz = new ExtractModuleParWizard();
    // 
    final StructuredSelection ssel = new StructuredSelection(sourceProj);
    wiz.init(PlatformUI.getWorkbench(), ssel);
    final WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wiz);
    dialog.open();
    final boolean saveModuleParsOption = wiz.getSaveModuleParsOption();
    final IProject newProj = wiz.getProject();
    if (newProj == null) {
        ErrorReporter.logError("ExtractModuleParActionFromEditor: Wizard returned a null project. ");
        return null;
    }
    refactoring.setTargetProject(newProj);
    refactoring.setOption_saveModuleParList(saveModuleParsOption);
    // copy project settings to new project
    final ProjectFileHandler pfh = new ProjectFileHandler(sourceProj);
    if (pfh.projectFileExists()) {
        // IResource.copy(...) is used because ProjectFileHandler.getDocumentFromFile(...) is not working
        final IFile settingsFile = sourceProj.getFile("/" + ProjectFileHandler.XML_TITAN_PROPERTIES_FILE);
        final IFile settingsCopy = newProj.getFile("/" + ProjectFileHandler.XML_TITAN_PROPERTIES_FILE);
        try {
            if (settingsCopy.exists()) {
                settingsCopy.delete(true, new NullProgressMonitor());
            }
            settingsFile.copy(settingsCopy.getFullPath(), true, new NullProgressMonitor());
        } catch (CoreException ce) {
            ErrorReporter.logError("ExtractModuleParActionFromEditor: Copying project settings to new project failed.");
        }
    }
    // performing the refactor operation
    refactoring.perform();
    // reanalyze project
    final WorkspaceJob job = GlobalParser.getProjectSourceParser(newProj).analyzeAll();
    if (job != null) {
        try {
            job.join();
        } catch (InterruptedException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IProject(org.eclipse.core.resources.IProject) ProjectFileHandler(org.eclipse.titan.designer.properties.data.ProjectFileHandler) CoreException(org.eclipse.core.runtime.CoreException) WizardDialog(org.eclipse.jface.wizard.WizardDialog) HashSet(java.util.HashSet)

Example 18 with TTCN3Editor

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

the class SelectionFinder method findSelection.

private Definition findSelection() {
    // getting the active editor
    final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (editor == null || !(editor instanceof TTCN3Editor)) {
        return null;
    }
    final TTCN3Editor targetEditor = (TTCN3Editor) editor;
    // 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;
    sourceProj = selectedFile.getProject();
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(sourceProj);
    final Module selectedModule = projectSourceParser.containedModule(selectedFile);
    // getting current selection
    final ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
    final TextSelection textSelection = extractSelection(selectionService.getSelection());
    // 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.");
        final IStatusLineManager statusLineManager = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
        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)

Example 19 with TTCN3Editor

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

the class LazyficationActionFromBrowser method performLazyfication.

private void performLazyfication() {
    // 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, "Lazyfication");
    Activator.getDefault().pauseHandlingResourceChanges();
    // create refactoring
    final LazyficationRefactoring refactoring = new LazyficationRefactoring(structSelection);
    // open wizard
    final LazyficationWizard wiz = new LazyficationWizard(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("LazyficationActionFromBrowser: 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 20 with TTCN3Editor

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

the class LazyficationActionFromEditor method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    // update AST
    Utils.updateASTForProjectActiveInEditor("Lazyfication");
    Activator.getDefault().pauseHandlingResourceChanges();
    // getting the active editor
    final TTCN3Editor targetEditor = Utils.getActiveEditor();
    if (targetEditor == null) {
        return null;
    }
    // getting selected file
    final IFile selectedFile = Utils.getSelectedFileInEditor("Lazyfication");
    if (selectedFile == null) {
        return null;
    }
    final IStructuredSelection structSelection = new StructuredSelection(selectedFile);
    final LazyficationRefactoring refactoring = new LazyficationRefactoring(structSelection);
    // open wizard
    final LazyficationWizard wiz = new LazyficationWizard(refactoring);
    final RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(wiz);
    try {
        operation.run(targetEditor.getEditorSite().getShell(), "");
    } catch (InterruptedException irex) {
    // operation was cancelled
    } catch (Exception e) {
        ErrorReporter.logError("LazyficationActionFromEditor: 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) 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)

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