Java Code Examples for org.eclipse.core.runtime.IAdaptable

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project bndtools, under directory /bndtools.core/src/bndtools/preferences/ui/.

Source file: BndProjectPropertyPage.java

  22 
vote

IProject getProject(){
  IAdaptable elem=getElement();
  if (elem instanceof IProject)   return (IProject)elem;
  IProject project=(IProject)elem.getAdapter(IProject.class);
  if (project != null)   return project;
  throw new IllegalArgumentException("Target element does not adapt to IProject");
}
 

Example 2

From project Diver, under directory /ca.uvic.chisel.javasketch/src/ca/uvic/chisel/javasketch/ui/internal/presentation/.

Source file: JavaThreadSequenceView.java

  22 
vote

protected ASTMessageGroupingTree getGroupIng(IMessageGrouping group){
  if (group instanceof IAdaptable) {
    IAdaptable adapt=(IAdaptable)group;
    return (ASTMessageGroupingTree)adapt.getAdapter(ASTMessageGroupingTree.class);
  }
  return null;
}
 

Example 3

From project eclipse-instasearch, under directory /instasearch/src/it/unibz/instasearch/ui/.

Source file: InstaSearchUI.java

  22 
vote

public static String getActiveProject(){
  IEditorPart editor=getActiveEditor();
  if (editor == null)   return null;
  IAdaptable adaptable=editor.getEditorInput();
  IProject project=(IProject)adaptable.getAdapter(IProject.class);
  if (project == null) {
    IResource resource=(IResource)adaptable.getAdapter(IResource.class);
    if (resource != null)     project=resource.getProject();
  }
  if (project != null && project.isAccessible())   return project.getName();
  return null;
}
 

Example 4

From project eclipse-integration-gradle, under directory /org.springsource.ide.eclipse.gradle.ui/src/org/springsource/ide/eclipse/gradle/ui/.

Source file: GradleProjectPropertyPage.java

  22 
vote

private GradleProject getGradleProject(){
  IAdaptable el=getElement();
  IProject project=(IProject)el.getAdapter(IProject.class);
  if (project != null) {
    return GradleCore.create(project);
  }
  return null;
}
 

Example 5

From project eclipsefp, under directory /net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/actions/.

Source file: OpenHaskellPerspective.java

  22 
vote

@Override public void run(){
  IWorkbenchWindow window=getWorkbench().getActiveWorkbenchWindow();
  IWorkbenchPage page=window.getActivePage();
  IAdaptable input=(page != null) ? page.getInput() : ResourcesPlugin.getWorkspace().getRoot();
  try {
    String perspectiveId=HaskellUIPlugin.ID_PERSPECTIVE;
    getWorkbench().showPerspective(perspectiveId,window,input);
  }
 catch (  WorkbenchException wbex) {
    handleError(wbex,"Could not open perspective.\nSee error log for details.");
  }
}
 

Example 6

From project grails-ide, under directory /org.grails.ide.eclipse.runonserver/src/org/grails/ide/eclipse/runonserver/.

Source file: GrailsProjectPropertyTester.java

  22 
vote

private IProject toProject(Object receiver){
  if (receiver instanceof IProject)   return (IProject)receiver;
 else   if (receiver instanceof IAdaptable) {
    IAdaptable adapable=(IAdaptable)receiver;
    return (IProject)adapable.getAdapter(IProject.class);
  }
 else {
    return null;
  }
}
 

Example 7

From project mwe, under directory /plugins/org.eclipse.emf.mwe.ui/src/org/eclipse/emf/mwe/internal/ui/debug/launching/ui/launchable/.

Source file: LaunchableTester.java

  22 
vote

/** 
 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object,java.lang.String,java.lang.Object[],java.lang.Object)
 */
public boolean test(final Object receiver,final String property,final Object[] args,final Object expectedValue){
  if (receiver == null)   return false;
  final IAdaptable adaptable=(IAdaptable)receiver;
  final IFile file=(IFile)adaptable.getAdapter(IFile.class);
  if (file != null)   return checkFileCriteria(file);
  return false;
}
 

Example 8

From project mylyn.context, under directory /org.eclipse.mylyn.resources.ui/src/org/eclipse/mylyn/internal/resources/ui/.

Source file: ResourceStructureBridge.java

  22 
vote

@Override public boolean acceptsObject(Object object){
  if (object instanceof IResource) {
    return true;
  }
  if (object instanceof IAdaptable) {
    IAdaptable adaptable=(IAdaptable)object;
    Object adapter=adaptable.getAdapter(IResource.class);
    if (adapter instanceof IResource) {
      return true;
    }
  }
  return false;
}
 

Example 9

From project phresco-eclipse, under directory /com.photon.phresco.ui/src/com/photon/phresco/ui/propertypages/.

Source file: ConfigurationsPropertyPage.java

  22 
vote

@Override protected Control createContents(Composite parent){
  IAdaptable element2=getElement();
  Object adapter=element2.getAdapter(IProject.class);
  if (adapter instanceof IProject) {
    IProject project=(IProject)adapter;
    configPath=project.getFolder(".phresco").getFile("phresco-env-config.xml").getFullPath();
    projectCode=project.getName();
  }
  PhrescoConfigControl configParent=new PhrescoConfigControl(parent,SWT.NONE,configPath,projectCode);
  return configParent;
}
 

Example 10

From project radrails, under directory /plugins/org.radrails.rails.ui/src/org/radrails/rails/ui/.

Source file: RunMigrationAction.java

  22 
vote

private IResource getFile(Object element){
  if (element instanceof IResource)   return (IResource)element;
  if (element instanceof IAdaptable) {
    IAdaptable adapt=(IAdaptable)element;
    return (IResource)adapt.getAdapter(IResource.class);
  }
  return null;
}
 

Example 11

From project ceylon-ide-eclipse, under directory /plugins/com.redhat.ceylon.eclipse.ui/src/com/redhat/ceylon/eclipse/code/explorer/.

Source file: PackageExplorerPart.java

  21 
vote

private Object convertElement(Object original){
  if (original instanceof IJavaElement) {
    if (original instanceof ICompilationUnit) {
      ICompilationUnit cu=(ICompilationUnit)original;
      IJavaProject javaProject=cu.getJavaProject();
      if (javaProject != null && javaProject.exists() && !javaProject.isOnClasspath(cu)) {
        IResource resource=cu.getResource();
        if (resource != null)         return resource;
      }
    }
    return original;
  }
 else   if (original instanceof IResource) {
    IJavaElement je=JavaCore.create((IResource)original);
    if (je != null && je.exists()) {
      IJavaProject javaProject=je.getJavaProject();
      if (javaProject != null && javaProject.exists()) {
        if (javaProject.equals(je) || javaProject.isOnClasspath(je)) {
          return je;
        }
 else {
          return original;
        }
      }
    }
  }
 else   if (original instanceof IAdaptable) {
    IAdaptable adaptable=(IAdaptable)original;
    IJavaElement je=(IJavaElement)adaptable.getAdapter(IJavaElement.class);
    if (je != null && je.exists())     return je;
    IResource r=(IResource)adaptable.getAdapter(IResource.class);
    if (r != null) {
      je=JavaCore.create(r);
      if (je != null && je.exists())       return je;
 else       return r;
    }
  }
  return original;
}
 

Example 12

From project dawn-common, under directory /org.dawb.common.ui/src/org/dawb/common/ui/util/.

Source file: EclipseUtils.java

  21 
vote

/** 
 * Returns the active project based on active selection
 */
public static IProject getActiveProject(){
  final IWorkbenchPage page=EclipseUtils.getActivePage();
  if (page == null)   return null;
  final IEditorPart activeEditor=page.getActiveEditor();
  if (activeEditor != null) {
    final IEditorInput input=activeEditor.getEditorInput();
    if (input instanceof FileEditorInput) {
      return ((FileEditorInput)input).getFile().getProject();
    }
  }
  final ISelectionService service=page.getWorkbenchWindow().getSelectionService();
  final ISelection sel=service.getSelection();
  if (!(sel instanceof IStructuredSelection))   return null;
  final IStructuredSelection ss=(IStructuredSelection)sel;
  final Object element=ss.getFirstElement();
  if (element instanceof IResource)   return ((IResource)element).getProject();
  if (!(element instanceof IAdaptable))   return null;
  IAdaptable adaptable=(IAdaptable)element;
  Object adapter=adaptable.getAdapter(IResource.class);
  return ((IResource)adapter).getProject();
}
 

Example 13

From project Eclipse, under directory /com.mobilesorcery.sdk.html5/src/com/mobilesorcery/sdk/html5/ui/.

Source file: ReloadHandler.java

  21 
vote

public static boolean extractVMs(Object receiver,List<ReloadVirtualMachine> result){
  if (receiver instanceof IStructuredSelection) {
    IStructuredSelection selection=(IStructuredSelection)receiver;
    List potentialVMs=selection.toList();
    for (    Object potentialVM : potentialVMs) {
      extractVMs(potentialVM,result);
    }
    return !potentialVMs.isEmpty();
  }
  if (receiver instanceof ILaunch) {
    ILaunch launch=(ILaunch)receiver;
    receiver=launch.getDebugTarget();
  }
  if (receiver instanceof IThread) {
    IThread thread=(IThread)receiver;
    receiver=thread.getDebugTarget();
  }
  if (receiver instanceof IStackFrame) {
    IStackFrame stackFrame=(IStackFrame)receiver;
    stackFrame.getDebugTarget();
  }
  if (receiver instanceof IAdaptable) {
    IAdaptable adapt=(IAdaptable)receiver;
    receiver=adapt.getAdapter(IDebugTarget.class);
  }
  if (receiver instanceof IJavaScriptDebugTarget) {
    IJavaScriptDebugTarget debugTarget=(IJavaScriptDebugTarget)receiver;
    List<ReloadVirtualMachine> vms=Html5Plugin.getDefault().getReloadServer().getVMs(false);
    for (    ReloadVirtualMachine vm : vms) {
      if (debugTarget == vm.getJavaScriptDebugTarget()) {
        if (result != null) {
          result.add(vm);
        }
        return true;
      }
    }
  }
  return false;
}
 

Example 14

From project eclipse.platform.runtime, under directory /bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/.

Source file: EclipseAdapter.java

  21 
vote

@SuppressWarnings("unchecked") @Override public <T>T adapt(Object element,Class<T> adapterType){
  Assert.isNotNull(adapterType);
  if (element == null) {
    return null;
  }
  if (adapterType.isInstance(element)) {
    return (T)element;
  }
  if (element instanceof IAdaptable) {
    IAdaptable adaptable=(IAdaptable)element;
    Object result=adaptable.getAdapter(adapterType);
    if (result != null) {
      Assert.isTrue(adapterType.isInstance(result));
      return (T)result;
    }
  }
  if (adapterManager == null)   adapterManager=lookupAdapterManager();
  if (adapterManager == null) {
    return null;
  }
  Object result=adapterManager.loadAdapter(element,adapterType.getName());
  if (result != null) {
    Assert.isTrue(adapterType.isInstance(result));
    return (T)result;
  }
  return null;
}
 

Example 15

From project gda-common-rcp, under directory /uk.ac.gda.common.rcp/src/uk/ac/gda/common/rcp/util/.

Source file: EclipseUtils.java

  21 
vote

/** 
 * Returns the active project based on active selection
 */
public static IProject getActiveProject(){
  final IWorkbenchPage page=EclipseUtils.getActivePage();
  if (page == null)   return null;
  final IEditorPart activeEditor=page.getActiveEditor();
  if (activeEditor != null) {
    final IEditorInput input=activeEditor.getEditorInput();
    if (input instanceof FileEditorInput) {
      return ((FileEditorInput)input).getFile().getProject();
    }
  }
  final ISelectionService service=page.getWorkbenchWindow().getSelectionService();
  final ISelection sel=service.getSelection();
  if (!(sel instanceof IStructuredSelection))   return null;
  final IStructuredSelection ss=(IStructuredSelection)sel;
  final Object element=ss.getFirstElement();
  if (element instanceof IResource)   return ((IResource)element).getProject();
  if (!(element instanceof IAdaptable))   return null;
  IAdaptable adaptable=(IAdaptable)element;
  Object adapter=adaptable.getAdapter(IResource.class);
  return ((IResource)adapter).getProject();
}
 

Example 16

From project JGit, under directory /org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/.

Source file: GitLightweightDecorator.java

  21 
vote

private static IResource getResource(Object element){
  if (element instanceof ResourceMapping) {
    element=((ResourceMapping)element).getModelObject();
  }
  IResource resource=null;
  if (element instanceof IResource) {
    resource=(IResource)element;
  }
 else   if (element instanceof IAdaptable) {
    final IAdaptable adaptable=(IAdaptable)element;
    resource=(IResource)adaptable.getAdapter(IResource.class);
    if (resource == null) {
      final IContributorResourceAdapter adapter=(IContributorResourceAdapter)adaptable.getAdapter(IContributorResourceAdapter.class);
      if (adapter != null)       resource=adapter.getAdaptedResource(adaptable);
    }
  }
  return resource;
}
 

Example 17

From project m2eclipse-webby, under directory /org.sonatype.m2e.webby/src/org/sonatype/m2e/webby/internal/launch/ui/.

Source file: WebbyLaunchShortcut.java

  21 
vote

public void launch(ISelection selection,String mode){
  if (selection instanceof IStructuredSelection) {
    IStructuredSelection structuredSelection=(IStructuredSelection)selection;
    Object object=structuredSelection.getFirstElement();
    IContainer container=null;
    if (object instanceof IProject || object instanceof IFolder) {
      container=(IContainer)object;
    }
 else     if (object instanceof IFile) {
      container=((IFile)object).getParent();
    }
 else     if (object instanceof IAdaptable) {
      IAdaptable adaptable=(IAdaptable)object;
      Object adapter=adaptable.getAdapter(IProject.class);
      if (adapter != null) {
        container=(IContainer)adapter;
      }
 else {
        adapter=adaptable.getAdapter(IFolder.class);
        if (adapter != null) {
          container=(IContainer)adapter;
        }
 else {
          adapter=adaptable.getAdapter(IFile.class);
          if (adapter != null) {
            container=((IFile)object).getParent();
          }
        }
      }
    }
    launch(container,mode);
  }
}
 

Example 18

From project mylyn-mantis, under directory /com.itsolut.mantis.ui/src/com/itsolut/mantis/ui/wizard/.

Source file: NewMantisTaskWizard.java

  21 
vote

@Override public void addPages(){
  IStructuredSelection selection=MantisUIUtil.getCurrentSelection();
  if (selection != null && !selection.isEmpty()) {
    Object selectedElement=selection.getFirstElement();
    String projectName=null;
    if (selectedElement instanceof ITask) {
      ITask task=(ITask)selectedElement;
      projectName=task.getAttribute(PROJECT.getKey());
    }
 else     if (selectedElement instanceof IRepositoryQuery) {
      IRepositoryQuery query=(IRepositoryQuery)selectedElement;
      projectName=query.getAttribute(IMantisClient.PROJECT_NAME);
    }
 else     if (selectedElement instanceof IAdaptable) {
      IAdaptable adaptable=(IAdaptable)selectedElement;
      ITask task=(ITask)adaptable.getAdapter(ITask.class);
      if (task != null)       projectName=task.getAttribute(PROJECT.getKey());
    }
    if (projectName != null && !MantisProject.ALL_PROJECTS.getName().equals(projectName)) {
      mapping=new ProductOnlyTaskMapping(projectName);
      return;
    }
  }
  newTaskPage=new MantisProjectPage(taskRepository,clientManager);
  addPage(newTaskPage);
}
 

Example 19

From project mylyn.builds, under directory /org.eclipse.mylyn.builds.ui/src/org/eclipse/mylyn/builds/ui/spi/.

Source file: BuildServerWizardPage.java

  21 
vote

public BuildServerWizardPage(String pageName){
  super(pageName);
  setTitle("Build Server Properties");
  setElement(new IAdaptable(){
    public Object getAdapter(    Class adapter){
      if (adapter == RepositoryLocation.class) {
        return getModel().getLocation();
      }
      return null;
    }
  }
);
}
 

Example 20

From project mylyn.docs, under directory /org.eclipse.mylyn.wikitext.tasks.ui/src/org/eclipse/mylyn/wikitext/tasks/ui/editor/.

Source file: MarkupTaskEditorExtension.java

  21 
vote

@SuppressWarnings({"rawtypes"}) private static IAdaptable createDefaultHyperlinkDetectorContext(final TaskRepository repository){
  return new IAdaptable(){
    public Object getAdapter(    Class adapter){
      if (adapter == TaskRepository.class) {
        return repository;
      }
      return null;
    }
  }
;
}
 

Example 21

From project scisoft-icat, under directory /uk.ac.diamond.scisoft.icatexplorer.rcp/src/uk/ac/diamond/scisoft/icatexplorer/rcp/dnd/.

Source file: ICATDropAdapterAssistant.java

  21 
vote

/** 
 * Returns the resource selection from the LocalSelectionTransfer.
 * @return the resource selection from the LocalSelectionTransfer
 */
private IResource[] getSelectedResources(IStructuredSelection selection){
  ArrayList selectedResources=new ArrayList();
  for (Iterator i=selection.iterator(); i.hasNext(); ) {
    Object o=i.next();
    if (o instanceof IResource) {
      selectedResources.add(o);
    }
 else     if (o instanceof IAdaptable) {
      IAdaptable a=(IAdaptable)o;
      IResource r=(IResource)a.getAdapter(IResource.class);
      if (r != null) {
        selectedResources.add(r);
      }
 else {
        System.out.println("r is NULL");
      }
    }
  }
  return (IResource[])selectedResources.toArray(new IResource[selectedResources.size()]);
}
 

Example 22

From project sketch, under directory /org.eclipse.sketch.examples.shapes.diagram/src/org/eclipse/sketch/examples/shapes/diagram/edit/policies/.

Source file: DiagramCanonicalEditPolicy.java

  21 
vote

/** 
 * @generated
 */
private Collection createConnections(Collection linkDescriptors,Map domain2NotationMap){
  List adapters=new LinkedList();
  for (Iterator linkDescriptorsIterator=linkDescriptors.iterator(); linkDescriptorsIterator.hasNext(); ) {
    final ShapesLinkDescriptor nextLinkDescriptor=(ShapesLinkDescriptor)linkDescriptorsIterator.next();
    EditPart sourceEditPart=getEditPart(nextLinkDescriptor.getSource(),domain2NotationMap);
    EditPart targetEditPart=getEditPart(nextLinkDescriptor.getDestination(),domain2NotationMap);
    if (sourceEditPart == null || targetEditPart == null) {
      continue;
    }
    CreateConnectionViewRequest.ConnectionViewDescriptor descriptor=new CreateConnectionViewRequest.ConnectionViewDescriptor(nextLinkDescriptor.getSemanticAdapter(),String.valueOf(nextLinkDescriptor.getVisualID()),ViewUtil.APPEND,false,((IGraphicalEditPart)getHost()).getDiagramPreferencesHint());
    CreateConnectionViewRequest ccr=new CreateConnectionViewRequest(descriptor);
    ccr.setType(RequestConstants.REQ_CONNECTION_START);
    ccr.setSourceEditPart(sourceEditPart);
    sourceEditPart.getCommand(ccr);
    ccr.setTargetEditPart(targetEditPart);
    ccr.setType(RequestConstants.REQ_CONNECTION_END);
    Command cmd=targetEditPart.getCommand(ccr);
    if (cmd != null && cmd.canExecute()) {
      executeCommand(cmd);
      IAdaptable viewAdapter=(IAdaptable)ccr.getNewObject();
      if (viewAdapter != null) {
        adapters.add(viewAdapter);
      }
    }
  }
  return adapters;
}
 

Example 23

From project bel-editor, under directory /org.openbel.editor.ui/src/org/openbel/editor/ui/.

Source file: BuilderPropertyTester.java

  19 
vote

/** 
 * Executes the property test determined by the parameter property.
 * @param receiver The receiver of the property to test
 * @param property The property to test
 * @param args Additional arguments to evaluate the property. May havezero-length.
 * @param expectedValue Expected value of the property - either{@link String} or a boxed primitive
 * @return {@code true} if the property is equal to the expected value,{@code false} otherwise
 */
@Override public boolean test(Object receiver,String property,Object[] args,Object expectedValue){
  IFile f=null;
  if (receiver instanceof IFile) {
    f=(IFile)receiver;
  }
 else   if (receiver instanceof IAdaptable) {
    f=(IFile)((IAdaptable)receiver).getAdapter(IFile.class);
  }
  if (f == null) {
    return false;
  }
  if (isBuilder(f)) {
    return true;
  }
  return false;
}
 

Example 24

From project CBCJVM, under directory /eclipse/src/cbclipse/builder/.

Source file: ToggleNatureAction.java

  19 
vote

@SuppressWarnings("unchecked") public void run(IAction action){
  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);
      }
    }
  }
}
 

Example 25

From project ccw, under directory /ccw.core/src/java/ccw/commands/.

Source file: ToggleNatureCommand.java

  19 
vote

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) {
        toggleNature(project,false);
      }
    }
  }
  return null;
}
 

Example 26

From project dawn-isenciaui, under directory /com.isencia.passerelle.workbench.model.editor.ui/src/main/java/com/isencia/passerelle/workbench/model/editor/ui/dnd/.

Source file: FileTransferDropTargetListener.java

  19 
vote

private IResource getSelected(){
  final ISelection sel=EclipseUtils.getPage().getSelection();
  if (!(sel instanceof IStructuredSelection))   return null;
  final IStructuredSelection ss=(IStructuredSelection)sel;
  final Object element=ss.getFirstElement();
  if (element instanceof IResource) {
    return (IResource)element;
  }
  if (element instanceof IContributorResourceAdapter) {
    return ((IContributorResourceAdapter)element).getAdaptedResource((IAdaptable)element);
  }
  return null;
}
 

Example 27

From project ds-annotation-builder, under directory /com.wuetherich.osgi.ds.annotations/src/com/wuetherich/osgi/ds/annotations/internal/actions/.

Source file: DisableNatureAction.java

  19 
vote

@Override public void run(IAction action){
  if (selection instanceof IStructuredSelection) {
    IStructuredSelection structuredSelection=(IStructuredSelection)selection;
    for (Iterator<?> it=structuredSelection.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 {
          disableNature(project,structuredSelection.size() == 1);
        }
 catch (        CoreException e) {
          e.printStackTrace();
        }
      }
    }
  }
}
 

Example 28

From project eclipse-integration-cloudfoundry, under directory /org.cloudfoundry.ide.eclipse.server.core/src/org/cloudfoundry/ide/eclipse/internal/server/core/standalone/.

Source file: StandaloneArtifactAdapter.java

  19 
vote

public IModuleArtifact getModuleArtifact(Object obj){
  IProject project=(IProject)((IAdaptable)obj).getAdapter(IProject.class);
  if (!StandAloneModuleFactory.canHandle(project)) {
    return null;
  }
  IModule[] modules=ServerUtil.getModules(project);
  if (modules == null || modules.length == 0) {
    return null;
  }
  return new WebResource(modules[0],Path.EMPTY);
}
 

Example 29

From project eclipse-integration-commons, under directory /org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/.

Source file: SpringCoreUtils.java

  19 
vote

/** 
 * Returns the specified adapter for the given object or <code>null</code> if adapter is not supported.
 */
@SuppressWarnings("unchecked") public static <T>T getAdapter(Object object,Class<T> adapter){
  if (object != null && adapter != null) {
    if (adapter.isAssignableFrom(object.getClass())) {
      return (T)object;
    }
    if (object instanceof IAdaptable) {
      return (T)((IAdaptable)object).getAdapter(adapter);
    }
  }
  return null;
}
 

Example 30

From project esbt, under directory /src/org/scalastuff/esbt/.

Source file: WorkspaceInfo.java

  19 
vote

public static ProjectInfo adaptToProject(Object obj){
  if (obj instanceof IAdaptable) {
    IProject project=(IProject)((IAdaptable)obj).getAdapter(IProject.class);
    if (project != null) {
      try {
        return getProject(project);
      }
 catch (      Exception e) {
      }
    }
  }
  return null;
}
 

Example 31

From project hackergarten-moreunit, under directory /org.moreunit.core/src/org/moreunit/core/commands/.

Source file: JumpActionHandler.java

  19 
vote

private IFile getSelectedFile(ExecutionEvent event){
  Object firstElement=getUniqueSelectedElement(event);
  if (firstElement instanceof IAdaptable) {
    IFile file=toFile((IAdaptable)firstElement);
    if (file != null) {
      return file;
    }
  }
  IFile file=toFile(getActiveEditorInput(event));
  if (file != null) {
    return file;
  }
  return null;
}
 

Example 32

From project ivyde, under directory /org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/handlers/.

Source file: AbstractIvyDEHandler.java

  19 
vote

public static Map getProjectAndContainers(IStructuredSelection selection){
  Map projects=new HashMap();
  Iterator it=selection.iterator();
  while (it.hasNext()) {
    Object element=it.next();
    if (element instanceof IWorkingSet) {
      IAdaptable[] elements=((IWorkingSet)element).getElements();
      for (int i=0; i < elements.length; i++) {
        addElement(projects,elements[i]);
      }
    }
 else     if (element instanceof ClassPathContainer) {
      IvyClasspathContainer ivycp=IvyClasspathUtil.jdt2IvyCPC(((ClassPathContainer)element));
      IJavaProject javaProject=ivycp.getConf().getJavaProject();
      if (javaProject != null) {
        Set cplist=(Set)projects.get(javaProject.getProject());
        if (cplist == null) {
          cplist=new HashSet();
          projects.put(javaProject.getProject(),cplist);
        }
        cplist.add(ivycp);
      }
    }
 else {
      addElement(projects,element);
    }
  }
  return projects;
}
 

Example 33

From project js4emf, under directory /org.eclipse.emf.js4emf.ui/src/org/eclipse/emf/js4emf/ui/.

Source file: AbstractSelectionView.java

  19 
vote

public Object getAdapter(Class type){
  Object o=super.getAdapter(type);
  if (o == null && editingDomainProvider instanceof IAdaptable) {
    o=((IAdaptable)editingDomainProvider).getAdapter(type);
  }
  return o;
}
 

Example 34

From project libra, under directory /plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/popup/actions/.

Source file: ConvertProjectsToBundlesAction.java

  19 
vote

private IProject[] getSelectedProjects(){
  List<IProject> selected=new ArrayList<IProject>();
  if (fSelection instanceof IStructuredSelection) {
    Object[] objs=((IStructuredSelection)fSelection).toArray();
    for (    Object obj : objs) {
      IProject project=null;
      if (obj instanceof IProject) {
        project=(IProject)obj;
      }
 else       if (obj instanceof IAdaptable) {
        project=(IProject)((IAdaptable)obj).getAdapter(IProject.class);
      }
 else {
        IAdapterManager manager=Platform.getAdapterManager();
        project=(IProject)manager.getAdapter(obj,IProject.class);
      }
      if (project != null) {
        selected.add(project);
      }
    }
  }
  return selected.toArray(new IProject[selected.size()]);
}
 

Example 35

From project mylyn.docs.intent.main, under directory /plugins/org.eclipse.mylyn.docs.intent.client.ui.ide/src/org/eclipse/mylyn/docs/intent/client/ui/ide/builder/.

Source file: ToggleNatureAction.java

  19 
vote

/** 
 * {@inheritDoc}
 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
  ISelection currentSelection=HandlerUtil.getCurrentSelection(event);
  if (currentSelection instanceof IStructuredSelection) {
    for (Iterator<?> it=((IStructuredSelection)currentSelection).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;
}
 

Example 36

From project mylyn.incubator, under directory /org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/.

Source file: InteractionEventObfuscator.java

  19 
vote

public String obfuscateHandle(String structureKind,String structureHandle){
  if (structureHandle == null || structureHandle.equals("")) {
    return structureHandle;
  }
  StringBuilder obfuscated=new StringBuilder();
  AbstractContextStructureBridge bridge=ContextCore.getStructureBridge(structureKind);
  Object object=bridge.getObjectForHandle(structureHandle);
  if (object instanceof IAdaptable) {
    Object adapter=((IAdaptable)object).getAdapter(IResource.class);
    if (adapter instanceof IResource) {
      obfuscated.append(obfuscateResourcePath(((IResource)adapter).getFullPath()));
      obfuscated.append(DELIM_PATH);
    }
  }
  obfuscated.append(obfuscateString(structureHandle));
  return obfuscated.toString();
}
 

Example 37

From project netifera, under directory /platform/com.netifera.platform.ui/com.netifera.platform.ui.spaces/src/com/netifera/platform/ui/spaces/.

Source file: ElementFactory.java

  19 
vote

public IAdaptable createElement(IMemento memento){
  final Integer spaceId=memento.getInteger("space-id");
  if (spaceId == null)   return null;
  ISpace space=createSpaceFromId(spaceId);
  if (space == null)   return null;
  space.open();
  return new SpaceEditorInput(space);
}
 

Example 38

From project Newsreader, under directory /bundles/org.eclipse.ecf.salvo.ui.navigator/src/org/eclipse/ecf/salvo/ui/navigator/internal/views/.

Source file: GroupView.java

  19 
vote

@Override protected IAdaptable getInitialInput(){
  StoreStore.instance().addListener(this,SALVO.EVENT_STORE);
  ISalvoResource root=SalvoResourceFactory.getResource("root","root");
  root.setChildProvider(new SubscribedServerProvider());
  for (  IStore store : ServerStoreFactory.instance().getServerStoreFacade().getStores())   store.addListener(this,SALVO.EVENT_ALL_EVENTS);
  return root;
}
 

Example 39

From project org.openscada.orilla, under directory /org.openscada.core.ui.connection/src/org/openscada/core/ui/connection/data/.

Source file: ConnectionDiscovererAdapterFactory.java

  19 
vote

@Override @SuppressWarnings("rawtypes") public Object getAdapter(final Object adaptableObject,final Class adapterType){
  if (adaptableObject instanceof IAdaptable) {
    return ((IAdaptable)adaptableObject).getAdapter(adapterType);
  }
  return null;
}
 

Example 40

From project samolisov-demo, under directory /Eclipse/RCP/Hyperbola/org.rcpbook.hyperbola.ui/src/org/rcpbook/hyperbola/ui/.

Source file: HyperbolaContentProvider.java

  19 
vote

protected IWorkbenchAdapter getAdapter(Object element){
  IWorkbenchAdapter adapter=null;
  if (element instanceof IAdaptable)   adapter=(IWorkbenchAdapter)((IAdaptable)element).getAdapter(IWorkbenchAdapter.class);
  if (element != null && adapter == null)   adapter=(IWorkbenchAdapter)Platform.getAdapterManager().loadAdapter(element,IWorkbenchAdapter.class.getName());
  return adapter;
}
 

Example 41

From project sandbox, under directory /xeclipse/org.xwiki.eclipse.ui/src/main/java/org/xwiki/eclipse/ui/editors/.

Source file: PageEditorInputFactory.java

  19 
vote

public IAdaptable createElement(IMemento memento){
  final String page=memento.getString(EDITOR);
  if (page == null || page.equalsIgnoreCase("")) {
    return null;
  }
  if (page != null) {
    Job job1=new Job("Restoring Editor History"){
      @Override protected IStatus run(      IProgressMonitor monitor){
        Display.getDefault().asyncExec(new Runnable(){
          public void run(){
            try {
              String pages[]=page.split("\\.");
              PageEditorInput page_input=null;
              while (page_input != null) {
                page_input=new PageEditorInput(DataManagerRegistry.getDefault().getDataManagerByName(pages[0]).getPage(pages[1] + "." + pages[2]),false);
              }
              object=page_input;
            }
 catch (            XWikiEclipseException e) {
              e.printStackTrace();
            }
          }
        }
);
        return Status.OK_STATUS;
      }
    }
;
    job1.schedule(1000);
    return object;
  }
 else {
    return null;
  }
}
 

Example 42

From project scisoft-ui, under directory /uk.ac.diamond.scisoft.analysis.rcp/src/uk/ac/diamond/scisoft/analysis/rcp/views/.

Source file: SidePageView.java

  19 
vote

@Override public void partActivated(IWorkbenchPart part){
  super.partActivated(part);
  final IPage page=getCurrentPage();
  final String title=page instanceof IAdaptable ? (String)((IAdaptable)page).getAdapter(String.class) : null;
  if (title != null) {
    setPartName(title);
  }
 else {
    setPartName("Data");
  }
}