Search in sources :

Example 31 with IAdaptable

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

the class BndProjectPropertyPage method getProject.

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");
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IProject(org.eclipse.core.resources.IProject)

Example 32 with IAdaptable

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

the class ToggleNatureAction method run.

/*
     * (non-Javadoc)
     * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
     */
@Override
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) {
                boolean isJavaProject = false;
                try {
                    isJavaProject = project.hasNature(JavaCore.NATURE_ID);
                } catch (CoreException e) {
                /* swallow */
                }
                if (isJavaProject) {
                    IStatus status = toggleNature(JavaCore.create(project));
                    if (!status.isOK())
                        ErrorDialog.openError(targetPart.getSite().getShell(), "Toggle Bnd Nature", null, status);
                }
            }
        }
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject)

Example 33 with IAdaptable

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

the class WorkingSetTracker method doWorkingSets.

static void doWorkingSets(final Project model, final IProject targetProject) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    final IWorkingSetManager workingSetManager = workbench.getWorkingSetManager();
    String mergeProperties = model.mergeProperties("-workingset");
    if (mergeProperties == null)
        return;
    Parameters memberShips = new Parameters(mergeProperties);
    IWorkingSet[] allWorkingSets = workingSetManager.getAllWorkingSets();
    for (IWorkingSet currentWorkingSet : allWorkingSets) {
        Attrs attrs = memberShips.remove(currentWorkingSet.getName());
        boolean shouldBeMember = attrs != null && Processor.isTrue(attrs.get("member", "true"));
        IAdaptable[] elements = currentWorkingSet.getElements();
        List<IAdaptable> members = new ExtList<>(elements);
        boolean foundProjectInCurrentWorkingSet = false;
        for (Iterator<IAdaptable> it = members.iterator(); it.hasNext(); ) {
            IAdaptable member = it.next();
            if (member.getAdapter(IProject.class) == targetProject) {
                foundProjectInCurrentWorkingSet = true;
                if (!shouldBeMember) {
                    it.remove();
                }
            }
        }
        if (!foundProjectInCurrentWorkingSet && shouldBeMember) {
            members.add(targetProject);
        }
        if (elements.length != members.size()) {
            updateWorkingSet(currentWorkingSet, members);
        }
    }
    for (final Entry<String, Attrs> e : memberShips.entrySet()) {
        String name = e.getKey();
        boolean isMember = Processor.isTrue(e.getValue().get("member", "true"));
        if (!isMember)
            continue;
        if (!JAVAID_P.matcher(name).matches()) {
            SetLocation error = model.warning("Invalid working set name '%s'. Must use pattern of Java identifier", name);
            error.file(model.getPropertiesFile().getAbsolutePath());
            error.header("-workingset");
            continue;
        }
        IAdaptable[] members = new IAdaptable[1];
        members[0] = targetProject;
        IWorkingSet newWorkingSet = workingSetManager.createWorkingSet(name, members);
        newWorkingSet.setId("org.eclipse.jdt.ui.JavaWorkingSetPage");
        newWorkingSet.setLabel(null);
        workingSetManager.addWorkingSet(newWorkingSet);
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) Parameters(aQute.bnd.header.Parameters) ExtList(aQute.lib.collections.ExtList) Attrs(aQute.bnd.header.Attrs) IProject(org.eclipse.core.resources.IProject) IWorkbench(org.eclipse.ui.IWorkbench) IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) SetLocation(aQute.service.reporter.Reporter.SetLocation) IWorkingSet(org.eclipse.ui.IWorkingSet)

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