Java tutorial
// ======================================================================== // Copyright (c) 2009 Intalio, Inc. // ------------------------------------------------------------------------ // All rights reserved. This program and the accompanying materials // are made available under the terms of the Eclipse Public License v1.0 // and Apache License v2.0 which accompanies this distribution. // The Eclipse Public License is available at // http://www.eclipse.org/legal/epl-v10.html // The Apache License v2.0 is available at // http://www.opensource.org/licenses/apache2.0.php // You may elect to redistribute this code under either of these licenses. // Contributors: // Hugues Malphettes - initial API and implementation // ======================================================================== package org.eclipse.jetty.osgi.pde.launch.ui.console; import java.util.HashSet; import java.util.Set; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchDelegate; import org.eclipse.debug.core.model.RuntimeProcess; import org.eclipse.jetty.osgi.pde.launch.ui.JettyEquinoxLaunchConfiguration; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.ui.console.IConsole; import org.eclipse.ui.console.IConsoleConstants; import org.eclipse.ui.console.IConsolePageParticipant; import org.eclipse.ui.console.IOConsole; import org.eclipse.ui.part.IPageBookViewPage; /** * Called whenever a new console is started. * When that console is related to the launch of jetty-osgi we add some buttons * to the console to make it easier to relaunch web-applications. */ public class JettyConsolePageParticipant implements IConsolePageParticipant { private ReloadDeployedWebappsAction _reloadWebapps; /** * Called during page initialization. Marks the start of this * page participant's lifecycle. * * @param page the page corresponding to the given console * @param console the console for which a page has been created */ public void init(IPageBookViewPage page, IConsole console) { if (!(console instanceof IOConsole)) { return;//we should not even be here as we are testing for the java property //in the plugin.xml so it is always an IOConsole } Object o = ((IOConsole) console).getAttribute("org.eclipse.debug.ui.ATTR_CONSOLE_PROCESS"); if (o == null || !(o instanceof RuntimeProcess)) { return; } RuntimeProcess runProc = (RuntimeProcess) o; ILaunchConfiguration launchConfig = runProc.getLaunch().getLaunchConfiguration(); if (launchConfig == null) { return; } try { ILaunchConfigurationType launchConfigType = launchConfig.getType(); if (launchConfigType == null) { return; } boolean foundJetty = false; for (Object modes : launchConfigType.getSupportedModeCombinations()) { for (ILaunchDelegate del : launchConfigType.getDelegates((Set) modes)) { if (del.getDelegate() instanceof JettyEquinoxLaunchConfiguration) { foundJetty = true;//oof break; } } if (foundJetty) { break; } } if (!foundJetty) { return; } } catch (Exception e) { return; } _reloadWebapps = new ReloadDeployedWebappsAction(console, launchConfig); IToolBarManager manager = page.getSite().getActionBars().getToolBarManager(); manager.appendToGroup(IConsoleConstants.LAUNCH_GROUP, _reloadWebapps); } /** * Disposes this page participant. Marks the end of this * page participant's lifecycle. */ public void dispose() { } /** * Notification this participant's page has been activated. */ public void activated() { } /** * Notification this participant's page has been deactivated. */ public void deactivated() { if (_reloadWebapps != null) { _reloadWebapps.setEnabled(false); } } /** * @return null. */ public Object getAdapter(Class adapter) { return null; } }