List of usage examples for org.eclipse.jface.viewers ISelectionProvider getSelection
public ISelection getSelection();
From source file:at.spardat.xma.guidesign.presentation.action.GuidesignActionBarContributor.java
License:Open Source License
/** * the sense of this override of the superclass method is to remove * undo/redo from the global actions// w w w . ja va 2 s.com */ public void update() { ISelectionProvider selectionProvider = activeEditor instanceof ISelectionProvider ? (ISelectionProvider) activeEditor : activeEditor.getEditorSite().getSelectionProvider(); ISelection selection = selectionProvider.getSelection(); IStructuredSelection structuredSelection = selection instanceof IStructuredSelection ? (IStructuredSelection) selection : StructuredSelection.EMPTY; deleteAction.updateSelection(structuredSelection); cutAction.updateSelection(structuredSelection); copyAction.updateSelection(structuredSelection); pasteAction.updateSelection(structuredSelection); //undoAction.update(); //redoAction.update(); }
From source file:cideplus.ui.astview.ASTView.java
License:Open Source License
protected void performLinkWithEditor() { fDoLinkWithEditor = fLinkWithEditor.isChecked(); fDialogSettings.put(SETTINGS_LINK_WITH_EDITOR, fDoLinkWithEditor); if (fDoLinkWithEditor && fEditor != null) { ISelectionProvider selectionProvider = fEditor.getSelectionProvider(); if (selectionProvider != null) { // can be null when editor is closed doLinkWithEditor(selectionProvider.getSelection()); }/*from www. j a va 2 s . c o m*/ } }
From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.actions.BaseCommandHandler.java
License:Open Source License
protected void initializeSelection(ExecutionEvent event) throws ExecutionException { IWorkbenchPart activePart = HandlerUtil.getActivePart(event); if (activePart != null) { partSite = activePart.getSite(); if (partSite != null) { ISelectionProvider selectionProvider = partSite.getSelectionProvider(); if (selectionProvider != null) { ISelection selection = selectionProvider.getSelection(); if (selection instanceof IStructuredSelection) { Object obj = ((IStructuredSelection) selection).getFirstElement(); if (obj instanceof IServer) { this.selectedServer = (IServer) obj; } else if (obj instanceof IServerModule) { IServerModule sm = (IServerModule) obj; IModule[] module = sm.getModule(); this.selectedModule = module[module.length - 1]; if (this.selectedModule != null) { this.selectedServer = sm.getServer(); }/* ww w. j ava 2s. co m*/ } } } else { logSelectionDetectionFailure(); } } else { logSelectionDetectionFailure(); } } else { logSelectionDetectionFailure(); } }
From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.CloudUiUtil.java
License:Open Source License
/** * If the Servers view is available and it contains a selection, the * corresponding structured selection is returned. In any other case, * including the Servers view being unavailable, either because it is not * installed or it is closed, null is returned. * @return structured selection in the Servers view, if the Servers view is * open and available, or null otherwise */// ww w . j av a2 s . co m public static IStructuredSelection getServersViewSelection() { IViewRegistry registry = PlatformUI.getWorkbench().getViewRegistry(); String serversViewID = SERVERS_VIEW_ID; // fast check to verify that the servers View is available. IViewDescriptor serversViewDescriptor = registry.find(serversViewID); if (serversViewDescriptor != null) { // Granular null checks required as any of the workbench components // may not be available at some given point in time (e.g., during // start/shutdown) IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (activeWorkbenchWindow != null) { IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); if (activePage != null) { IViewReference[] references = activePage.getViewReferences(); if (references != null) { IViewPart serversViewPart = null; for (IViewReference reference : references) { if (serversViewID.equals(reference.getId())) { serversViewPart = reference.getView(true); break; } } if (serversViewPart != null) { IViewSite viewSite = serversViewPart.getViewSite(); if (viewSite != null) { ISelectionProvider selectionProvider = viewSite.getSelectionProvider(); if (selectionProvider != null) { ISelection selection = selectionProvider.getSelection(); if (selection instanceof IStructuredSelection) { return (IStructuredSelection) selection; } } } } } } } } return null; }
From source file:coloredide.astview.ASTView.java
License:Open Source License
protected void performLinkWithEditor() { fDoLinkWithEditor = fLinkWithEditor.isChecked(); fDialogSettings.put(SETTINGS_LINK_WITH_EDITOR, fDoLinkWithEditor); if (fDoLinkWithEditor && fEditor != null) { ISelectionProvider selectionProvider = fEditor.getSelectionProvider(); if (selectionProvider != null) { // can be null when editor is // closed doLinkWithEditor(selectionProvider.getSelection()); }/*from ww w . j a v a 2 s. c o m*/ } }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.SelectionManager.java
License:Open Source License
/** * Syncs the current selection to the outline, synchronously. *///from w w w . ja v a 2s .c o m public void syncOutlineSelection() { OutlinePage outlinePage = mCanvas.getOutlinePage(); IWorkbenchPartSite site = outlinePage.getEditor().getSite(); ISelectionProvider selectionProvider = site.getSelectionProvider(); ISelection selection = selectionProvider.getSelection(); if (selection != null) { outlinePage.setSelection(selection); } }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.refactoring.RefactoringAssistant.java
License:Open Source License
@Override public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) { ISourceViewer sourceViewer = invocationContext.getSourceViewer(); AndroidXmlEditor xmlEditor = AndroidXmlEditor.fromTextViewer(sourceViewer); if (xmlEditor == null) { return null; }/*from www .ja va2 s .c om*/ IFile file = xmlEditor.getInputFile(); if (file == null) { return null; } int offset = invocationContext.getOffset(); // Ensure that we are over a tag name (for element-based refactoring // operations) or a value (for the extract include refactoring) boolean isValue = false; boolean isReferenceValue = false; boolean isTagName = false; boolean isAttributeName = false; boolean isStylableAttribute = false; ResourceUrl resource = null; IStructuredModel model = null; try { model = xmlEditor.getModelForRead(); IStructuredDocument doc = model.getStructuredDocument(); IStructuredDocumentRegion region = doc.getRegionAtCharacterOffset(offset); ITextRegion subRegion = region.getRegionAtCharacterOffset(offset); if (subRegion != null) { String type = subRegion.getType(); if (type.equals(DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) { String value = region.getText(subRegion); // Only extract values that aren't already resources // (and value includes leading ' or ") isValue = true; if (value.startsWith("'@") || value.startsWith("\"@")) { //$NON-NLS-1$ //$NON-NLS-2$ isReferenceValue = true; resource = RenameResourceXmlTextAction.findResource(doc, offset); } } else if (type.equals(DOMRegionContext.XML_TAG_NAME) || type.equals(DOMRegionContext.XML_TAG_OPEN) || type.equals(DOMRegionContext.XML_TAG_CLOSE)) { isTagName = true; } else if (type.equals(DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)) { isAttributeName = true; String name = region.getText(subRegion); int index = name.indexOf(':'); if (index != -1) { name = name.substring(index + 1); } isStylableAttribute = ExtractStyleRefactoring.isStylableAttribute(name); } else if (type.equals(DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS)) { // On the edge of an attribute name and an attribute value isAttributeName = true; isStylableAttribute = true; } else if (type.equals(DOMRegionContext.XML_CONTENT)) { resource = RenameResourceXmlTextAction.findResource(doc, offset); } } } finally { if (model != null) { model.releaseFromRead(); } } List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(); if (isTagName || isAttributeName || isValue || resource != null) { StructuredTextEditor structuredEditor = xmlEditor.getStructuredTextEditor(); ISelectionProvider provider = structuredEditor.getSelectionProvider(); ISelection selection = provider.getSelection(); if (selection instanceof ITextSelection) { ITextSelection textSelection = (ITextSelection) selection; ITextSelection originalSelection = textSelection; // Most of the visual refactorings do not work on text ranges // ...except for Extract Style where the actual attributes overlapping // the selection is going to be the set of eligible attributes boolean selectionOkay = false; if (textSelection.getLength() == 0 && !isValue) { selectionOkay = true; ISourceViewer textViewer = xmlEditor.getStructuredSourceViewer(); int caretOffset = textViewer.getTextWidget().getCaretOffset(); if (caretOffset >= 0) { Node node = DomUtilities.getNode(textViewer.getDocument(), caretOffset); if (node instanceof IndexedRegion) { IndexedRegion region = (IndexedRegion) node; int startOffset = region.getStartOffset(); int length = region.getEndOffset() - region.getStartOffset(); textSelection = new TextSelection(startOffset, length); } } } if (isValue && !isReferenceValue) { proposals.add(new RefactoringProposal(xmlEditor, new ExtractStringRefactoring(file, xmlEditor, textSelection))); } else if (resource != null) { RenameResourceProcessor processor = new RenameResourceProcessor(file.getProject(), resource.type, resource.name, null); RenameRefactoring refactoring = new RenameRefactoring(processor); proposals.add(new RefactoringProposal(xmlEditor, refactoring)); } LayoutEditorDelegate delegate = LayoutEditorDelegate.fromEditor(xmlEditor); if (delegate != null) { boolean showStyleFirst = isValue || (isAttributeName && isStylableAttribute); if (showStyleFirst) { proposals.add(new RefactoringProposal(xmlEditor, new ExtractStyleRefactoring(file, delegate, originalSelection, null))); } if (selectionOkay) { proposals.add(new RefactoringProposal(xmlEditor, new WrapInRefactoring(file, delegate, textSelection, null))); proposals.add(new RefactoringProposal(xmlEditor, new UnwrapRefactoring(file, delegate, textSelection, null))); proposals.add(new RefactoringProposal(xmlEditor, new ChangeViewRefactoring(file, delegate, textSelection, null))); proposals.add(new RefactoringProposal(xmlEditor, new ChangeLayoutRefactoring(file, delegate, textSelection, null))); } // Extract Include must always have an actual block to be extracted if (textSelection.getLength() > 0) { proposals.add(new RefactoringProposal(xmlEditor, new ExtractIncludeRefactoring(file, delegate, textSelection, null))); } // If it's not a value or attribute name, don't place it on top if (!showStyleFirst) { proposals.add(new RefactoringProposal(xmlEditor, new ExtractStyleRefactoring(file, delegate, originalSelection, null))); } } } } if (proposals.size() == 0) { return null; } else { return proposals.toArray(new ICompletionProposal[proposals.size()]); } }
From source file:com.android.ide.eclipse.adt.internal.refactorings.core.RenameResourceXmlTextAction.java
License:Open Source License
private ITextSelection getSelection() { ISelectionProvider selectionProvider = mEditor.getSelectionProvider(); if (selectionProvider == null) { return null; }/*from w ww. j av a 2s .co m*/ ISelection selection = selectionProvider.getSelection(); if (!(selection instanceof ITextSelection)) { return null; } return (ITextSelection) selection; }
From source file:com.android.ide.eclipse.auidt.internal.editors.layout.refactoring.RefactoringAssistant.java
License:Open Source License
@Override public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) { ISourceViewer sourceViewer = invocationContext.getSourceViewer(); AndroidXmlEditor xmlEditor = AndroidXmlEditor.fromTextViewer(sourceViewer); if (xmlEditor == null) { return null; }/*www. jav a 2 s . c o m*/ IFile file = xmlEditor.getInputFile(); if (file == null) { return null; } int offset = invocationContext.getOffset(); // Ensure that we are over a tag name (for element-based refactoring // operations) or a value (for the extract include refactoring) boolean isValue = false; boolean isReferenceValue = false; boolean isTagName = false; boolean isAttributeName = false; boolean isStylableAttribute = false; IStructuredModel model = null; try { model = xmlEditor.getModelForRead(); IStructuredDocument doc = model.getStructuredDocument(); IStructuredDocumentRegion region = doc.getRegionAtCharacterOffset(offset); ITextRegion subRegion = region.getRegionAtCharacterOffset(offset); if (subRegion != null) { String type = subRegion.getType(); if (type.equals(DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) { String value = region.getText(subRegion); // Only extract values that aren't already resources // (and value includes leading ' or ") isValue = true; if (value.startsWith("'@") || value.startsWith("\"@")) { //$NON-NLS-1$ //$NON-NLS-2$ isReferenceValue = true; } } else if (type.equals(DOMRegionContext.XML_TAG_NAME) || type.equals(DOMRegionContext.XML_TAG_OPEN) || type.equals(DOMRegionContext.XML_TAG_CLOSE)) { isTagName = true; } else if (type.equals(DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)) { isAttributeName = true; String name = region.getText(subRegion); int index = name.indexOf(':'); if (index != -1) { name = name.substring(index + 1); } isStylableAttribute = ExtractStyleRefactoring.isStylableAttribute(name); } else if (type.equals(DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS)) { // On the edge of an attribute name and an attribute value isAttributeName = true; isStylableAttribute = true; } } } finally { if (model != null) { model.releaseFromRead(); } } List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(); if (isTagName || isAttributeName || isValue) { StructuredTextEditor structuredEditor = xmlEditor.getStructuredTextEditor(); ISelectionProvider provider = structuredEditor.getSelectionProvider(); ISelection selection = provider.getSelection(); if (selection instanceof ITextSelection) { ITextSelection textSelection = (ITextSelection) selection; ITextSelection originalSelection = textSelection; // Most of the visual refactorings do not work on text ranges // ...except for Extract Style where the actual attributes overlapping // the selection is going to be the set of eligible attributes boolean selectionOkay = false; if (textSelection.getLength() == 0 && !isValue) { selectionOkay = true; ISourceViewer textViewer = xmlEditor.getStructuredSourceViewer(); int caretOffset = textViewer.getTextWidget().getCaretOffset(); if (caretOffset >= 0) { Node node = DomUtilities.getNode(textViewer.getDocument(), caretOffset); if (node instanceof IndexedRegion) { IndexedRegion region = (IndexedRegion) node; int startOffset = region.getStartOffset(); int length = region.getEndOffset() - region.getStartOffset(); textSelection = new TextSelection(startOffset, length); } } } if (isValue && !isReferenceValue) { proposals.add(new RefactoringProposal(xmlEditor, new ExtractStringRefactoring(file, xmlEditor, textSelection))); } LayoutEditorDelegate delegate = LayoutEditorDelegate.fromEditor(xmlEditor); if (delegate != null) { boolean showStyleFirst = isValue || (isAttributeName && isStylableAttribute); if (showStyleFirst) { proposals.add(new RefactoringProposal(xmlEditor, new ExtractStyleRefactoring(file, delegate, originalSelection, null))); } if (selectionOkay) { proposals.add(new RefactoringProposal(xmlEditor, new WrapInRefactoring(file, delegate, textSelection, null))); proposals.add(new RefactoringProposal(xmlEditor, new UnwrapRefactoring(file, delegate, textSelection, null))); proposals.add(new RefactoringProposal(xmlEditor, new ChangeViewRefactoring(file, delegate, textSelection, null))); proposals.add(new RefactoringProposal(xmlEditor, new ChangeLayoutRefactoring(file, delegate, textSelection, null))); } // Extract Include must always have an actual block to be extracted if (textSelection.getLength() > 0) { proposals.add(new RefactoringProposal(xmlEditor, new ExtractIncludeRefactoring(file, delegate, textSelection, null))); } // If it's not a value or attribute name, don't place it on top if (!showStyleFirst) { proposals.add(new RefactoringProposal(xmlEditor, new ExtractStyleRefactoring(file, delegate, originalSelection, null))); } } } } if (proposals.size() == 0) { return null; } else { return proposals.toArray(new ICompletionProposal[proposals.size()]); } }
From source file:com.aptana.editor.common.CommonOccurrencesUpdater.java
License:Open Source License
public void propertyChange(PropertyChangeEvent event) { final String property = event.getProperty(); if (IPreferenceConstants.EDITOR_MARK_OCCURRENCES.equals(property)) { boolean newBooleanValue = false; Object newValue = event.getNewValue(); if (newValue != null) { newBooleanValue = Boolean.valueOf(newValue.toString()).booleanValue(); }/* w w w .ja va 2s .co m*/ if (newBooleanValue) { install(); } else { uninstall(); } // force update if (editor != null) { ISelectionProvider selectionProvider = editor.getSelectionProvider(); if (selectionProvider != null) { updateAnnotations(selectionProvider.getSelection()); } } } }