Search in sources :

Example 1 with AddSubmoduleWizard

use of org.eclipse.egit.ui.internal.submodule.AddSubmoduleWizard in project egit by eclipse.

the class SubmoduleAddCommand method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    List<RepositoryTreeNode<?>> nodes = getSelectedNodes(event);
    if (nodes.isEmpty())
        return null;
    final Repository repo = nodes.get(0).getRepository();
    if (repo == null)
        return null;
    AddSubmoduleWizard wizard = new AddSubmoduleWizard(repo);
    WizardDialog dialog = new WizardDialog(getShell(event), wizard);
    if (dialog.open() == Window.OK) {
        final String path = wizard.getPath();
        final String uri = wizard.getUri().toPrivateASCIIString();
        final SubmoduleAddOperation op = new SubmoduleAddOperation(repo, path, uri);
        Job job = new WorkspaceJob(MessageFormat.format(UIText.SubmoduleAddCommand_JobTitle, path, uri)) {

            @Override
            public IStatus runInWorkspace(IProgressMonitor monitor) {
                // $NON-NLS-1$
                monitor.beginTask("", IProgressMonitor.UNKNOWN);
                try {
                    op.execute(monitor);
                } catch (CoreException e) {
                    Activator.logError(UIText.SubmoduleAddCommand_AddError, e);
                }
                return Status.OK_STATUS;
            }

            @Override
            public boolean belongsTo(Object family) {
                if (JobFamilies.SUBMODULE_ADD.equals(family))
                    return true;
                return super.belongsTo(family);
            }
        };
        job.setUser(true);
        job.setRule(op.getSchedulingRule());
        job.schedule();
    }
    return null;
}
Also used : AddSubmoduleWizard(org.eclipse.egit.ui.internal.submodule.AddSubmoduleWizard) Repository(org.eclipse.jgit.lib.Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) CoreException(org.eclipse.core.runtime.CoreException) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) WizardDialog(org.eclipse.jface.wizard.WizardDialog) SubmoduleAddOperation(org.eclipse.egit.core.op.SubmoduleAddOperation)

Aggregations

WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 SubmoduleAddOperation (org.eclipse.egit.core.op.SubmoduleAddOperation)1 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)1 AddSubmoduleWizard (org.eclipse.egit.ui.internal.submodule.AddSubmoduleWizard)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 Repository (org.eclipse.jgit.lib.Repository)1