diff --git a/plugins/generate-tostring/generate-tostring.iml b/plugins/generate-tostring/generate-tostring.iml
index 1a5701c2a8c2..e8e22247a171 100644
--- a/plugins/generate-tostring/generate-tostring.iml
+++ b/plugins/generate-tostring/generate-tostring.iml
@@ -14,6 +14,7 @@
+
diff --git a/plugins/generate-tostring/src/org/jetbrains/generate/tostring/GenerateToStringActionHandler.java b/plugins/generate-tostring/src/org/jetbrains/generate/tostring/GenerateToStringActionHandler.java
index c349724e6a16..2e15736ccdee 100644
--- a/plugins/generate-tostring/src/org/jetbrains/generate/tostring/GenerateToStringActionHandler.java
+++ b/plugins/generate-tostring/src/org/jetbrains/generate/tostring/GenerateToStringActionHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2007 the original author or authors.
+ * Copyright 2001-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,8 +15,6 @@
*/
package org.jetbrains.generate.tostring;
-import com.intellij.openapi.actionSystem.DataContext;
-import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
@@ -28,22 +26,11 @@ import com.intellij.psi.PsiClass;
public interface GenerateToStringActionHandler {
/**
- * The action that does the actual generation of the code.
- *
- * This is called automatically by IDEA when user invokes the plugin from the generate menu.
- *
- * @param editor the current editor.
- * @param dataContext the current data context.
- */
- void executeWriteAction(Editor editor, DataContext dataContext);
-
-
- /**
* Action to be executed from quick fix.
*
* @param project the current project.
* @param clazz the class.
*/
- void executeActionQickFix(Project project, PsiClass clazz);
+ void executeActionQuickFix(Project project, PsiClass clazz);
}
diff --git a/plugins/generate-tostring/src/org/jetbrains/generate/tostring/GenerateToStringActionHandlerImpl.java b/plugins/generate-tostring/src/org/jetbrains/generate/tostring/GenerateToStringActionHandlerImpl.java
index 58819249bdc8..0f7541163689 100644
--- a/plugins/generate-tostring/src/org/jetbrains/generate/tostring/GenerateToStringActionHandlerImpl.java
+++ b/plugins/generate-tostring/src/org/jetbrains/generate/tostring/GenerateToStringActionHandlerImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2007 the original author or authors.
+ * Copyright 2001-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,8 +40,6 @@ import com.intellij.psi.util.PsiUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.generate.tostring.config.Config;
-import org.jetbrains.generate.tostring.psi.PsiAdapter;
-import org.jetbrains.generate.tostring.psi.PsiAdapterFactory;
import org.jetbrains.generate.tostring.template.TemplateResource;
import org.jetbrains.generate.tostring.template.TemplatesManager;
import org.jetbrains.generate.tostring.view.TemplatesPanel;
@@ -72,7 +70,7 @@ public class GenerateToStringActionHandlerImpl extends EditorWriteActionHandler
}
- public void executeActionQickFix(final Project project, final PsiClass clazz) {
+ public void executeActionQuickFix(final Project project, final PsiClass clazz) {
doExecuteAction(project, clazz, null);
}
@@ -218,7 +216,7 @@ public class GenerateToStringActionHandlerImpl extends EditorWriteActionHandler
Configurable composite = new TabbedConfigurable(disposable) {
protected List createConfigurables() {
List res = new ArrayList();
- res.add(new GenerateToStringConfigurable());
+ res.add(new GenerateToStringConfigurable(clazz.getProject()));
res.add(ui);
return res;
}
@@ -227,7 +225,7 @@ public class GenerateToStringActionHandlerImpl extends EditorWriteActionHandler
return "toString() Generation Settings";
}
- public String getHelpTopic() {
+ public String getHelpTopic() {
return null; // TODO:
}
diff --git a/plugins/generate-tostring/src/org/jetbrains/generate/tostring/GenerateToStringConfigurable.java b/plugins/generate-tostring/src/org/jetbrains/generate/tostring/GenerateToStringConfigurable.java
index 797dda99a641..bee539235d1f 100644
--- a/plugins/generate-tostring/src/org/jetbrains/generate/tostring/GenerateToStringConfigurable.java
+++ b/plugins/generate-tostring/src/org/jetbrains/generate/tostring/GenerateToStringConfigurable.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.jetbrains.generate.tostring;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
+import com.intellij.openapi.project.Project;
import org.jetbrains.generate.tostring.config.Config;
import org.jetbrains.generate.tostring.view.ConfigUI;
@@ -30,6 +31,11 @@ public class GenerateToStringConfigurable implements Configurable {
private static final Logger log = Logger.getInstance("#org.jetbrains.generate.tostring.GenerateToStringConfigurable");
private ConfigUI configUI;
+ private final Project myProject;
+
+ public GenerateToStringConfigurable(Project project) {
+ myProject = project;
+ }
public String getDisplayName() {
return "Settings";
@@ -40,7 +46,7 @@ public class GenerateToStringConfigurable implements Configurable {
}
public JComponent createComponent() {
- return configUI = new ConfigUI(GenerateToStringContext.getConfig());
+ return configUI = new ConfigUI(GenerateToStringContext.getConfig(), myProject);
}
public boolean isModified() {
@@ -49,7 +55,6 @@ public class GenerateToStringConfigurable implements Configurable {
public void apply() throws ConfigurationException {
Config config = configUI.getConfig();
-
GenerateToStringContext.setConfig(config); // update context
if (log.isDebugEnabled()) log.debug("Config updated:\n" + config);
@@ -62,6 +67,4 @@ public class GenerateToStringConfigurable implements Configurable {
public void disposeUIResources() {
configUI = null;
}
-
-
}
diff --git a/plugins/generate-tostring/src/org/jetbrains/generate/tostring/config/Config.java b/plugins/generate-tostring/src/org/jetbrains/generate/tostring/config/Config.java
index 8d11c87f357b..57b9cd1e9321 100644
--- a/plugins/generate-tostring/src/org/jetbrains/generate/tostring/config/Config.java
+++ b/plugins/generate-tostring/src/org/jetbrains/generate/tostring/config/Config.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2007 the original author or authors.
+ * Copyright 2001-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -89,6 +89,9 @@ public class Config {
}
public String getFilterFieldName() {
+ if (filterFieldName == null) {
+ return "";
+ }
return filterFieldName;
}
@@ -113,6 +116,9 @@ public class Config {
}
public String getFilterMethodName() {
+ if (filterMethodName == null) {
+ return "";
+ }
return filterMethodName;
}
@@ -145,6 +151,9 @@ public class Config {
}
public String getFilterFieldType() {
+ if (filterFieldType == null) {
+ return "";
+ }
return filterFieldType;
}
@@ -161,6 +170,9 @@ public class Config {
}
public String getFilterMethodType() {
+ if (filterMethodType == null) {
+ return "";
+ }
return filterMethodType;
}
@@ -169,7 +181,7 @@ public class Config {
}
/**
- * Get's the filter pattern that this configuration represent.
+ * Gets the filter pattern that this configuration represent.
*
* @return the filter pattern.
*/
diff --git a/plugins/generate-tostring/src/org/jetbrains/generate/tostring/view/ConfigUI.java b/plugins/generate-tostring/src/org/jetbrains/generate/tostring/view/ConfigUI.java
index e66f402d60d7..208b50f6988d 100644
--- a/plugins/generate-tostring/src/org/jetbrains/generate/tostring/view/ConfigUI.java
+++ b/plugins/generate-tostring/src/org/jetbrains/generate/tostring/view/ConfigUI.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2007 the original author or authors.
+ * Copyright 2001-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,11 +15,14 @@
*/
package org.jetbrains.generate.tostring.view;
+import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.ui.IdeBorderFactory;
+import com.intellij.ui.LanguageTextField;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.ParseErrorException;
+import org.intellij.lang.regexp.RegExpLanguage;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.generate.tostring.config.Config;
import org.jetbrains.generate.tostring.config.DuplicatonPolicy;
@@ -30,8 +33,6 @@ import org.jetbrains.generate.tostring.template.TemplateResource;
import org.jetbrains.generate.tostring.velocity.VelocityFactory;
import javax.swing.*;
-import javax.swing.border.Border;
-import javax.swing.border.EtchedBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -43,36 +44,38 @@ import java.io.StringWriter;
* The configuration is in the menu File - Settings - GenerateToString
*/
public class ConfigUI extends JPanel {
- private final Border etched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
- private final JCheckBox fullyQualifiedName = new JCheckBox("Use fully qualified classname in code generation ($classname)");
+ private final JCheckBox fullyQualifiedName = new JCheckBox("Use fully qualified class name in code generation ($classname)");
private final JCheckBox enableMethods = new JCheckBox("Enable getters in code generation ($methods)");
private final JCheckBox moveCaretToMethod = new JCheckBox("Move caret to generated method");
private JRadioButton[] initialValueForReplaceDialog;
private JRadioButton[] initialValueForNewMethodDialog;
- private final JCheckBox filterConstant = new JCheckBox("Exclude all constant fields");
- private final JCheckBox filterEnum = new JCheckBox("Exclude all enum fields");
- private final JCheckBox filterStatic = new JCheckBox("Exclude all static fields");
- private final JCheckBox filterTransient = new JCheckBox("Exclude all transient fields");
- private final JCheckBox filterLoggers = new JCheckBox("Exclude all logger fields (Log4j, JDK Logging, Jakarta Commons Logging)");
- private final JTextField filterFieldName = new JTextField();
- private final JTextField filterFieldType = new JTextField();
- private final JTextField filterMethodName = new JTextField();
- private final JTextField filterMethodType = new JTextField();
+ private final JCheckBox filterConstant = new JCheckBox("Exclude constant fields");
+ private final JCheckBox filterEnum = new JCheckBox("Exclude enum fields");
+ private final JCheckBox filterStatic = new JCheckBox("Exclude static fields");
+ private final JCheckBox filterTransient = new JCheckBox("Exclude transient fields");
+ private final JCheckBox filterLoggers = new JCheckBox("Exclude logger fields (Log4j, JDK Logging, Jakarta Commons Logging)");
+ private final LanguageTextField filterFieldName;
+ private final LanguageTextField filterFieldType;
+ private final LanguageTextField filterMethodName;
+ private final LanguageTextField filterMethodType;
private final JComboBox sortElementsComboBox = new JComboBox();
private final JCheckBox sortElements = new JCheckBox("Sort elements");
- private final JCheckBox autoAddImplementsSerializable = new JCheckBox("Automatic add implements java.io.Serializable");
-
/**
* Constructor.
*
* @param config Configuration for this UI to display.
+ * @param project
*/
- public ConfigUI(Config config) {
+ public ConfigUI(Config config, Project project) {
super(new BorderLayout());
+ filterFieldName = new LanguageTextField(RegExpLanguage.INSTANCE, project, config.getFilterFieldName());
+ filterFieldType = new LanguageTextField(RegExpLanguage.INSTANCE, project, config.getFilterFieldType());
+ filterMethodName = new LanguageTextField(RegExpLanguage.INSTANCE, project, config.getFilterMethodName());
+ filterMethodType = new LanguageTextField(RegExpLanguage.INSTANCE, project, config.getFilterMethodType());
init();
setConfig(config);
}
@@ -95,8 +98,7 @@ public class ConfigUI extends JPanel {
*/
private JPanel initSettingPanel() {
GridBagConstraints constraint = new GridBagConstraints();
- JPanel outer = new JPanel();
- outer.setLayout(new GridBagLayout());
+ JPanel outer = new JPanel(new GridBagLayout());
// UI Layout - Settings
JPanel panel = new JPanel();
@@ -126,6 +128,8 @@ public class ConfigUI extends JPanel {
constraint.fill = GridBagConstraints.BOTH;
constraint.gridx = 0;
constraint.gridy = 0;
+ constraint.insets.left = 5;
+ constraint.insets.right = 5;
outer.add(panel, constraint);
// UI Layout - Conflict Resolution
@@ -195,7 +199,7 @@ public class ConfigUI extends JPanel {
filterFieldName.setMinimumSize(new Dimension(100, 20)); // avoid input field to small
panel.add(innerPanel);
innerPanel = Box.createHorizontalBox();
- innerPanel.add(new JLabel("Exclude fields by typename (reg exp)"));
+ innerPanel.add(new JLabel("Exclude fields by type name (reg exp)"));
innerPanel.add(Box.createHorizontalStrut(3));
innerPanel.add(filterFieldType);
filterFieldType.setMinimumSize(new Dimension(100, 20)); // avoid input field to small
@@ -207,7 +211,7 @@ public class ConfigUI extends JPanel {
filterMethodName.setMinimumSize(new Dimension(100, 20)); // avoid input field to small
panel.add(innerPanel);
innerPanel = Box.createHorizontalBox();
- innerPanel.add(new JLabel("Exclude methods by return typename (reg exp)"));
+ innerPanel.add(new JLabel("Exclude methods by return type name (reg exp)"));
innerPanel.add(Box.createHorizontalStrut(3));
innerPanel.add(filterMethodType);
filterMethodType.setMinimumSize(new Dimension(100, 20)); // avoid input field to small
@@ -245,12 +249,7 @@ public class ConfigUI extends JPanel {
filterStatic.setSelected(config.isFilterStaticModifier());
filterTransient.setSelected(config.isFilterTransientModifier());
filterLoggers.setSelected(config.isFilterLoggers());
- filterFieldName.setText(config.getFilterFieldName());
- filterFieldType.setText(config.getFilterFieldType());
- filterMethodName.setText(config.getFilterMethodName());
- filterMethodType.setText(config.getFilterMethodType());
- autoAddImplementsSerializable.setSelected(config.isAddImplementSerializable());
enableMethods.setSelected(config.isEnableMethods());
moveCaretToMethod.setSelected(config.isJumpToMethod());
@@ -301,7 +300,6 @@ public class ConfigUI extends JPanel {
config.setFilterMethodName(emptyToNull(filterMethodName.getText()));
config.setFilterMethodType(emptyToNull(filterMethodType.getText()));
- config.setAddImplementSerializable(autoAddImplementsSerializable.isSelected());
config.setEnableMethods(enableMethods.isSelected());
config.setJumpToMethod(moveCaretToMethod.isSelected());
@@ -355,39 +353,4 @@ public class ConfigUI extends JPanel {
sortElementsComboBox.setEnabled(sortElements.isSelected());
}
}
-
- /**
- * Action listener for user clicking syntax check
- */
- private class OnSyntaxCheck implements ActionListener {
- private final JTextArea methodBody = new JTextArea();
- public void actionPerformed(ActionEvent event) {
-
- // validate template first
- if (!TemplateResource.isValidTemplate(methodBody.getText())) {
- Messages.showWarningDialog("The template is incompatible with this version of the plugin.", "Incompatible Template");
- return;
- }
-
- // okay let veloicty do it's syntax check
- try {
- StringWriter sw = new StringWriter();
- VelocityContext vc = new VelocityContext();
-
- // velocity
- VelocityEngine velocity = VelocityFactory.getVelocityEngine();
- velocity.evaluate(vc, sw, "org.intellij.idea.plugin.tostring.view.ConfigUI$OnSyntaxCheck", methodBody.getText());
-
- // no errors
- Messages.showMessageDialog("Syntax check complete - no errors found", "Syntax Check", Messages.getInformationIcon());
-
- } catch (ParseErrorException e) {
- // Syntax Error - display to user
- Messages.showMessageDialog("Syntax Error:\n" + e.getMessage(), "Syntax Error", Messages.getErrorIcon());
- } catch (Exception e) {
- throw new PluginException("Error syntax checking template", e);
- }
- }
- }
-
}