From 2ef0a883982ac6707a39d610ad91ee83bbec4e5c Mon Sep 17 00:00:00 2001 From: John Cortell Date: Tue, 10 Apr 2007 19:28:22 +0000 Subject: [PATCH] Fixed bug 181829. Debugger was not enforcing extension point schema. Also renamed 'breakpointActionPage' extension point to have an uppercase first letter, for consistency with all other CDT debugger extension points. --- .../cdt/debug/core/CDebugCorePlugin.java | 14 +- .../BreakpointActionManager.java | 496 ++++++++-------- .../org.eclipse.cdt.debug.mi.core/plugin.xml | 9 +- debug/org.eclipse.cdt.debug.mi.ui/plugin.xml | 9 +- debug/org.eclipse.cdt.debug.ui/plugin.xml | 38 +- .../schema/BreakpointActionPage.exsd | 8 +- .../eclipse/cdt/debug/ui/CDebugUIPlugin.java | 14 +- .../ui/breakpointactions/ActionDialog.java | 562 +++++++++--------- 8 files changed, 580 insertions(+), 570 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java index 8bf3db754ca..14ef42e0b06 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java @@ -76,8 +76,12 @@ public class CDebugCorePlugin extends Plugin { * Breakpoint action manager. */ private BreakpointActionManager breakpointActionManager; + + public static final String CDEBUGGER_EXTENSION_POINT_ID = "CDebugger"; //$NON-NLS-1$ + public static final String DEBUGGER_ELEMENT = "debugger"; //$NON-NLS-1$ - public static final String BREAKPOINT_ACTION_SIMPLE_ID = "BreakpointActionType"; //$NON-NLS-1$ + public static final String BREAKPOINT_ACTION_EXTENSION_POINT_ID = "BreakpointActionType"; //$NON-NLS-1$ + public static final String ACTION_TYPE_ELEMENT = "actionType"; //$NON-NLS-1$ /** * Dummy source lookup director needed to manage common source containers. @@ -165,13 +169,15 @@ public class CDebugCorePlugin extends Plugin { } private void initializeDebugConfiguration() { - IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint( getUniqueIdentifier(), "CDebugger" ); //$NON-NLS-1$ + IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint( getUniqueIdentifier(), CDEBUGGER_EXTENSION_POINT_ID ); //$NON-NLS-1$ IConfigurationElement[] infos = extensionPoint.getConfigurationElements(); fDebugConfigurations = new HashMap( infos.length ); for( int i = 0; i < infos.length; i++ ) { IConfigurationElement configurationElement = infos[i]; - DebugConfiguration configType = new DebugConfiguration( configurationElement ); - fDebugConfigurations.put( configType.getID(), configType ); + if (configurationElement.getName().equals(DEBUGGER_ELEMENT)) { + DebugConfiguration configType = new DebugConfiguration( configurationElement ); + fDebugConfigurations.put( configType.getID(), configType ); + } } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/breakpointactions/BreakpointActionManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/breakpointactions/BreakpointActionManager.java index 2f861a718e8..911a81d4d97 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/breakpointactions/BreakpointActionManager.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/breakpointactions/BreakpointActionManager.java @@ -1,247 +1,249 @@ -/******************************************************************************* - * Copyright (c) 2007 Nokia 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: - * Nokia - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.debug.core.breakpointactions; - -import java.io.ByteArrayOutputStream; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.StringTokenizer; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.Platform; -import org.eclipse.debug.core.model.IBreakpoint; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import org.xml.sax.helpers.DefaultHandler; - -public class BreakpointActionManager { - - public static final String BREAKPOINT_ACTION_ATTRIBUTE = "BREAKPOINT_ACTIONS"; //$NON-NLS-1$ - private static final String BREAKPOINT_ACTION_DATA = "BreakpointActionManager.actionData"; //$NON-NLS-1$ - - private IExtension[] breakpointActionExtensions = null; - private ArrayList breakpointActions = null; - - public BreakpointActionManager() { - } - - public void addAction(IBreakpointAction action) { - getBreakpointActions().add(action); - } - - private IBreakpointAction createActionFromClassName(String name, String className) { - - IBreakpointAction action = null; - IExtension[] actionExtensions = CDebugCorePlugin.getDefault().getBreakpointActionManager().getBreakpointActionExtensions(); - - try { - - for (int i = 0; i < actionExtensions.length && action == null; i++) { - IConfigurationElement[] elements = actionExtensions[i].getConfigurationElements(); - for (int j = 0; j < elements.length && action == null; j++) { - - if (elements[j].getAttribute("class").equals(className)) { //$NON-NLS-1$ - action = (IBreakpointAction) elements[j].createExecutableExtension("class"); //$NON-NLS-1$ - action.setName(name); - CDebugCorePlugin.getDefault().getBreakpointActionManager().addAction(action); - } - } - } - - } catch (CoreException e) { - e.printStackTrace(); - } - - return action; - } - - public void deleteAction(IBreakpointAction action) { - getBreakpointActions().remove(action); - } - - public boolean breakpointHasActions(IBreakpoint breakpoint) { - if (breakpoint != null) { - IMarker marker = breakpoint.getMarker(); - String actionNames = marker.getAttribute(BREAKPOINT_ACTION_ATTRIBUTE, ""); //$NON-NLS-1$ - return actionNames.length() > 0; - } - return false; - } - - public void executeActions(IBreakpoint breakpoint, IAdaptable context) { - - if (breakpoint != null) { - IMarker marker = breakpoint.getMarker(); - String actionNames = marker.getAttribute(BREAKPOINT_ACTION_ATTRIBUTE, ""); //$NON-NLS-1$ - StringTokenizer tok = new StringTokenizer(actionNames, ","); //$NON-NLS-1$ - while (tok.hasMoreTokens()) { - String actionName = tok.nextToken(); - IBreakpointAction action = findBreakpointAction(actionName); - if (action != null) { - action.execute(breakpoint, context); - } - } - } - } - - public IBreakpointAction findBreakpointAction(String name) { - for (Iterator iter = getBreakpointActions().iterator(); iter.hasNext();) { - IBreakpointAction action = (IBreakpointAction) iter.next(); - if (action.getName().equals(name)) - return action; - } - return null; - } - - public IExtension[] getBreakpointActionExtensions() { - if (breakpointActionExtensions == null) { - IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CDebugCorePlugin.PLUGIN_ID, CDebugCorePlugin.BREAKPOINT_ACTION_SIMPLE_ID); - if (point == null) - breakpointActionExtensions = new IExtension[0]; - else { - breakpointActionExtensions = point.getExtensions(); - } - } - - return breakpointActionExtensions; - } - - public ArrayList getBreakpointActions() { - if (breakpointActions == null) { - breakpointActions = new ArrayList(); - CDebugCorePlugin.getDefault().getBreakpointActionManager().loadActionData(); - } - return breakpointActions; - } - - private void loadActionData() { - - String actionData = CDebugCorePlugin.getDefault().getPluginPreferences().getString(BREAKPOINT_ACTION_DATA); - - if (actionData == null || actionData.length() == 0) - return; - - Element root = null; - DocumentBuilder parser; - try { - parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - parser.setErrorHandler(new DefaultHandler()); - root = parser.parse(new InputSource(new StringReader(actionData))).getDocumentElement(); - - NodeList nodeList = root.getChildNodes(); - int entryCount = nodeList.getLength(); - - for (int i = 0; i < entryCount; i++) { - Node node = nodeList.item(i); - short type = node.getNodeType(); - if (type == Node.ELEMENT_NODE) { - Element subElement = (Element) node; - String nodeName = subElement.getNodeName(); - if (nodeName.equalsIgnoreCase("actionEntry")) { //$NON-NLS-1$ - String name = subElement.getAttribute("name"); //$NON-NLS-1$ - if (name == null) - throw new Exception(); - String value = subElement.getAttribute("value"); //$NON-NLS-1$ - if (value == null) - throw new Exception(); - String className = subElement.getAttribute("class"); //$NON-NLS-1$ - if (className == null) - throw new Exception(); - - IBreakpointAction action = createActionFromClassName(name, className); - action.initializeFromMemento(value); - } - } - } - - } catch (Exception e) { - e.printStackTrace(); - } - } - - public String makeUniqueActionName(String defaultName) { - String result = defaultName; - IBreakpointAction action = findBreakpointAction(defaultName); - int actionCount = 1; - while (action != null) { - result = defaultName + "(" + actionCount + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - action = findBreakpointAction(result); - actionCount++; - } - return result; - } - - public void revertActionData() { - breakpointActions = null; - } - - public void saveActionData() { - String actionData = new String(""); //$NON-NLS-1$ - - DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder docBuilder = null; - try { - docBuilder = dfactory.newDocumentBuilder(); - Document doc = docBuilder.newDocument(); - - Element rootElement = doc.createElement("breakpointActionData"); //$NON-NLS-1$ - doc.appendChild(rootElement); - - for (Iterator iter = getBreakpointActions().iterator(); iter.hasNext();) { - IBreakpointAction action = (IBreakpointAction) iter.next(); - - Element element = doc.createElement("actionEntry"); //$NON-NLS-1$ - element.setAttribute("name", action.getName()); //$NON-NLS-1$ - element.setAttribute("class", action.getClass().getName()); //$NON-NLS-1$ - element.setAttribute("value", action.getMemento()); //$NON-NLS-1$ - rootElement.appendChild(element); - - } - - ByteArrayOutputStream s = new ByteArrayOutputStream(); - - TransformerFactory factory = TransformerFactory.newInstance(); - Transformer transformer = factory.newTransformer(); - transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ - - DOMSource source = new DOMSource(doc); - StreamResult outputTarget = new StreamResult(s); - transformer.transform(source, outputTarget); - - actionData = s.toString("UTF8"); //$NON-NLS-1$ - - } catch (Exception e) { - e.printStackTrace(); - } - CDebugCorePlugin.getDefault().getPluginPreferences().setValue(BREAKPOINT_ACTION_DATA, actionData); - CDebugCorePlugin.getDefault().savePluginPreferences(); - } - -} +/******************************************************************************* + * Copyright (c) 2007 Nokia 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: + * Nokia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.debug.core.breakpointactions; + +import java.io.ByteArrayOutputStream; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.StringTokenizer; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.Platform; +import org.eclipse.debug.core.model.IBreakpoint; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.helpers.DefaultHandler; + +public class BreakpointActionManager { + + public static final String BREAKPOINT_ACTION_ATTRIBUTE = "BREAKPOINT_ACTIONS"; //$NON-NLS-1$ + private static final String BREAKPOINT_ACTION_DATA = "BreakpointActionManager.actionData"; //$NON-NLS-1$ + + private IExtension[] breakpointActionExtensions = null; + private ArrayList breakpointActions = null; + + public BreakpointActionManager() { + } + + public void addAction(IBreakpointAction action) { + getBreakpointActions().add(action); + } + + private IBreakpointAction createActionFromClassName(String name, String className) { + + IBreakpointAction action = null; + IExtension[] actionExtensions = CDebugCorePlugin.getDefault().getBreakpointActionManager().getBreakpointActionExtensions(); + + try { + + for (int i = 0; i < actionExtensions.length && action == null; i++) { + IConfigurationElement[] elements = actionExtensions[i].getConfigurationElements(); + for (int j = 0; j < elements.length && action == null; j++) { + IConfigurationElement element = elements[j]; + if (element.getName().equals(CDebugCorePlugin.ACTION_TYPE_ELEMENT)) { + if (element.getAttribute("class").equals(className)) { //$NON-NLS-1$ + action = (IBreakpointAction) element.createExecutableExtension("class"); //$NON-NLS-1$ + action.setName(name); + CDebugCorePlugin.getDefault().getBreakpointActionManager().addAction(action); + } + } + } + } + + } catch (CoreException e) { + e.printStackTrace(); + } + + return action; + } + + public void deleteAction(IBreakpointAction action) { + getBreakpointActions().remove(action); + } + + public boolean breakpointHasActions(IBreakpoint breakpoint) { + if (breakpoint != null) { + IMarker marker = breakpoint.getMarker(); + String actionNames = marker.getAttribute(BREAKPOINT_ACTION_ATTRIBUTE, ""); //$NON-NLS-1$ + return actionNames.length() > 0; + } + return false; + } + + public void executeActions(IBreakpoint breakpoint, IAdaptable context) { + + if (breakpoint != null) { + IMarker marker = breakpoint.getMarker(); + String actionNames = marker.getAttribute(BREAKPOINT_ACTION_ATTRIBUTE, ""); //$NON-NLS-1$ + StringTokenizer tok = new StringTokenizer(actionNames, ","); //$NON-NLS-1$ + while (tok.hasMoreTokens()) { + String actionName = tok.nextToken(); + IBreakpointAction action = findBreakpointAction(actionName); + if (action != null) { + action.execute(breakpoint, context); + } + } + } + } + + public IBreakpointAction findBreakpointAction(String name) { + for (Iterator iter = getBreakpointActions().iterator(); iter.hasNext();) { + IBreakpointAction action = (IBreakpointAction) iter.next(); + if (action.getName().equals(name)) + return action; + } + return null; + } + + public IExtension[] getBreakpointActionExtensions() { + if (breakpointActionExtensions == null) { + IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CDebugCorePlugin.PLUGIN_ID, CDebugCorePlugin.BREAKPOINT_ACTION_EXTENSION_POINT_ID); + if (point == null) + breakpointActionExtensions = new IExtension[0]; + else { + breakpointActionExtensions = point.getExtensions(); + } + } + + return breakpointActionExtensions; + } + + public ArrayList getBreakpointActions() { + if (breakpointActions == null) { + breakpointActions = new ArrayList(); + CDebugCorePlugin.getDefault().getBreakpointActionManager().loadActionData(); + } + return breakpointActions; + } + + private void loadActionData() { + + String actionData = CDebugCorePlugin.getDefault().getPluginPreferences().getString(BREAKPOINT_ACTION_DATA); + + if (actionData == null || actionData.length() == 0) + return; + + Element root = null; + DocumentBuilder parser; + try { + parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + parser.setErrorHandler(new DefaultHandler()); + root = parser.parse(new InputSource(new StringReader(actionData))).getDocumentElement(); + + NodeList nodeList = root.getChildNodes(); + int entryCount = nodeList.getLength(); + + for (int i = 0; i < entryCount; i++) { + Node node = nodeList.item(i); + short type = node.getNodeType(); + if (type == Node.ELEMENT_NODE) { + Element subElement = (Element) node; + String nodeName = subElement.getNodeName(); + if (nodeName.equalsIgnoreCase("actionEntry")) { //$NON-NLS-1$ + String name = subElement.getAttribute("name"); //$NON-NLS-1$ + if (name == null) + throw new Exception(); + String value = subElement.getAttribute("value"); //$NON-NLS-1$ + if (value == null) + throw new Exception(); + String className = subElement.getAttribute("class"); //$NON-NLS-1$ + if (className == null) + throw new Exception(); + + IBreakpointAction action = createActionFromClassName(name, className); + action.initializeFromMemento(value); + } + } + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + public String makeUniqueActionName(String defaultName) { + String result = defaultName; + IBreakpointAction action = findBreakpointAction(defaultName); + int actionCount = 1; + while (action != null) { + result = defaultName + "(" + actionCount + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + action = findBreakpointAction(result); + actionCount++; + } + return result; + } + + public void revertActionData() { + breakpointActions = null; + } + + public void saveActionData() { + String actionData = new String(""); //$NON-NLS-1$ + + DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder = null; + try { + docBuilder = dfactory.newDocumentBuilder(); + Document doc = docBuilder.newDocument(); + + Element rootElement = doc.createElement("breakpointActionData"); //$NON-NLS-1$ + doc.appendChild(rootElement); + + for (Iterator iter = getBreakpointActions().iterator(); iter.hasNext();) { + IBreakpointAction action = (IBreakpointAction) iter.next(); + + Element element = doc.createElement("actionEntry"); //$NON-NLS-1$ + element.setAttribute("name", action.getName()); //$NON-NLS-1$ + element.setAttribute("class", action.getClass().getName()); //$NON-NLS-1$ + element.setAttribute("value", action.getMemento()); //$NON-NLS-1$ + rootElement.appendChild(element); + + } + + ByteArrayOutputStream s = new ByteArrayOutputStream(); + + TransformerFactory factory = TransformerFactory.newInstance(); + Transformer transformer = factory.newTransformer(); + transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ + + DOMSource source = new DOMSource(doc); + StreamResult outputTarget = new StreamResult(s); + transformer.transform(source, outputTarget); + + actionData = s.toString("UTF8"); //$NON-NLS-1$ + + } catch (Exception e) { + e.printStackTrace(); + } + CDebugCorePlugin.getDefault().getPluginPreferences().setValue(BREAKPOINT_ACTION_DATA, actionData); + CDebugCorePlugin.getDefault().savePluginPreferences(); + } + +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/plugin.xml b/debug/org.eclipse.cdt.debug.mi.core/plugin.xml index 5859e7ba65b..9b5f7ac48a9 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/plugin.xml +++ b/debug/org.eclipse.cdt.debug.mi.core/plugin.xml @@ -11,24 +11,21 @@ id="org.eclipse.cdt.debug.mi.core.CDebuggerNew" modes="run,core,attach" name="%GDBMIDebugger.name" - platform="*"> - + platform="*"/> - + id="org.eclipse.cdt.debug.mi.core.CygwinCDebugger"/> - + id="org.eclipse.cdt.debug.mi.core.GDBServerCDebugger"/> - + id="org.eclipse.cdt.debug.mi.GDBDebuggerPage"/> - + id="org.eclipse.cdt.debug.mi.CygwinDebuggerPage"/> - + id="org.eclipse.cdt.debug.mi.GDBServerDebuggerPage"/> - + - + id="org.eclipse.cdt.debug.ui.breakpointactions.SoundAction"/> - + id="org.eclipse.cdt.debug.ui.breakpointactions.LogAction"/> - + id="org.eclipse.cdt.debug.ui.breakpointactions.ResumeAction"/> - - + id="org.eclipse.cdt.debug.ui.breakpointactions.ExternalToolAction"/> - + point="org.eclipse.cdt.debug.ui.BreakpointActionPage"> - + actionType="org.eclipse.cdt.debug.ui.breakpointactions.SoundAction"/> + point="org.eclipse.cdt.debug.ui.BreakpointActionPage"> - + actionType="org.eclipse.cdt.debug.ui.breakpointactions.LogAction"/> + point="org.eclipse.cdt.debug.ui.BreakpointActionPage"> - + actionType="org.eclipse.cdt.debug.ui.breakpointactions.ResumeAction"/> - + point="org.eclipse.cdt.debug.ui.BreakpointActionPage"> - + actionType="org.eclipse.cdt.debug.ui.breakpointactions.ExternalToolAction"/> diff --git a/debug/org.eclipse.cdt.debug.ui/schema/BreakpointActionPage.exsd b/debug/org.eclipse.cdt.debug.ui/schema/BreakpointActionPage.exsd index 684aaed6e6a..e890bdacce2 100644 --- a/debug/org.eclipse.cdt.debug.ui/schema/BreakpointActionPage.exsd +++ b/debug/org.eclipse.cdt.debug.ui/schema/BreakpointActionPage.exsd @@ -3,14 +3,14 @@ - + This extension point provides a mechanism for contributing UI to define and edit a breakpoint action. - + @@ -34,7 +34,7 @@ - + @@ -50,7 +50,7 @@ - + diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java index aff58cc6290..e5430d2b5b5 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java @@ -65,6 +65,9 @@ public class CDebugUIPlugin extends AbstractUIPlugin { */ public static final String PLUGIN_ID = "org.eclipse.cdt.debug.ui"; //$NON-NLS-1$ + public static final String CDEBUGGER_PAGE_EXTENSION_POINT_ID = "CDebuggerPage"; + public static final String DEBUGGER_PAGE_ELEMENT = "debuggerPage"; + //The shared instance. private static CDebugUIPlugin plugin; @@ -173,11 +176,16 @@ public class CDebugUIPlugin extends AbstractUIPlugin { protected void initializeDebuggerPageMap() { fDebuggerPageMap = new HashMap( 10 ); - IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint( PLUGIN_ID, "CDebuggerPage" ); //$NON-NLS-1$ + IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint( PLUGIN_ID, CDEBUGGER_PAGE_EXTENSION_POINT_ID ); //$NON-NLS-1$ IConfigurationElement[] infos = extensionPoint.getConfigurationElements(); for( int i = 0; i < infos.length; i++ ) { - String id = infos[i].getAttribute( "debuggerID" ); //$NON-NLS-1$ - fDebuggerPageMap.put( id, infos[i] ); + IConfigurationElement info = infos[i]; + if (info.getName().equals(DEBUGGER_PAGE_ELEMENT)) { + String id = info.getAttribute( "debuggerID" ); //$NON-NLS-1$ + if (id != null) { + fDebuggerPageMap.put( id, info ); + } + } } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpointactions/ActionDialog.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpointactions/ActionDialog.java index 5e78d2f2fd5..c0e7310c854 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpointactions/ActionDialog.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpointactions/ActionDialog.java @@ -1,276 +1,286 @@ -/******************************************************************************* - * Copyright (c) 2007 Nokia 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: - * Nokia - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.debug.ui.breakpointactions; - -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.breakpointactions.IBreakpointAction; -import org.eclipse.cdt.debug.ui.CDebugUIPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StackLayout; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -public class ActionDialog extends Dialog { - - public static final String BREAKPOINT_ACTION_PAGE_SIMPLE_ID = "breakpointActionPage"; //$NON-NLS-1$ - - private static final String ACTION_DIALOG_LAST_SELECTED = "ActionDialog.lastSelectedAction"; //$NON-NLS-1$ - - private Composite actionArea; - private Composite[] actionComposites; - private IBreakpointAction breakpointAction; - private IBreakpointActionPage actionPage; - private IBreakpointAction[] breakpointActions; - private IBreakpointActionPage[] actionPages; - private String actionName; - private Text actionNameTextWidget; - private Combo combo; - private Composite dialogArea; - private int lastSelectedActionTypeIndex; - private IBreakpointAction originalAction; - - private IExtension[] breakpointActionPageExtensions; - - /** - * Create the dialog - * - * @param parentShell - */ - public ActionDialog(Shell parentShell, IBreakpointAction action) { - super(parentShell); - setShellStyle(getShellStyle() | SWT.MAX | SWT.RESIZE); - this.originalAction = action; - this.breakpointAction = action; - lastSelectedActionTypeIndex = 0; - } - - protected void cancelPressed() { - actionPage.actionDialogCanceled(); - super.cancelPressed(); - } - - protected void configureShell(Shell newShell) { - super.configureShell(newShell); - if (originalAction == null) - newShell.setText(Messages.getString("ActionDialog.0")); //$NON-NLS-1$ - else - newShell.setText(originalAction.getName()); - } - - /** - * Create contents of the button bar - * - * @param parent - */ - protected void createButtonsForButtonBar(Composite parent) { - createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); - createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); - } - - /** - * Create contents of the dialog - * - * @param parent - */ - protected Control createDialogArea(Composite parent) { - dialogArea = (Composite) super.createDialogArea(parent); - final GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - dialogArea.setLayout(gridLayout); - - final Label actionNameLabel = new Label(dialogArea, SWT.NONE); - actionNameLabel.setText(Messages.getString("ActionDialog.1")); //$NON-NLS-1$ - - actionNameTextWidget = new Text(dialogArea, SWT.BORDER); - actionNameTextWidget.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - - final Label breakpointActionTypeLabel = new Label(dialogArea, SWT.NONE); - breakpointActionTypeLabel.setText(Messages.getString("ActionDialog.2")); //$NON-NLS-1$ - - combo = new Combo(dialogArea, SWT.READ_ONLY); - combo.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - try { - showActionComposite(); - } catch (CoreException e1) { - } - } - }); - combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - // - - IExtension[] actionExtensions = CDebugCorePlugin.getDefault().getBreakpointActionManager().getBreakpointActionExtensions(); - - breakpointActions = new IBreakpointAction[actionExtensions.length]; - actionPages = new IBreakpointActionPage[actionExtensions.length]; - actionComposites = new Composite[actionExtensions.length]; - - if (actionExtensions.length > 0) { - - String lastTypeName = CDebugUIPlugin.getDefault().getPreferenceStore().getString(ACTION_DIALOG_LAST_SELECTED); - - if (breakpointAction != null) { - lastTypeName = breakpointAction.getTypeName(); - actionName = breakpointAction.getName(); - } - - for (int i = 0; i < actionExtensions.length; i++) { - IConfigurationElement[] elements = actionExtensions[i].getConfigurationElements(); - for (int j = 0; j < elements.length; j++) { - String actionTypeName = elements[j].getAttribute("name"); //$NON-NLS-1$ - combo.add(actionTypeName); - if (actionTypeName.equals(lastTypeName)) - lastSelectedActionTypeIndex = i; - } - } - - combo.select(lastSelectedActionTypeIndex); - if (originalAction != null) - combo.setEnabled(false); - - breakpointActions[combo.getSelectionIndex()] = breakpointAction; - - actionArea = new Composite(dialogArea, SWT.NONE); - actionArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); - actionArea.setLayout(new StackLayout()); - try { - showActionComposite(); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - return dialogArea; - } - - public IBreakpointAction getBreakpointAction() { - return breakpointAction; - } - - public String getActionName() { - return actionName; - } - - /** - * Return the initial size of the dialog - */ - protected Point getInitialSize() { - return new Point(500, 375); - } - - protected void okPressed() { - if (originalAction == null) - CDebugUIPlugin.getDefault().getPreferenceStore().setValue(ACTION_DIALOG_LAST_SELECTED, breakpointAction.getTypeName()); - String newName = actionNameTextWidget.getText(); - if (originalAction == null || !originalAction.getName().equals(newName)) { - actionName = CDebugCorePlugin.getDefault().getBreakpointActionManager().makeUniqueActionName(newName); - breakpointAction.setName(actionName); - } - actionPage.actionDialogOK(); - super.okPressed(); - } - - void showActionComposite() throws CoreException { - // Find the selected extension - int selectedTypeIndex = combo.getSelectionIndex(); - lastSelectedActionTypeIndex = selectedTypeIndex; - breakpointAction = breakpointActions[selectedTypeIndex]; - if (breakpointAction == null) { - int elementCount = 0; - IConfigurationElement selectedElement = null; - - IExtension[] actionExtensions = CDebugCorePlugin.getDefault().getBreakpointActionManager().getBreakpointActionExtensions(); - - for (int i = 0; i < actionExtensions.length && selectedElement == null; i++) { - IConfigurationElement[] elements = actionExtensions[i].getConfigurationElements(); - for (int j = 0; j < elements.length && selectedElement == null; j++) { - if (elementCount == selectedTypeIndex) - selectedElement = elements[j]; - elementCount++; - } - } - - breakpointAction = (IBreakpointAction) selectedElement.createExecutableExtension("class"); //$NON-NLS-1$ - breakpointAction.setName(breakpointAction.getDefaultName()); - breakpointActions[selectedTypeIndex] = breakpointAction; - } - actionPage = actionPages[selectedTypeIndex]; - if (actionPage == null) { - actionPages[selectedTypeIndex] = getActionPage(breakpointActions[selectedTypeIndex]); - actionPage = actionPages[selectedTypeIndex]; - } - if (actionComposites[selectedTypeIndex] == null) { - Composite actionComposite = actionPages[selectedTypeIndex].createComposite(breakpointAction, actionArea, SWT.NONE); - actionComposites[selectedTypeIndex] = actionComposite; - } - actionName = breakpointAction.getName(); - - actionNameTextWidget.setText(actionName); - StackLayout stacklayout = (StackLayout) actionArea.getLayout(); - stacklayout.topControl = actionComposites[selectedTypeIndex]; - actionArea.layout(); - } - - public IExtension[] getBreakpointActionPageExtensions() { - if (breakpointActionPageExtensions == null) { - IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CDebugUIPlugin.PLUGIN_ID, BREAKPOINT_ACTION_PAGE_SIMPLE_ID); - if (point == null) - breakpointActionPageExtensions = new IExtension[0]; - else { - breakpointActionPageExtensions = point.getExtensions(); - } - } - - return breakpointActionPageExtensions; - } - - private IBreakpointActionPage getActionPage(IBreakpointAction breakpointAction) { - IExtension[] actionExtensions = getBreakpointActionPageExtensions(); - - IBreakpointActionPage actionPageResult = null; - try { - - for (int i = 0; i < actionExtensions.length && actionPageResult == null; i++) { - IConfigurationElement[] elements = actionExtensions[i].getConfigurationElements(); - for (int j = 0; j < elements.length && actionPageResult == null; j++) { - - if (elements[j].getAttribute("actionType").equals(breakpointAction.getIdentifier())) { //$NON-NLS-1$ - actionPageResult = (IBreakpointActionPage) elements[j].createExecutableExtension("class"); //$NON-NLS-1$ - } - } - } - - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return actionPageResult; - } - -} +/******************************************************************************* + * Copyright (c) 2007 Nokia 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: + * Nokia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.debug.ui.breakpointactions; + +import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.cdt.debug.core.breakpointactions.IBreakpointAction; +import org.eclipse.cdt.debug.ui.CDebugUIPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +public class ActionDialog extends Dialog { + + public static final String BREAKPOINT_ACTION_PAGE_EXTENSION_POINT_ID = "BreakpointActionPage"; //$NON-NLS-1$ + + public static final String ACTION_PAGE_ELEMENT = "actionPage"; //$NON-NLS-1$ + + private static final String ACTION_DIALOG_LAST_SELECTED = "ActionDialog.lastSelectedAction"; //$NON-NLS-1$ + + private Composite actionArea; + private Composite[] actionComposites; + private IBreakpointAction breakpointAction; + private IBreakpointActionPage actionPage; + private IBreakpointAction[] breakpointActions; + private IBreakpointActionPage[] actionPages; + private String actionName; + private Text actionNameTextWidget; + private Combo combo; + private Composite dialogArea; + private int lastSelectedActionTypeIndex; + private IBreakpointAction originalAction; + + private IExtension[] breakpointActionPageExtensions; + + /** + * Create the dialog + * + * @param parentShell + */ + public ActionDialog(Shell parentShell, IBreakpointAction action) { + super(parentShell); + setShellStyle(getShellStyle() | SWT.MAX | SWT.RESIZE); + this.originalAction = action; + this.breakpointAction = action; + lastSelectedActionTypeIndex = 0; + } + + protected void cancelPressed() { + actionPage.actionDialogCanceled(); + super.cancelPressed(); + } + + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + if (originalAction == null) + newShell.setText(Messages.getString("ActionDialog.0")); //$NON-NLS-1$ + else + newShell.setText(originalAction.getName()); + } + + /** + * Create contents of the button bar + * + * @param parent + */ + protected void createButtonsForButtonBar(Composite parent) { + createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); + createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); + } + + /** + * Create contents of the dialog + * + * @param parent + */ + protected Control createDialogArea(Composite parent) { + dialogArea = (Composite) super.createDialogArea(parent); + final GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 2; + dialogArea.setLayout(gridLayout); + + final Label actionNameLabel = new Label(dialogArea, SWT.NONE); + actionNameLabel.setText(Messages.getString("ActionDialog.1")); //$NON-NLS-1$ + + actionNameTextWidget = new Text(dialogArea, SWT.BORDER); + actionNameTextWidget.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + final Label breakpointActionTypeLabel = new Label(dialogArea, SWT.NONE); + breakpointActionTypeLabel.setText(Messages.getString("ActionDialog.2")); //$NON-NLS-1$ + + combo = new Combo(dialogArea, SWT.READ_ONLY); + combo.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent e) { + try { + showActionComposite(); + } catch (CoreException e1) { + } + } + }); + combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + // + + IExtension[] actionExtensions = CDebugCorePlugin.getDefault().getBreakpointActionManager().getBreakpointActionExtensions(); + + breakpointActions = new IBreakpointAction[actionExtensions.length]; + actionPages = new IBreakpointActionPage[actionExtensions.length]; + actionComposites = new Composite[actionExtensions.length]; + + if (actionExtensions.length > 0) { + + String lastTypeName = CDebugUIPlugin.getDefault().getPreferenceStore().getString(ACTION_DIALOG_LAST_SELECTED); + + if (breakpointAction != null) { + lastTypeName = breakpointAction.getTypeName(); + actionName = breakpointAction.getName(); + } + + for (int i = 0; i < actionExtensions.length; i++) { + IConfigurationElement[] elements = actionExtensions[i].getConfigurationElements(); + for (int j = 0; j < elements.length; j++) { + IConfigurationElement element = elements[j]; + if (element.getName().equals(CDebugCorePlugin.ACTION_TYPE_ELEMENT)) { + String actionTypeName = element.getAttribute("name"); //$NON-NLS-1$ + combo.add(actionTypeName); + if (actionTypeName.equals(lastTypeName)) + lastSelectedActionTypeIndex = i; + } + } + } + + combo.select(lastSelectedActionTypeIndex); + if (originalAction != null) + combo.setEnabled(false); + + breakpointActions[combo.getSelectionIndex()] = breakpointAction; + + actionArea = new Composite(dialogArea, SWT.NONE); + actionArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); + actionArea.setLayout(new StackLayout()); + try { + showActionComposite(); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + return dialogArea; + } + + public IBreakpointAction getBreakpointAction() { + return breakpointAction; + } + + public String getActionName() { + return actionName; + } + + /** + * Return the initial size of the dialog + */ + protected Point getInitialSize() { + return new Point(500, 375); + } + + protected void okPressed() { + if (originalAction == null) + CDebugUIPlugin.getDefault().getPreferenceStore().setValue(ACTION_DIALOG_LAST_SELECTED, breakpointAction.getTypeName()); + String newName = actionNameTextWidget.getText(); + if (originalAction == null || !originalAction.getName().equals(newName)) { + actionName = CDebugCorePlugin.getDefault().getBreakpointActionManager().makeUniqueActionName(newName); + breakpointAction.setName(actionName); + } + actionPage.actionDialogOK(); + super.okPressed(); + } + + void showActionComposite() throws CoreException { + // Find the selected extension + int selectedTypeIndex = combo.getSelectionIndex(); + lastSelectedActionTypeIndex = selectedTypeIndex; + breakpointAction = breakpointActions[selectedTypeIndex]; + if (breakpointAction == null) { + int elementCount = 0; + IConfigurationElement selectedElement = null; + + IExtension[] actionExtensions = CDebugCorePlugin.getDefault().getBreakpointActionManager().getBreakpointActionExtensions(); + + for (int i = 0; i < actionExtensions.length && selectedElement == null; i++) { + IConfigurationElement[] elements = actionExtensions[i].getConfigurationElements(); + for (int j = 0; j < elements.length && selectedElement == null; j++) { + IConfigurationElement element = elements[j]; + if (element.getName().equals(CDebugCorePlugin.ACTION_TYPE_ELEMENT)) { + if (elementCount == selectedTypeIndex) + selectedElement = element; + elementCount++; + } + } + } + + breakpointAction = (IBreakpointAction) selectedElement.createExecutableExtension("class"); //$NON-NLS-1$ + breakpointAction.setName(breakpointAction.getDefaultName()); + breakpointActions[selectedTypeIndex] = breakpointAction; + } + actionPage = actionPages[selectedTypeIndex]; + if (actionPage == null) { + actionPages[selectedTypeIndex] = getActionPage(breakpointActions[selectedTypeIndex]); + actionPage = actionPages[selectedTypeIndex]; + } + if (actionComposites[selectedTypeIndex] == null) { + Composite actionComposite = actionPages[selectedTypeIndex].createComposite(breakpointAction, actionArea, SWT.NONE); + actionComposites[selectedTypeIndex] = actionComposite; + } + actionName = breakpointAction.getName(); + + actionNameTextWidget.setText(actionName); + StackLayout stacklayout = (StackLayout) actionArea.getLayout(); + stacklayout.topControl = actionComposites[selectedTypeIndex]; + actionArea.layout(); + } + + public IExtension[] getBreakpointActionPageExtensions() { + if (breakpointActionPageExtensions == null) { + IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CDebugUIPlugin.PLUGIN_ID, BREAKPOINT_ACTION_PAGE_EXTENSION_POINT_ID); + if (point == null) + breakpointActionPageExtensions = new IExtension[0]; + else { + breakpointActionPageExtensions = point.getExtensions(); + } + } + + return breakpointActionPageExtensions; + } + + private IBreakpointActionPage getActionPage(IBreakpointAction breakpointAction) { + IExtension[] actionExtensions = getBreakpointActionPageExtensions(); + + IBreakpointActionPage actionPageResult = null; + try { + + for (int i = 0; i < actionExtensions.length && actionPageResult == null; i++) { + IConfigurationElement[] elements = actionExtensions[i].getConfigurationElements(); + for (int j = 0; j < elements.length && actionPageResult == null; j++) { + IConfigurationElement element = elements[j]; + if (element.getName().equals(ACTION_PAGE_ELEMENT)) { + if (element.getAttribute("actionType").equals(breakpointAction.getIdentifier())) { //$NON-NLS-1$ + actionPageResult = (IBreakpointActionPage) element.createExecutableExtension("class"); //$NON-NLS-1$ + } + } + } + } + + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return actionPageResult; + } + +}