|
What this is
Other links
The source code/******************************************************************************* * Copyright (c) 2007 IBM Corporation 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: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.pde.internal.ui.editor; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.ui.ILaunchShortcut; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.pde.internal.ui.PDEPluginImages; import org.eclipse.pde.internal.ui.editor.actions.ActionMenu; public abstract class PDELauncherFormEditor extends MultiSourceEditor { Action[][] fActions = null; protected abstract ILauncherFormPageHelper getLauncherHelper(); protected void contributeLaunchersToToolbar(IToolBarManager manager) { // this should never be null (no point in using this class if you don't provide an ILauncherFormPageHelper) // but we'll guard against it anyway if (getLauncherHelper() != null) { Action[][] actions = getActions(); if (actions[RUN_LAUNCHER_INDEX].length > 0) { Action runAction = new ActionMenu(actions[RUN_LAUNCHER_INDEX]); manager.add(runAction); } if (actions[DEBUG_LAUNCHER_INDEX].length > 0) { Action runAction = new ActionMenu(actions[DEBUG_LAUNCHER_INDEX]); manager.add(runAction); } if (actions[PROFILE_LAUNCHER_INDEX].length > 0) { Action runAction = new ActionMenu(actions[PROFILE_LAUNCHER_INDEX]); manager.add(runAction); } } } private Action[][] getActions() { if (fActions == null) { fActions = new Action[3][]; IConfigurationElement[][] elements = getLaunchers(getLauncherHelper().isOSGi()); fActions[RUN_LAUNCHER_INDEX] = getLauncherActions(elements[RUN_LAUNCHER_INDEX]); fActions[DEBUG_LAUNCHER_INDEX] = getLauncherActions(elements[DEBUG_LAUNCHER_INDEX]); fActions[PROFILE_LAUNCHER_INDEX] = getLauncherActions(elements[PROFILE_LAUNCHER_INDEX]); } return fActions; } private Action[] getLauncherActions(IConfigurationElement[] elements) { Action[] result = new Action[elements.length]; for (int i = 0; i < elements.length; i++) { String label = elements[i].getAttribute("label"); //$NON-NLS-1$ final String thisLaunchShortcut = getLaunchString(elements[i]); Action thisAction = new Action(label) { //$NON-NLS-1$ public void run() { doSave(null); launch(thisLaunchShortcut, getPreLaunchRunnable(), getLauncherHelper().getLaunchObject()); } }; thisAction.setToolTipText(label); thisAction.setImageDescriptor(getImageDescriptor(elements[i])); result[i] = thisAction; } return result; } protected Runnable getPreLaunchRunnable() { return new Runnable() { public void run() { getLauncherHelper().preLaunch(); } }; } public String getLaunchString(IConfigurationElement e) { StringBuffer sb = new StringBuffer("launchShortcut."); //$NON-NLS-1$ sb.append(e.getAttribute("mode")); //$NON-NLS-1$ sb.append("."); //$NON-NLS-1$ sb.append(e.getAttribute("id")); //$NON-NLS-1$ return sb.toString(); } private ImageDescriptor getImageDescriptor(IConfigurationElement element) { String mode = element.getAttribute("mode"); //$NON-NLS-1$ if (mode == null) return null; else if (mode.equals(ILaunchManager.RUN_MODE)) return PDEPluginImages.DESC_RUN_EXC; else if (mode.equals(ILaunchManager.DEBUG_MODE)) return PDEPluginImages.DESC_DEBUG_EXC; else if (mode.equals(ILaunchManager.PROFILE_MODE)) return PDEPluginImages.DESC_PROFILE_EXC; return null; } public void launch(String launchShortcut, Runnable preLaunch, Object launchObject) { if (launchShortcut.startsWith("launchShortcut.")) { //$NON-NLS-1$ launchShortcut = launchShortcut.substring(15); int index = launchShortcut.indexOf('.'); if (index < 0) return; // error. Format of launchShortcut should be launchShortcut.<mode>. |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.