Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cd59ed8ce6f9fac48348a64e0237ab1494c546c3 (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
79
80
81
82
83
84
/*******************************************************************************
 * Copyright (c) 2009 Red Hat, Inc.
 * 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:
 *     Red Hat Incorporated - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.rpmstubby.popup.actions;

import java.util.Iterator;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.linuxtools.rpmstubby.SpecfilePomWriter;
import org.eclipse.ui.handlers.HandlerUtil;

/**
 * Action handling stybifying RPM spec file from a Maven pom.xml file.
 * 
 */
public class StubifyPomAction extends StubifyAction {

	@Override
	public void run(IAction action) {
		IFile pomFile = null;
		StructuredSelection structuredSelection = (StructuredSelection) selection;
		for (Iterator<?> selectionIter = structuredSelection.iterator(); selectionIter
				.hasNext();) {
			Object selected = selectionIter.next();
			if (selected instanceof IFile) {
				pomFile = (IFile) selected;
			} else {
				// FIXME: error
			}
		}
		SpecfilePomWriter specfileWriter = new SpecfilePomWriter();
		specfileWriter.write(pomFile);
	}

	public Object execute(ExecutionEvent event) {
		IFile featureFile = null;
		ISelection selection = HandlerUtil.getCurrentSelection(event);
		if (selection instanceof IStructuredSelection) {
			for (Object element : ((IStructuredSelection) selection).toList()) {
				if (element instanceof IFile) {
					featureFile = (IFile) element;
				} else if (element instanceof IAdaptable) {
					featureFile = (IFile) ((IAdaptable) element)
							.getAdapter(IFile.class);
				}
				if (featureFile != null) {
					SpecfilePomWriter specfileWriter = new SpecfilePomWriter();
					specfileWriter.write(featureFile);
				}
			}
			// StructuredSelection structuredSelection = (StructuredSelection)
			// selection;
			// for (Iterator<?> selectionIter = structuredSelection.iterator();
			// selectionIter
			// .hasNext();) {
			// Object selected = selectionIter.next();
			// if (selected instanceof IProject) {
			// featureFile = ((IProject) selected).getFile(new Path(
			// "/feature.xml"));
			// } else if (selected instanceof IFile) {
			// featureFile = (IFile) selected;
			// } else {
			// // FIXME: error
			// }
			// }

		}
		return null;
	}

}

Back to the top