Search in sources :

Example 11 with ResourceMapping

use of org.eclipse.core.resources.mapping.ResourceMapping in project che by eclipse.

the class CopyModifications method copy.

public void copy(IPackageFragmentRoot sourceFolder, CopyArguments javaArgs, CopyArguments resourceArgs) {
    add(sourceFolder, javaArgs, null);
    ResourceMapping mapping = JavaElementResourceMapping.create(sourceFolder);
    if (mapping != null) {
        add(mapping, resourceArgs, null);
    }
    IResource sourceResource = sourceFolder.getResource();
    if (sourceResource != null) {
        getResourceModifications().addCopyDelta(sourceResource, resourceArgs);
        IFile classpath = getClasspathFile((IResource) resourceArgs.getDestination());
        if (classpath != null) {
            getResourceModifications().addChanged(classpath);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) JavaElementResourceMapping(org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IResource(org.eclipse.core.resources.IResource)

Example 12 with ResourceMapping

use of org.eclipse.core.resources.mapping.ResourceMapping in project che by eclipse.

the class CopyModifications method copy.

public void copy(ICompilationUnit unit, CopyArguments javaArgs, CopyArguments resourceArgs) {
    add(unit, javaArgs, null);
    ResourceMapping mapping = JavaElementResourceMapping.create(unit);
    if (mapping != null) {
        add(mapping, resourceArgs, null);
    }
    if (unit.getResource() != null) {
        getResourceModifications().addCopyDelta(unit.getResource(), resourceArgs);
    }
}
Also used : JavaElementResourceMapping(org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping)

Example 13 with ResourceMapping

use of org.eclipse.core.resources.mapping.ResourceMapping in project che by eclipse.

the class CreateCopyOfCompilationUnitChange method perform.

@Override
public Change perform(IProgressMonitor monitor) throws CoreException {
    ResourceMapping mapping = JavaElementResourceMapping.create(fOldCu);
    final Change result = super.perform(monitor);
    markAsExecuted(fOldCu, mapping);
    return result;
}
Also used : JavaElementResourceMapping(org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) Change(org.eclipse.ltk.core.refactoring.Change) CreateTextFileChange(org.eclipse.jdt.internal.corext.refactoring.nls.changes.CreateTextFileChange)

Example 14 with ResourceMapping

use of org.eclipse.core.resources.mapping.ResourceMapping in project yamcs-studio by yamcs.

the class OpenActionProvider method addOpenWithMenu.

private void addOpenWithMenu(IMenuManager aMenu) {
    IStructuredSelection ss = (IStructuredSelection) getContext().getSelection();
    if (ss == null || ss.size() != 1) {
        return;
    }
    Object o = ss.getFirstElement();
    // first try IResource
    IAdaptable openable = Adapters.adapt(o, IResource.class);
    // otherwise try ResourceMapping
    if (openable == null) {
        openable = Adapters.adapt(o, ResourceMapping.class);
    } else if (((IResource) openable).getType() != IResource.FILE) {
        openable = null;
    }
    if (openable != null) {
        IMenuManager submenu = new MenuManager("Open With", ICommonMenuConstants.GROUP_OPEN_WITH);
        submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP));
        submenu.add(new OpenWithMenu(viewSite.getPage(), openable));
        submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_ADDITIONS));
        if (submenu.getItems().length > 2 && submenu.isEnabled()) {
            aMenu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, submenu);
        }
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) GroupMarker(org.eclipse.jface.action.GroupMarker) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IMenuManager(org.eclipse.jface.action.IMenuManager) IResource(org.eclipse.core.resources.IResource)

Example 15 with ResourceMapping

use of org.eclipse.core.resources.mapping.ResourceMapping in project polymap4-core by Polymap4.

the class ResourceMappingPropertyTester method test.

public boolean test(Object receiver, String method, Object[] args, Object expectedValue) {
    if (!(receiver instanceof ResourceMapping))
        return false;
    if (!method.equals(PROJECT_PERSISTENT_PROPERTY))
        return false;
    // Note: we currently say the test is satisfied if any project associated
    // with the mapping satisfies the test.
    IProject[] projects = ((ResourceMapping) receiver).getProjects();
    if (projects.length == 0)
        return false;
    String propertyName;
    String expectedVal;
    if (args.length == 0) {
        propertyName = toString(expectedValue);
        // any value will do
        expectedVal = null;
    } else if (args.length == 1) {
        propertyName = toString(args[0]);
        // any value will do
        expectedVal = null;
    } else {
        propertyName = toString(args[0]);
        expectedVal = toString(args[1]);
    }
    QualifiedName key = toQualifedName(propertyName);
    boolean found = false;
    for (int i = 0; i < projects.length; i++) {
        try {
            Object actualVal = projects[i].getPersistentProperty(key);
            // the value is not set, so keep looking on other projects
            if (actualVal == null)
                continue;
            // record that we have found at least one value
            found = true;
            // expected value of null means we expect *any* value, rather than expecting no value
            if (expectedVal == null)
                continue;
            // if the value we find does not match, then the property is not satisfied
            if (!expectedVal.equals(actualVal.toString()))
                return false;
        } catch (CoreException e) {
        // ignore
        }
    }
    // if any projects had the property set, the condition is satisfied
    return found;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) QualifiedName(org.eclipse.core.runtime.QualifiedName) IProject(org.eclipse.core.resources.IProject)

Aggregations

ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)28 IResource (org.eclipse.core.resources.IResource)14 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 JavaElementResourceMapping (org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping)7 CoreException (org.eclipse.core.runtime.CoreException)6 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)6 HashSet (java.util.HashSet)5 LinkedHashSet (java.util.LinkedHashSet)5 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)5 IFile (org.eclipse.core.resources.IFile)4 ResourceTraversal (org.eclipse.core.resources.mapping.ResourceTraversal)4 IAdaptable (org.eclipse.core.runtime.IAdaptable)4 Change (org.eclipse.ltk.core.refactoring.Change)4 File (java.io.File)3 IProject (org.eclipse.core.resources.IProject)3 ResourceMappingContext (org.eclipse.core.resources.mapping.ResourceMappingContext)3 GitResourceVariantTreeSubscriber (org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber)3 GitSubscriberMergeContext (org.eclipse.egit.core.synchronize.GitSubscriberMergeContext)3 GitSubscriberResourceMappingContext (org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext)3 ResourceChange (org.eclipse.ltk.core.refactoring.resource.ResourceChange)3