aboutsummaryrefslogtreecommitdiffstats
path: root/org.openembedded.bc.ui/src/org/openembedded/bc/ui/views/RecipeContentProvider.java
blob: 3482b9be39f3005ee98ff060111e5b09d2cbd0d6 (plain)
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
/*****************************************************************************
 * Copyright (c) 2009 Ken Gilmer
 * 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:
 *     Ken Gilmer - initial API and implementation
 *******************************************************************************/
package org.openembedded.bc.ui.views;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.openembedded.bc.bitbake.BBSession;
import org.openembedded.bc.ui.Activator;
import org.openembedded.bc.ui.builder.BitbakeCommanderNature;


class RecipeContentProvider implements IStructuredContentProvider {
	public void dispose() {
	}

	public Object[] getElements(Object parent) {
		List recipes = new ArrayList();
		IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
		IProjectNature nature = null;
		for (int i = 0; i < projects.length; ++i) {
			try {
				if (projects[i].isOpen() && projects[i].hasNature(BitbakeCommanderNature.NATURE_ID)) {
					recipes.addAll(getRecipesFromProject(projects[i]));
				}
			} catch (CoreException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return recipes.toArray();
	}

	private Collection getRecipesFromProject(IProject project) throws Exception {
		BBSession session = Activator.getBBSession(project.getLocationURI().getPath(), null);
		
		if (!session.isInitialized()) {
			session.initialize();
		}
		
		return session.getRecipeFiles(project);
	}

	public void inputChanged(Viewer v, Object oldInput, Object newInput) {
	}
}