本文整理汇总了Java中org.eclipse.core.runtime.IAdapterManager.getAdapter方法的典型用法代码示例。如果您正苦于以下问题:Java IAdapterManager.getAdapter方法的具体用法?Java IAdapterManager.getAdapter怎么用?Java IAdapterManager.getAdapter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.core.runtime.IAdapterManager
的用法示例。
在下文中一共展示了IAdapterManager.getAdapter方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAdapter
import org.eclipse.core.runtime.IAdapterManager; //导入方法依赖的package包/类
/**
* Returns an instance of the adaptable object with type of adapterType, or
* null if the given object could not be adapted to that type. See
* {@link IAdapterManager#getAdapter(Object, Class)}.
*/
@SuppressWarnings("unchecked")
public static <T> T getAdapter(Object adaptable,
Class<? extends T> adapterType) {
/*
* Try a simple instanceof check. This also safeguards against a misuse of
* getAdapter. For example, ISelection is adaptable (there is a
* SelectionAdapterFactory), so the user may incorrectly try adapting it to
* IStructuredSelection. However, in this case, the implementation of
* SelectionAdapterFactory would return null.
*/
if (adapterType.isInstance(adaptable)) {
return (T) adaptable;
}
IAdapterManager adapterManager = Platform.getAdapterManager();
assert (adapterManager != null);
return (T) adapterManager.getAdapter(adaptable, adapterType);
}
示例2: execute
import org.eclipse.core.runtime.IAdapterManager; //导入方法依赖的package包/类
@Override
public final Object execute(final ExecutionEvent event)
{
final List<String> arguments = new ArrayList<String>();
final String command = Activator.getDefault().getPreferenceStore().getString(this.getMergeCommandPathName());
final TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
if (selection.isEmpty() == false)
{
final IAdapterManager adapterManager = Platform.getAdapterManager();
final IResource resource = adapterManager.getAdapter(selection.getFirstElement(), IResource.class);
if (resource != null)
{
arguments.add("/patchpath:" + resource.getLocation().toString());
ProcessWrapper.executeCommand(command, arguments);
}
}
return null;
}
示例3: buildController
import org.eclipse.core.runtime.IAdapterManager; //导入方法依赖的package包/类
private static SaveToServerActionController buildController(final IStructuredSelection selection) {
final IAdapterManager adapterManager = Platform.getAdapterManager();
final List<IResource> selectedResources = new ArrayList<>();
for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
final IResource selectedResource = (IResource) adapterManager.getAdapter(iterator.next(), IResource.class);
if (null != selectedResource) {
selectedResources.add(selectedResource);
}
}
final List<IResource> filteredResources = filter(selectedResources);
if (filteredResources.isEmpty())
return null;
final IProject project = filteredResources.get(0).getProject();
for (final IResource resource : filteredResources) {
if (!project.equals(resource.getProject())) {
logger.warn("Unable to save resources from multiple projects at the same time. Only saving resources from "
+ project.getName());
break;
}
}
return buildController(selection, filteredResources, project);
}
示例4: getAdapter
import org.eclipse.core.runtime.IAdapterManager; //导入方法依赖的package包/类
/**
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
*/
public <T> T getAdapter(Class<T> adapter) {
// lookup the IAdapterManager service
final IAdapterManager manager = Platform.getAdapterManager();
// forward the request to IAdapterManager service
return manager.getAdapter(this, adapter);
}
示例5: getBreakpoint
import org.eclipse.core.runtime.IAdapterManager; //导入方法依赖的package包/类
private ChromiumLineBreakpoint getBreakpoint() {
IAdapterManager manager= Platform.getAdapterManager();
IAdaptable adaptable = getElement();
ChromiumLineBreakpoint adapted =
(ChromiumLineBreakpoint) manager.getAdapter(adaptable, ChromiumLineBreakpoint.class);
return adapted;
}
示例6: test
import org.eclipse.core.runtime.IAdapterManager; //导入方法依赖的package包/类
@Override
public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue)
{
boolean result = false;
if ((receiver != null) && (expectedValue != null))
{
int expectedType = IResource.NONE;
if (expectedValue.toString().toUpperCase().equals("IResource.FILE".toUpperCase()))
{
expectedType = IResource.FILE;
}
else if (expectedValue.toString().toUpperCase().equals("IResource.FOLDER".toUpperCase()))
{
expectedType = IResource.FOLDER;
}
else if (expectedValue.toString().toUpperCase().equals("IResource.PROJECT".toUpperCase()))
{
expectedType = IResource.PROJECT;
}
else
{
// Invalid or unknown expected value
return false;
}
final IAdapterManager adapterManager = Platform.getAdapterManager();
if (adapterManager != null)
{
// Check if selected item is of expected type
final IResource resource = adapterManager.getAdapter(receiver, IResource.class);
if ((resource != null) && ((resource.getType() & expectedType) != IResource.NONE))
{
result = true;
}
}
}
return result;
}
示例7: execute
import org.eclipse.core.runtime.IAdapterManager; //导入方法依赖的package包/类
@Override
public final Object execute(final ExecutionEvent event) throws ExecutionException
{
final ISelection selection = HandlerUtil.getCurrentSelection(event);
IResource resource = null;
if (selection instanceof TreeSelection)
{
final IAdapterManager adapterManager = Platform.getAdapterManager();
final TreeSelection treeSelection = (TreeSelection) selection;
resource = adapterManager.getAdapter(treeSelection.getFirstElement(), IResource.class);
}
else if (selection instanceof TextSelection)
{
resource = WorkbenchUtil.getCurrentDocument();
}
if (resource != null)
{
final BeyondCompare bc = new BeyondCompare();
final int resourceType = resource.getType();
if ((resourceType == IResource.FOLDER) || (resourceType == IResource.PROJECT))
{
bc.setSavedLeft(resource.getLocation().toString());
bc.setSavedLeftType(BeyondCompareSavedLeft.Directory);
bc.writeRegistry();
}
else if (resourceType == IResource.FILE)
{
bc.setSavedLeft(resource.getLocation().toString());
bc.setSavedLeftType(BeyondCompareSavedLeft.File);
bc.writeRegistry();
}
}
return null;
}
示例8: execute
import org.eclipse.core.runtime.IAdapterManager; //导入方法依赖的package包/类
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException
{
final TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
final Object[] paths = selection.toArray();
final IAdapterManager adapterManager = Platform.getAdapterManager();
final IResource leftResource = adapterManager.getAdapter(paths[0], IResource.class);
final IResource rightResource = adapterManager.getAdapter(paths[1], IResource.class);
if ((leftResource != null) && (rightResource != null))
{
BeyondCompare.compare(leftResource.getLocation().toString(), rightResource.getLocation().toString());
}
return null;
}
示例9: execute
import org.eclipse.core.runtime.IAdapterManager; //导入方法依赖的package包/类
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException
{
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection != null)
{
final IAdapterManager adapterManager = Platform.getAdapterManager();
if ((selection != null) && (selection.isEmpty() == false))
{
Object receiver = null;
// Context menu has been opened in a tree view
if (selection instanceof IStructuredSelection)
{
final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
receiver = structuredSelection.getFirstElement();
}
else if (selection instanceof TextSelection)
{
receiver = WorkbenchUtil.getCurrentDocument();
}
final IResource rightResource;
rightResource = adapterManager.getAdapter(receiver, IResource.class);
if (rightResource != null)
{
final BeyondCompare bc = new BeyondCompare();
bc.readRegistry();
final String savedLeft = bc.getSavedLeft();
BeyondCompare.compare(savedLeft, rightResource.getLocation().toString());
}
}
}
return null;
}
示例10: getCurrentDocument
import org.eclipse.core.runtime.IAdapterManager; //导入方法依赖的package包/类
/**
* @return The current document of the workbench.
*/
public static IResource getCurrentDocument()
{
final IAdapterManager adapterManager = Platform.getAdapterManager();
final IWorkbench wb = PlatformUI.getWorkbench();
final IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
final IWorkbenchPage page = window.getActivePage();
final IEditorPart editor = page.getActiveEditor();
if (editor != null)
{
final IEditorInput input = editor.getEditorInput();
return adapterManager.getAdapter(input, IResource.class);
}
return null;
}
示例11: getSelectedResources
import org.eclipse.core.runtime.IAdapterManager; //导入方法依赖的package包/类
protected static List<IResource> getSelectedResources(final IStructuredSelection selection) {
final IAdapterManager adapterManager = Platform.getAdapterManager();
final List<IResource> selectedResources = new ArrayList<>();
for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
final IResource selectedResource = (IResource) adapterManager.getAdapter(iterator.next(), IResource.class);
if (null != selectedResource) {
selectedResources.add(selectedResource);
}
}
return selectedResources;
}
示例12: getContributionItems
import org.eclipse.core.runtime.IAdapterManager; //导入方法依赖的package包/类
@Override
protected final IContributionItem[] getContributionItems()
{
// By default, return an empty list (if context menu entry must not be
// shown)
Boolean showEntry = false;
IContributionItem[] items = new IContributionItem[]
{};
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null)
{
final ISelection selection = window.getSelectionService().getSelection();
if ((selection != null) && (selection.isEmpty() == false))
{
Object receiver = null;
// Context menu has been opened in a tree view
if (selection instanceof IStructuredSelection)
{
final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
receiver = structuredSelection.getFirstElement();
}
else if (selection instanceof TextSelection)
{
receiver = WorkbenchUtil.getCurrentDocument();
}
if (receiver != null)
{
final BeyondCompareSavedLeft savedLeftType = bc.getSavedLeftType();
final IAdapterManager adapterManager = Platform.getAdapterManager();
if (adapterManager != null)
{
int resourceType = IResource.NONE;
final IResource resource = adapterManager.getAdapter(receiver, IResource.class);
if (resource != null)
{
resourceType = resource.getType();
}
if (((resourceType == IResource.PROJECT) || (resourceType == IResource.FOLDER)) && (savedLeftType == BeyondCompareSavedLeft.Directory))
{
showEntry = true;
}
else if ((resourceType == IResource.FILE) && (savedLeftType == BeyondCompareSavedLeft.File))
{
showEntry = true;
}
else
{
showEntry = false;
}
if (showEntry)
{
final String savedLeft = bc.getSavedLeft();
if (savedLeft != null)
{
final CommandContributionItemParameter parameter = new CommandContributionItemParameter(this.currentServiceLocator, null,
"ContextQuickie.commands.compareToRight", 0);
final String filename = new File(savedLeft).getName();
parameter.label = "Compare to " + filename;
parameter.icon = contextquickie.Activator.getImageDescriptor("icons/BeyondCompare/Compare.png");
items = new IContributionItem[]
{ new CommandContributionItem(parameter) };
}
}
}
}
}
}
return items;
}
示例13: test
import org.eclipse.core.runtime.IAdapterManager; //导入方法依赖的package包/类
@Override
public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue)
{
boolean returnValue = false;
final TreeSelection selection = (TreeSelection) receiver;
final Object[] paths = selection.toArray();
final IAdapterManager adapterManager = Platform.getAdapterManager();
if (adapterManager != null)
{
int leftType = IResource.NONE;
final IResource left = adapterManager.getAdapter(paths[0], IResource.class);
if (left != null)
{
leftType = left.getType();
}
int rightType = IResource.NONE;
final IResource right = adapterManager.getAdapter(paths[1], IResource.class);
if (right != null)
{
rightType = right.getType();
}
if ((leftType == IResource.FILE) && (rightType == IResource.FILE))
{
returnValue = true;
}
else if ((leftType == IResource.FOLDER) && (rightType == IResource.FOLDER))
{
returnValue = true;
}
else if ((leftType == IResource.FOLDER) && (rightType == IResource.PROJECT))
{
returnValue = true;
}
else if ((leftType == IResource.PROJECT) && (rightType == IResource.FOLDER))
{
returnValue = true;
}
else if ((leftType == IResource.PROJECT) && (rightType == IResource.PROJECT))
{
returnValue = true;
}
}
return returnValue;
}