Skip to main content
summaryrefslogtreecommitdiffstats
blob: 58406bc2aaf6f9ea679ea5e1d7e2509691ad03ec (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
/*
 * <copyright>
 *
 * Copyright (c) 2005-2006 Markus Voelter 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:
 *     Markus Voelter - Initial API and implementation
 *
 * </copyright>
 */
package org.eclipse.m2t.common.recipe.ui.action;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.m2t.common.recipe.ui.RecipePlugin;
import org.eclipse.m2t.common.recipe.ui.recipeBrowser.RecipeBrowserView;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

public class OpenRecipesAction implements IObjectActionDelegate {

	private IResource selectedResource = null;

	public OpenRecipesAction() {
		super();
	}

	public OpenRecipesAction(IFile file) {
		selectedResource = file;
	}

	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
	}

	public void run(IAction action) {
		if (selectedResource instanceof IFile) {
			RecipeBrowserView v;
			try {
				v = (RecipeBrowserView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(RecipeBrowserView.ID);
				v.openRecipeFile((IFile) selectedResource);
			} catch (PartInitException e) {
				RecipePlugin.log(e);
			}
		}
	}

	public void selectionChanged(IAction action, ISelection selection) {
		if (selection != null) {
			IStructuredSelection sel = (IStructuredSelection) selection;
			if (sel.getFirstElement() != null) {
				selectedResource = (IResource) sel.getFirstElement();
			}
		}
	}

}

Back to the top