Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b37173376d13058098d2ea0e856f9c15ca800628 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*******************************************************************************
 * Copyright (c) 2013 Red Hat Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Neil Guzman - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.internal.rpm.createrepo.handler;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.linuxtools.internal.rpm.createrepo.Activator;
import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProject;
import org.eclipse.linuxtools.rpm.createrepo.CreaterepoUtils;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.console.MessageConsoleStream;
import org.eclipse.ui.ide.ResourceUtil;

/**
 * Handle the execution of the Update and Execute button.
 */
public class CreaterepoCommandHandler extends AbstractHandler {

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		final String executionType = event.getParameter("executionType"); //$NON-NLS-1$
		try {
			IWorkbench wb = PlatformUI.getWorkbench();
			IWorkbenchPage wbPage = wb.getActiveWorkbenchWindow().getActivePage();
			IEditorInput editorInput = wbPage.getActiveEditor().getEditorInput();
			IResource resource = ResourceUtil.getResource(editorInput);
			final CreaterepoProject project = new CreaterepoProject(resource.getProject());
			Job executeCreaterepo = new Job(Messages.Createrepo_jobName) {
				@Override
				protected IStatus run(IProgressMonitor monitor) {
					try {
						monitor.beginTask(Messages.CreaterepoProject_executeCreaterepo, IProgressMonitor.UNKNOWN);
						MessageConsoleStream os = CreaterepoUtils.findConsole(Messages.CreaterepoProject_consoleName)
								.newMessageStream();
						if (executionType.equals("refresh")) { //$NON-NLS-1$
							return project.update(os);
						} else {
							return project.createrepo(os);
						}
					} catch (CoreException e) {
						Activator.logError(Messages.Createrepo_errorExecuting, e);
					} finally {
						monitor.done();
					}
					return null;
				}
			};
			executeCreaterepo.setUser(true);
			executeCreaterepo.schedule();
		} catch (CoreException e) {
			Activator.logError(Messages.CreaterepoProject_executeCreaterepo, e);
		}
		return null;
	}

}

Back to the top