blob: 7dd3ef3f89f6476558084517996dc85d93b745de [file] [log] [blame]
/**
* Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Florian Pirchner - Initial implementation
*/
package org.eclipse.osbp.ide.core.ui.nature;
import java.io.IOException;
import java.net.MalformedURLException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.equinox.region.Region;
import org.eclipse.equinox.region.RegionDigraph;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.slf4j.LoggerFactory;
/**
* @author Sven Efftinge - Initial contribution and API
*/
public class RunVaaclipseAction implements IObjectActionDelegate {
private static final org.slf4j.Logger log = LoggerFactory
.getLogger(RunVaaclipseAction.class);
private ISelection selection;
public void run(IAction action) {
try {
BundleContext bc = FrameworkUtil.getBundle(getClass())
.getBundleContext();
ServiceReference<RegionDigraph> ref = bc
.getServiceReference(RegionDigraph.class);
RegionDigraph digraph = bc.getService(ref);
Region vaaclipse = digraph.getRegion("vaaclipse");
if (vaaclipse != null) {
digraph.removeRegion(vaaclipse);
}
vaaclipse = digraph.createRegion("vaaclipse");
for (Bundle b : bc.getBundles()) {
Bundle newB = vaaclipse.installBundle(FileLocator
.getBundleFile(b).toURI().toURL().toExternalForm());
vaaclipse.addBundle(newB);
}
} catch (BundleException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void selectionChanged(IAction action, ISelection selection) {
this.selection = selection;
}
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
}
}