Search in sources :

Example 1 with TagNode

use of org.eclipse.egit.ui.internal.repository.tree.TagNode in project egit by eclipse.

the class PushCommand method createPushTagsWizard.

private PushTagsWizard createPushTagsWizard(List<RepositoryTreeNode> nodes) {
    List<String> tagNames = new ArrayList<>();
    for (RepositoryTreeNode node : nodes) {
        if (node instanceof TagNode) {
            TagNode tagNode = (TagNode) node;
            tagNames.add(tagNode.getObject().getName());
        }
    }
    Repository repository = nodes.get(0).getRepository();
    return new PushTagsWizard(repository, tagNames);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) PushTagsWizard(org.eclipse.egit.ui.internal.push.PushTagsWizard) ArrayList(java.util.ArrayList) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode)

Example 2 with TagNode

use of org.eclipse.egit.ui.internal.repository.tree.TagNode in project egit by eclipse.

the class DeleteTagCommand method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final List<TagNode> tags = getSelectedNodes(event);
    if (tags.isEmpty())
        return null;
    // Confirm deletion of selected tags
    final AtomicBoolean confirmed = new AtomicBoolean();
    final Shell shell = getActiveShell(event);
    shell.getDisplay().syncExec(new Runnable() {

        @Override
        public void run() {
            String message;
            if (tags.size() > 1)
                message = MessageFormat.format(UIText.DeleteTagCommand_messageConfirmMultipleTag, Integer.valueOf(tags.size()));
            else
                message = MessageFormat.format(UIText.DeleteTagCommand_messageConfirmSingleTag, Repository.shortenRefName(tags.get(0).getObject().getName()));
            confirmed.set(MessageDialog.openConfirm(shell, UIText.DeleteTagCommand_titleConfirm, message));
        }
    });
    if (!confirmed.get())
        return null;
    Job job = new Job(UIText.DeleteTagCommand_taskName) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            monitor.beginTask(UIText.DeleteTagCommand_taskName, tags.size());
            for (TagNode tag : tags) {
                final Repository repo = tag.getRepository();
                final String tagName = tag.getObject().getName();
                final DeleteTagOperation op = new DeleteTagOperation(repo, tagName);
                monitor.subTask(tagName);
                try {
                    op.execute(monitor);
                } catch (CoreException e) {
                    Activator.logError(e.getLocalizedMessage(), e);
                }
                monitor.worked(1);
            }
            monitor.done();
            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            if (JobFamilies.TAG.equals(family))
                return true;
            return super.belongsTo(family);
        }
    };
    job.setUser(true);
    job.schedule();
    return null;
}
Also used : DeleteTagOperation(org.eclipse.egit.core.op.DeleteTagOperation) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) CoreException(org.eclipse.core.runtime.CoreException) Job(org.eclipse.core.runtime.jobs.Job) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode)

Example 3 with TagNode

use of org.eclipse.egit.ui.internal.repository.tree.TagNode in project egit by eclipse.

the class MergeCommand method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    RepositoryTreeNode node = getSelectedNodes(event).get(0);
    final Repository repository = node.getRepository();
    if (!MergeActionHandler.checkMergeIsPossible(repository, getShell(event)) || LaunchFinder.shouldCancelBecauseOfRunningLaunches(repository, null)) {
        return null;
    }
    BasicConfigurationDialog.show(repository);
    String targetRef;
    if (node instanceof RefNode) {
        String refName = ((RefNode) node).getObject().getName();
        try {
            if (refName.equals(repository.getFullBranch()))
                targetRef = null;
            else
                targetRef = refName;
        } catch (IOException e) {
            targetRef = null;
        }
    } else if (node instanceof TagNode)
        targetRef = ((TagNode) node).getObject().getName();
    else
        targetRef = null;
    final String refName;
    final MergeOperation op;
    if (targetRef != null) {
        refName = targetRef;
        op = new MergeOperation(repository, refName);
    } else {
        MergeTargetSelectionDialog mergeTargetSelectionDialog = new MergeTargetSelectionDialog(getShell(event), repository);
        if (mergeTargetSelectionDialog.open() != IDialogConstants.OK_ID)
            return null;
        refName = mergeTargetSelectionDialog.getRefName();
        op = new MergeOperation(repository, refName);
        op.setSquash(mergeTargetSelectionDialog.isMergeSquash());
        op.setFastForwardMode(mergeTargetSelectionDialog.getFastForwardMode());
        op.setCommit(mergeTargetSelectionDialog.isCommit());
    }
    String jobname = NLS.bind(UIText.MergeAction_JobNameMerge, refName);
    Job job = new WorkspaceJob(jobname) {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) {
            try {
                op.execute(monitor);
            } catch (final CoreException e) {
                return e.getStatus();
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.setRule(op.getSchedulingRule());
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent jobEvent) {
            IStatus result = jobEvent.getJob().getResult();
            if (result.getSeverity() == IStatus.CANCEL)
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        // don't use getShell(event) here since
                        // the active shell has changed since the
                        // execution has been triggered.
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        MessageDialog.openInformation(shell, UIText.MergeAction_MergeCanceledTitle, UIText.MergeAction_MergeCanceledMessage);
                    }
                });
            else if (!result.isOK())
                Activator.handleError(result.getMessage(), result.getException(), true);
            else
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        MergeResultDialog.getDialog(shell, repository, op.getResult()).open();
                    }
                });
        }
    });
    job.schedule();
    return null;
}
Also used : MergeOperation(org.eclipse.egit.core.op.MergeOperation) IStatus(org.eclipse.core.runtime.IStatus) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IOException(java.io.IOException) MergeTargetSelectionDialog(org.eclipse.egit.ui.internal.dialogs.MergeTargetSelectionDialog) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode) Repository(org.eclipse.jgit.lib.Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Shell(org.eclipse.swt.widgets.Shell) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) CoreException(org.eclipse.core.runtime.CoreException) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode)

Example 4 with TagNode

use of org.eclipse.egit.ui.internal.repository.tree.TagNode in project egit by eclipse.

the class OpenCommand method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final List<RepositoryTreeNode> nodes = getSelectedNodes(event);
    if (nodes.isEmpty())
        return null;
    final RepositoryTreeNode node = nodes.get(0);
    if (node instanceof RefNode || node instanceof TagNode)
        return new CheckoutCommand().execute(event);
    if (node instanceof FileNode)
        return new OpenInEditorCommand().execute(event);
    if (node instanceof StashedCommitNode) {
        RepositoryCommit repositoryCommit = new RepositoryCommit(node.getRepository(), ((StashedCommitNode) node).getObject());
        repositoryCommit.setStash(true);
        CommitEditor.openQuiet(repositoryCommit);
    }
    return null;
}
Also used : RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) StashedCommitNode(org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode) FileNode(org.eclipse.egit.ui.internal.repository.tree.FileNode) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode)

Example 5 with TagNode

use of org.eclipse.egit.ui.internal.repository.tree.TagNode in project egit by eclipse.

the class RepositoriesViewLabelProvider method getImage.

@Override
public Image getImage(Object element) {
    RepositoryTreeNode node = (RepositoryTreeNode) element;
    RepositoryTreeNodeType type = node.getType();
    if (type == RepositoryTreeNodeType.TAG) {
        TagNode tagNode = (TagNode) node;
        if (tagNode.isAnnotated())
            return decorateImage(annotatedTagImage, element);
    } else if (type == RepositoryTreeNodeType.FILE) {
        Object object = node.getObject();
        if (object instanceof File) {
            ImageDescriptor descriptor = PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor(((File) object).getName());
            return decorateImage((Image) resourceManager.get(descriptor), element);
        }
    } else if (type == RepositoryTreeNodeType.REPO) {
        Object object = node.getObject();
        if (object instanceof Repository) {
            Repository r = (Repository) object;
            if (ResourcePropertyTester.hasGerritConfiguration(r))
                return gerritRepoImage;
        }
    }
    return decorateImage(node.getType().getIcon(), element);
}
Also used : RepositoryTreeNodeType(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNodeType) Repository(org.eclipse.jgit.lib.Repository) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) CompositeImageDescriptor(org.eclipse.jface.resource.CompositeImageDescriptor) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Image(org.eclipse.swt.graphics.Image) File(java.io.File) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode)

Aggregations

TagNode (org.eclipse.egit.ui.internal.repository.tree.TagNode)14 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)10 ArrayList (java.util.ArrayList)5 RefNode (org.eclipse.egit.ui.internal.repository.tree.RefNode)5 Ref (org.eclipse.jgit.lib.Ref)5 Repository (org.eclipse.jgit.lib.Repository)5 IOException (java.io.IOException)4 FileNode (org.eclipse.egit.ui.internal.repository.tree.FileNode)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 File (java.io.File)2 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 AdditionalRefNode (org.eclipse.egit.ui.internal.repository.tree.AdditionalRefNode)2 StashedCommitNode (org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 RevObject (org.eclipse.jgit.revwalk.RevObject)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2