Search in sources :

Example 6 with GitModelObject

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

the class GitAdapterFactory method getAdapter.

@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
    if (adapterType.isAssignableFrom(IHistoryPageSource.class)) {
        return GitHistoryPageSource.INSTANCE;
    }
    if (IWorkbenchAdapter.class == adapterType) {
        // property page names for git repository tree nodes
        if (adaptableObject instanceof RepositoryTreeNode) {
            return getRepositoryTreeNodeWorkbenchAdapter((RepositoryTreeNode) adaptableObject);
        }
        if (gitModelWorkbenchAdapter == null) {
            gitModelWorkbenchAdapter = new GitModelWorkbenchAdapter();
        }
        return gitModelWorkbenchAdapter;
    }
    if (adaptableObject instanceof IHistoryView && IShowInSource.class == adapterType) {
        IHistoryView historyView = (IHistoryView) adaptableObject;
        IHistoryPage historyPage = historyView.getHistoryPage();
        if (historyPage instanceof GitHistoryPage) {
            return historyPage;
        }
    }
    if (adaptableObject instanceof IURIEditorInput && adapterType == Repository.class) {
        return getRepository((IURIEditorInput) adaptableObject);
    }
    if (adaptableObject instanceof IURIEditorInput && adapterType == File.class) {
        return getFile((IURIEditorInput) adaptableObject);
    }
    if (adaptableObject instanceof GitModelObject && adapterType == ResourceMapping.class) {
        return GitObjectMapping.create((GitModelObject) adaptableObject);
    }
    if (adaptableObject instanceof GitModelObject && adapterType == IResource.class) {
        GitModelObject obj = (GitModelObject) adaptableObject;
        if (obj instanceof GitModelBlob) {
            IResource res = ResourceUtil.getFileForLocation(obj.getLocation(), false);
            if (res == null) {
                // Deleted resource?
                res = getWorkspaceResourceFromGitPath(obj.getLocation());
            }
            return res;
        }
        if (obj instanceof GitModelTree) {
            IResource res = root.getContainerForLocation(obj.getLocation());
            if (res == null) {
                res = root.getFolder(obj.getLocation());
            }
            return res;
        }
    }
    if (adapterType == Repository.class) {
        ResourceMapping m = AdapterUtils.adapt(adaptableObject, ResourceMapping.class);
        if (m != null) {
            return SelectionUtils.getRepository(new StructuredSelection(m));
        }
    }
    return null;
}
Also used : IURIEditorInput(org.eclipse.ui.IURIEditorInput) GitModelTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelTree) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject) IHistoryPage(org.eclipse.team.ui.history.IHistoryPage) Repository(org.eclipse.jgit.lib.Repository) GitHistoryPage(org.eclipse.egit.ui.internal.history.GitHistoryPage) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) GitModelWorkbenchAdapter(org.eclipse.egit.ui.internal.synchronize.mapping.GitModelWorkbenchAdapter) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IShowInSource(org.eclipse.ui.part.IShowInSource) IHistoryView(org.eclipse.team.ui.history.IHistoryView) File(java.io.File) IResource(org.eclipse.core.resources.IResource) GitModelBlob(org.eclipse.egit.ui.internal.synchronize.model.GitModelBlob)

Example 7 with GitModelObject

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

the class GitOpenInCompareAction method handleGitObjectComparison.

private void handleGitObjectComparison(GitModelBlob obj, boolean reuseEditor) {
    ITypedElement left;
    ITypedElement right;
    if (obj instanceof GitModelWorkingFile) {
        IPath location = obj.getLocation();
        if (location == null) {
            return;
        }
        IFile file = ResourceUtil.getFileForLocation(location, false);
        if (file == null) {
            Repository repository = null;
            GitModelObject modelObject = obj;
            while (modelObject != null) {
                if (modelObject instanceof GitModelRepository) {
                    repository = ((GitModelRepository) modelObject).getRepository();
                    break;
                }
                modelObject = modelObject.getParent();
            }
            if (repository == null) {
                return;
            }
            left = new LocalNonWorkspaceTypedElement(repository, location);
        } else {
            left = SaveableCompareEditorInput.createFileElement(file);
        }
        right = getCachedFileElement(obj);
    } else if (obj instanceof GitModelCacheFile) {
        left = getCachedFileElement(obj);
        right = getHeadFileElement(obj);
        if (right == null)
            return;
    } else {
        oldAction.run();
        return;
    }
    GitCompareFileRevisionEditorInput in = new GitCompareFileRevisionEditorInput(left, right, null);
    IWorkbenchPage page = getWorkbenchPage(conf.getSite());
    OpenInCompareAction.openCompareEditor(in, page, reuseEditor);
}
Also used : GitModelRepository(org.eclipse.egit.ui.internal.synchronize.model.GitModelRepository) Repository(org.eclipse.jgit.lib.Repository) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) GitModelWorkingFile(org.eclipse.egit.ui.internal.synchronize.model.GitModelWorkingFile) GitCompareFileRevisionEditorInput(org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput) ITypedElement(org.eclipse.compare.ITypedElement) LocalNonWorkspaceTypedElement(org.eclipse.egit.ui.internal.synchronize.compare.LocalNonWorkspaceTypedElement) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) GitModelRepository(org.eclipse.egit.ui.internal.synchronize.model.GitModelRepository) GitModelCacheFile(org.eclipse.egit.ui.internal.synchronize.model.GitModelCacheFile) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)

Example 8 with GitModelObject

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

the class OpenWorkingFileAction method run.

/*
	 * (non-Javadoc) Method declared on IAction.
	 */
@Override
public void run() {
    IStructuredSelection selection = getStructuredSelection();
    IResource resource = getExistingResource(selection);
    if (resource instanceof IFile)
        openWorkspaceFile((IFile) resource);
    else {
        Object element = selection.getFirstElement();
        if (element instanceof GitModelObject) {
            IPath location = ((GitModelObject) element).getLocation();
            if (location != null && location.toFile().exists())
                openExternalFile(location.toFile());
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)

Example 9 with GitModelObject

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

the class GitContainerMapping method getTraversals.

@Override
public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
    GitModelObject[] children = ((GitModelObjectContainer) getModelObject()).getChildren();
    Set<ResourceTraversal> result = new LinkedHashSet<>();
    final GitSynchronizeDataSet dataSet;
    if (context instanceof GitSubscriberResourceMappingContext)
        dataSet = ((GitSubscriberResourceMappingContext) context).getSyncData();
    else
        dataSet = null;
    for (GitModelObject child : children) {
        if (child.isContainer())
            result.addAll(createTraversalForContainer(child, dataSet));
        else
            result.add(createTraversalForFile(child, dataSet));
    }
    return result.toArray(new ResourceTraversal[result.size()]);
}
Also used : ResourceTraversal(org.eclipse.core.resources.mapping.ResourceTraversal) LinkedHashSet(java.util.LinkedHashSet) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) GitSubscriberResourceMappingContext(org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext) GitModelObjectContainer(org.eclipse.egit.ui.internal.synchronize.model.GitModelObjectContainer) 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