当前位置: 首页>>代码示例>>Java>>正文


Java HandlerUtil.getCurrentSelection方法代码示例

本文整理汇总了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;
	}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:25,代码来源:ConvertToHandler.java

示例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;
}
 
开发者ID:ioanaverebi,项目名称:Sparrow,代码行数:26,代码来源:AddRemoveOutcodeNatureHandler.java

示例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;
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:26,代码来源:AbstractMarksHandler.java

示例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;
}
 
开发者ID:SAP,项目名称:hybris-commerce-eclipse-plugin,代码行数:24,代码来源:AddRemoveHybrisNatureHandler.java

示例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;
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:21,代码来源:SortByNameHandler.java

示例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;
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:20,代码来源:CopyBookmarkUrlHandler.java

示例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;

}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:19,代码来源:RenameBookmarkHandler.java

示例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;
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:27,代码来源:NewBookmarkFolderHandler.java

示例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;
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:27,代码来源:ToggleHiddenCommentHandler.java

示例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);
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:19,代码来源:AbstractBookmarkPartOperationHandler.java

示例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;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:24,代码来源:CreateNewN4JSElementInModuleHandler.java

示例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;
}
 
开发者ID:gluonhq,项目名称:ide-plugins,代码行数:29,代码来源:InsertGluonFunctionHandler.java

示例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;
}
 
开发者ID:eclipse,项目名称:gemoc-studio-modeldebugging,代码行数:15,代码来源:OpenSemanticsHandler.java

示例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();
}
 
开发者ID:mduft,项目名称:lcdsl,代码行数:9,代码来源:AbstractLaunchConfigGeneratorHandler.java

示例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;
}
 
开发者ID:pgcodekeeper,项目名称:pgcodekeeper,代码行数:13,代码来源:AddBuilder.java


注:本文中的org.eclipse.ui.handlers.HandlerUtil.getCurrentSelection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。