本文整理汇总了Java中org.eclipse.ui.handlers.HandlerUtil.getCurrentSelection方法的典型用法代码示例。如果您正苦于以下问题:Java HandlerUtil.getCurrentSelection方法的具体用法?Java HandlerUtil.getCurrentSelection怎么用?Java HandlerUtil.getCurrentSelection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.ui.handlers.HandlerUtil
的用法示例。
在下文中一共展示了HandlerUtil.getCurrentSelection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection sel = HandlerUtil.getCurrentSelection(event);
if (sel.isEmpty())
return null;
if (!(sel instanceof IStructuredSelection))
return null;
Object obj = ((IStructuredSelection) sel).getFirstElement();
if (!(obj instanceof IFile))
return null;
try {
ConvertToFileCreationWizard wizard = new ConvertToFileCreationWizard( );
wizard.init(PlatformUI.getWorkbench(), (IStructuredSelection)sel);
Shell activeShell = HandlerUtil.getActiveShell(event);
if (activeShell==null) return null;
WizardDialog dialog = new WizardDialog(activeShell,wizard);
dialog.open();
} catch (Exception e) {
ResourceManager.logException(e);
}
return null;
}
示例2: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
for (Iterator<?> it = ((IStructuredSelection) selection).iterator(); it
.hasNext();) {
Object element = it.next();
IProject project = null;
if (element instanceof IProject) {
project = (IProject) element;
} else if (element instanceof IAdaptable) {
project = (IProject) ((IAdaptable) element)
.getAdapter(IProject.class);
}
if (project != null) {
try {
toggleNature(project);
} catch (CoreException e) {
throw new ExecutionException("Failed to toggle nature", e);
}
}
}
}
return null;
}
示例3: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
markSpec = getMark();
IEditorPart edPart = HandlerUtil.getActiveEditor(event);
if (edPart instanceof FluentMkEditor) {
editor = (FluentMkEditor) edPart;
doc = editor.getDocument();
if (doc != null) {
ISelection sel = HandlerUtil.getCurrentSelection(event);
if (sel instanceof TextSelection) {
TextSelection tsel = (TextSelection) sel;
int beg = tsel.getOffset();
int len = tsel.getLength();
cpos = editor.getCursorOffset();
if (len == 0) beg = cpos;
try {
if (samePartition(beg, len)) {
toggle(beg, len);
}
} catch (BadLocationException e) {}
}
}
}
return null;
}
示例4: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
public Object execute(ExecutionEvent event) throws ExecutionException {
// TODO Auto-generated method stub
ISelection selection = HandlerUtil.getCurrentSelection(event);
//
if (selection instanceof IStructuredSelection) {
for (Iterator<?> it = ((IStructuredSelection) selection).iterator(); it
.hasNext();) {
Object element = it.next();
IProject project = null;
if (element instanceof IProject) {
project = (IProject) element;
} else if (element instanceof IAdaptable) {
project = (IProject) ((IAdaptable) element)
.getAdapter(IProject.class);
}
if (project != null) {
toggleNature(project);
}
}
}
return null;
}
示例5: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
BookmarkFolder parent = null;
if (selection.isEmpty()) {
parent = bookmarksService.getBookmarksTree().getRootFolder();
} else {
Bookmark bookmark = (Bookmark) selection.getFirstElement();
if (!(bookmark instanceof BookmarkFolder)) {
return null;
}
parent = (BookmarkFolder) bookmark;
}
try {
bookmarksService.sortByName(parent.getId());
} catch (BookmarksException e) {
throw new ExecutionException("Could not sort by name", e);
}
return null;
}
示例6: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
String url = getBookmarkUrl(selection);
if (url == null) {
return null;
}
Clipboard clipboard = new Clipboard(null);
try {
TextTransfer textTransfer = TextTransfer.getInstance();
Transfer[] transfers = new Transfer[] { textTransfer };
Object[] data = new Object[] { url };
clipboard.setContents(data, transfers);
} finally {
clipboard.dispose();
}
return null;
}
示例7: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
Bookmark bookmark = getSelectedBookmark(selection);
Shell shell = HandlerUtil.getActiveShell(event);
String newName = askBookmarkName(shell, bookmark.getPropertyValue(Bookmark.PROPERTY_NAME));
if (newName == null) {
return null;
}
try {
bookmarksService.renameBookmark(bookmark.getId(), newName);
} catch (BookmarksException e) {
throw new ExecutionException("Could not rename bookmark", e);
}
return null;
}
示例8: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
BookmarkFolder parent = null;
if (selection.isEmpty()) {
parent = bookmarksService.getBookmarksTree().getRootFolder();
} else {
Bookmark bookmark = (Bookmark) selection.getFirstElement();
if (!(bookmark instanceof BookmarkFolder)) {
return null;
}
parent = (BookmarkFolder) bookmark;
}
Shell shell = HandlerUtil.getActiveShell(event);
String folderName = askBookmarkFolderName(shell);
if (folderName == null) {
return null;
}
try {
bookmarksService.addBookmarkFolder(parent.getId(), folderName);
} catch (BookmarksException e) {
throw new ExecutionException("Could not add bookmark folder", e);
}
return null;
}
示例9: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart edPart = HandlerUtil.getActiveEditor(event);
if (edPart instanceof FluentMkEditor) {
FluentMkEditor editor = (FluentMkEditor) edPart;
IDocument doc = editor.getDocument();
if (doc != null) {
ISelection sel = HandlerUtil.getCurrentSelection(event);
if (sel instanceof TextSelection) {
TextSelection tsel = (TextSelection) sel;
int beg = tsel.getOffset();
int len = tsel.getLength();
switch (checkPartition(doc, beg, len)) {
case NONE:
addComment(doc, beg, len);
break;
case SAME:
removeComment(doc, beg);
break;
}
}
}
}
return null;
}
示例10: getOperationContext
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
protected BookmarkPartOperationContext getOperationContext(ExecutionEvent event) {
IWorkbenchPart part = HandlerUtil.getActivePart(event);
ISelection selection;
if (part != null) {
// see bug #375220 or #282969 to understand why we don't use
// HandlerUtil.getCurrentSelection(event);
selection = part.getSite().getSelectionProvider().getSelection();
} else {
selection = HandlerUtil.getCurrentSelection(event);
}
if (part instanceof BookmarksView) {
part = ((BookmarksView) part).getPreviousActivePart();
if (part != null) {
selection = part.getSite().getSelectionProvider().getSelection();
}
}
return new BookmarkPartOperationContext(part, selection);
}
示例11: getActiveTreeResourceSelection
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
/**
* Returns the active tree resource selection if there is one.
*
* Examines the active workspace selection and if it is a resource inside of a tree returns it.
*
* @param event
* The execution event
* @returns The resource or {@code null} on failure.
*
*/
private static IResource getActiveTreeResourceSelection(ExecutionEvent event) {
ISelection activeSelection = HandlerUtil.getCurrentSelection(event);
if (activeSelection instanceof TreeSelection) {
Object firstElement = ((TreeSelection) activeSelection).getFirstElement();
if (firstElement instanceof IResource) {
return (IResource) firstElement;
}
}
return null;
}
示例12: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow == null) {
return null;
}
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
if (activePage == null) {
return null;
}
IEditorPart editor = activePage.getActiveEditor();
if (editor == null) {
return null;
}
IEditorInput input = editor.getEditorInput();
if (input == null || ! (input instanceof FileEditorInput)) {
return null;
}
IFile file = ((FileEditorInput) input).getFile();
if (file != null && file.getType() == IResource.FILE && file.getFileExtension().equals("java")) {
utils = new ProjectUtils(file.getProject());
if (utils.isGluonMobileProject()) {
ISelection selection = HandlerUtil.getCurrentSelection(event);
Display.getDefault().asyncExec(() -> new JCode(utils, selection, (JavaEditor) editor));
}
}
return null;
}
示例13: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
public Object execute(ExecutionEvent event) throws ExecutionException {
Supplier<IExecutionEngine> engineSupplier = org.eclipse.gemoc.executionframework.debugger.Activator.getDefault().getEngineSupplier();
Supplier<String> bundleSupplier = org.eclipse.gemoc.executionframework.debugger.Activator.getDefault().getBundleSymbolicNameSupplier();
if (engineSupplier != null) {
this.engine = engineSupplier.get();
}
if (bundleSupplier != null) {
this.bundleSymbolicName = bundleSupplier.get();
}
TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
locateAndOpenSource(selection);
return null;
}
示例14: getOutlineNode
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
private IOutlineNode getOutlineNode(ExecutionEvent event) {
ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
if (!(currentSelection instanceof IStructuredSelection)) {
return null;
}
IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
return (IOutlineNode) structuredSelection.getFirstElement();
}
示例15: getProject
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
public static IProject getProject(final ExecutionEvent event) {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
final Object element = ((IStructuredSelection) selection)
.getFirstElement();
return Platform.getAdapterManager().getAdapter(element,
IProject.class);
}
return null;
}