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