Search in sources :

Example 36 with ISelectionService

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));
    }
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) ISelectionService(org.eclipse.ui.ISelectionService) ControlPart(org.eclipse.titan.designer.AST.TTCN3.definitions.ControlPart) IEditorPart(org.eclipse.ui.IEditorPart) IResource(org.eclipse.core.resources.IResource) Location(org.eclipse.titan.designer.AST.Location)

Example 37 with ISelectionService

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);
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ISelectionService(org.eclipse.ui.ISelectionService)

Example 38 with ISelectionService

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;
}
Also used : IOpenshiftUIElement(org.jboss.tools.openshift.internal.ui.models.IOpenshiftUIElement) ISelectionService(org.eclipse.ui.ISelectionService) OpenShiftImages(org.jboss.tools.openshift.internal.ui.OpenShiftImages) CompoundContributionItem(org.eclipse.ui.actions.CompoundContributionItem) PlatformUI(org.eclipse.ui.PlatformUI) ResourceWrapperUtils(org.jboss.tools.openshift.internal.ui.utils.ResourceWrapperUtils) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) HashMap(java.util.HashMap) OpenshiftUIModel(org.jboss.tools.openshift.internal.ui.models.OpenshiftUIModel) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) IPod(com.openshift.restclient.model.IPod) UIUtils(org.jboss.tools.openshift.internal.common.ui.utils.UIUtils) MenuItem(org.eclipse.swt.widgets.MenuItem) IWorkbenchContribution(org.eclipse.ui.menus.IWorkbenchContribution) IRunningPodHolder(org.jboss.tools.openshift.internal.ui.models.IRunningPodHolder) Map(java.util.Map) SWT(org.eclipse.swt.SWT) IContributionItem(org.eclipse.jface.action.IContributionItem) ISelection(org.eclipse.jface.viewers.ISelection) IServiceLocator(org.eclipse.ui.services.IServiceLocator) Menu(org.eclipse.swt.widgets.Menu) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem) IOpenshiftUIElement(org.jboss.tools.openshift.internal.ui.models.IOpenshiftUIElement) IService(com.openshift.restclient.model.IService) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) IRunningPodHolder(org.jboss.tools.openshift.internal.ui.models.IRunningPodHolder) ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService)

Aggregations

ISelectionService (org.eclipse.ui.ISelectionService)38 ISelection (org.eclipse.jface.viewers.ISelection)19 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)19 IResource (org.eclipse.core.resources.IResource)15 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)12 IProject (org.eclipse.core.resources.IProject)9 IWorkbench (org.eclipse.ui.IWorkbench)8 IJavaProject (org.eclipse.jdt.core.IJavaProject)7 IEditorPart (org.eclipse.ui.IEditorPart)7 IFile (org.eclipse.core.resources.IFile)6 ExecutionException (org.eclipse.core.commands.ExecutionException)3 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)3 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)3 Repository (org.eclipse.jgit.lib.Repository)3 SWT (org.eclipse.swt.SWT)3 ISelectionListener (org.eclipse.ui.ISelectionListener)3 PlatformUI (org.eclipse.ui.PlatformUI)3 StyleService (eu.esdihumboldt.hale.ui.common.service.style.StyleService)2 GeometrySchemaService (eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService)2 InstanceService (eu.esdihumboldt.hale.ui.service.instance.InstanceService)2