Search in sources :

Example 1 with GitModelObject

use of org.eclipse.egit.ui.internal.synchronize.model.GitModelObject in project egit by eclipse.

the class GitActionContributor method fillContextMenu.

@Override
public void fillContextMenu(IMenuManager menu) {
    IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
    if (selection.isEmpty())
        return;
    Object element = selection.getFirstElement();
    IResource resource = ResourceUtil.getResource(element);
    if (resource != null) {
        // add standard git action for 'workspace' models
        menu.appendToGroup(GIT_ACTIONS, createItem(COMMIT_ACTION));
        IResourceState state = ResourceStateFactory.getInstance().get(resource);
        if (state.hasUnstagedChanges()) {
            menu.appendToGroup(GIT_ACTIONS, createItem(ADD_TO_INDEX));
        }
        if (state.isStaged()) {
            menu.appendToGroup(GIT_ACTIONS, createItem(REMOVE_FROM_INDEX));
        }
        if (!state.isIgnored()) {
            menu.appendToGroup(GIT_ACTIONS, createItem(IGNORE_ACTION));
        }
        menu.appendToGroup(GIT_ACTIONS, createItem(MERGE_TOOL_ACTION));
        menu.appendToGroup(GIT_ACTIONS, createItem(CREATE_PATCH));
    } else if (element instanceof GitModelObject && selection.size() == 1) {
        createMenuForGitModelObject(menu, (GitModelObject) element);
    }
    IContributionItem fileGroup = findGroup(menu, ISynchronizePageConfiguration.FILE_GROUP);
    if (fileGroup != null) {
        ModelSynchronizeParticipant msp = ((ModelSynchronizeParticipant) getConfiguration().getParticipant());
        if (msp.hasCompareInputFor(element))
            menu.appendToGroup(fileGroup.getId(), openWorkingFileAction);
    }
}
Also used : IResourceState(org.eclipse.egit.ui.internal.resources.IResourceState) IContributionItem(org.eclipse.jface.action.IContributionItem) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ModelSynchronizeParticipant(org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant) IResource(org.eclipse.core.resources.IResource) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)

Example 2 with GitModelObject

use of org.eclipse.egit.ui.internal.synchronize.model.GitModelObject in project egit by eclipse.

the class GitChangeSetModelProvider method getMappings.

@Override
public ResourceMapping[] getMappings(IResource resource, ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
    if (context instanceof GitSubscriberResourceMappingContext) {
        GitSubscriberResourceMappingContext gitContext = (GitSubscriberResourceMappingContext) context;
        GitSynchronizeDataSet gsds = gitContext.getSyncData();
        GitSynchronizeData data = gsds.getData(resource.getProject());
        if (data != null) {
            GitModelObject object = null;
            try {
                object = GitModelObject.createRoot(data);
            } catch (IOException e) {
                Activator.logError(e.getMessage(), e);
            }
            if (object != null) {
                ResourceMapping rm = AdapterUtils.adapt(object, ResourceMapping.class);
                return new ResourceMapping[] { rm };
            }
        }
    }
    return super.getMappings(resource, context, monitor);
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) GitSubscriberResourceMappingContext(org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IOException(java.io.IOException) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)

Example 3 with GitModelObject

use of org.eclipse.egit.ui.internal.synchronize.model.GitModelObject in project egit by eclipse.

the class GitContainerMapping method createTraversalForContainer.

private Set<ResourceTraversal> createTraversalForContainer(GitModelObject child, GitSynchronizeDataSet dataSet) {
    GitModelObject[] containerChildren = child.getChildren();
    Set<ResourceTraversal> result = new LinkedHashSet<>();
    for (GitModelObject aChild : containerChildren) {
        if (aChild.isContainer())
            result.addAll(createTraversalForContainer(aChild, dataSet));
        else {
            ResourceTraversal traversal = createTraversalForFile(aChild, dataSet);
            if (traversal != null)
                result.add(traversal);
        }
    }
    return result;
}
Also used : ResourceTraversal(org.eclipse.core.resources.mapping.ResourceTraversal) LinkedHashSet(java.util.LinkedHashSet) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)

Example 4 with GitModelObject

use of org.eclipse.egit.ui.internal.synchronize.model.GitModelObject in project egit by eclipse.

the class GitTreeMapping method getTraversals.

@Override
public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
    GitModelObject[] objects = tree.getChildren();
    ResourceTraversal[] result = new ResourceTraversal[objects.length];
    for (int i = 0; i < objects.length; i++) {
        if (objects[i] instanceof GitModelTree)
            result[i] = new GitTreeTraversal((GitModelTree) objects[i]);
        else {
            IResource[] resources = getResources((GitModelBlob) objects[i]);
            result[i] = new ResourceTraversal(resources, IResource.DEPTH_ZERO, IResource.ALLOW_MISSING_LOCAL);
        }
    }
    return result;
}
Also used : ResourceTraversal(org.eclipse.core.resources.mapping.ResourceTraversal) GitModelTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelTree) IResource(org.eclipse.core.resources.IResource) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)

Example 5 with GitModelObject

use of org.eclipse.egit.ui.internal.synchronize.model.GitModelObject in project egit by eclipse.

the class GitTreeTraversal method getResourcesImpl.

private static IResource[] getResourcesImpl(GitModelObject[] children) {
    List<IResource> result = new ArrayList<>(children.length);
    for (GitModelObject object : children) {
        IPath location = object.getLocation();
        IResource resource;
        if (object.isContainer())
            resource = ROOT.getContainerForLocation(location);
        else
            resource = ROOT.getFileForLocation(location);
        if (resource != null)
            result.add(resource);
    }
    return result.toArray(new IResource[result.size()]);
}
Also used : IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)

Aggregations

GitModelObject (org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)9 IResource (org.eclipse.core.resources.IResource)5 ResourceTraversal (org.eclipse.core.resources.mapping.ResourceTraversal)3 IPath (org.eclipse.core.runtime.IPath)3 LinkedHashSet (java.util.LinkedHashSet)2 IFile (org.eclipse.core.resources.IFile)2 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)2 GitSubscriberResourceMappingContext (org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext)2 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)2 GitModelTree (org.eclipse.egit.ui.internal.synchronize.model.GitModelTree)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Repository (org.eclipse.jgit.lib.Repository)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ITypedElement (org.eclipse.compare.ITypedElement)1 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)1 GitHistoryPage (org.eclipse.egit.ui.internal.history.GitHistoryPage)1 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)1 IResourceState (org.eclipse.egit.ui.internal.resources.IResourceState)1