use of org.eclipse.ui.ISelectionService in project titan.EclipsePlug-ins by eclipse.
the class SelectionFinder method perform.
void perform() {
// getting the active editor
final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editor == null || !(editor instanceof TTCN3Editor)) {
return;
}
final TTCN3Editor targetEditor = (TTCN3Editor) editor;
statusLineManager = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
// getting current selection
final ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
textSelection = extractSelection(selectionService.getSelection());
if (textSelection == null) {
ErrorReporter.logError("No valid statements were found in the selection.");
ExtractToFunctionRefactoring.setStatusLineMsg(ERR_MSG_NO_SELECTION, statusLineManager);
return;
}
// getting selected module
final IResource selectedRes = extractResource(targetEditor);
if (!(selectedRes instanceof IFile)) {
ErrorReporter.logError("ExtractToFunctionRefactoring.findSelection(): Selected resource `" + selectedRes.getName() + "' is not a file.");
return;
}
selectedFile = (IFile) selectedRes;
project = selectedFile.getProject();
sourceParser = GlobalParser.getProjectSourceParser(project);
selectedModule = sourceParser.containedModule(selectedFile);
// iterating through the module for the selected statements
final SelectionVisitor selectionVisitor = new SelectionVisitor(textSelection.getOffset(), textSelection.getLength());
selectedModule.accept(selectionVisitor);
selectedStatements = selectionVisitor.createStatementList(textSelection);
if (selectedStatements.isEmpty()) {
ExtractToFunctionRefactoring.setStatusLineMsg(ERR_MSG_NO_SELECTION, statusLineManager);
return;
}
if (ExtractToFunctionRefactoring.DEBUG_MESSAGES_ON) {
ErrorReporter.logError(selectedStatements.createDebugInfo());
ErrorReporter.logError(createDebugInfo());
}
// finding return type & runs on clause
final RunsOnClauseFinder runsonVisitor = new RunsOnClauseFinder(selectedStatements.getLocation());
selectedModule.accept(runsonVisitor);
runsOnRef = runsonVisitor.getRunsOnRef();
parentFunc = runsonVisitor.getFuncDef();
// finding insert location
if (parentFunc instanceof Definition) {
insertLoc = ((Definition) parentFunc).getLocation().getEndOffset();
} else if (parentFunc instanceof ControlPart) {
final ControlPart cp = (ControlPart) parentFunc;
final Location commentLoc = cp.getCommentLocation();
insertLoc = commentLoc == null ? cp.getLocation().getOffset() : commentLoc.getOffset();
}
//
final ReturnVisitor retVis = new ReturnVisitor();
selectedStatements.accept(retVis);
returnCertainty = retVis.getCertainty();
if (retVis.getCertainty() != ReturnCertainty.NO) {
returnType = runsonVisitor.getReturnType();
}
// checking erroneousness of selection
checkErroneousGoto();
if (containsBreakWithoutLoop()) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_ERRONEOUS_BREAK));
}
if (containsContinueWithoutLoop()) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_ERRONEOUS_CONTINUE));
}
if (retVis.getCertainty() == ReturnCertainty.MAYBE) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_UNCERTAIN_RETURN));
}
}
use of org.eclipse.ui.ISelectionService in project arduino-eclipse-plugin by Sloeber.
the class ProjectExplorerListener method registerListener.
public static void registerListener() {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow awbw = wb.getActiveWorkbenchWindow();
ISelectionService ss = awbw.getSelectionService();
ProjectExplorerListener selectionListener = new ProjectExplorerListener();
ss.addPostSelectionListener(IPageLayout.ID_PROJECT_EXPLORER, selectionListener);
}
use of org.eclipse.ui.ISelectionService in project jbosstools-openshift by jbosstools.
the class ScaleDeploymentContributionItem method isRelevant.
private boolean isRelevant() {
ISelectionService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
ISelection selection = service != null ? service.getSelection() : null;
if (selection == null || selection.isEmpty()) {
return false;
}
IRunningPodHolder podHolder = UIUtils.getFirstElement(selection, IRunningPodHolder.class);
if (podHolder == null) {
return false;
}
IOpenshiftUIElement<?, IOpenshiftUIElement<?, ?, OpenshiftUIModel>, ?> podUIElement = podHolder.getPodUIElement();
if (!(podUIElement instanceof IResourceWrapper)) {
return false;
}
IResourceWrapper<?, ?> podWrapper = (IResourceWrapper<?, ?>) podUIElement;
if (ResourceWrapperUtils.getServiceWrapperFor(podWrapper, serviceWrapper -> ResourceUtils.areRelated((IPod) podWrapper.getWrapped(), (IService) serviceWrapper.getWrapped())) == null) {
return false;
}
return true;
}
Aggregations