JPanel () { // 'Search template:' label final JBLabel searchTemplateLabel = new JBLabel(SSRBundle.message("search.template")); // File type chooser myFileType = UIUtil.detectFileType(mySearchContext); myDialect = myFileType.getLanguage(); final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(myFileType); if (profile != null) { final List<PatternContext> contexts = profile.getPatternContexts(); if (!contexts.isEmpty()) { myPatternContext = contexts.get(0); } } myFileTypeChooser.setSelectedItem(myFileType, myDialect, myPatternContext); myFileTypeChooser.setFileTypeInfoConsumer(info -> { myFileType = info.getFileType(); myDialect = info.getDialect(); myPatternContext = info.getContext(); final MatchOptions matchOptions = myConfiguration.getMatchOptions(); matchOptions.setFileType(myFileType); matchOptions.setDialect(myDialect); matchOptions.setPatternContext(myPatternContext); myOptionsToolbar.updateActionsImmediately(); myFilterPanel.setFileType(myFileType); final String contextId = (myPatternContext == null) ? "" : myPatternContext.getId(); final StructuralSearchProfile profile1 = StructuralSearchUtil.getProfileByFileType(myFileType); final Document searchDocument = UIUtil.createDocument(myProject, myFileType, myDialect, myPatternContext, mySearchCriteriaEdit.getText(), profile1); searchDocument.addDocumentListener(this, myDisposable); mySearchCriteriaEdit.setNewDocumentAndFileType((myFileType == null) ? PlainTextFileType.INSTANCE : myFileType, searchDocument); searchDocument.putUserData(STRUCTURAL_SEARCH_PATTERN_CONTEXT_ID, contextId); final Document replaceDocument = UIUtil.createDocument(myProject, myFileType, myDialect, myPatternContext, myReplaceCriteriaEdit.getText(), profile1); replaceDocument.addDocumentListener(this, myDisposable); myReplaceCriteriaEdit.setNewDocumentAndFileType((myFileType == null) ? PlainTextFileType.INSTANCE : myFileType, replaceDocument); replaceDocument.putUserData(STRUCTURAL_SEARCH_PATTERN_CONTEXT_ID, contextId); updateOptions(); initValidation(); }); myFileTypeChooser.setUserActionFileTypeInfoConsumer(info -> { myExistingTemplatesComponent.selectFileType(info.getFileType()); }); // Existing templates action final AnAction showTemplatesAction = new DumbAwareToggleAction(SSRBundle.message("templates.button"), SSRBundle.message("templates.button.description"), AllIcons.Actions.PreviewDetails) { @Override public @NotNull ActionUpdateThread getActionUpdateThread() { return ActionUpdateThread.EDT; } @Override public boolean isSelected(@NotNull AnActionEvent e) { return isExistingTemplatesPanelVisible(); } @Override public void setSelected(@NotNull AnActionEvent e, boolean state) { setExistingTemplatesPanelVisible(state); } }; // Filter action final BadgeIconSupplier filterIcon = new BadgeIconSupplier(AllIcons.General.Filter); final AnAction filterAction = new DumbAwareToggleAction(SSRBundle.message("filter.button"), SSRBundle.message("filter.button.description"), filterIcon.getLiveIndicatorIcon(true)) { @Override public @NotNull ActionUpdateThread getActionUpdateThread() { return ActionUpdateThread.EDT; } @Override public void update(@NotNull AnActionEvent e) { super.update(e); final Presentation presentation = e.getPresentation(); presentation.setIcon(filterIcon.getLiveIndicatorIcon(myFilterPanel.hasVisibleFilter())); } @Override public boolean isSelected(@NotNull AnActionEvent e) { return isFilterPanelVisible(); } @Override public void setSelected(@NotNull AnActionEvent e, boolean state) { setFilterPanelVisible(state); } }; // Filter panel myFilterPanel = new FilterPanel(myProject, myFileType, getDisposable()); myFilterPanel.setConstraintChangedCallback(() -> initValidation()); myFilterPanel.getComponent().setMinimumSize(new Dimension(300, 50)); // Pin action final DumbAwareToggleAction pinAction = new DumbAwareToggleAction(SSRBundle.message("pin.button"), SSRBundle.message("pin.button.description"), AllIcons.General.Pin_tab) { @Override public @NotNull ActionUpdateThread getActionUpdateThread() { return ActionUpdateThread.BGT; } @Override public boolean isSelected(@NotNull AnActionEvent e) { return myPinned; } @Override public void setSelected(@NotNull AnActionEvent e, boolean state) { myPinned = state; } @Override public void update(@NotNull AnActionEvent e) { super.update(e); e.getPresentation().setEnabledAndVisible(!myEditConfigOnly); } }; final DefaultActionGroup optionsActionGroup = new DefaultActionGroup(myFileTypeChooser, showTemplatesAction, filterAction, new Separator(), pinAction, new SwitchAction()); final ActionManager actionManager = ActionManager.getInstance(); myOptionsToolbar = (ActionToolbarImpl)actionManager.createActionToolbar("StructuralSearchDialog", optionsActionGroup, true); myOptionsToolbar.setTargetComponent(mySearchCriteriaEdit); myOptionsToolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY); myOptionsToolbar.setForceMinimumSize(true); myOptionsToolbar.setBorder(JBUI.Borders.empty(DEFAULT_VGAP, 0)); // Search editor panel, 1st splitter element final var searchEditorPanel = new JPanel(new GridBagLayout()); // Search panel options myTargetComboBox = new LinkComboBox(SSRBundle.message("complete.match.variable.name")); myTargetComboBox.setItemConsumer(item -> { final MatchOptions matchOptions = myConfiguration.getMatchOptions(); for (String name : matchOptions.getVariableConstraintNames()) { matchOptions.getVariableConstraint(name).setPartOfSearchResults(name.equals(item)); } initValidation(); }); final String text = SSRBundle.message("search.target.label"); final JLabel searchTargetLabel = new JLabel(text); myTargetComboBox.setLabel(searchTargetLabel); myInjected = new JBCheckBox(SSRBundle.message("search.in.injected.checkbox")); myInjected.setOpaque(false); myInjected.addActionListener(e -> { myConfiguration.getMatchOptions().setSearchInjectedCode(myInjected.isSelected()); initValidation(); }); myInjected.setVisible(!myEditConfigOnly); myMatchCase = new JBCheckBox(FindBundle.message("find.popup.case.sensitive")); myMatchCase.setOpaque(false); myMatchCase.addActionListener(e -> { myConfiguration.getMatchOptions().setCaseSensitiveMatch(myMatchCase.isSelected()); initValidation(); }); // Splitter mySearchEditorPanel = new OnePixelSplitter(false, 1.0f); mySearchEditorPanel.setLackOfSpaceStrategy(Splitter.LackOfSpaceStrategy.HONOR_THE_SECOND_MIN_SIZE); mySearchCriteriaEdit = createEditor(false); mySearchEditorPanel.setFirstComponent(searchEditorPanel); myComponentsWithEditorBackground.add(searchEditorPanel); // Wrapper mySearchWrapper = new JPanel(new BorderLayout()); // needed for border mySearchWrapper.add(mySearchEditorPanel, BorderLayout.CENTER); final var searchConstraint = new GridBag().setDefaultInsets(DEFAULT_VGAP, DEFAULT_HGAP, DEFAULT_VGAP, 0); searchEditorPanel.add(mySearchCriteriaEdit, searchConstraint .nextLine().fillCell().coverLine() .weightx(1.0).weighty(1.0) .emptyInsets()); searchEditorPanel.add(searchTargetLabel, searchConstraint.nextLine()); searchEditorPanel.add(myTargetComboBox, searchConstraint); searchEditorPanel.add(myInjected, searchConstraint); searchEditorPanel.add(myMatchCase, searchConstraint.anchor(WEST).insetRight(DEFAULT_HGAP)); mySearchEditorPanel.setSecondComponent(myFilterPanel.getComponent()); myComponentsWithEditorBackground.add(myFilterPanel.getTable()); final JPanel searchPanel = new JPanel(new GridBagLayout()); final var northConstraint = new GridBag().setDefaultWeightX(1.0); searchPanel.add(searchTemplateLabel, northConstraint.nextLine().weightx(0.0).insets(JBInsets.create(0, DEFAULT_HGAP))); searchPanel.add(myOptionsToolbar, northConstraint.anchor(EAST)); searchPanel.add(mySearchWrapper, northConstraint.nextLine().coverLine().fillCell().emptyInsets().weighty(1.0)); return searchPanel; }