summaryrefslogtreecommitdiff
path: root/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui')
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/Configuration.java87
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/ConfigurationCreator.java12
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/ConfigurationManager.java179
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/DialogBase.java152
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/EditVarConstraintsDialog.java635
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/ExistingTemplatesComponent.java333
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchCommand.java145
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchConfiguration.java39
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchContext.java59
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchDialog.java1000
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchModel.java29
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SelectTemplateDialog.java294
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SubstitutionShortInfoHandler.java114
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UIUtil.java241
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UsageViewContext.java183
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/VarConstraints.form350
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/actions/DoSearchAction.java24
17 files changed, 0 insertions, 3876 deletions
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/Configuration.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/Configuration.java
deleted file mode 100644
index 440d33164f1d..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/Configuration.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package com.intellij.structuralsearch.plugin.ui;
-
-import com.intellij.openapi.util.JDOMExternalizable;
-import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.structuralsearch.MatchOptions;
-import org.jdom.Element;
-import org.jetbrains.annotations.NonNls;
-
-/**
- * Created by IntelliJ IDEA.
- * User: Maxim.Mossienko
- * Date: Apr 14, 2004
- * Time: 5:29:37 PM
- * To change this template use File | Settings | File Templates.
- */
-public abstract class Configuration implements JDOMExternalizable, Comparable<Configuration> {
- public static final Configuration[] EMPTY_ARRAY = {};
- @NonNls protected static final String NAME_ATTRIBUTE_NAME = "name";
- private String name = "";
- private String category = null;
- private boolean predefined;
-
- private static ConfigurationCreator configurationCreator;
-
- public String getName() {
- return name;
- }
-
- public void setName(String value) {
- name = value;
- }
-
- public String getCategory() {
- return category;
- }
-
- public void setCategory(String category) {
- this.category = category;
- }
-
- public void readExternal(Element element) {
- name = element.getAttributeValue(NAME_ATTRIBUTE_NAME);
- }
-
- public void writeExternal(Element element) {
- element.setAttribute(NAME_ATTRIBUTE_NAME,name);
- }
-
- public boolean isPredefined() {
- return predefined;
- }
-
- public void setPredefined(boolean predefined) {
- this.predefined = predefined;
- }
-
- public abstract MatchOptions getMatchOptions();
-
- @Override
- public int compareTo(Configuration other) {
- int result = StringUtil.naturalCompare(getCategory(), other.getCategory());
- return result != 0 ? result : StringUtil.naturalCompare(getName(), other.getName());
- }
-
- public boolean equals(Object configuration) {
- if (!(configuration instanceof Configuration)) return false;
- Configuration other = (Configuration)configuration;
- if (category != null ? !category.equals(other.category) : other.category != null) {
- return false;
- }
- return name.equals(other.name);
- }
-
- public int hashCode() {
- return getMatchOptions().hashCode();
- }
-
- public static void setActiveCreator(ConfigurationCreator creator) {
- configurationCreator = creator;
- }
-
- public static ConfigurationCreator getConfigurationCreator() {
- return configurationCreator;
- }
-
- @NonNls public static final String CONTEXT_VAR_NAME = "__context__";
-}
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/ConfigurationCreator.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/ConfigurationCreator.java
deleted file mode 100644
index 74332fd72e74..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/ConfigurationCreator.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.intellij.structuralsearch.plugin.ui;
-
-/**
- * Created by IntelliJ IDEA.
- * User: Maxim.Mossienko
- * Date: Apr 21, 2004
- * Time: 7:46:16 PM
- * To change this template use File | Settings | File Templates.
- */
-public interface ConfigurationCreator {
- Configuration createConfiguration();
-}
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/ConfigurationManager.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/ConfigurationManager.java
deleted file mode 100644
index 151e78d6863f..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/ConfigurationManager.java
+++ /dev/null
@@ -1,179 +0,0 @@
-package com.intellij.structuralsearch.plugin.ui;
-
-import com.intellij.icons.AllIcons;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.Messages;
-import com.intellij.openapi.ui.NonEmptyInputValidator;
-import com.intellij.structuralsearch.SSRBundle;
-import com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration;
-import org.jdom.Element;
-import org.jetbrains.annotations.NonNls;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.*;
-
-/**
- * Created by IntelliJ IDEA.
- * User: maxim
- * Date: 10.02.2004
- * Time: 14:29:45
- * To change this template use File | Settings | File Templates.
- */
-public class ConfigurationManager {
- @NonNls static final String SEARCH_TAG_NAME = "searchConfiguration";
- @NonNls static final String REPLACE_TAG_NAME = "replaceConfiguration";
- @NonNls private static final String SAVE_HISTORY_ATTR_NAME = "history";
-
- private List<Configuration> configurations;
- private LinkedList<Configuration> historyConfigurations;
-
- public void addHistoryConfigurationToFront(Configuration configuration) {
- if (historyConfigurations == null) historyConfigurations = new LinkedList<Configuration>();
-
- if (historyConfigurations.indexOf(configuration) == -1) {
- historyConfigurations.addFirst(configuration);
- }
- }
-
- public void removeHistoryConfiguration(Configuration configuration) {
- if (historyConfigurations != null) {
- historyConfigurations.remove(configuration);
- }
- }
-
- public void addConfiguration(Configuration configuration) {
- if (configurations == null) configurations = new ArrayList<Configuration>();
-
- if (configurations.indexOf(configuration) == -1) {
- configurations.add(configuration);
- }
- }
-
- public void removeConfiguration(Configuration configuration) {
- if (configurations != null) {
- configurations.remove(configuration);
- }
- }
-
- public void saveConfigurations(Element element) {
- writeConfigurations(element, configurations, historyConfigurations);
- }
-
- public static void writeConfigurations(final Element element,
- final Collection<Configuration> configurations,
- final Collection<Configuration> historyConfigurations) {
- if (configurations != null) {
- for (final Configuration configuration : configurations) {
- saveConfiguration(element, configuration);
- }
- }
-
- if (historyConfigurations != null) {
- for (final Configuration historyConfiguration : historyConfigurations) {
- final Element infoElement = saveConfiguration(element, historyConfiguration);
- infoElement.setAttribute(SAVE_HISTORY_ATTR_NAME, "1");
- }
- }
- }
-
- public static Element saveConfiguration(Element element, final Configuration config) {
- Element infoElement = new Element(config instanceof SearchConfiguration ? SEARCH_TAG_NAME : REPLACE_TAG_NAME);
- element.addContent(infoElement);
- config.writeExternal(infoElement);
-
- return infoElement;
- }
-
- public void loadConfigurations(Element element) {
- if (configurations != null) return;
- ArrayList<Configuration> configurations = new ArrayList<Configuration>();
- ArrayList<Configuration> historyConfigurations = new ArrayList<Configuration>();
- readConfigurations(element, configurations, historyConfigurations);
- for (Configuration configuration : historyConfigurations) {
- addHistoryConfigurationToFront(configuration);
- }
- for (Configuration configuration : configurations) {
- addConfiguration(configuration);
- }
- if (this.historyConfigurations != null) {
- Collections.reverse(this.historyConfigurations);
- }
- }
-
- public static void readConfigurations(final Element element, @NotNull Collection<Configuration> configurations, @NotNull Collection<Configuration> historyConfigurations) {
- final List<Element> patterns = element.getChildren();
-
- if (patterns != null && patterns.size() > 0) {
- for (final Element pattern : patterns) {
- final Configuration config = readConfiguration(pattern);
- if (config == null) continue;
-
- if (pattern.getAttribute(SAVE_HISTORY_ATTR_NAME) != null) {
- historyConfigurations.add(config);
- }
- else {
- configurations.add(config);
- }
- }
- }
- }
-
- public static Configuration readConfiguration(final Element childElement) {
- String s = childElement.getName();
- final Configuration config =
- s.equals(SEARCH_TAG_NAME) ? new SearchConfiguration() : s.equals(REPLACE_TAG_NAME) ? new ReplaceConfiguration():null;
- if (config != null) config.readExternal(childElement);
- return config;
- }
-
- public Collection<Configuration> getConfigurations() {
- return configurations;
- }
-
- public static Configuration findConfigurationByName(final Collection<Configuration> configurations, final String name) {
- for(Configuration config:configurations) {
- if (config.getName().equals(name)) return config;
- }
-
- return null;
- }
-
- public Collection<Configuration> getHistoryConfigurations() {
- return historyConfigurations;
- }
-
- public static @Nullable String findAppropriateName(@NotNull final Collection<Configuration> configurations, @NotNull String _name,
- @NotNull final Project project) {
- Configuration config;
- String name = _name;
-
- while ((config = findConfigurationByName(configurations, name)) != null) {
- int i = Messages.showYesNoDialog(
- project,
- SSRBundle.message("overwrite.message"),
- SSRBundle.message("overwrite.title"),
- AllIcons.General.QuestionDialog
- );
-
- if (i == Messages.YES) {
- configurations.remove(config);
- break;
- }
- name = showSaveTemplateAsDialog(name, project);
- if (name == null) break;
- }
- return name;
- }
-
- public static @Nullable String showSaveTemplateAsDialog(@NotNull String initial, @NotNull Project project) {
- return Messages.showInputDialog(
- project,
- SSRBundle.message("template.name.button"),
- SSRBundle.message("save.template.description.button"),
- AllIcons.General.QuestionDialog,
- initial,
- new NonEmptyInputValidator()
- );
- }
-}
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/DialogBase.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/DialogBase.java
deleted file mode 100644
index 83d93ba0d05c..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/DialogBase.java
+++ /dev/null
@@ -1,152 +0,0 @@
-package com.intellij.structuralsearch.plugin.ui;
-
-import com.intellij.openapi.MnemonicHelper;
-import com.intellij.CommonBundle;
-
-import javax.swing.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.KeyEvent;
-import java.awt.event.InputEvent;
-import java.awt.*;
-
-import org.jetbrains.annotations.NonNls;
-
-/**
- * Base dialog class
- */
-public abstract class DialogBase extends JDialog {
- private JButton ok;
- private JButton cancel;
-
- private Action okAction;
- private Action cancelAction;
- private static Rectangle virtualBounds;
-
- class OkAction extends AbstractAction {
- OkAction() {
- putValue(NAME, CommonBundle.getOkButtonText());
- }
- public void actionPerformed(ActionEvent e) {
- doOKAction();
- }
- }
-
- class CancelAction extends AbstractAction {
- CancelAction() {
- putValue(NAME,CommonBundle.getCancelButtonText());
- }
-
- public void actionPerformed(ActionEvent e) {
- doCancelAction();
- }
- }
-
- protected DialogBase() {
- this(null);
- }
-
- protected DialogBase(Frame frame) {
- this(frame,true);
- }
-
- protected DialogBase(Frame frame,boolean modal) {
- super(frame,modal);
-
- new MnemonicHelper().register(getContentPane());
-
- okAction = new OkAction();
- cancelAction = new CancelAction();
-
- ok = createJButtonForAction(okAction);
- cancel = createJButtonForAction(cancelAction);
-
- if (virtualBounds == null) {
- GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
- GraphicsDevice[] gs = ge.getScreenDevices();
- virtualBounds = new Rectangle();
-
- for (int j = 0; j < gs.length; j++) {
- GraphicsDevice gd = gs[j];
- GraphicsConfiguration[] gc = gd.getConfigurations();
-
- for (int i=0; i < gc.length; i++) {
- virtualBounds = virtualBounds.union(gc[i].getBounds());
- }
- }
- }
-
- @NonNls String cancelCommandName = "close";
- KeyStroke escKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0);
- ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escKeyStroke, cancelCommandName);
- ok.getActionMap().put(cancelCommandName, cancelAction);
-
- @NonNls String startCommandName = "start";
- KeyStroke enterKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,InputEvent.CTRL_MASK);
- ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(enterKeyStroke, startCommandName);
- ok.getActionMap().put(startCommandName, okAction);
- }
-
- protected JButton getCancelButton() {
- return cancel;
- }
-
- protected JButton getOkButton() {
- return ok;
- }
-
- protected abstract JComponent createCenterPanel();
-
- protected JComponent createSouthPanel() {
- JPanel p = new JPanel( null );
- p.setLayout( new BoxLayout(p,BoxLayout.X_AXIS) );
- p.add(Box.createHorizontalGlue());
- p.add(getOkButton());
- p.add(getCancelButton());
- return p;
- }
-
- public void init() {
- getContentPane().setLayout(new BorderLayout());
- getContentPane().add(BorderLayout.CENTER,createCenterPanel());
- getContentPane().add(BorderLayout.SOUTH,createSouthPanel());
- pack();
-
- Dimension dim = getPreferredSize();
- setLocation(
- (int)(virtualBounds.getWidth()/2 - dim.getWidth()/2),
- (int)(virtualBounds.getHeight()/2 - dim.getHeight()/2)
- );
- }
-
- public void show() {
- pack();
- super.show();
- }
-
- protected void doCancelAction() {
- setVisible(false);
- }
-
- protected void doOKAction() {
- setVisible(false);
- }
-
- protected void setOKActionEnabled(boolean b) {
- okAction.setEnabled(b);
- }
-
- protected void setOKButtonText(String text) {
- okAction.putValue(Action.NAME,text);
- }
-
- protected void setCancelButtonText(String text) {
- cancelAction.putValue(Action.NAME,text);
- }
-
- protected JButton createJButtonForAction(Action _action) {
- JButton jb = new JButton( (String)_action.getValue(Action.NAME) );
- jb.setAction(_action);
-
- return jb;
- }
-}
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/EditVarConstraintsDialog.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/EditVarConstraintsDialog.java
deleted file mode 100644
index 368240ff50be..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/EditVarConstraintsDialog.java
+++ /dev/null
@@ -1,635 +0,0 @@
-package com.intellij.structuralsearch.plugin.ui;
-
-import com.intellij.codeInsight.template.impl.Variable;
-import com.intellij.find.impl.RegExHelpPopup;
-import com.intellij.ide.highlighter.HighlighterFactory;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.EditorFactory;
-import com.intellij.openapi.editor.EditorSettings;
-import com.intellij.openapi.editor.colors.ex.DefaultColorSchemesManager;
-import com.intellij.openapi.editor.event.DocumentAdapter;
-import com.intellij.openapi.editor.event.DocumentEvent;
-import com.intellij.openapi.editor.ex.EditorEx;
-import com.intellij.openapi.fileTypes.FileType;
-import com.intellij.openapi.fileTypes.FileTypeManager;
-import com.intellij.openapi.fileTypes.FileTypes;
-import com.intellij.openapi.fileTypes.StdFileTypes;
-import com.intellij.openapi.help.HelpManager;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.ComponentWithBrowseButton;
-import com.intellij.openapi.ui.DialogWrapper;
-import com.intellij.openapi.ui.Messages;
-import com.intellij.openapi.ui.popup.JBPopup;
-import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.psi.PsiDocumentManager;
-import com.intellij.psi.PsiFile;
-import com.intellij.psi.PsiFileFactory;
-import com.intellij.structuralsearch.MatchVariableConstraint;
-import com.intellij.structuralsearch.NamedScriptableDefinition;
-import com.intellij.structuralsearch.ReplacementVariableDefinition;
-import com.intellij.structuralsearch.SSRBundle;
-import com.intellij.structuralsearch.impl.matcher.predicates.ScriptSupport;
-import com.intellij.structuralsearch.plugin.replace.ReplaceOptions;
-import com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration;
-import com.intellij.ui.ComboboxWithBrowseButton;
-import com.intellij.ui.EditorTextField;
-import com.intellij.ui.components.labels.LinkLabel;
-import com.intellij.ui.components.labels.LinkListener;
-import org.jetbrains.annotations.NonNls;
-import org.jetbrains.annotations.NotNull;
-
-import javax.swing.*;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-import javax.swing.event.ListSelectionEvent;
-import javax.swing.event.ListSelectionListener;
-import javax.swing.text.BadLocationException;
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.List;
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
-
-/**
- * @author Maxim.Mossienko
- * Date: Mar 25, 2004
- * Time: 1:52:18 PM
- */
-class EditVarConstraintsDialog extends DialogWrapper {
- private static final Logger LOG = Logger.getInstance("#com.intellij.structuralsearch.plugin.ui.EditVarConstraintsDialog");
-
- private JTextField maxoccurs;
- private JCheckBox applyWithinTypeHierarchy;
- private JCheckBox notRegexp;
- private EditorTextField regexp;
- private JTextField minoccurs;
- private JPanel mainForm;
- private JCheckBox notWrite;
- private JCheckBox notRead;
- private JCheckBox write;
- private JCheckBox read;
- private JList parameterList;
- private JCheckBox partOfSearchResults;
- private JCheckBox notExprType;
- private EditorTextField regexprForExprType;
- private final SearchModel model;
- private JCheckBox exprTypeWithinHierarchy;
-
- private final List<Variable> variables;
- private Variable current;
- private JCheckBox wholeWordsOnly;
- private JCheckBox formalArgTypeWithinHierarchy;
- private JCheckBox invertFormalArgType;
- private EditorTextField formalArgType;
- private ComponentWithBrowseButton<EditorTextField> customScriptCode;
- private JCheckBox maxoccursUnlimited;
-
- private ComboboxWithBrowseButton withinCombo;
- private JPanel containedInConstraints;
- private JCheckBox invertWithinIn;
- private JPanel expressionConstraints;
- private JPanel occurencePanel;
- private JPanel textConstraintsPanel;
- private JLabel myRegExHelpLabel;
-
- private static Project myProject;
-
- EditVarConstraintsDialog(final Project project,SearchModel _model,List<Variable> _variables, boolean replaceContext, FileType fileType) {
- super(project, false);
-
- variables = _variables;
- model = _model;
-
- setTitle(SSRBundle.message("editvarcontraints.edit.variables"));
-
- regexp.getDocument().addDocumentListener(new MyDocumentListener(notRegexp, applyWithinTypeHierarchy, wholeWordsOnly));
- read.addChangeListener(new MyChangeListener(notRead, false));
- write.addChangeListener(new MyChangeListener(notWrite, false));
- regexprForExprType.getDocument().addDocumentListener(new MyDocumentListener(exprTypeWithinHierarchy, notExprType));
- formalArgType.getDocument().addDocumentListener(new MyDocumentListener(formalArgTypeWithinHierarchy, invertFormalArgType));
-
- partOfSearchResults.setEnabled(!replaceContext); // todo: this doesn't do anything
- containedInConstraints.setVisible(false);
- withinCombo.getComboBox().setEditable(true);
-
- withinCombo.getButton().addActionListener(new ActionListener() {
- public void actionPerformed(final ActionEvent e) {
- final SelectTemplateDialog dialog = new SelectTemplateDialog(project, false, false);
- dialog.show();
- if (dialog.getExitCode() == OK_EXIT_CODE) {
- final Configuration[] selectedConfigurations = dialog.getSelectedConfigurations();
- if (selectedConfigurations.length == 1) {
- withinCombo.getComboBox().getEditor().setItem(selectedConfigurations[0].getMatchOptions().getSearchPattern()); // TODO:
- }
- }
- }
- });
-
- boolean hasContextVar = false;
- for(Variable var:variables) {
- if (Configuration.CONTEXT_VAR_NAME.equals(var.getName())) {
- hasContextVar = true; break;
- }
- }
-
- if (!hasContextVar) {
- variables.add(new Variable(Configuration.CONTEXT_VAR_NAME, "", "", true));
- }
-
- if (fileType == StdFileTypes.JAVA) {
-
- formalArgTypeWithinHierarchy.setEnabled(true);
- invertFormalArgType.setEnabled(true);
- formalArgType.setEnabled(true);
-
- exprTypeWithinHierarchy.setEnabled(true);
- notExprType.setEnabled(true);
- regexprForExprType.setEnabled(true);
-
- read.setEnabled(true);
- notRead.setEnabled(false);
- write.setEnabled(true);
- notWrite.setEnabled(false);
-
- applyWithinTypeHierarchy.setEnabled(true);
- } else {
- formalArgTypeWithinHierarchy.setEnabled(false);
- invertFormalArgType.setEnabled(false);
- formalArgType.setEnabled(false);
-
- exprTypeWithinHierarchy.setEnabled(false);
- notExprType.setEnabled(false);
- regexprForExprType.setEnabled(false);
-
- read.setEnabled(false);
- notRead.setEnabled(false);
- write.setEnabled(false);
- notWrite.setEnabled(false);
-
- applyWithinTypeHierarchy.setEnabled(false);
- }
-
- parameterList.setModel(
- new AbstractListModel() {
- public Object getElementAt(int index) {
- return variables.get(index);
- }
-
- public int getSize() {
- return variables.size();
- }
- }
- );
-
- parameterList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
-
- parameterList.getSelectionModel().addListSelectionListener(
- new ListSelectionListener() {
- boolean rollingBackSelection;
-
- public void valueChanged(ListSelectionEvent e) {
- if (e.getValueIsAdjusting()) return;
- if (rollingBackSelection) {
- rollingBackSelection=false;
- return;
- }
- final Variable var = variables.get(parameterList.getSelectedIndex());
- if (validateParameters()) {
- if (current!=null) copyValuesFromUI(current);
- ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { copyValuesToUI(var); }});
- current = var;
- } else {
- rollingBackSelection = true;
- parameterList.setSelectedIndex(e.getFirstIndex()==parameterList.getSelectedIndex()?e.getLastIndex():e.getFirstIndex());
- }
- }
- }
- );
-
- parameterList.setCellRenderer(
- new DefaultListCellRenderer() {
- public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
- String name = ((Variable)value).getName();
- if (Configuration.CONTEXT_VAR_NAME.equals(name)) name = SSRBundle.message("complete.match.variable.name");
- if (isReplacementVariable(name)) {
- name = stripReplacementVarDecoration(name);
- }
- return super.getListCellRendererComponent(list, name, index, isSelected, cellHasFocus);
- }
- }
- );
-
- maxoccursUnlimited.addChangeListener(new MyChangeListener(maxoccurs, true));
-
- customScriptCode.getButton().addActionListener(new ActionListener() {
- public void actionPerformed(final ActionEvent e) {
- final EditScriptDialog dialog = new EditScriptDialog(project, customScriptCode.getChildComponent().getText());
- dialog.show();
- if (dialog.getExitCode() == OK_EXIT_CODE) {
- customScriptCode.getChildComponent().setText(dialog.getScriptText());
- }
- }
- });
- init();
-
- if (variables.size() > 0) parameterList.setSelectedIndex(0);
- }
-
- private static String stripReplacementVarDecoration(String name) {
- name = name.substring(0, name.length() - ReplaceConfiguration.REPLACEMENT_VARIABLE_SUFFIX.length());
- return name;
- }
-
- private static boolean isReplacementVariable(String name) {
- return name.endsWith(ReplaceConfiguration.REPLACEMENT_VARIABLE_SUFFIX);
- }
-
- private boolean validateParameters() {
- return validateRegExp(regexp) && validateRegExp(regexprForExprType) &&
- validateIntOccurence(minoccurs) &&
- validateScript(customScriptCode.getChildComponent()) &&
- (maxoccursUnlimited.isSelected() || validateIntOccurence(maxoccurs));
- }
-
- protected JComponent createCenterPanel() {
- return mainForm;
- }
-
- protected void doOKAction() {
- if(validateParameters()) {
- if (current!=null) copyValuesFromUI(current);
- super.doOKAction();
- }
- }
-
- void copyValuesFromUI(Variable var) {
- String varName = var.getName();
- Configuration configuration = model.getConfig();
-
- if (isReplacementVariable(varName)) {
- saveScriptInfo(getOrAddReplacementVariableDefinition(varName, configuration));
- return;
- }
-
- MatchVariableConstraint varInfo = getOrAddVariableConstraint(varName, configuration);
-
- varInfo.setInvertReadAccess(notRead.isSelected());
- varInfo.setReadAccess(read.isSelected());
- varInfo.setInvertWriteAccess(notWrite.isSelected());
- varInfo.setWriteAccess(write.isSelected());
- varInfo.setRegExp(regexp.getDocument().getText());
- varInfo.setInvertRegExp(notRegexp.isSelected());
-
- int minCount = Integer.parseInt( minoccurs.getText() );
- varInfo.setMinCount(minCount);
-
- int maxCount;
- if (maxoccursUnlimited.isSelected()) maxCount = Integer.MAX_VALUE;
- else maxCount = Integer.parseInt( maxoccurs.getText() );
-
- varInfo.setMaxCount(maxCount);
- varInfo.setWithinHierarchy(applyWithinTypeHierarchy.isSelected());
- varInfo.setInvertRegExp(notRegexp.isSelected());
-
- varInfo.setPartOfSearchResults(partOfSearchResults.isEnabled() && partOfSearchResults.isSelected());
-
- varInfo.setInvertExprType(notExprType.isSelected());
- varInfo.setNameOfExprType(regexprForExprType.getDocument().getText());
- varInfo.setExprTypeWithinHierarchy(exprTypeWithinHierarchy.isSelected());
- varInfo.setWholeWordsOnly(wholeWordsOnly.isSelected());
- varInfo.setInvertFormalType(invertFormalArgType.isSelected());
- varInfo.setFormalArgTypeWithinHierarchy(formalArgTypeWithinHierarchy.isSelected());
- varInfo.setNameOfFormalArgType(formalArgType.getDocument().getText());
- saveScriptInfo(varInfo);
-
- final String withinConstraint = (String)withinCombo.getComboBox().getEditor().getItem();
- varInfo.setWithinConstraint(withinConstraint.length() > 0 ? "\"" + withinConstraint +"\"":"");
- varInfo.setInvertWithinConstraint(invertWithinIn.isSelected());
- }
-
- private static MatchVariableConstraint getOrAddVariableConstraint(String varName, Configuration configuration) {
- MatchVariableConstraint varInfo = configuration.getMatchOptions().getVariableConstraint(varName);
-
- if (varInfo == null) {
- varInfo = new MatchVariableConstraint();
- varInfo.setName(varName);
- configuration.getMatchOptions().addVariableConstraint(varInfo);
- }
- return varInfo;
- }
-
- private static ReplacementVariableDefinition getOrAddReplacementVariableDefinition(String varName, Configuration configuration) {
- ReplaceOptions replaceOptions = ((ReplaceConfiguration)configuration).getOptions();
- String realVariableName = stripReplacementVarDecoration(varName);
- ReplacementVariableDefinition variableDefinition = replaceOptions.getVariableDefinition(realVariableName);
-
- if (variableDefinition == null) {
- variableDefinition = new ReplacementVariableDefinition();
- variableDefinition.setName(realVariableName);
- replaceOptions.addVariableDefinition(variableDefinition);
- }
- return variableDefinition;
- }
-
- private void saveScriptInfo(NamedScriptableDefinition varInfo) {
- varInfo.setScriptCodeConstraint("\"" + customScriptCode.getChildComponent().getText() + "\"");
- }
-
- private void copyValuesToUI(Variable var) {
- Configuration configuration = model.getConfig();
- String varName = var.getName();
-
- if (isReplacementVariable(varName)) {
- ReplacementVariableDefinition definition = ((ReplaceConfiguration)configuration).getOptions().getVariableDefinition(
- stripReplacementVarDecoration(varName)
- );
-
- restoreScriptCode(definition);
- setSearchConstraintsVisible(false);
- return;
- } else {
- setSearchConstraintsVisible(true);
- }
-
- MatchVariableConstraint varInfo = configuration.getMatchOptions().getVariableConstraint(varName);
-
- if (varInfo == null) {
- notRead.setSelected(false);
- notRegexp.setSelected(false);
- read.setSelected(false);
- notWrite.setSelected(false);
- write.setSelected(false);
- regexp.getDocument().setText("");
-
- minoccurs.setText("1");
- maxoccurs.setText("1");
- maxoccursUnlimited.setSelected(false);
- applyWithinTypeHierarchy.setSelected(false);
- partOfSearchResults.setSelected(false);
-
- regexprForExprType.getDocument().setText("");
- notExprType.setSelected(false);
- exprTypeWithinHierarchy.setSelected(false);
- wholeWordsOnly.setSelected(false);
-
- invertFormalArgType.setSelected(false);
- formalArgTypeWithinHierarchy.setSelected(false);
- formalArgType.getDocument().setText("");
- customScriptCode.getChildComponent().setText("");
-
- withinCombo.getComboBox().getEditor().setItem("");
- invertWithinIn.setSelected(false);
- } else {
- notRead.setSelected(varInfo.isInvertReadAccess());
- read.setSelected(varInfo.isReadAccess());
- notWrite.setSelected(varInfo.isInvertWriteAccess());
- write.setSelected(varInfo.isWriteAccess());
-
- applyWithinTypeHierarchy.setSelected(varInfo.isWithinHierarchy());
- regexp.getDocument().setText(varInfo.getRegExp());
- //doProcessing(applyWithinTypeHierarchy,regexp);
-
- notRegexp.setSelected(varInfo.isInvertRegExp());
- minoccurs.setText(Integer.toString(varInfo.getMinCount()));
-
- if(varInfo.getMaxCount() == Integer.MAX_VALUE) {
- maxoccursUnlimited.setSelected(true);
- maxoccurs.setText("");
- } else {
- maxoccursUnlimited.setSelected(false);
- maxoccurs.setText(Integer.toString(varInfo.getMaxCount()));
- }
-
- partOfSearchResults.setSelected( partOfSearchResults.isEnabled() && varInfo.isPartOfSearchResults() );
-
- exprTypeWithinHierarchy.setSelected(varInfo.isExprTypeWithinHierarchy());
- regexprForExprType.getDocument().setText(varInfo.getNameOfExprType());
-
- notExprType.setSelected( varInfo.isInvertExprType() );
- wholeWordsOnly.setSelected( varInfo.isWholeWordsOnly() );
-
- invertFormalArgType.setSelected( varInfo.isInvertFormalType() );
- formalArgTypeWithinHierarchy.setSelected(varInfo.isFormalArgTypeWithinHierarchy());
- formalArgType.getDocument().setText(varInfo.getNameOfFormalArgType());
- restoreScriptCode(varInfo);
-
- withinCombo.getComboBox().getEditor().setItem(StringUtil.stripQuotesAroundValue(varInfo.getWithinConstraint()));
- invertWithinIn.setSelected(varInfo.isInvertWithinConstraint());
- }
-
- boolean isExprContext = true;
- final boolean contextVar = Configuration.CONTEXT_VAR_NAME.equals(var.getName());
- if (contextVar) isExprContext = false;
- containedInConstraints.setVisible(contextVar);
- expressionConstraints.setVisible(isExprContext);
- partOfSearchResults.setEnabled(!contextVar); //?
-
- occurencePanel.setVisible(!contextVar);
- }
-
- private void setSearchConstraintsVisible(boolean b) {
- textConstraintsPanel.setVisible(b);
- occurencePanel.setVisible(b);
- expressionConstraints.setVisible(b);
- partOfSearchResults.setVisible(b);
- containedInConstraints.setVisible(b);
- pack();
- }
-
- private void restoreScriptCode(NamedScriptableDefinition varInfo) {
- customScriptCode.getChildComponent().setText(
- varInfo != null ? StringUtil.stripQuotesAroundValue(varInfo.getScriptCodeConstraint()) : "");
- }
-
- protected String getDimensionServiceKey() {
- return "#com.intellij.structuralsearch.plugin.ui.EditVarConstraintsDialog";
- }
-
- private static boolean validateRegExp(EditorTextField field) {
- try {
- final String s = field.getDocument().getText();
- if (s.length() > 0) {
- Pattern.compile(s);
- }
- } catch(PatternSyntaxException ex) {
- Messages.showErrorDialog(SSRBundle.message("invalid.regular.expression"), SSRBundle.message("invalid.regular.expression"));
- field.requestFocus();
- return false;
- }
- return true;
- }
-
- private static boolean validateScript(EditorTextField field) {
- final String text = field.getText();
-
- if (text.length() > 0) {
- final String message = ScriptSupport.checkValidScript(text);
-
- if (message != null) {
- Messages.showErrorDialog(message, SSRBundle.message("invalid.groovy.script"));
- field.requestFocus();
- return false;
- }
- }
- return true;
- }
-
- private static boolean validateIntOccurence(JTextField field) {
- try {
- int a = Integer.parseInt(field.getText());
- if (a==-1) throw new NumberFormatException();
- } catch(NumberFormatException ex) {
- Messages.showErrorDialog(SSRBundle.message("invalid.occurence.count"), SSRBundle.message("invalid.occurence.count"));
- field.requestFocus();
- return false;
- }
- return true;
- }
-
- @NotNull
- protected Action[] createActions() {
- return new Action[]{getOKAction(), getCancelAction(), getHelpAction()};
- }
-
- protected void doHelpAction() {
- HelpManager.getInstance().invokeHelp("reference.dialogs.search.replace.structural.editvariable");
- }
-
- private void createUIComponents() {
- regexp = createRegexComponent();
- regexprForExprType = createRegexComponent();
- formalArgType = createRegexComponent();
- customScriptCode = new ComponentWithBrowseButton<EditorTextField>(createScriptComponent(), null);
-
- myRegExHelpLabel = new LinkLabel(SSRBundle.message("regular.expression.help.label"), null, new LinkListener() {
- public void linkSelected(LinkLabel aSource, Object aLinkData) {
- try {
- final JBPopup helpPopup = RegExHelpPopup.createRegExHelpPopup();
- helpPopup.showInCenterOf(mainForm);
- }
- catch (BadLocationException e) {
- LOG.info(e);
- }
- }
- });
-
- myRegExHelpLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
- }
-
- private static EditorTextField createRegexComponent() {
- @NonNls final String fileName = "1.regexp";
- final FileType fileType = getFileType(fileName);
- final Document doc = createDocument(fileName, fileType, "");
- return new EditorTextField(doc, myProject, fileType);
- }
-
- private static EditorTextField createScriptComponent() {
- @NonNls final String fileName = "1.groovy";
- final FileType fileType = getFileType(fileName);
- final Document doc = createDocument(fileName, fileType, "");
- return new EditorTextField(doc, myProject, fileType);
- }
-
- private static Document createDocument(final String fileName, final FileType fileType, String text) {
- final PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText(fileName, fileType, text, -1, true);
-
- return PsiDocumentManager.getInstance(myProject).getDocument(file);
- }
-
- private static FileType getFileType(final String fileName) {
- FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(fileName);
- if (fileType == FileTypes.UNKNOWN) fileType = FileTypes.PLAIN_TEXT;
- return fileType;
- }
-
- public static void setProject(final Project project) {
- myProject = project;
- }
-
- private static class MyChangeListener implements ChangeListener {
- private final JComponent component;
- private final boolean inverted;
-
- MyChangeListener(JComponent _component, boolean _inverted) {
- component = _component;
- inverted = _inverted;
- }
-
- public void stateChanged(ChangeEvent e) {
- final JCheckBox jCheckBox = (JCheckBox)e.getSource();
- component.setEnabled(inverted ^ jCheckBox.isSelected());
- }
- }
-
- private static class MyDocumentListener extends DocumentAdapter {
- private final JComponent[] components;
-
- private MyDocumentListener(JComponent... _components) {
- components = _components;
- }
-
- @Override
- public void documentChanged(DocumentEvent e) {
- final boolean enable = e.getDocument().getTextLength() > 0;
- for (JComponent component : components) {
- component.setEnabled(enable);
- }
- }
- }
-
- private static Editor createEditor(final Project project, final String text, final String fileName) {
- final FileType fileType = getFileType(fileName);
- final Document doc = createDocument(fileName, fileType, text);
- final Editor editor = EditorFactory.getInstance().createEditor(doc, project);
-
- ((EditorEx)editor).setEmbeddedIntoDialogWrapper(true);
- final EditorSettings settings = editor.getSettings();
- settings.setLineNumbersShown(false);
- settings.setFoldingOutlineShown(false);
- settings.setRightMarginShown(false);
- settings.setLineMarkerAreaShown(false);
- settings.setIndentGuidesShown(false);
- ((EditorEx)editor).setHighlighter(HighlighterFactory.createHighlighter(fileType, DefaultColorSchemesManager.getInstance().getAllSchemes()[0], project));
-
- return editor;
- }
-
- private static class EditScriptDialog extends DialogWrapper {
- private final Editor editor;
-
- public EditScriptDialog(final Project project, String text) {
- super(project, true);
- setTitle(SSRBundle.message("edit.groovy.script.constraint.title"));
- editor = createEditor(project, text, "1.groovy");
- init();
- }
-
- @Override
- protected String getDimensionServiceKey() {
- return getClass().getName();
- }
-
- @Override
- public JComponent getPreferredFocusedComponent() {
- return editor.getContentComponent();
- }
-
- protected JComponent createCenterPanel() {
- return editor.getComponent();
- }
-
- String getScriptText() {
- return editor.getDocument().getText();
- }
-
- @Override
- protected void dispose() {
- EditorFactory.getInstance().releaseEditor(editor);
- super.dispose();
- }
- }
-}
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/ExistingTemplatesComponent.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/ExistingTemplatesComponent.java
deleted file mode 100644
index 3dd79e16175c..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/ExistingTemplatesComponent.java
+++ /dev/null
@@ -1,333 +0,0 @@
-package com.intellij.structuralsearch.plugin.ui;
-
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.DialogWrapper;
-import com.intellij.structuralsearch.SSRBundle;
-import com.intellij.structuralsearch.StructuralSearchUtil;
-import com.intellij.structuralsearch.plugin.StructuralSearchPlugin;
-import com.intellij.ui.*;
-import com.intellij.ui.components.JBList;
-import com.intellij.ui.treeStructure.Tree;
-import com.intellij.util.containers.Convertor;
-import com.intellij.util.ui.tree.TreeUtil;
-
-import javax.swing.*;
-import javax.swing.tree.*;
-import java.awt.*;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseEvent;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Created by IntelliJ IDEA.
- * User: Maxim.Mossienko
- * Date: Apr 2, 2004
- * Time: 1:27:54 PM
- * To change this template use File | Settings | File Templates.
- */
-public class ExistingTemplatesComponent {
- private final Tree patternTree;
- private final DefaultTreeModel patternTreeModel;
- private final DefaultMutableTreeNode userTemplatesNode;
- private final JComponent panel;
- private final DefaultListModel historyModel;
- private final JList historyList;
- private final JComponent historyPanel;
- private DialogWrapper owner;
- private final Project project;
-
- private ExistingTemplatesComponent(Project project) {
-
- this.project = project;
- final DefaultMutableTreeNode root;
- patternTreeModel = new DefaultTreeModel(
- root = new DefaultMutableTreeNode(null)
- );
-
- DefaultMutableTreeNode parent = null;
- String lastCategory = null;
- LinkedList<Object> nodesToExpand = new LinkedList<Object>();
-
- final List<Configuration> predefined = StructuralSearchUtil.getPredefinedTemplates();
- for (final Configuration info : predefined) {
- final DefaultMutableTreeNode node = new DefaultMutableTreeNode(info);
-
- if (lastCategory == null || !lastCategory.equals(info.getCategory())) {
- if (info.getCategory().length() > 0) {
- root.add(parent = new DefaultMutableTreeNode(info.getCategory()));
- nodesToExpand.add(parent);
- lastCategory = info.getCategory();
- }
- else {
- root.add(node);
- continue;
- }
- }
-
- parent.add(node);
- }
-
- parent = new DefaultMutableTreeNode(SSRBundle.message("user.defined.category"));
- userTemplatesNode = parent;
- root.add(parent);
- nodesToExpand.add(parent);
-
- final ConfigurationManager configurationManager = StructuralSearchPlugin.getInstance(this.project).getConfigurationManager();
- if (configurationManager.getConfigurations() != null) {
- for (final Configuration config : configurationManager.getConfigurations()) {
- parent.add(new DefaultMutableTreeNode(config));
- }
- }
-
- patternTree = createTree(patternTreeModel);
-
- for (final Object aNodesToExpand : nodesToExpand) {
- patternTree.expandPath(
- new TreePath(new Object[]{root, aNodesToExpand})
- );
- }
-
- panel = ToolbarDecorator.createDecorator(patternTree)
- .setAddAction(new AnActionButtonRunnable() {
- @Override
- public void run(AnActionButton button) {
- addSelectedTreeNodeAndClose();
- }
- }).setRemoveAction(new AnActionButtonRunnable() {
- @Override
- public void run(AnActionButton button) {
- Object selection = patternTree.getLastSelectedPathComponent();
-
- if (selection instanceof DefaultMutableTreeNode) {
- DefaultMutableTreeNode node = (DefaultMutableTreeNode)selection;
-
- if (node.getUserObject() instanceof Configuration) {
- Configuration configuration = (Configuration)node.getUserObject();
- patternTreeModel.removeNodeFromParent(node);
- configurationManager.removeConfiguration(configuration);
- }
- }
- }
- }).createPanel();
-
- new JPanel(new BorderLayout());
-
- configureSelectTemplateAction(patternTree);
-
- historyModel = new DefaultListModel();
- historyPanel = new JPanel(new BorderLayout());
- historyPanel.add(
- BorderLayout.NORTH,
- new JLabel(SSRBundle.message("used.templates"))
- );
- Component view = historyList = new JBList(historyModel);
- historyPanel.add(
- BorderLayout.CENTER,
- ScrollPaneFactory.createScrollPane(view)
- );
-
- historyList.setCellRenderer(
- new ListCellRenderer()
- );
-
- historyList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
-
- new ListSpeedSearch(historyList);
-
- if (configurationManager.getHistoryConfigurations() != null) {
- for (final Configuration configuration : configurationManager.getHistoryConfigurations()) {
- historyModel.addElement(configuration);
- }
-
- historyList.setSelectedIndex(0);
- }
-
- configureSelectTemplateAction(historyList);
- }
-
- private void configureSelectTemplateAction(JComponent component) {
- component.addKeyListener(
- new KeyAdapter() {
- public void keyPressed(KeyEvent e) {
- if (e.getKeyCode() == KeyEvent.VK_ENTER) {
- owner.close(DialogWrapper.OK_EXIT_CODE);
- }
- }
- }
- );
-
- new DoubleClickListener() {
- @Override
- protected boolean onDoubleClick(MouseEvent event) {
- owner.close(DialogWrapper.OK_EXIT_CODE);
- return true;
- }
- }.installOn(component);
- }
-
- private void addSelectedTreeNodeAndClose() {
- addConfigurationToUserTemplates(
- Configuration.getConfigurationCreator().createConfiguration()
- );
- owner.close(DialogWrapper.OK_EXIT_CODE);
- }
-
- private static Tree createTree(TreeModel treeModel) {
- final Tree tree = new Tree(treeModel);
-
- tree.setRootVisible(false);
- tree.setShowsRootHandles(true);
- tree.setDragEnabled(false);
- tree.setEditable(false);
- tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
-
- tree.setCellRenderer(new TreeCellRenderer());
-
- new TreeSpeedSearch(
- tree,
- new Convertor<TreePath, String>() {
- public String convert(TreePath object) {
- DefaultMutableTreeNode node = (DefaultMutableTreeNode)object.getLastPathComponent();
- Object displayValue = node.getUserObject();
-
- if (displayValue instanceof Configuration) {
- displayValue = ((Configuration)displayValue).getName();
- }
- else {
- displayValue = "";
- }
- return displayValue.toString();
- }
- }
- );
-
- return tree;
- }
-
- public JTree getPatternTree() {
- return patternTree;
- }
-
- public JComponent getTemplatesPanel() {
- return panel;
- }
-
- public static ExistingTemplatesComponent getInstance(Project project) {
- StructuralSearchPlugin plugin = StructuralSearchPlugin.getInstance(project);
-
- if (plugin.getExistingTemplatesComponent() == null) {
- plugin.setExistingTemplatesComponent(new ExistingTemplatesComponent(project));
- }
-
- return plugin.getExistingTemplatesComponent();
- }
-
- static class ListCellRenderer extends DefaultListCellRenderer {
- public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
- if (value instanceof Configuration) {
- value = ((Configuration)value).getName();
- }
-
- Component comp = super.getListCellRendererComponent(
- list,
- value,
- index,
- isSelected,
- cellHasFocus
- );
-
- return comp;
- }
- }
-
- static class TreeCellRenderer extends DefaultTreeCellRenderer {
- TreeCellRenderer() {
- setOpenIcon(null);
- setLeafIcon(null);
- setClosedIcon(null);
- }
-
- public Component getTreeCellRendererComponent(JTree tree,
- Object value,
- boolean sel,
- boolean expanded,
- boolean leaf,
- int row,
- boolean hasFocus) {
- DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)value;
- Object displayValue = treeNode.getUserObject();
-
- if (displayValue instanceof Configuration) {
- displayValue = ((Configuration)displayValue).getName();
- }
-
- Component comp = super.getTreeCellRendererComponent(
- tree,
- displayValue,
- sel,
- expanded,
- leaf,
- row,
- hasFocus
- );
-
- return comp;
- }
- }
-
- void addConfigurationToHistory(Configuration configuration) {
- //configuration.setName( configuration.getName() +" "+new Date());
- historyModel.insertElementAt(configuration, 0);
- ConfigurationManager configurationManager = StructuralSearchPlugin.getInstance(project).getConfigurationManager();
- configurationManager.addHistoryConfigurationToFront(configuration);
- historyList.setSelectedIndex(0);
-
- if (historyModel.getSize() > 25) {
- configurationManager.removeHistoryConfiguration(
- (Configuration)historyModel.getElementAt(25)
- );
- // we add by one!
- historyModel.removeElementAt(25);
- }
- }
-
- private void insertNode(Configuration configuration, DefaultMutableTreeNode parent, int index) {
- DefaultMutableTreeNode node;
- patternTreeModel.insertNodeInto(
- node = new DefaultMutableTreeNode(
- configuration
- ),
- parent,
- index
- );
-
- TreeUtil.selectPath(
- patternTree,
- new TreePath(new Object[]{patternTreeModel.getRoot(), parent, node})
- );
- }
-
- void addConfigurationToUserTemplates(Configuration configuration) {
- insertNode(configuration, userTemplatesNode, userTemplatesNode.getChildCount());
- ConfigurationManager configurationManager = StructuralSearchPlugin.getInstance(project).getConfigurationManager();
- configurationManager.addConfiguration(configuration);
- }
-
- boolean isConfigurationFromHistory(Configuration config) {
- return historyModel.indexOf(config) != -1;
- }
-
- public JList getHistoryList() {
- return historyList;
- }
-
- public JComponent getHistoryPanel() {
- return historyPanel;
- }
-
- public void setOwner(DialogWrapper owner) {
- this.owner = owner;
- }
-}
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchCommand.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchCommand.java
deleted file mode 100644
index 7c51fa85af3b..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchCommand.java
+++ /dev/null
@@ -1,145 +0,0 @@
-package com.intellij.structuralsearch.plugin.ui;
-
-import com.intellij.notification.NotificationGroup;
-import com.intellij.openapi.application.ModalityState;
-import com.intellij.openapi.progress.ProgressIndicator;
-import com.intellij.openapi.progress.ProgressManager;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.MessageType;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.openapi.wm.ToolWindowId;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiFile;
-import com.intellij.psi.PsiNameIdentifierOwner;
-import com.intellij.structuralsearch.*;
-import com.intellij.structuralsearch.impl.matcher.MatchResultImpl;
-import com.intellij.structuralsearch.plugin.StructuralSearchPlugin;
-import com.intellij.structuralsearch.plugin.ui.actions.DoSearchAction;
-import com.intellij.usageView.UsageInfo;
-import com.intellij.usages.Usage;
-import com.intellij.usages.UsageInfo2UsageAdapter;
-import com.intellij.util.Alarm;
-import com.intellij.util.ObjectUtils;
-import com.intellij.util.Processor;
-
-/**
- * Created by IntelliJ IDEA.
- * User: Maxim.Mossienko
- * Date: Mar 15, 2004
- * Time: 4:49:07 PM
- * To change this template use File | Settings | File Templates.
- */
-public class SearchCommand {
- protected UsageViewContext context;
- private MatchingProcess process;
- protected Project project;
-
- public SearchCommand(Project _project, UsageViewContext _context) {
- project = _project;
- context = _context;
- }
-
- public void findUsages(final Processor<Usage> processor) {
- final ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
-
- try {
- DoSearchAction.execute(
- project,
- new MatchResultSink() {
- int count;
-
- public void setMatchingProcess(MatchingProcess _process) {
- process = _process;
- findStarted();
- }
-
- public void processFile(PsiFile element) {
- final VirtualFile virtualFile = element.getVirtualFile();
- if (virtualFile != null)
- progress.setText(SSRBundle.message("looking.in.progress.message", virtualFile.getPresentableName()));
- }
-
- public void matchingFinished() {
- findEnded();
- progress.setText(SSRBundle.message("found.progress.message", count));
- }
-
- public ProgressIndicator getProgressIndicator() {
- return progress;
- }
-
- public void newMatch(MatchResult result) {
- UsageInfo info;
-
- if (MatchResult.MULTI_LINE_MATCH.equals(result.getName())) {
- int start = -1;
- int end = -1;
- PsiElement parent = result.getMatchRef().getElement().getParent();
-
- for (final MatchResult matchResult : ((MatchResultImpl)result).getMatches()) {
- PsiElement el = matchResult.getMatchRef().getElement();
- final int elementStart = el.getTextRange().getStartOffset();
-
- if (start == -1 || start > elementStart) {
- start = elementStart;
- }
- final int newend = elementStart + el.getTextLength();
-
- if (newend > end) {
- end = newend;
- }
- }
-
- final int parentStart = parent.getTextRange().getStartOffset();
- int startOffset = start - parentStart;
- info = new UsageInfo(parent, startOffset, end - parentStart);
- }
- else {
- PsiElement element = result.getMatch();
- if (element instanceof PsiNameIdentifierOwner) {
- element = ObjectUtils.notNull(((PsiNameIdentifierOwner)element).getNameIdentifier(), element);
- }
- info = new UsageInfo(element, result.getStart(), result.getEnd() == -1 ? element.getTextLength() : result.getEnd());
- }
-
- Usage usage = new UsageInfo2UsageAdapter(info);
- processor.process(usage);
- foundUsage(result, usage);
- ++count;
- }
- },
- context.getConfiguration()
- );
- }
- catch (final StructuralSearchException e) {
- final Alarm alarm = new Alarm();
- alarm.addRequest(
- new Runnable() {
- @Override
- public void run() {
- NotificationGroup.toolWindowGroup("Structural Search", ToolWindowId.FIND, true)
- .createNotification(SSRBundle.message("problem", e.getMessage()), MessageType.ERROR).notify(project);
- }
- },
- 100, ModalityState.NON_MODAL
- );
- }
- }
-
- public void stopAsyncSearch() {
- if (process!=null) process.stop();
- }
-
- protected void findStarted() {
- StructuralSearchPlugin.getInstance(project).setSearchInProgress(true);
- }
-
- protected void findEnded() {
- if (!project.isDisposed()) {
- StructuralSearchPlugin.getInstance(project).setSearchInProgress(false);
- }
- }
-
- protected void foundUsage(MatchResult result, Usage usage) {
- }
-}
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchConfiguration.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchConfiguration.java
deleted file mode 100644
index afb2f9451bbe..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchConfiguration.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.intellij.structuralsearch.plugin.ui;
-
-import com.intellij.structuralsearch.MatchOptions;
-import com.intellij.openapi.actionSystem.AnAction;
-import org.jdom.Element;
-import org.jdom.Attribute;
-import org.jdom.DataConversionException;
-
-/**
- * Configuration of the search
- */
-public class SearchConfiguration extends Configuration {
- private MatchOptions matchOptions;
-
- public SearchConfiguration() {
- matchOptions = new MatchOptions();
- }
-
- public MatchOptions getMatchOptions() {
- return matchOptions;
- }
-
- public void setMatchOptions(MatchOptions matchOptions) {
- this.matchOptions = matchOptions;
- }
-
- public void readExternal(Element element) {
- super.readExternal(element);
-
- matchOptions.readExternal(element);
- }
-
- public void writeExternal(Element element) {
- super.writeExternal(element);
-
- matchOptions.writeExternal(element);
- }
-
-}
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchContext.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchContext.java
deleted file mode 100644
index 62371e7e29d1..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchContext.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.intellij.structuralsearch.plugin.ui;
-
-import com.intellij.openapi.actionSystem.CommonDataKeys;
-import com.intellij.openapi.actionSystem.DataContext;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.fileEditor.FileEditorManager;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.project.ProjectManager;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.PsiFile;
-import com.intellij.psi.PsiManager;
-import com.intellij.structuralsearch.impl.matcher.DataProvider;
-
-/**
- * Context of the search to be done
- */
-public final class SearchContext implements DataProvider, Cloneable {
- private final PsiFile file;
- private final Project project;
-
- private SearchContext(Project project, PsiFile file) {
- this.project = project;
- this.file = file;
- }
-
- public PsiFile getFile() {
- return file;
- }
-
- public Project getProject() {
- return project;
- }
-
- public static SearchContext buildFromDataContext(DataContext context) {
- Project project = CommonDataKeys.PROJECT.getData(context);
- if (project == null) {
- project = ProjectManager.getInstance().getDefaultProject();
- }
-
- PsiFile file = CommonDataKeys.PSI_FILE.getData(context);
- final VirtualFile vFile = CommonDataKeys.VIRTUAL_FILE.getData(context);
- if (vFile != null && (file == null || !vFile.equals(file.getContainingFile().getVirtualFile()))) {
- file = PsiManager.getInstance(project).findFile(vFile);
- }
- return new SearchContext(project, file);
- }
-
- public Editor getEditor() {
- return FileEditorManager.getInstance(project).getSelectedTextEditor();
- }
-
- protected Object clone() {
- try {
- return super.clone();
- } catch(CloneNotSupportedException ex) {
- return null;
- }
- }
-}
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchDialog.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchDialog.java
deleted file mode 100644
index 5255472d4ce6..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchDialog.java
+++ /dev/null
@@ -1,1000 +0,0 @@
-package com.intellij.structuralsearch.plugin.ui;
-
-import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
-import com.intellij.codeInsight.template.impl.Variable;
-import com.intellij.find.FindBundle;
-import com.intellij.find.FindProgressIndicator;
-import com.intellij.find.FindSettings;
-import com.intellij.ide.IdeBundle;
-import com.intellij.ide.util.scopeChooser.ScopeChooserCombo;
-import com.intellij.lang.Language;
-import com.intellij.lang.LanguageUtil;
-import com.intellij.openapi.application.Result;
-import com.intellij.openapi.application.WriteAction;
-import com.intellij.openapi.command.WriteCommandAction;
-import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.EditorFactory;
-import com.intellij.openapi.editor.SelectionModel;
-import com.intellij.openapi.editor.event.DocumentEvent;
-import com.intellij.openapi.editor.event.DocumentListener;
-import com.intellij.openapi.fileEditor.FileEditorManager;
-import com.intellij.openapi.fileTypes.FileType;
-import com.intellij.openapi.fileTypes.LanguageFileType;
-import com.intellij.openapi.fileTypes.impl.FileTypeRenderer;
-import com.intellij.openapi.progress.ProgressIndicator;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.ComboBox;
-import com.intellij.openapi.ui.DialogWrapper;
-import com.intellij.openapi.util.Disposer;
-import com.intellij.openapi.util.Factory;
-import com.intellij.openapi.util.TextRange;
-import com.intellij.openapi.wm.ToolWindow;
-import com.intellij.openapi.wm.ToolWindowId;
-import com.intellij.openapi.wm.ToolWindowManager;
-import com.intellij.psi.PsiDocumentManager;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiFile;
-import com.intellij.psi.codeStyle.CodeStyleManager;
-import com.intellij.psi.search.GlobalSearchScope;
-import com.intellij.psi.search.SearchScope;
-import com.intellij.structuralsearch.*;
-import com.intellij.structuralsearch.impl.matcher.MatcherImpl;
-import com.intellij.structuralsearch.plugin.StructuralSearchPlugin;
-import com.intellij.ui.ComboboxSpeedSearch;
-import com.intellij.ui.IdeBorderFactory;
-import com.intellij.ui.ListCellRendererWrapper;
-import com.intellij.ui.TitledSeparator;
-import com.intellij.usages.*;
-import com.intellij.util.Alarm;
-import com.intellij.util.Processor;
-import org.jetbrains.annotations.NonNls;
-import org.jetbrains.annotations.NotNull;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.util.*;
-import java.util.List;
-
-/**
- * Class to show the user the request for search
- */
-@SuppressWarnings({"RefusedBequest", "AssignmentToStaticFieldFromInstanceMethod"})
-public class SearchDialog extends DialogWrapper implements ConfigurationCreator {
- protected SearchContext searchContext;
-
- // text for search
- protected Editor searchCriteriaEdit;
-
- // options of search scope
- private ScopeChooserCombo myScopeChooserCombo;
-
- private JCheckBox recursiveMatching;
- private JCheckBox caseSensitiveMatch;
-
- private JComboBox fileTypes;
- private JComboBox contexts;
- private JComboBox dialects;
- private JLabel status;
- private JLabel statusText;
-
- protected SearchModel model;
- private JCheckBox openInNewTab;
- private final Alarm myAlarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD);
-
- public static final String USER_DEFINED = SSRBundle.message("new.template.defaultname");
- protected final ExistingTemplatesComponent existingTemplatesComponent;
-
- private boolean useLastConfiguration;
-
- private static boolean ourOpenInNewTab;
-
- @NonNls private FileType ourFtSearchVariant = StructuralSearchUtil.getDefaultFileType();
- private static Language ourDialect = null;
- private static String ourContext = null;
-
- private final boolean myShowScopePanel;
- private final boolean myRunFindActionOnClose;
- private boolean myDoingOkAction;
-
- private String mySavedEditorText;
- private JPanel myContentPanel;
- private JComponent myEditorPanel;
-
- public SearchDialog(SearchContext searchContext) {
- this(searchContext, true, true);
- }
-
- public SearchDialog(SearchContext searchContext, boolean showScope, boolean runFindActionOnClose) {
- super(searchContext.getProject(), true);
-
- if (showScope) setModal(false);
- myShowScopePanel = showScope;
- myRunFindActionOnClose = runFindActionOnClose;
- this.searchContext = (SearchContext)searchContext.clone();
- setTitle(getDefaultTitle());
-
- if (runFindActionOnClose) {
- setOKButtonText(FindBundle.message("find.dialog.find.button"));
- }
-
- existingTemplatesComponent = ExistingTemplatesComponent.getInstance(this.searchContext.getProject());
- model = new SearchModel(createConfiguration());
-
- init();
- }
-
- protected UsageViewContext createUsageViewContext(Configuration configuration) {
- return new UsageViewContext(searchContext, configuration);
- }
-
- public void setUseLastConfiguration(boolean useLastConfiguration) {
- this.useLastConfiguration = useLastConfiguration;
- }
-
- protected boolean isChanged(Configuration configuration) {
- return configuration.getMatchOptions().getSearchPattern() != null &&
- !searchCriteriaEdit.getDocument().getText().equals(configuration.getMatchOptions().getSearchPattern());
- }
-
- public void setSearchPattern(final Configuration config) {
- model.setShadowConfig(config);
- setValuesFromConfig(config);
- initiateValidation();
- }
-
- protected Editor createEditor(final SearchContext searchContext, String text) {
- Editor editor = null;
-
- if (fileTypes != null) {
- final FileType fileType = (FileType)fileTypes.getSelectedItem();
- final Language dialect = (Language)dialects.getSelectedItem();
-
- final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(fileType);
- if (profile != null) {
- editor = profile.createEditor(searchContext, fileType, dialect, text, useLastConfiguration);
- }
- }
-
- if (editor == null) {
- final EditorFactory factory = EditorFactory.getInstance();
- final Document document = factory.createDocument("");
- editor = factory.createEditor(document, searchContext.getProject());
- editor.getSettings().setFoldingOutlineShown(false);
- }
-
- editor.getDocument().addDocumentListener(new DocumentListener() {
- @Override
- public void beforeDocumentChange(final DocumentEvent event) {
- }
-
- @Override
- public void documentChanged(final DocumentEvent event) {
- initiateValidation();
- }
- });
-
- return editor;
- }
-
- private void initiateValidation() {
- myAlarm.cancelAllRequests();
- myAlarm.addRequest(new Runnable() {
-
- @Override
- public void run() {
- try {
- new WriteAction(){
- @Override
- protected void run(Result result) throws Throwable {
- if (!isValid()) {
- getOKAction().setEnabled(false);
- }
- else {
- getOKAction().setEnabled(true);
- reportMessage(null, null);
- }
- }
- }.execute();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- }, 500);
- }
-
- protected void buildOptions(JPanel searchOptions) {
- recursiveMatching = new JCheckBox(SSRBundle.message("recursive.matching.checkbox"), true);
- if (isRecursiveSearchEnabled()) {
- searchOptions.add(UIUtil.createOptionLine(recursiveMatching));
- }
-
- caseSensitiveMatch = new JCheckBox(FindBundle.message("find.options.case.sensitive"), true);
- searchOptions.add(UIUtil.createOptionLine(caseSensitiveMatch));
-
- final List<FileType> types = new ArrayList<FileType>();
-
- for (FileType fileType : StructuralSearchUtil.getSuitableFileTypes()) {
- if (StructuralSearchUtil.getProfileByFileType(fileType) != null) {
- types.add(fileType);
- }
- }
- Collections.sort(types, new Comparator<FileType>() {
- @Override
- public int compare(FileType o1, FileType o2) {
- return o1.getName().compareToIgnoreCase(o2.getName());
- }
- });
-
- final DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel(types.toArray(new FileType[types.size()]));
- comboBoxModel.setSelectedItem(ourFtSearchVariant);
- fileTypes = new ComboBox(comboBoxModel);
- fileTypes.setRenderer(new FileTypeRenderer());
- new ComboboxSpeedSearch(fileTypes) {
- @Override
- protected String getElementText(Object element) {
- return ((FileType)element).getName();
- }
- };
- fileTypes.addItemListener(new ItemListener() {
- @Override
- public void itemStateChanged(ItemEvent e) {
- updateDialectsAndContexts();
- updateEditor();
- }
- });
-
- contexts = new JComboBox(new DefaultComboBoxModel());
- contexts.setPreferredSize(new Dimension(60, -1));
-
- dialects = new JComboBox(new DefaultComboBoxModel());
- dialects.setRenderer(new ListCellRendererWrapper() {
- @Override
- public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
- if (value == null) {
- setText("None");
- }
- else if (value instanceof Language) {
- setText(((Language)value).getDisplayName());
- }
- }
- });
- dialects.addItemListener(new ItemListener() {
- @Override
- public void itemStateChanged(ItemEvent e) {
- updateEditor();
- }
- });
- new ComboboxSpeedSearch(dialects);
- dialects.setPreferredSize(new Dimension(120, -1));
-
- final JLabel jLabel = new JLabel(SSRBundle.message("search.dialog.file.type.label"));
- final JLabel jLabel2 = new JLabel(SSRBundle.message("search.dialog.context.label"));
- final JLabel jLabel3 = new JLabel(SSRBundle.message("search.dialog.file.dialect.label"));
- searchOptions.add(
- UIUtil.createOptionLine(
- new JComponent[]{
- jLabel,
- fileTypes,
- (JComponent)Box.createHorizontalStrut(8),
- jLabel2,
- contexts,
- (JComponent)Box.createHorizontalStrut(8),
- jLabel3,
- dialects,
- }
- )
- );
-
- jLabel.setLabelFor(fileTypes);
- jLabel2.setLabelFor(contexts);
- jLabel3.setLabelFor(dialects);
-
- detectFileTypeAndDialect();
-
- fileTypes.setSelectedItem(ourFtSearchVariant);
- fileTypes.addItemListener(new ItemListener() {
- @Override
- public void itemStateChanged(ItemEvent e) {
- if (e.getStateChange() == ItemEvent.SELECTED) initiateValidation();
- }
- });
-
- dialects.setSelectedItem(ourDialect);
- contexts.setSelectedItem(ourContext);
-
- updateDialectsAndContexts();
- }
-
- private void updateEditor() {
- if (myContentPanel != null) {
- if (myEditorPanel != null) {
- myContentPanel.remove(myEditorPanel);
- }
- disposeEditorContent();
- myEditorPanel = createEditorContent();
- myContentPanel.add(myEditorPanel, BorderLayout.CENTER);
- myContentPanel.revalidate();
- }
- }
-
- private void updateDialectsAndContexts() {
- final FileType fileType = (FileType)fileTypes.getSelectedItem();
- if (fileType instanceof LanguageFileType) {
- Language language = ((LanguageFileType)fileType).getLanguage();
- Language[] languageDialects = LanguageUtil.getLanguageDialects(language);
- Arrays.sort(languageDialects, new Comparator<Language>() {
- @Override
- public int compare(Language o1, Language o2) {
- return o1.getDisplayName().compareTo(o2.getDisplayName());
- }
- });
- Language[] variants = new Language[languageDialects.length + 1];
- variants[0] = null;
- System.arraycopy(languageDialects, 0, variants, 1, languageDialects.length);
- dialects.setModel(new DefaultComboBoxModel(variants));
- dialects.setEnabled(variants.length > 1);
- }
-
- final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(fileType);
-
- if (profile instanceof StructuralSearchProfileBase) {
- final String[] contextNames = ((StructuralSearchProfileBase)profile).getContextNames();
- if (contextNames.length > 0) {
- contexts.setModel(new DefaultComboBoxModel(contextNames));
- contexts.setSelectedItem(contextNames[0]);
- contexts.setEnabled(true);
- return;
- }
- }
- contexts.setSelectedItem(null);
- contexts.setEnabled(false);
- }
-
- private void detectFileTypeAndDialect() {
- final PsiFile file = searchContext.getFile();
- if (file != null) {
- PsiElement context = null;
-
- if (searchContext.getEditor() != null) {
- context = file.findElementAt(searchContext.getEditor().getCaretModel().getOffset());
- if (context != null) {
- context = context.getParent();
- }
- }
- if (context == null) {
- context = file;
- }
-
- FileType detectedFileType = null;
-
- StructuralSearchProfile profile = StructuralSearchUtil.getProfileByPsiElement(context);
- if (profile != null) {
- FileType fileType = profile.detectFileType(context);
- if (fileType != null) {
- detectedFileType = fileType;
- }
- }
-
- if (detectedFileType == null) {
- for (FileType fileType : StructuralSearchUtil.getSuitableFileTypes()) {
- if (fileType instanceof LanguageFileType && ((LanguageFileType)fileType).getLanguage().equals(context.getLanguage())) {
- detectedFileType = fileType;
- break;
- }
- }
- }
-
- ourFtSearchVariant = detectedFileType != null ?
- detectedFileType :
- StructuralSearchUtil.getDefaultFileType();
-
- // todo: detect dialect
-
- /*if (file.getLanguage() == StdLanguages.HTML ||
- (file.getFileType() == StdFileTypes.JSP &&
- contextLanguage == StdLanguages.HTML
- )
- ) {
- ourFileType = "html";
- }
- else if (file.getLanguage() == StdLanguages.XHTML ||
- (file.getFileType() == StdFileTypes.JSPX &&
- contextLanguage == StdLanguages.HTML
- )) {
- ourFileType = "xml";
- }
- else {
- ourFileType = DEFAULT_TYPE_NAME;
- }*/
- }
- }
-
- protected boolean isRecursiveSearchEnabled() {
- return true;
- }
-
- public void setValuesFromConfig(Configuration configuration) {
- //searchCriteriaEdit.putUserData(SubstitutionShortInfoHandler.CURRENT_CONFIGURATION_KEY, configuration);
-
- setDialogTitle(configuration);
- final MatchOptions matchOptions = configuration.getMatchOptions();
-
- UIUtil.setContent(
- searchCriteriaEdit,
- matchOptions.getSearchPattern(),
- 0,
- searchCriteriaEdit.getDocument().getTextLength(),
- searchContext.getProject()
- );
-
- model.getConfig().getMatchOptions().setSearchPattern(
- matchOptions.getSearchPattern()
- );
-
- recursiveMatching.setSelected(
- isRecursiveSearchEnabled() && matchOptions.isRecursiveSearch()
- );
-
- caseSensitiveMatch.setSelected(
- matchOptions.isCaseSensitiveMatch()
- );
-
- model.getConfig().getMatchOptions().clearVariableConstraints();
- if (matchOptions.hasVariableConstraints()) {
- for (Iterator<String> i = matchOptions.getVariableConstraintNames(); i.hasNext(); ) {
- final MatchVariableConstraint constraint = (MatchVariableConstraint)matchOptions.getVariableConstraint(i.next()).clone();
- model.getConfig().getMatchOptions().addVariableConstraint(constraint);
- }
- }
-
- MatchOptions options = configuration.getMatchOptions();
- StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(options.getFileType());
- assert profile != null;
- fileTypes.setSelectedItem(options.getFileType());
- dialects.setSelectedItem(options.getDialect());
- if (options.getPatternContext() != null) {
- contexts.setSelectedItem(options.getPatternContext());
- }
- }
-
- private void setDialogTitle(final Configuration configuration) {
- setTitle(getDefaultTitle() + " - " + configuration.getName());
- }
-
- @Override
- public Configuration createConfiguration() {
- SearchConfiguration configuration = new SearchConfiguration();
- configuration.setName(USER_DEFINED);
- return configuration;
- }
-
- protected void addOrReplaceSelection(final String selection) {
- addOrReplaceSelectionForEditor(selection, searchCriteriaEdit);
- }
-
- protected final void addOrReplaceSelectionForEditor(final String selection, Editor editor) {
- final Project project = searchContext.getProject();
- UIUtil.setContent(editor, selection, 0, -1, project);
- final Document document = editor.getDocument();
- editor.getSelectionModel().setSelection(0, document.getTextLength());
- final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
- documentManager.commitDocument(document);
- final PsiFile file = documentManager.getPsiFile(document);
- if (file == null) return;
-
- new WriteCommandAction(project, file) {
- @Override protected void run(@NotNull Result result) throws Throwable {
- CodeStyleManager.getInstance(project).adjustLineIndent(file, new TextRange(0, document.getTextLength()));
- }
- }.execute();
- }
-
- protected void runAction(final Configuration config, final SearchContext searchContext) {
- createUsageView(searchContext, config);
- }
-
- protected void createUsageView(final SearchContext searchContext, final Configuration config) {
- UsageViewManager manager = UsageViewManager.getInstance(searchContext.getProject());
-
- final UsageViewContext context = createUsageViewContext(config);
- final UsageViewPresentation presentation = new UsageViewPresentation();
- presentation.setOpenInNewTab(openInNewTab.isSelected());
- presentation.setScopeText(config.getMatchOptions().getScope().getDisplayName());
- context.configure(presentation);
-
- final FindUsagesProcessPresentation processPresentation = new FindUsagesProcessPresentation(presentation);
- processPresentation.setShowNotFoundMessage(true);
- processPresentation.setShowPanelIfOnlyOneUsage(true);
-
- processPresentation.setProgressIndicatorFactory(
- new Factory<ProgressIndicator>() {
- @Override
- public ProgressIndicator create() {
- return new FindProgressIndicator(searchContext.getProject(), presentation.getScopeText()) {
- @Override
- public void cancel() {
- context.getCommand().stopAsyncSearch();
- super.cancel();
- }
- };
- }
- }
- );
-
- PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
-
- manager.searchAndShowUsages(
- new UsageTarget[]{
- context.getTarget()
- },
- new Factory<UsageSearcher>() {
- @Override
- public UsageSearcher create() {
- return new UsageSearcher() {
- @Override
- public void generate(@NotNull final Processor<Usage> processor) {
- context.getCommand().findUsages(processor);
- }
- };
- }
- },
- processPresentation,
- presentation,
- new UsageViewManager.UsageViewStateListener() {
- @Override
- public void usageViewCreated(@NotNull UsageView usageView) {
- context.setUsageView(usageView);
- context.configureActions();
- }
-
- @Override
- public void findingUsagesFinished(final UsageView usageView) {
- }
- }
- );
- }
-
- protected String getDefaultTitle() {
- return SSRBundle.message("structural.search.title");
- }
-
- protected JComponent createEditorContent() {
- JPanel result = new JPanel(new BorderLayout());
-
- result.add(BorderLayout.NORTH, new JLabel(SSRBundle.message("search.template")));
- searchCriteriaEdit = createEditor(searchContext, mySavedEditorText != null ? mySavedEditorText : "");
- result.add(BorderLayout.CENTER, searchCriteriaEdit.getComponent());
- result.setMinimumSize(new Dimension(150, 100));
-
- return result;
- }
-
- protected int getRowsCount() {
- return 4;
- }
-
- @Override
- protected JComponent createCenterPanel() {
- myContentPanel = new JPanel(new BorderLayout());
- myEditorPanel = createEditorContent();
- myContentPanel.add(BorderLayout.CENTER, myEditorPanel);
- myContentPanel.add(BorderLayout.SOUTH, Box.createVerticalStrut(8));
- JComponent centerPanel = new JPanel(new BorderLayout());
- {
- JPanel panel = new JPanel(new BorderLayout());
- panel.add(BorderLayout.CENTER, myContentPanel);
- panel.add(BorderLayout.SOUTH, createTemplateManagementButtons());
- centerPanel.add(BorderLayout.CENTER, panel);
- }
-
- JPanel optionsContent = new JPanel(new BorderLayout());
- centerPanel.add(BorderLayout.SOUTH, optionsContent);
-
- JPanel searchOptions = new JPanel();
- searchOptions.setLayout(new GridLayout(getRowsCount(), 1, 0, 0));
- searchOptions.setBorder(IdeBorderFactory.createTitledBorder(SSRBundle.message("ssdialog.options.group.border"),
- true));
-
- myScopeChooserCombo = new ScopeChooserCombo(
- searchContext.getProject(),
- true,
- false,
- FindSettings.getInstance().getDefaultScopeName()
- );
- Disposer.register(myDisposable, myScopeChooserCombo);
- JPanel allOptions = new JPanel(new BorderLayout());
- if (myShowScopePanel) {
- JPanel scopePanel = new JPanel(new GridBagLayout());
-
- TitledSeparator separator = new TitledSeparator(SSRBundle.message("search.dialog.scope.label"), myScopeChooserCombo.getComboBox());
- scopePanel.add(separator, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
- new Insets(5, 0, 0, 0), 0, 0));
-
- scopePanel.add(myScopeChooserCombo, new GridBagConstraints(0, 1, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
- new Insets(0, 10, 0, 0), 0, 0));
-
- allOptions.add(
- scopePanel,
- BorderLayout.SOUTH
- );
-
- myScopeChooserCombo.getComboBox().addItemListener(new ItemListener() {
- @Override
- public void itemStateChanged(ItemEvent e) {
- initiateValidation();
- }
- });
- }
-
- buildOptions(searchOptions);
-
- allOptions.add(searchOptions, BorderLayout.CENTER);
- optionsContent.add(allOptions, BorderLayout.CENTER);
-
- if (myRunFindActionOnClose) {
- JPanel panel = new JPanel(new BorderLayout());
- panel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0));
- openInNewTab = new JCheckBox(FindBundle.message("find.open.in.new.tab.checkbox"));
- openInNewTab.setSelected(ourOpenInNewTab);
- ToolWindow findWindow = ToolWindowManager.getInstance(searchContext.getProject()).getToolWindow(ToolWindowId.FIND);
- openInNewTab.setEnabled(findWindow != null && findWindow.isAvailable());
- panel.add(openInNewTab, BorderLayout.EAST);
-
- optionsContent.add(BorderLayout.SOUTH, panel);
- }
-
- updateEditor();
- return centerPanel;
- }
-
-
- @Override
- protected JComponent createSouthPanel() {
- final JPanel statusPanel = new JPanel(new BorderLayout(5, 0));
- statusPanel.add(super.createSouthPanel(), BorderLayout.NORTH);
- statusPanel.add(statusText = new JLabel(SSRBundle.message("status.message")), BorderLayout.WEST);
- statusPanel.add(status = new JLabel(), BorderLayout.CENTER);
- return statusPanel;
- }
-
- private JPanel createTemplateManagementButtons() {
- JPanel panel = new JPanel(null);
- panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
- panel.add(Box.createHorizontalGlue());
-
- panel.add(
- createJButtonForAction(new AbstractAction() {
- {
- putValue(NAME, SSRBundle.message("save.template.text.button"));
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- String name = showSaveTemplateAsDialog();
-
- if (name != null) {
- final Project project = searchContext.getProject();
- final ConfigurationManager configurationManager = StructuralSearchPlugin.getInstance(project).getConfigurationManager();
- final Collection<Configuration> configurations = configurationManager.getConfigurations();
-
- if (configurations != null) {
- name = ConfigurationManager.findAppropriateName(configurations, name, project);
- if (name == null) return;
- }
-
- model.getConfig().setName(name);
- setValuesToConfig(model.getConfig());
- setDialogTitle(model.getConfig());
-
- if (model.getShadowConfig() == null ||
- model.getShadowConfig().isPredefined()) {
- existingTemplatesComponent.addConfigurationToUserTemplates(model.getConfig());
- }
- else { // ???
- setValuesToConfig(model.getShadowConfig());
- model.getShadowConfig().setName(name);
- }
- }
- }
- })
- );
-
- panel.add(
- Box.createHorizontalStrut(8)
- );
-
- panel.add(
- createJButtonForAction(
- new AbstractAction() {
- {
- putValue(NAME, SSRBundle.message("edit.variables.button"));
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- EditVarConstraintsDialog.setProject(searchContext.getProject());
- new EditVarConstraintsDialog(
- searchContext.getProject(),
- model, getVariablesFromListeners(),
- isReplaceDialog(),
- (FileType)fileTypes.getSelectedItem()
- ).show();
- initiateValidation();
- EditVarConstraintsDialog.setProject(null);
- }
- }
- )
- );
-
- panel.add(
- Box.createHorizontalStrut(8)
- );
-
- panel.add(
- createJButtonForAction(
- new AbstractAction() {
- {
- putValue(NAME, SSRBundle.message("history.button"));
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- SelectTemplateDialog dialog = new SelectTemplateDialog(searchContext.getProject(), true, isReplaceDialog());
- dialog.show();
-
- if (!dialog.isOK()) {
- return;
- }
- Configuration[] configurations = dialog.getSelectedConfigurations();
- if (configurations.length == 1) {
- setSearchPattern(configurations[0]);
- }
- }
- }
- )
- );
-
- panel.add(
- Box.createHorizontalStrut(8)
- );
-
- panel.add(
- createJButtonForAction(
- new AbstractAction() {
- {
- putValue(NAME, SSRBundle.message("copy.existing.template.button"));
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- SelectTemplateDialog dialog = new SelectTemplateDialog(searchContext.getProject(), false, isReplaceDialog());
- dialog.show();
-
- if (!dialog.isOK()) {
- return;
- }
- Configuration[] configurations = dialog.getSelectedConfigurations();
- if (configurations.length == 1) {
- setSearchPattern(configurations[0]);
- }
- }
- }
- )
- );
-
- return panel;
- }
-
- protected List<Variable> getVariablesFromListeners() {
- return getVarsFrom(searchCriteriaEdit);
- }
-
- protected static ArrayList<Variable> getVarsFrom(Editor searchCriteriaEdit) {
- SubstitutionShortInfoHandler handler = searchCriteriaEdit.getUserData(UIUtil.LISTENER_KEY);
- return new ArrayList<Variable>(handler.getVariables());
- }
-
- public final Project getProject() {
- return searchContext.getProject();
- }
-
- public String showSaveTemplateAsDialog() {
- return ConfigurationManager.showSaveTemplateAsDialog(
- model.getShadowConfig() != null ? model.getShadowConfig().getName() : SSRBundle.message("user.defined.category"),
- searchContext.getProject()
- );
- }
-
- protected boolean isReplaceDialog() {
- return false;
- }
-
- @Override
- public void show() {
- StructuralSearchPlugin.getInstance(getProject()).setDialogVisible(true);
- Configuration.setActiveCreator(this);
- searchCriteriaEdit.putUserData(
- SubstitutionShortInfoHandler.CURRENT_CONFIGURATION_KEY,
- model.getConfig()
- );
-
- if (!useLastConfiguration) {
- final Editor editor = FileEditorManager.getInstance(searchContext.getProject()).getSelectedTextEditor();
- boolean setSomeText = false;
-
- if (editor != null) {
- final SelectionModel selectionModel = editor.getSelectionModel();
-
- if (selectionModel.hasSelection()) {
- addOrReplaceSelection(selectionModel.getSelectedText());
- existingTemplatesComponent.getPatternTree().setSelectionPath(null);
- existingTemplatesComponent.getHistoryList().setSelectedIndex(-1);
- setSomeText = true;
- }
- }
-
- if (!setSomeText) {
- int selection = existingTemplatesComponent.getHistoryList().getSelectedIndex();
- if (selection != -1) {
- setValuesFromConfig(
- (Configuration)existingTemplatesComponent.getHistoryList().getSelectedValue()
- );
- }
- }
- }
-
- initiateValidation();
-
- super.show();
- }
-
- @Override
- public JComponent getPreferredFocusedComponent() {
- return searchCriteriaEdit.getContentComponent();
- }
-
- // Performs ok action
- @Override
- protected void doOKAction() {
- SearchScope selectedScope = getSelectedScope();
- if (selectedScope == null) return;
-
- myDoingOkAction = true;
- boolean result = isValid();
- myDoingOkAction = false;
- if (!result) return;
-
- myAlarm.cancelAllRequests();
- super.doOKAction();
- if (!myRunFindActionOnClose) return;
-
- FindSettings.getInstance().setDefaultScopeName(selectedScope.getDisplayName());
- ourOpenInNewTab = openInNewTab.isSelected();
-
- try {
- if (model.getShadowConfig() != null) {
- if (model.getShadowConfig().isPredefined()) {
- model.getConfig().setName(
- model.getShadowConfig().getName()
- );
- } //else {
- // // user template, save it
- // setValuesToConfig(model.getShadowConfig());
- //}
- }
- existingTemplatesComponent.addConfigurationToHistory(model.getConfig());
-
- runAction(model.getConfig(), searchContext);
- }
- catch (MalformedPatternException ex) {
- reportMessage("this.pattern.is.malformed.message", searchCriteriaEdit, ex.getMessage());
- }
- }
-
- public Configuration getConfiguration() {
- return model.getConfig();
- }
-
- private SearchScope getSelectedScope() {
- return myScopeChooserCombo.getSelectedScope();
- }
-
- protected boolean isValid() {
- setValuesToConfig(model.getConfig());
- boolean result = true;
-
- try {
- MatcherImpl.validate(searchContext.getProject(), model.getConfig().getMatchOptions());
- }
- catch (MalformedPatternException ex) {
- if (myRunFindActionOnClose) {
- reportMessage(
- "this.pattern.is.malformed.message",
- searchCriteriaEdit,
- ex.getMessage() != null ? ex.getMessage() : ""
- );
- result = false;
- }
- }
- catch (UnsupportedPatternException ex) {
- reportMessage("this.pattern.is.unsupported.message", searchCriteriaEdit, ex.getMessage());
- result = false;
- }
-
- //getOKAction().setEnabled(result);
- return result;
- }
-
- protected void reportMessage(@NonNls String messageId, Editor editor, Object... params) {
- final String message = messageId != null ? SSRBundle.message(messageId, params) : "";
- status.setText(message);
- status.setToolTipText(message);
- status.revalidate();
- statusText.setLabelFor(editor != null ? editor.getContentComponent() : null);
- }
-
- protected void setValuesToConfig(Configuration config) {
-
- MatchOptions options = config.getMatchOptions();
-
- boolean searchWithinHierarchy = IdeBundle.message("scope.class.hierarchy").equals(myScopeChooserCombo.getSelectedScopeName());
- // We need to reset search within hierarchy scope during online validation since the scope works with user participation
- options.setScope(
- searchWithinHierarchy && !myDoingOkAction ? GlobalSearchScope.projectScope(getProject()) : myScopeChooserCombo.getSelectedScope());
- options.setLooseMatching(true);
- options.setRecursiveSearch(isRecursiveSearchEnabled() && recursiveMatching.isSelected());
-
- ourFtSearchVariant = (FileType)fileTypes.getSelectedItem();
- ourDialect = (Language)dialects.getSelectedItem();
- ourContext = (String)contexts.getSelectedItem();
- FileType fileType = ourFtSearchVariant;
- options.setFileType(fileType);
- options.setDialect(ourDialect);
- options.setPatternContext(ourContext);
-
- options.setSearchPattern(searchCriteriaEdit.getDocument().getText());
- options.setCaseSensitiveMatch(caseSensitiveMatch.isSelected());
- }
-
- @Override
- protected String getDimensionServiceKey() {
- return "#com.intellij.structuralsearch.plugin.ui.SearchDialog";
- }
-
- @Override
- public void dispose() {
- Configuration.setActiveCreator(null);
- disposeEditorContent();
-
- myAlarm.cancelAllRequests();
-
- super.dispose();
- StructuralSearchPlugin.getInstance(getProject()).setDialogVisible(false);
- }
-
- protected void disposeEditorContent() {
- mySavedEditorText = searchCriteriaEdit.getDocument().getText();
-
- // this will remove from myExcludedSet
- final PsiFile file = PsiDocumentManager.getInstance(searchContext.getProject()).getPsiFile(searchCriteriaEdit.getDocument());
- if (file != null) {
- DaemonCodeAnalyzer.getInstance(searchContext.getProject()).setHighlightingEnabled(file, true);
- }
-
- EditorFactory.getInstance().releaseEditor(searchCriteriaEdit);
- }
-
- @Override
- protected String getHelpId() {
- return "find.structuredSearch";
- }
-
- public SearchContext getSearchContext() {
- return searchContext;
- }
-}
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchModel.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchModel.java
deleted file mode 100644
index 812ca6b0dc9b..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SearchModel.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.intellij.structuralsearch.plugin.ui;
-
-/**
- * Created by IntelliJ IDEA.
- * User: Maxim.Mossienko
- * Date: Mar 25, 2004
- * Time: 1:33:10 PM
- * To change this template use File | Settings | File Templates.
- */
-public class SearchModel {
- private final Configuration config;
- private Configuration shadowConfig;
-
- public SearchModel(Configuration config) {
- this.config = config;
- }
-
- public Configuration getConfig() {
- return config;
- }
-
- public void setShadowConfig(Configuration shadowConfig) {
- this.shadowConfig = shadowConfig;
- }
-
- public Configuration getShadowConfig() {
- return shadowConfig;
- }
-}
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SelectTemplateDialog.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SelectTemplateDialog.java
deleted file mode 100644
index b74715ecf07a..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SelectTemplateDialog.java
+++ /dev/null
@@ -1,294 +0,0 @@
-package com.intellij.structuralsearch.plugin.ui;
-
-import com.intellij.codeInsight.template.TemplateContextType;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.EditorFactory;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.DialogWrapper;
-import com.intellij.openapi.ui.Splitter;
-import com.intellij.structuralsearch.MatchOptions;
-import com.intellij.structuralsearch.SSRBundle;
-import com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration;
-import com.intellij.util.containers.ContainerUtil;
-import org.jetbrains.annotations.NonNls;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import javax.swing.*;
-import javax.swing.event.ListSelectionEvent;
-import javax.swing.event.ListSelectionListener;
-import javax.swing.event.TreeSelectionEvent;
-import javax.swing.event.TreeSelectionListener;
-import javax.swing.tree.DefaultMutableTreeNode;
-import javax.swing.tree.TreePath;
-import java.awt.*;
-import java.util.ArrayList;
-import java.util.Collection;
-
-/**
- * Created by IntelliJ IDEA.
- * User: Maxim.Mossienko
- * Date: Apr 23, 2004
- * Time: 5:03:52 PM
- * To change this template use File | Settings | File Templates.
- */
-public class SelectTemplateDialog extends DialogWrapper {
- private final boolean showHistory;
- private Editor searchPatternEditor;
- private Editor replacePatternEditor;
- private final boolean replace;
- private final Project project;
- private final ExistingTemplatesComponent existingTemplatesComponent;
-
- private MySelectionListener selectionListener;
- private CardLayout myCardLayout;
- private JPanel myPreviewPanel;
- @NonNls private static final String PREVIEW_CARD = "Preview";
- @NonNls private static final String SELECT_TEMPLATE_CARD = "SelectCard";
-
- public SelectTemplateDialog(Project project, boolean showHistory, boolean replace) {
- super(project, false);
-
- this.project = project;
- this.showHistory = showHistory;
- this.replace = replace;
- existingTemplatesComponent = ExistingTemplatesComponent.getInstance(this.project);
-
- setTitle(SSRBundle.message(this.showHistory ? "used.templates.history.dialog.title" : "existing.templates.dialog.title"));
- init();
-
- if (this.showHistory) {
- final int selection = existingTemplatesComponent.getHistoryList().getSelectedIndex();
- if (selection != -1) {
- setPatternFromList(selection);
- }
- }
- else {
- final TreePath selection = existingTemplatesComponent.getPatternTree().getSelectionPath();
- if (selection != null) {
- setPatternFromNode((DefaultMutableTreeNode)selection.getLastPathComponent());
- }
- else {
- showPatternPreviewFromConfiguration(null);
- }
- }
-
- setupListeners();
- }
-
- class MySelectionListener implements TreeSelectionListener, ListSelectionListener {
- public void valueChanged(TreeSelectionEvent e) {
- if (e.getNewLeadSelectionPath() != null) {
- setPatternFromNode(
- (DefaultMutableTreeNode)e.getNewLeadSelectionPath().getLastPathComponent()
- );
- }
- }
-
- public void valueChanged(ListSelectionEvent e) {
- if (e.getValueIsAdjusting() || e.getLastIndex() == -1) return;
- int selectionIndex = existingTemplatesComponent.getHistoryList().getSelectedIndex();
- if (selectionIndex != -1) {
- setPatternFromList(selectionIndex);
- }
- }
- }
-
- private void setPatternFromList(int index) {
- showPatternPreviewFromConfiguration(
- (Configuration)existingTemplatesComponent.getHistoryList().getModel().getElementAt(index)
- );
- }
-
- protected JComponent createCenterPanel() {
- final JPanel centerPanel = new JPanel(new BorderLayout());
- Splitter splitter;
-
- centerPanel.add(BorderLayout.CENTER, splitter = new Splitter(false, 0.3f));
- centerPanel.add(splitter);
-
- splitter.setFirstComponent(
- showHistory ?
- existingTemplatesComponent.getHistoryPanel() :
- existingTemplatesComponent.getTemplatesPanel()
- );
- final JPanel panel;
- splitter.setSecondComponent(
- panel = new JPanel(new BorderLayout())
- );
-
- searchPatternEditor = UIUtil.createEditor(
- EditorFactory.getInstance().createDocument(""),
- project,
- false,
- true,
- ContainerUtil.findInstance(TemplateContextType.EP_NAME.getExtensions(), TemplateContextType.class)
- );
-
- JComponent centerComponent;
-
- if (replace) {
- replacePatternEditor = UIUtil.createEditor(
- EditorFactory.getInstance().createDocument(""),
- project,
- false,
- true,
- ContainerUtil.findInstance(TemplateContextType.EP_NAME.getExtensions(), TemplateContextType.class)
- );
- centerComponent = new Splitter(true);
- ((Splitter)centerComponent).setFirstComponent(searchPatternEditor.getComponent());
- ((Splitter)centerComponent).setSecondComponent(replacePatternEditor.getComponent());
- }
- else {
- centerComponent = searchPatternEditor.getComponent();
- }
-
- myCardLayout = new CardLayout();
- myPreviewPanel = new JPanel(myCardLayout);
- myPreviewPanel.add(centerComponent, PREVIEW_CARD);
- JPanel selectPanel = new JPanel(new GridBagLayout());
- GridBagConstraints gb = new GridBagConstraints(0,0,0,0,0,0,GridBagConstraints.CENTER,GridBagConstraints.NONE, new Insets(0,0,0,0),0,0);
- selectPanel.add(new JLabel(SSRBundle.message("selecttemplate.template.label.please.select.template")), gb);
- myPreviewPanel.add(selectPanel, SELECT_TEMPLATE_CARD);
-
- panel.add(BorderLayout.CENTER, myPreviewPanel);
-
- panel.add(BorderLayout.NORTH, new JLabel(SSRBundle.message("selecttemplate.template.preview")));
- return centerPanel;
- }
-
- public void dispose() {
- EditorFactory.getInstance().releaseEditor(searchPatternEditor);
- if (replacePatternEditor != null) EditorFactory.getInstance().releaseEditor(replacePatternEditor);
- removeListeners();
- super.dispose();
- }
-
- public JComponent getPreferredFocusedComponent() {
- return showHistory ?
- existingTemplatesComponent.getHistoryList() :
- existingTemplatesComponent.getPatternTree();
- }
-
- protected String getDimensionServiceKey() {
- return "#com.intellij.structuralsearch.plugin.ui.SelectTemplateDialog";
- }
-
- private void setupListeners() {
- existingTemplatesComponent.setOwner(this);
- selectionListener = new MySelectionListener();
-
- if (showHistory) {
- existingTemplatesComponent.getHistoryList().getSelectionModel().addListSelectionListener(
- selectionListener
- );
- }
- else {
- existingTemplatesComponent.getPatternTree().getSelectionModel().addTreeSelectionListener(
- selectionListener
- );
- }
- }
-
- private void removeListeners() {
- existingTemplatesComponent.setOwner(null);
- if (showHistory) {
- existingTemplatesComponent.getHistoryList().getSelectionModel().removeListSelectionListener(
- selectionListener
- );
- }
- else {
- existingTemplatesComponent.getPatternTree().getSelectionModel().removeTreeSelectionListener(selectionListener);
- }
- }
-
- private void setPatternFromNode(DefaultMutableTreeNode node) {
- if (node == null) return;
- final Object userObject = node.getUserObject();
- final Configuration configuration;
-
- // root could be without search template
- if (userObject instanceof Configuration) {
- configuration = (Configuration)userObject;
- }
- else {
- configuration = null;
- }
-
- showPatternPreviewFromConfiguration(configuration);
- }
-
- private void showPatternPreviewFromConfiguration(@Nullable final Configuration configuration) {
- if (configuration == null) {
- myCardLayout.show(myPreviewPanel, SELECT_TEMPLATE_CARD);
- return;
- }
- else {
- myCardLayout.show(myPreviewPanel, PREVIEW_CARD);
- }
- final MatchOptions matchOptions = configuration.getMatchOptions();
-
- UIUtil.setContent(
- searchPatternEditor,
- matchOptions.getSearchPattern(),
- 0,
- searchPatternEditor.getDocument().getTextLength(),
- project
- );
-
- searchPatternEditor.putUserData(SubstitutionShortInfoHandler.CURRENT_CONFIGURATION_KEY, configuration);
-
- if (replace) {
- String replacement;
-
- if (configuration instanceof ReplaceConfiguration) {
- replacement = ((ReplaceConfiguration)configuration).getOptions().getReplacement();
- }
- else {
- replacement = configuration.getMatchOptions().getSearchPattern();
- }
-
- UIUtil.setContent(
- replacePatternEditor,
- replacement,
- 0,
- replacePatternEditor.getDocument().getTextLength(),
- project
- );
-
- replacePatternEditor.putUserData(SubstitutionShortInfoHandler.CURRENT_CONFIGURATION_KEY, configuration);
- }
- }
-
- @NotNull public Configuration[] getSelectedConfigurations() {
- if (showHistory) {
- Object[] selectedValues = existingTemplatesComponent.getHistoryList().getSelectedValues();
- if (selectedValues == null) {
- return new Configuration[0];
- }
- Collection<Configuration> configurations = new ArrayList<Configuration>();
- for (Object selectedValue : selectedValues) {
- if (selectedValue instanceof Configuration) {
- configurations.add((Configuration)selectedValue);
- }
- }
- return configurations.toArray(new Configuration[configurations.size()]);
- }
- else {
- TreePath[] paths = existingTemplatesComponent.getPatternTree().getSelectionModel().getSelectionPaths();
- if (paths == null) {
- return new Configuration[0];
- }
- Collection<Configuration> configurations = new ArrayList<Configuration>();
- for (TreePath path : paths) {
-
- DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
- final Object userObject = node.getUserObject();
- if (userObject instanceof Configuration) {
- configurations.add((Configuration)userObject);
- }
- }
- return configurations.toArray(new Configuration[configurations.size()]);
- }
- }
-}
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SubstitutionShortInfoHandler.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SubstitutionShortInfoHandler.java
deleted file mode 100644
index 32f1302336f3..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SubstitutionShortInfoHandler.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package com.intellij.structuralsearch.plugin.ui;
-
-import com.intellij.codeInsight.hint.TooltipGroup;
-import com.intellij.codeInsight.template.impl.TemplateImplUtil;
-import com.intellij.codeInsight.template.impl.Variable;
-import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.LogicalPosition;
-import com.intellij.openapi.editor.event.*;
-import com.intellij.openapi.util.Key;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-
-/**
- * Created by IntelliJ IDEA.
- * User: Maxim.Mossienko
- * Date: Apr 23, 2004
- * Time: 5:20:56 PM
- * To change this template use File | Settings | File Templates.
- */
-public class SubstitutionShortInfoHandler implements DocumentListener, EditorMouseMotionListener, CaretListener {
- private static final TooltipGroup SS_INFO_TOOLTIP_GROUP = new TooltipGroup("SS_INFO_TOOLTIP_GROUP", 0);
-
- private long modificationTimeStamp;
- private final ArrayList<Variable> variables = new ArrayList<Variable>();
- private final Editor editor;
- public static final Key<Configuration> CURRENT_CONFIGURATION_KEY = Key.create("SS.CurrentConfiguration");
-
- SubstitutionShortInfoHandler(@NotNull Editor _editor) {
- editor = _editor;
- }
-
- public void beforeDocumentChange(DocumentEvent event) {
- }
-
- public void documentChanged(DocumentEvent event) {
- }
-
- public void mouseMoved(EditorMouseEvent e) {
- LogicalPosition position = editor.xyToLogicalPosition( e.getMouseEvent().getPoint() );
-
- handleInputFocusMovement(position);
- }
-
- private void handleInputFocusMovement(LogicalPosition position) {
- checkModelValidity();
- String text = "";
- final int offset = editor.logicalPositionToOffset(position);
- final int length = editor.getDocument().getTextLength();
- final CharSequence elements = editor.getDocument().getCharsSequence();
-
- int start = offset-1;
- int end = -1;
- while(start >=0 && Character.isJavaIdentifierPart(elements.charAt(start)) && elements.charAt(start)!='$') start--;
-
- if (start >=0 && elements.charAt(start)=='$') {
- end = offset;
-
- while(end < length && Character.isJavaIdentifierPart(elements.charAt(end)) && elements.charAt(end)!='$') end++;
- if (end < length && elements.charAt(end)=='$') {
- String varname = elements.subSequence(start + 1, end).toString();
- Variable foundVar = null;
-
- for(Iterator<Variable> i=variables.iterator();i.hasNext();) {
- final Variable var = i.next();
-
- if (var.getName().equals(varname)) {
- foundVar = var;
- break;
- }
- }
-
- if (foundVar!=null) {
- text = UIUtil.getShortParamString(editor.getUserData(CURRENT_CONFIGURATION_KEY),varname);
- }
- }
- }
-
- if (text.length() > 0) {
- UIUtil.showTooltip(editor, start, end, text, SS_INFO_TOOLTIP_GROUP);
- }
- }
-
- private void checkModelValidity() {
- Document document = editor.getDocument();
- if (modificationTimeStamp != document.getModificationStamp()) {
- variables.clear();
- variables.addAll(TemplateImplUtil.parseVariables(document.getCharsSequence()).values());
- modificationTimeStamp = document.getModificationStamp();
- }
- }
-
- public void mouseDragged(EditorMouseEvent e) {
- }
-
- public void caretPositionChanged(CaretEvent e) {
- handleInputFocusMovement(e.getNewPosition());
- }
-
- @Override
- public void caretAdded(CaretEvent e) {
- }
-
- @Override
- public void caretRemoved(CaretEvent e) {
- }
-
- public ArrayList<Variable> getVariables() {
- checkModelValidity();
- return variables;
- }
-}
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UIUtil.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UIUtil.java
deleted file mode 100644
index aa3ca82725b0..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UIUtil.java
+++ /dev/null
@@ -1,241 +0,0 @@
-package com.intellij.structuralsearch.plugin.ui;
-
-import com.intellij.codeInsight.hint.TooltipController;
-import com.intellij.codeInsight.hint.TooltipGroup;
-import com.intellij.codeInsight.template.TemplateContextType;
-import com.intellij.codeInsight.template.impl.TemplateContext;
-import com.intellij.codeInsight.template.impl.TemplateEditorUtil;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.command.CommandProcessor;
-import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.EditorFactory;
-import com.intellij.openapi.editor.EditorSettings;
-import com.intellij.openapi.editor.colors.EditorColors;
-import com.intellij.openapi.editor.colors.EditorColorsManager;
-import com.intellij.openapi.editor.colors.EditorColorsScheme;
-import com.intellij.openapi.editor.ex.EditorEx;
-import com.intellij.openapi.fileEditor.FileEditorManager;
-import com.intellij.openapi.fileEditor.OpenFileDescriptor;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Key;
-import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.psi.*;
-import com.intellij.structuralsearch.*;
-import com.intellij.structuralsearch.plugin.StructuralReplaceAction;
-import com.intellij.structuralsearch.plugin.StructuralSearchAction;
-import com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration;
-import com.intellij.structuralsearch.plugin.util.SmartPsiPointer;
-import org.jetbrains.annotations.NonNls;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import javax.swing.*;
-import java.awt.*;
-
-/**
- * @author Maxim.Mossienko
- * Date: Apr 21, 2004
- * Time: 7:50:48 PM
- */
-public class UIUtil {
- static Key<SubstitutionShortInfoHandler> LISTENER_KEY = Key.create("sslistener.key");
- private static final String MODIFY_EDITOR_CONTENT = SSRBundle.message("modify.editor.content.command.name");
- @NonNls private static final String SS_GROUP = "structuralsearchgroup";
-
- @NotNull
- public static Editor createEditor(Document doc, final Project project, boolean editable, @Nullable TemplateContextType contextType) {
- return createEditor(doc, project, editable, false, contextType);
- }
-
- @NotNull
- public static Editor createEditor(@NotNull Document doc,
- final Project project,
- boolean editable,
- boolean addToolTipForVariableHandler,
- @Nullable TemplateContextType contextType) {
- final Editor editor =
- editable ? EditorFactory.getInstance().createEditor(doc, project) : EditorFactory.getInstance().createViewer(doc, project);
-
- EditorSettings editorSettings = editor.getSettings();
- editorSettings.setVirtualSpace(false);
- editorSettings.setLineMarkerAreaShown(false);
- editorSettings.setIndentGuidesShown(false);
- editorSettings.setLineNumbersShown(false);
- editorSettings.setFoldingOutlineShown(false);
-
- EditorColorsScheme scheme = editor.getColorsScheme();
- scheme.setColor(EditorColors.CARET_ROW_COLOR, null);
- if (!editable) {
- final EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme();
- Color c = globalScheme.getColor(EditorColors.READONLY_BACKGROUND_COLOR);
-
- if (c == null) {
- c = globalScheme.getDefaultBackground();
- }
-
- ((EditorEx)editor).setBackgroundColor(c);
- }
- else {
- ((EditorEx)editor).setEmbeddedIntoDialogWrapper(true);
- }
-
- if (contextType != null) {
- TemplateContext context = new TemplateContext();
- context.setEnabled(contextType, true);
- TemplateEditorUtil.setHighlighter(editor, context);
- }
-
- if (addToolTipForVariableHandler) {
- SubstitutionShortInfoHandler handler = new SubstitutionShortInfoHandler(editor);
- editor.addEditorMouseMotionListener(handler);
- editor.getDocument().addDocumentListener(handler);
- editor.getCaretModel().addCaretListener(handler);
- editor.putUserData(LISTENER_KEY, handler);
- }
-
- return editor;
- }
-
- public static JComponent createOptionLine(JComponent[] options) {
- JPanel tmp = new JPanel();
-
- tmp.setLayout(new BoxLayout(tmp, BoxLayout.X_AXIS));
- for (int i = 0; i < options.length; i++) {
- if (i != 0) {
- tmp.add(Box.createHorizontalStrut(com.intellij.util.ui.UIUtil.DEFAULT_HGAP));
- }
- tmp.add(options[i]);
- }
- tmp.add(Box.createHorizontalGlue());
-
- return tmp;
- }
-
- public static JComponent createOptionLine(JComponent option) {
- return createOptionLine(new JComponent[]{option});
- }
-
- public static void setContent(final Editor editor, String val, final int from, final int end, final Project project) {
- final String value = val != null ? val : "";
-
- CommandProcessor.getInstance().executeCommand(project, new Runnable() {
- public void run() {
- ApplicationManager.getApplication().runWriteAction(new Runnable() {
- public void run() {
- editor.getDocument().replaceString(from, (end == -1) ? editor.getDocument().getTextLength() : end, value);
- }
- });
- }
- }, MODIFY_EDITOR_CONTENT, SS_GROUP);
- }
-
- static String getShortParamString(Configuration config, String varname) {
- if (config == null) return "";
- final MatchOptions options = config.getMatchOptions();
-
-
- final MatchVariableConstraint constraint = options == null ? null : options.getVariableConstraint(varname);
- NamedScriptableDefinition namedScriptableDefinition = constraint;
-
- final ReplacementVariableDefinition replacementVariableDefinition =
- config instanceof ReplaceConfiguration ? ((ReplaceConfiguration)config).getOptions().getVariableDefinition(varname) : null;
- if (replacementVariableDefinition != null) namedScriptableDefinition = replacementVariableDefinition;
-
- if (constraint == null && replacementVariableDefinition == null) {
- return SSRBundle.message("no.constraints.specified.tooltip.message");
- }
-
- final StringBuilder buf = new StringBuilder();
-
- if (constraint != null) {
- if (constraint.isPartOfSearchResults()) {
- append(buf, SSRBundle.message("target.tooltip.message"));
- }
- if (constraint.getRegExp() != null && constraint.getRegExp().length() > 0) {
- append(buf, SSRBundle.message("text.tooltip.message", constraint.isInvertRegExp() ? SSRBundle.message("not.tooltip.message") : "",
- constraint.getRegExp(),
- constraint.isWithinHierarchy() || constraint.isStrictlyWithinHierarchy() ?
- SSRBundle.message("within.hierarchy.tooltip.message") : ""));
- }
-
- if (constraint.getNameOfExprType() != null && constraint.getNameOfExprType().length() > 0) {
- append(buf, SSRBundle.message("exprtype.tooltip.message",
- constraint.isInvertExprType() ? SSRBundle.message("not.tooltip.message") : "",
- constraint.getNameOfExprType(),
- constraint.isExprTypeWithinHierarchy() ? SSRBundle.message("within.hierarchy.tooltip.message") : ""));
- }
-
- if (constraint.getMinCount() == constraint.getMaxCount()) {
- append(buf, SSRBundle.message("occurs.tooltip.message", constraint.getMinCount()));
- }
- else {
- append(buf, SSRBundle.message("min.occurs.tooltip.message", constraint.getMinCount(),
- constraint.getMaxCount() == Integer.MAX_VALUE ?
- StringUtil.decapitalize(SSRBundle.message("editvarcontraints.unlimited")) :
- constraint.getMaxCount()));
- }
- }
-
- final String script = namedScriptableDefinition.getScriptCodeConstraint();
- if (script != null && script.length() > 2) {
- final String str = SSRBundle.message("script.tooltip.message", StringUtil.stripQuotesAroundValue(script));
- append(buf, str);
- }
-
- return buf.toString();
- }
-
- private static void append(final StringBuilder buf, final String str) {
- if (buf.length() > 0) buf.append(", ");
- buf.append(str);
- }
-
- public static void navigate(PsiElement result) {
- FileEditorManager.getInstance(result.getProject()).openTextEditor(
- new OpenFileDescriptor(result.getProject(), result.getContainingFile().getVirtualFile(), result.getTextOffset()), true);
- }
-
- public static void navigate(MatchResult result) {
- final SmartPsiPointer ref = result.getMatchRef();
-
- FileEditorManager.getInstance(ref.getProject())
- .openTextEditor(new OpenFileDescriptor(ref.getProject(), ref.getFile(), ref.getOffset()), true);
- }
-
- public static void invokeAction(Configuration config, SearchContext context) {
- if (config instanceof SearchConfiguration) {
- StructuralSearchAction.triggerAction(config, context);
- }
- else {
- StructuralReplaceAction.triggerAction(config, context);
- }
- }
-
- static void showTooltip(@NotNull Editor editor, final int start, int end, @NotNull String text, @NotNull TooltipGroup group) {
- Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
- Point top = editor.logicalPositionToXY(editor.offsetToLogicalPosition(start));
- final int documentLength = editor.getDocument().getTextLength();
- if (end >= documentLength) end = documentLength;
- Point bottom = editor.logicalPositionToXY(editor.offsetToLogicalPosition(end));
-
- Point bestPoint = new Point(top.x, bottom.y + editor.getLineHeight());
-
- if (!visibleArea.contains(bestPoint)) {
- int defaultOffset = editor.logicalPositionToOffset(editor.xyToLogicalPosition(new Point(0, 0)));
- bestPoint = editor.logicalPositionToXY(editor.offsetToLogicalPosition(defaultOffset));
- }
-
- Point p = SwingUtilities.convertPoint(editor.getContentComponent(), bestPoint, editor.getComponent().getRootPane().getLayeredPane());
- TooltipController.getInstance().showTooltip(editor, p, text, false, group);
- }
-
- public static void updateHighlighter(Editor editor, StructuralSearchProfile profile) {
- final TemplateContextType contextType = profile.getTemplateContextType();
- if (contextType != null) {
- TemplateContext context = new TemplateContext();
- context.setEnabled(contextType, true);
- TemplateEditorUtil.setHighlighter(editor, context);
- }
- }
-}
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UsageViewContext.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UsageViewContext.java
deleted file mode 100644
index a55a16d4c379..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UsageViewContext.java
+++ /dev/null
@@ -1,183 +0,0 @@
-package com.intellij.structuralsearch.plugin.ui;
-
-import com.intellij.navigation.ItemPresentation;
-import com.intellij.openapi.actionSystem.ActionManager;
-import com.intellij.openapi.actionSystem.KeyboardShortcut;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.fileEditor.FileEditor;
-import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.PsiFile;
-import com.intellij.structuralsearch.SSRBundle;
-import com.intellij.structuralsearch.plugin.replace.ui.ReplaceCommand;
-import com.intellij.usages.*;
-import org.jetbrains.annotations.NotNull;
-
-import javax.swing.*;
-import java.util.Set;
-
-/**
- * Created by IntelliJ IDEA.
- * User: Maxim.Mossienko
- * Date: Mar 9, 2005
- * Time: 2:47:49 PM
- * To change this template use File | Settings | File Templates.
- */
-public class UsageViewContext {
- protected final SearchContext mySearchContext;
- private UsageView myUsageView;
- protected final Configuration myConfiguration;
- private Set<Usage> myExcludedSet;
- private SearchCommand myCommand;
-
- protected UsageViewContext(SearchContext _searchContext,Configuration _configuration) {
- myConfiguration = _configuration;
- mySearchContext = _searchContext;
- }
-
- public boolean isExcluded(Usage usage) {
- if (myExcludedSet == null) myExcludedSet = myUsageView.getExcludedUsages();
- return myExcludedSet.contains(usage);
- }
-
- public UsageView getUsageView() {
- return myUsageView;
- }
-
- public void setUsageView(final UsageView usageView) {
- myUsageView = usageView;
- }
-
- public Configuration getConfiguration() {
- return myConfiguration;
- }
-
- public SearchCommand getCommand() {
- if (myCommand == null) myCommand = createCommand();
- return myCommand;
- }
-
- protected SearchCommand createCommand() {
- return new SearchCommand(mySearchContext.getProject(), this);
- }
-
- protected String _getPresentableText() {
- return myConfiguration.getMatchOptions().getSearchPattern();
- }
-
- public UsageTarget getTarget() {
- return new MyUsageTarget(_getPresentableText());
- }
-
- public void configure(@NotNull UsageViewPresentation presentation) {
- String s = _getPresentableText();
- if (s.length() > 15) s = s.substring(0,15) + "...";
- final String usagesString = SSRBundle.message("occurrences.of", s);
- presentation.setUsagesString(usagesString);
- presentation.setTabText(StringUtil.capitalize(usagesString));
- presentation.setUsagesWord(SSRBundle.message("occurrence"));
- presentation.setCodeUsagesString(SSRBundle.message("found.occurrences"));
- }
-
- protected void configureActions() {}
-
- private class MyUsageTarget implements ConfigurableUsageTarget,ItemPresentation {
- private final String myPresentableText;
-
- MyUsageTarget(String str) {
- myPresentableText = str;
- }
-
- @Override
- public String getPresentableText() {
- return myPresentableText;
- }
-
- @Override
- public String getLocationString() {
- //noinspection HardCodedStringLiteral
- return "Do Not Know Where";
- }
-
- @Override
- public Icon getIcon(boolean open) {
- return null;
- }
-
- @Override
- public void findUsages() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void findUsagesInEditor(@NotNull FileEditor editor) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void highlightUsages(@NotNull PsiFile file, @NotNull Editor editor, boolean clearHighlights) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean isValid() {
- return true;
- }
-
- @Override
- public boolean isReadOnly() {
- return true;
- }
-
- @Override
- public VirtualFile[] getFiles() {
- return null;
- }
-
- @Override
- public void update() {
- }
-
- @Override
- public String getName() {
- //noinspection HardCodedStringLiteral
- return "my name";
- }
-
- @Override
- public ItemPresentation getPresentation() {
- return this;
- }
-
- @Override
- public void navigate(boolean requestFocus) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean canNavigate() {
- return false;
- }
-
- @Override
- public boolean canNavigateToSource() {
- return false;
- }
-
- @Override
- public void showSettings() {
- UIUtil.invokeAction(myConfiguration, mySearchContext);
- }
-
- @Override
- public KeyboardShortcut getShortcut() {
- return ActionManager.getInstance().getKeyboardShortcut(getCommand() instanceof ReplaceCommand ? "StructuralSearchPlugin.StructuralReplaceAction":"StructuralSearchPlugin.StructuralSearchAction");
- }
-
- @NotNull
- @Override
- public String getLongDescriptiveName() {
- return _getPresentableText();
- }
- }
-}
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/VarConstraints.form b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/VarConstraints.form
deleted file mode 100644
index 20094b213e64..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/VarConstraints.form
+++ /dev/null
@@ -1,350 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.structuralsearch.plugin.ui.EditVarConstraintsDialog">
- <grid id="53af4" binding="mainForm" layout-manager="GridLayoutManager" row-count="8" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <xy x="24" y="82" width="889" height="681"/>
- </constraints>
- <properties/>
- <border type="none"/>
- <children>
- <grid id="33d30" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <grid row="0" column="0" row-span="8" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties/>
- <clientProperties>
- <BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithoutIndent"/>
- </clientProperties>
- <border type="none" title-resource-bundle="messages/SSRBundle" title-key="var.constraints.variables.border"/>
- <children>
- <grid id="d6a7" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties/>
- <border type="none"/>
- <children>
- <component id="e85ba" class="com.intellij.ui.components.JBList" binding="parameterList">
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
- <preferred-size width="150" height="50"/>
- </grid>
- </constraints>
- <properties/>
- </component>
- </children>
- </grid>
- </children>
- </grid>
- <grid id="4cae8" binding="textConstraintsPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties/>
- <clientProperties>
- <BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
- </clientProperties>
- <border type="none" title-resource-bundle="messages/SSRBundle" title-key="var.constraints.text.constraints.border"/>
- <children>
- <component id="cc210" class="javax.swing.JLabel">
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.text.regular.expression"/>
- </properties>
- </component>
- <component id="3b03c" class="com.intellij.ui.EditorTextField" binding="regexp" custom-create="true">
- <constraints>
- <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
- <preferred-size width="150" height="-1"/>
- </grid>
- </constraints>
- <properties/>
- </component>
- <component id="f7d70" class="javax.swing.JCheckBox" binding="applyWithinTypeHierarchy">
- <constraints>
- <grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.apply.constraint.within.type.hierarchy"/>
- </properties>
- </component>
- <component id="b766f" class="javax.swing.JCheckBox" binding="notRegexp">
- <constraints>
- <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.invert.condition"/>
- </properties>
- </component>
- <component id="51cbf" class="javax.swing.JCheckBox" binding="wholeWordsOnly">
- <constraints>
- <grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.whole.words.only"/>
- </properties>
- </component>
- </children>
- </grid>
- <grid id="bb81f" binding="expressionConstraints" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties/>
- <clientProperties>
- <BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
- </clientProperties>
- <border type="none" title-resource-bundle="messages/SSRBundle" title-key="var.constraints.expression.constraints.border"/>
- <children>
- <component id="2bdb4" class="javax.swing.JCheckBox" binding="read">
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.value.is.read"/>
- </properties>
- </component>
- <component id="aba7e" class="javax.swing.JCheckBox" binding="write">
- <constraints>
- <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.value.is.written"/>
- </properties>
- </component>
- <component id="5698c" class="javax.swing.JCheckBox" binding="notRead">
- <constraints>
- <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.invert.condition"/>
- </properties>
- </component>
- <component id="79e72" class="javax.swing.JCheckBox" binding="notWrite">
- <constraints>
- <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.invert.condition"/>
- </properties>
- </component>
- <component id="e9391" class="com.intellij.ui.EditorTextField" binding="regexprForExprType" custom-create="true">
- <constraints>
- <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
- <preferred-size width="150" height="-1"/>
- </grid>
- </constraints>
- <properties/>
- </component>
- <component id="59512" class="javax.swing.JCheckBox" binding="exprTypeWithinHierarchy">
- <constraints>
- <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.apply.constraint.within.type.hierarchy"/>
- </properties>
- </component>
- <component id="17342" class="javax.swing.JCheckBox" binding="notExprType">
- <constraints>
- <grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.invert.condition"/>
- </properties>
- </component>
- <component id="4d6d0" class="javax.swing.JLabel">
- <constraints>
- <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.text.regular.expression.for.java.expression.type"/>
- </properties>
- </component>
- <component id="a97fa" class="javax.swing.JLabel">
- <constraints>
- <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.text.regular.expression.for.formal.argument.type.of.the.method"/>
- </properties>
- </component>
- <component id="d02c2" class="com.intellij.ui.EditorTextField" binding="formalArgType" custom-create="true">
- <constraints>
- <grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
- <preferred-size width="150" height="-1"/>
- </grid>
- </constraints>
- <properties/>
- </component>
- <component id="bc6d0" class="javax.swing.JCheckBox" binding="invertFormalArgType">
- <constraints>
- <grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.invert.condition"/>
- </properties>
- </component>
- <component id="2b0ea" class="javax.swing.JCheckBox" binding="formalArgTypeWithinHierarchy">
- <constraints>
- <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.apply.constraint.within.type.hierarchy"/>
- </properties>
- </component>
- </children>
- </grid>
- <component id="9a3a8" class="javax.swing.JCheckBox" binding="partOfSearchResults">
- <constraints>
- <grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.this.variable.is.target.of.the.search"/>
- </properties>
- </component>
- <vspacer id="d06dd">
- <constraints>
- <grid row="7" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
- </constraints>
- </vspacer>
- <grid id="2a918" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <grid row="5" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties/>
- <border type="none"/>
- <children>
- <grid id="964fd" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties/>
- <clientProperties>
- <BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
- </clientProperties>
- <border type="none" title-resource-bundle="messages/SSRBundle" title-key="var.constraints.script.constraints.border"/>
- <children>
- <component id="cdf9" class="javax.swing.JLabel">
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="script.option.text"/>
- </properties>
- </component>
- <component id="e7633" class="com.intellij.openapi.ui.ComponentWithBrowseButton" binding="customScriptCode" custom-create="true">
- <constraints>
- <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
- <preferred-size width="150" height="-1"/>
- </grid>
- </constraints>
- <properties/>
- </component>
- </children>
- </grid>
- </children>
- </grid>
- <grid id="d8664" binding="occurencePanel" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties/>
- <clientProperties>
- <BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
- </clientProperties>
- <border type="none" title-resource-bundle="messages/SSRBundle" title-key="var.constraints.occurrences.count.border"/>
- <children>
- <component id="e4b4a" class="javax.swing.JLabel">
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.minimum.count"/>
- </properties>
- </component>
- <component id="f6a1a" class="javax.swing.JTextField" binding="minoccurs">
- <constraints>
- <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
- <preferred-size width="50" height="-1"/>
- <maximum-size width="50" height="-1"/>
- </grid>
- </constraints>
- <properties>
- <text value="1"/>
- </properties>
- </component>
- <component id="881e7" class="javax.swing.JLabel">
- <constraints>
- <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.maximum.count"/>
- </properties>
- </component>
- <component id="42" class="javax.swing.JTextField" binding="maxoccurs">
- <constraints>
- <grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
- <preferred-size width="50" height="-1"/>
- </grid>
- </constraints>
- <properties>
- <columns value="0"/>
- <text value="1"/>
- </properties>
- </component>
- <component id="7c33b" class="javax.swing.JCheckBox" binding="maxoccursUnlimited">
- <constraints>
- <grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.unlimited"/>
- </properties>
- </component>
- </children>
- </grid>
- <grid id="463bd" binding="containedInConstraints" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties/>
- <clientProperties>
- <BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
- </clientProperties>
- <border type="none" title="Contained in constraints"/>
- <children>
- <component id="7003f" class="com.intellij.ui.ComboboxWithBrowseButton" binding="withinCombo">
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties/>
- </component>
- <component id="896c2" class="javax.swing.JCheckBox" binding="invertWithinIn">
- <constraints>
- <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="messages/SSRBundle" key="editvarcontraints.invert.condition"/>
- </properties>
- </component>
- </children>
- </grid>
- <component id="ce461" class="javax.swing.JLabel" binding="myRegExHelpLabel" custom-create="true">
- <constraints>
- <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties/>
- </component>
- </children>
- </grid>
-</form>
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/actions/DoSearchAction.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/actions/DoSearchAction.java
deleted file mode 100644
index ed0da3a3f391..000000000000
--- a/plugins/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/actions/DoSearchAction.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.intellij.structuralsearch.plugin.ui.actions;
-
-import com.intellij.structuralsearch.plugin.ui.Configuration;
-import com.intellij.structuralsearch.*;
-import com.intellij.openapi.project.Project;
-
-/**
- * Does the search action
- */
-public class DoSearchAction {
- public static void execute(final Project project, MatchResultSink sink,
- final Configuration configuration) {
- final MatchOptions options = configuration.getMatchOptions();
-
- final Matcher matcher = new Matcher(project);
- try {
- matcher.findMatches(sink, options);
- }
- finally {
- sink.matchingFinished();
- }
- }
-
-}