Search in sources :

Example 1 with IAdaptable

use of org.eclipse.core.runtime.IAdaptable in project che by eclipse.

the class JavaSearchScopeFactory method addJavaElements.

private void addJavaElements(Set<IJavaElement> javaElements, IWorkingSet workingSet) {
    if (workingSet == null)
        return;
    if (workingSet.isAggregateWorkingSet() && workingSet.isEmpty()) {
        try {
            IJavaProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects();
            javaElements.addAll(Arrays.asList(projects));
        } catch (JavaModelException e) {
            JavaPlugin.log(e);
        }
        return;
    }
    IAdaptable[] elements = workingSet.getElements();
    for (int i = 0; i < elements.length; i++) {
        IJavaElement javaElement = (IJavaElement) elements[i].getAdapter(IJavaElement.class);
        if (javaElement != null) {
            addJavaElements(javaElements, javaElement);
            continue;
        }
        IResource resource = (IResource) elements[i].getAdapter(IResource.class);
        if (resource != null) {
            addJavaElements(javaElements, resource);
        }
    // else we don't know what to do with it, ignore.
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IResource(org.eclipse.core.resources.IResource)

Example 2 with IAdaptable

use of org.eclipse.core.runtime.IAdaptable in project che by eclipse.

the class Changes method getModifiedFiles.

private static void getModifiedFiles(List<IFile> result, Change[] changes) {
    for (int i = 0; i < changes.length; i++) {
        Change change = changes[i];
        Object modifiedElement = change.getModifiedElement();
        if (modifiedElement instanceof IAdaptable) {
            IFile file = (IFile) ((IAdaptable) modifiedElement).getAdapter(IFile.class);
            if (file != null)
                result.add(file);
        }
        if (change instanceof CompositeChange) {
            getModifiedFiles(result, ((CompositeChange) change).getChildren());
        }
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Change(org.eclipse.ltk.core.refactoring.Change) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Example 3 with IAdaptable

use of org.eclipse.core.runtime.IAdaptable in project flux by eclipse.

the class SyncDisconnectHandler method getSelectedProjects.

protected IProject[] getSelectedProjects(ISelection selection) {
    List<IProject> selectedProjects = new ArrayList<IProject>();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        Object[] selectedObjects = structuredSelection.toArray();
        for (int i = 0; i < selectedObjects.length; i++) {
            if (selectedObjects[i] instanceof IAdaptable) {
                IProject project = (IProject) ((IAdaptable) selectedObjects[i]).getAdapter(IProject.class);
                if (project != null) {
                    selectedProjects.add(project);
                }
            }
        }
    }
    return (IProject[]) selectedProjects.toArray(new IProject[selectedProjects.size()]);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject)

Example 4 with IAdaptable

use of org.eclipse.core.runtime.IAdaptable in project jop by jop-devel.

the class ToggleJOPNatureAction method run.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
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);
                System.err.println(project + " > Nature");
                PropertyTester jopPropTest = new JOPNaturePropertyTester();
                jopPropTest.test(project, "hasJOPNature", null, null);
            }
        }
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) PropertyTester(org.eclipse.core.expressions.PropertyTester) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject)

Example 5 with IAdaptable

use of org.eclipse.core.runtime.IAdaptable in project translationstudio8 by heartsome.

the class ProjectExplorer method updateTitle.

/**
	 * The superclass does not deal with the content description, handle it
	 * here.
	 * 
	 * @noreference
	 */
public void updateTitle() {
    super.updateTitle();
    Object input = getCommonViewer().getInput();
    if (input == null || input instanceof IAggregateWorkingSet) {
        //$NON-NLS-1$
        setContentDescription("");
        return;
    }
    if (!(input instanceof IResource)) {
        if (input instanceof IAdaptable) {
            IWorkbenchAdapter wbadapter = (IWorkbenchAdapter) ((IAdaptable) input).getAdapter(IWorkbenchAdapter.class);
            if (wbadapter != null) {
                setContentDescription(wbadapter.getLabel(input));
                return;
            }
        }
        setContentDescription(input.toString());
        return;
    }
    IResource res = (IResource) input;
    setContentDescription(res.getName());
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IAggregateWorkingSet(org.eclipse.ui.IAggregateWorkingSet) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) IResource(org.eclipse.core.resources.IResource)

Aggregations

IAdaptable (org.eclipse.core.runtime.IAdaptable)33 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 IProject (org.eclipse.core.resources.IProject)11 ArrayList (java.util.ArrayList)9 IResource (org.eclipse.core.resources.IResource)8 IFile (org.eclipse.core.resources.IFile)7 CoreException (org.eclipse.core.runtime.CoreException)5 Iterator (java.util.Iterator)4 List (java.util.List)4 IOException (java.io.IOException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 File (java.io.File)2 LinkedList (java.util.LinkedList)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 EditPart (org.eclipse.gef.EditPart)2 AbstractTransactionalCommand (org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand)2 Diagram (org.eclipse.gmf.runtime.notation.Diagram)2