Search in sources :

Example 21 with RefactoringWizardOpenOperation

use of org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation in project titan.EclipsePlug-ins by eclipse.

the class UngroupModuleparActionFromEditor method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    // update AST
    Utils.updateASTForProjectActiveInEditor("UngroupModulepar");
    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("UngroupModulepar");
    if (selectedFile == null) {
        return null;
    }
    final IStructuredSelection structSelection = new StructuredSelection(selectedFile);
    final UngroupModuleparRefactoring refactoring = new UngroupModuleparRefactoring(structSelection);
    // open wizard
    final UngroupModuleparWizard wiz = new UngroupModuleparWizard(refactoring);
    final RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(wiz);
    try {
        operation.run(targetEditor.getEditorSite().getShell(), "");
    } catch (InterruptedException irex) {
    // operation was cancelled
    } catch (Exception e) {
        ErrorReporter.logError("UngroupModuleparActionFromEditor: 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 22 with RefactoringWizardOpenOperation

use of org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation in project titan.EclipsePlug-ins by eclipse.

the class RenameRefactoring method runAction.

/**
 * Helper function used by RenameRefactoringAction classes for TTCN-3,
 * ASN.1 and TTCNPP editors
 */
public static void runAction(final IEditorPart targetEditor, final ISelection selection) {
    final IStatusLineManager statusLineManager = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
    statusLineManager.setErrorMessage(null);
    final IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        statusLineManager.setErrorMessage(FILENOTIDENTIFIABLE);
        return;
    }
    if (!TITANNature.hasTITANNature(file.getProject())) {
        statusLineManager.setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
        return;
    }
    final IPreferencesService prefs = Platform.getPreferencesService();
    final boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    int offset;
    if (selection instanceof TextSelection && !selection.isEmpty() && !"".equals(((TextSelection) selection).getText())) {
        if (reportDebugInformation) {
            TITANDebugConsole.getConsole().newMessageStream().println("text selected: " + ((TextSelection) selection).getText());
        }
        TextSelection tSelection = (TextSelection) selection;
        offset = tSelection.getOffset() + tSelection.getLength();
    } else {
        offset = ((IEditorWithCarretOffset) targetEditor).getCarretOffset();
    }
    // run semantic analysis to have up-to-date AST
    // FIXME: it does not work for incremental parsing
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    final WorkspaceJob job = projectSourceParser.analyzeAll();
    if (job == null) {
        if (reportDebugInformation) {
            TITANDebugConsole.getConsole().newMessageStream().println("Rename refactoring: WorkspaceJob to analyze project could not be created.");
        }
        return;
    }
    try {
        job.join();
    } catch (InterruptedException e) {
        ErrorReporter.logExceptionStackTrace(e);
        return;
    }
    // find the module
    if (ResourceExclusionHelper.isExcluded(file)) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(MessageFormat.format(EXCLUDEDFROMBUILD, file.getFullPath()));
        return;
    }
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        statusLineManager.setErrorMessage(MessageFormat.format(NOTFOUNDMODULE, file.getName()));
        return;
    }
    ReferenceFinder rf = findOccurrencesLocationBased(module, offset);
    if (rf == null) {
        rf = new ReferenceFinder();
        boolean isDetected = rf.detectAssignmentDataByOffset(module, offset, targetEditor, true, reportDebugInformation);
        if (!isDetected) {
            return;
        }
    }
    RenameRefactoring renameRefactoring = new RenameRefactoring(file, module, rf);
    RenameRefactoringWizard renameWizard = new RenameRefactoringWizard(renameRefactoring);
    RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(renameWizard);
    try {
        operation.run(targetEditor.getEditorSite().getShell(), "");
    } catch (InterruptedException irex) {
        // operation was canceled
        if (reportDebugInformation) {
            TITANDebugConsole.getConsole().newMessageStream().println("Rename refactoring has been cancelled");
        }
    } finally {
        // ===================================
        // === Re-analysis after renaming ====
        // ===================================
        Map<Module, List<Hit>> changed = rf.findAllReferences(module, file.getProject(), null, reportDebugInformation);
        final Set<Module> modules = new HashSet<Module>();
        modules.add(module);
        modules.addAll(changed.keySet());
        reanalyseAstAfterRefactoring(file.getProject(), modules);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) TextSelection(org.eclipse.jface.text.TextSelection) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) ReferenceFinder(org.eclipse.titan.designer.AST.ReferenceFinder) List(java.util.List) ArrayList(java.util.ArrayList) Module(org.eclipse.titan.designer.AST.Module) ASN1Module(org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module) HashSet(java.util.HashSet)

Aggregations

RefactoringWizardOpenOperation (org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation)22 ExecutionException (org.eclipse.core.commands.ExecutionException)14 IProject (org.eclipse.core.resources.IProject)14 TTCN3Editor (org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 IFile (org.eclipse.core.resources.IFile)9 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)6 RefactoringWizard (org.eclipse.ltk.ui.refactoring.RefactoringWizard)6 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)5 RenameRefactoringWizard (org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard)5 ArrayList (java.util.ArrayList)2 IResource (org.eclipse.core.resources.IResource)2 TextSelection (org.eclipse.jface.text.TextSelection)2 ISelection (org.eclipse.jface.viewers.ISelection)2 Shell (org.eclipse.swt.widgets.Shell)2 RefactoringComponent (org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent)2 XMLRefactoringComponent (org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent)2 RenameComponentProcessor (org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameComponentProcessor)2 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 HashSet (java.util.HashSet)1