java-xbreakpoints: support suspend policy defaults

This commit is contained in:
Egor.Ushakov
2014-02-27 20:54:53 +04:00
parent d3a084dd9b
commit 299183575d
5 changed files with 65 additions and 47 deletions
@@ -562,7 +562,7 @@ public abstract class Breakpoint<P extends JavaBreakpointProperties> implements
}
}
private static SuspendPolicy transformSuspendPolicy(String policy) {
static SuspendPolicy transformSuspendPolicy(String policy) {
if (DebuggerSettings.SUSPEND_ALL.equals(policy)) {
return SuspendPolicy.ALL;
} else if (DebuggerSettings.SUSPEND_THREAD.equals(policy)) {
@@ -54,6 +54,7 @@ import com.intellij.xdebugger.XDebuggerUtil;
import com.intellij.xdebugger.breakpoints.*;
import com.intellij.xdebugger.impl.DebuggerSupport;
import com.intellij.xdebugger.impl.XDebugSessionImpl;
import com.intellij.xdebugger.impl.breakpoints.BreakpointState;
import com.intellij.xdebugger.impl.breakpoints.XBreakpointManagerImpl;
import com.intellij.xdebugger.impl.breakpoints.XDependentBreakpointManager;
import com.sun.jdi.InternalException;
@@ -85,7 +86,7 @@ public class BreakpointManager {
private final Map<XBreakpoint, Breakpoint> myBreakpoints = new HashMap<XBreakpoint, Breakpoint>(); // breakpoints storage, access should be synchronized
@Nullable private List<Breakpoint> myBreakpointsListForIteration = null; // another list for breakpoints iteration, unsynchronized access ok
private final Map<String, String> myUIProperties = new LinkedHashMap<String, String>();
private final Map<Key<? extends Breakpoint>, BreakpointDefaults> myBreakpointDefaults = new LinkedHashMap<Key<? extends Breakpoint>, BreakpointDefaults>();
//private final Map<Key<? extends Breakpoint>, BreakpointDefaults> myBreakpointDefaults = new LinkedHashMap<Key<? extends Breakpoint>, BreakpointDefaults>();
private final EventDispatcher<BreakpointManagerListener> myDispatcher = EventDispatcher.create(BreakpointManagerListener.class);
@@ -190,17 +191,34 @@ public class BreakpointManager {
});
}
@NotNull
public BreakpointDefaults getBreakpointDefaults(Key<? extends Breakpoint> category) {
BreakpointDefaults defaults = myBreakpointDefaults.get(category);
if (defaults == null) {
defaults = new BreakpointDefaults();
}
return defaults;
}
//@NotNull
//public BreakpointDefaults getBreakpointDefaults(Key<? extends Breakpoint> category) {
// BreakpointDefaults defaults = myBreakpointDefaults.get(category);
// if (defaults == null) {
// defaults = new BreakpointDefaults();
// }
// return defaults;
//}
public void setBreakpointDefaults(Key<? extends Breakpoint> category, BreakpointDefaults defaults) {
myBreakpointDefaults.put(category, defaults);
Class typeCls = null;
if (LineBreakpoint.CATEGORY.toString().equals(category.toString())) {
typeCls = JavaLineBreakpointType.class;
}
else if (MethodBreakpoint.CATEGORY.toString().equals(category.toString())) {
typeCls = JavaMethodBreakpointType.class;
}
else if (FieldBreakpoint.CATEGORY.toString().equals(category.toString())) {
typeCls = JavaFieldBreakpointType.class;
}
else if (ExceptionBreakpoint.CATEGORY.toString().equals(category.toString())) {
typeCls = JavaExceptionBreakpointType.class;
}
if (typeCls != null) {
XBreakpointType<XBreakpoint<?>, ?> type = XDebuggerUtil.getInstance().findBreakpointType(typeCls);
BreakpointState.setDefaultSuspendPolicy(type.getId(), Breakpoint.transformSuspendPolicy(defaults.getSuspendPolicy()));
}
//myBreakpointDefaults.put(category, defaults);
}
@@ -421,6 +439,10 @@ public class BreakpointManager {
if (group.getName().equals(RULES_GROUP_NAME)) {
continue;
}
// skip already converted
if (group.getAttribute(CONVERTED_PARAM) != null) {
continue;
}
final String categoryName = group.getName();
final Key<Breakpoint> breakpointCategory = BreakpointCategory.lookup(categoryName);
final String defaultPolicy = group.getAttributeValue(DEFAULT_SUSPEND_POLICY_ATTRIBUTE_NAME);
@@ -433,10 +455,6 @@ public class BreakpointManager {
//final BreakpointFactory factory = BreakpointFactory.getInstance(breakpointCategory);
//if (factory != null) {
for (Element breakpointNode : group.getChildren("breakpoint")) {
// skip already converted
if (breakpointNode.getAttribute(CONVERTED_PARAM) != null) {
continue;
}
//Breakpoint breakpoint = factory.createBreakpoint(myProject, breakpointNode);
Breakpoint breakpoint = createBreakpoint(categoryName, breakpointNode);
breakpoint.readExternal(breakpointNode);
@@ -624,20 +642,10 @@ public class BreakpointManager {
public void writeExternal(@NotNull final Element parentNode) {
// restore old breakpoints
for (Element group : myOriginalBreakpointsNodes) {
if (group.getAttribute(CONVERTED_PARAM) == null) {
group.setAttribute(CONVERTED_PARAM, "true");
}
group.detach();
for (Element breakpoint : group.getChildren("breakpoint")) {
if (breakpoint.getAttribute(CONVERTED_PARAM) == null) {
breakpoint.setAttribute(CONVERTED_PARAM, "true");
}
}
if (RULES_GROUP_NAME.equals(group.getName())) {
List<Element> rules = group.getChildren("rule");
for (Element rule : rules) {
if (rule.getAttribute(CONVERTED_PARAM) == null) {
rule.setAttribute(CONVERTED_PARAM, "true");
}
}
}
}
parentNode.addContent(myOriginalBreakpointsNodes);
@@ -211,8 +211,8 @@ public abstract class BreakpointPropertiesPanel {
final ItemListener suspendPolicyChangeListener = new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
final BreakpointDefaults defaults = getBreakpointManager(myProject).getBreakpointDefaults(breakpointCategory);
myMakeDefaultButton.setEnabled(!defaults.getSuspendPolicy().equals(getSelectedSuspendPolicy()) || defaults.isConditionEnabled() != myConditionCheckbox.isSelected());
//final BreakpointDefaults defaults = getBreakpointManager(myProject).getBreakpointDefaults(breakpointCategory);
//myMakeDefaultButton.setEnabled(!defaults.getSuspendPolicy().equals(getSelectedSuspendPolicy()) || defaults.isConditionEnabled() != myConditionCheckbox.isSelected());
}
};
@@ -429,13 +429,13 @@ public abstract class BreakpointPropertiesPanel {
}
private void updateSuspendPolicyRbFont() {
final String defPolicy = getBreakpointManager(myProject).getBreakpointDefaults(myBreakpointCategory).getSuspendPolicy();
//final String defPolicy = getBreakpointManager(myProject).getBreakpointDefaults(myBreakpointCategory).getSuspendPolicy();
final Font font = myRbSuspendAll.getFont().deriveFont(Font.PLAIN);
final Font boldFont = font.deriveFont(Font.BOLD);
myRbSuspendAll.setFont(DebuggerSettings.SUSPEND_ALL.equals(defPolicy)? boldFont : font);
myRbSuspendThread.setFont(DebuggerSettings.SUSPEND_THREAD.equals(defPolicy)? boldFont : font);
//myRbSuspendAll.setFont(DebuggerSettings.SUSPEND_ALL.equals(defPolicy)? boldFont : font);
//myRbSuspendThread.setFont(DebuggerSettings.SUSPEND_THREAD.equals(defPolicy)? boldFont : font);
}
protected ClassFilter createClassConditionFilter() {
@@ -15,6 +15,7 @@
*/
package com.intellij.xdebugger.impl.breakpoints;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.util.xmlb.annotations.Attribute;
import com.intellij.util.xmlb.annotations.Property;
import com.intellij.util.xmlb.annotations.Tag;
@@ -48,6 +49,7 @@ public class BreakpointState<B extends XBreakpoint<P>, P extends XBreakpointProp
myEnabled = enabled;
myTypeId = typeId;
myTimeStamp = timeStamp;
mySuspendPolicy = getDefaultSuspendPolicy(myTypeId); // apply default
}
@Attribute("enabled")
@@ -142,4 +144,17 @@ public class BreakpointState<B extends XBreakpoint<P>, P extends XBreakpointProp
public void setTimeStamp(long timeStamp) {
myTimeStamp = timeStamp;
}
public static SuspendPolicy getDefaultSuspendPolicy(String typeId) {
String defaultPolicy = PropertiesComponent.getInstance().getValue(getDefaultSuspendPolicyKey(typeId));
return defaultPolicy != null ? SuspendPolicy.valueOf(defaultPolicy) : SuspendPolicy.ALL;
}
public static void setDefaultSuspendPolicy(String typeId, SuspendPolicy suspendPolicy) {
PropertiesComponent.getInstance().setValue(getDefaultSuspendPolicyKey(typeId), suspendPolicy.name());
}
private static String getDefaultSuspendPolicyKey(String typeId) {
return "debugger.suspend.policy-" + typeId;
}
}
@@ -15,11 +15,11 @@
*/
package com.intellij.xdebugger.impl.breakpoints.ui;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.project.Project;
import com.intellij.xdebugger.breakpoints.SuspendPolicy;
import com.intellij.xdebugger.breakpoints.XBreakpoint;
import com.intellij.xdebugger.breakpoints.XBreakpointManager;
import com.intellij.xdebugger.impl.breakpoints.BreakpointState;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -72,7 +72,7 @@ public class XSuspendPolicyPanel<B extends XBreakpoint<?>> extends XBreakpointPr
mySuspendPolicyGroup.add(mySuspendAll);
mySuspendPolicyGroup.add(mySuspendThread);
updateSuspendPolicyFont(createSettingsKey());
updateSuspendPolicyFont();
ItemListener suspendPolicyChangeListener = new ItemListener() {
@Override
@@ -89,9 +89,8 @@ public class XSuspendPolicyPanel<B extends XBreakpoint<?>> extends XBreakpointPr
@Override
public void actionPerformed(ActionEvent e) {
SuspendPolicy suspendPolicy = getSelectedSuspendPolicy();
String settingsKey = createSettingsKey();
PropertiesComponent.getInstance().setValue(settingsKey, suspendPolicy.name());
updateSuspendPolicyFont(settingsKey);
BreakpointState.setDefaultSuspendPolicy(myBreakpointType.getId(), suspendPolicy);
updateSuspendPolicyFont();
if (SuspendPolicy.THREAD == suspendPolicy) {
mySuspendThread.requestFocus();
}
@@ -104,20 +103,16 @@ public class XSuspendPolicyPanel<B extends XBreakpoint<?>> extends XBreakpointPr
}
private void updateMakeDefaultEnableState() {
myMakeDefaultButton.setEnabled(!getSelectedSuspendPolicy().name().equalsIgnoreCase(PropertiesComponent.getInstance().getValue(createSettingsKey(), SuspendPolicy.ALL.name())));
myMakeDefaultButton.setEnabled(!getSelectedSuspendPolicy().equals(BreakpointState.getDefaultSuspendPolicy(myBreakpointType.getId())));
}
private String createSettingsKey() {
return "debugger.suspend.policy-" + myBreakpointType.getId();
}
private void updateSuspendPolicyFont(String settingsKey) {
String defaultPolicy = PropertiesComponent.getInstance().getValue(settingsKey, SuspendPolicy.ALL.name());
private void updateSuspendPolicyFont() {
SuspendPolicy defaultPolicy = BreakpointState.getDefaultSuspendPolicy(myBreakpointType.getId());
Font font = mySuspendAll.getFont().deriveFont(Font.PLAIN);
Font boldFont = font.deriveFont(Font.BOLD);
mySuspendAll.setFont(SuspendPolicy.ALL.name().equalsIgnoreCase(defaultPolicy) ? boldFont : font);
mySuspendThread.setFont(SuspendPolicy.THREAD.name().equalsIgnoreCase(defaultPolicy) ? boldFont : font);
mySuspendAll.setFont(SuspendPolicy.ALL.equals(defaultPolicy) ? boldFont : font);
mySuspendThread.setFont(SuspendPolicy.THREAD.equals(defaultPolicy) ? boldFont : font);
}
private void changeEnableState(boolean selected) {