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;
}
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);
}
}
Aggregations