Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure left search results panel is always visible. #8088

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.AbstractButton;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import org.netbeans.modules.search.BasicComposition;
import org.netbeans.modules.search.ContextView;
import org.netbeans.modules.search.FindDialogMemory;
import org.netbeans.modules.search.Manager;
import org.netbeans.modules.search.ReplaceTask;
import org.netbeans.modules.search.ResultModel;
Expand All @@ -43,55 +40,44 @@
import org.openide.nodes.Node;
import org.openide.util.Mutex;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;

/**
*
* @author jhavlin
*/
public class BasicReplaceResultsPanel extends BasicAbstractResultsPanel {
public class BasicReplaceResultsPanel extends BasicSearchResultsPanel {

private static final RequestProcessor RP =
new RequestProcessor(BasicReplaceResultsPanel.class.getName());
private final RequestProcessor.Task SAVE_TASK = RP.create(new SaveTask());
private JButton replaceButton;
private JSplitPane splitPane;

public BasicReplaceResultsPanel(ResultModel resultModel,
BasicComposition composition, Node infoNode) {
super(resultModel, composition, true,
new ResultsOutlineSupport(true, true, resultModel, composition,
infoNode));
init();

public BasicReplaceResultsPanel(ResultModel resultModel, BasicComposition composition, Node infoNode) {
super(resultModel, composition, true,
new ResultsOutlineSupport(true, true, resultModel, composition, infoNode));
}

private void init() {
JPanel leftPanel = new JPanel();
@Override
protected JComponent createLeftComponent() {
replaceButton = new JButton();
replaceButton.addActionListener((ActionEvent e) -> replace());
replaceButton.setMaximumSize(replaceButton.getPreferredSize());
replaceButton.getAccessibleContext().setAccessibleDescription(
NbBundle.getMessage(ResultView.class,
"ACS_TEXT_BUTTON_REPLACE")); //NOI18N
updateReplaceButton();
leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));

JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.LEADING, 2, 1));
buttonPanel.add(replaceButton);
replaceButton.setMaximumSize(replaceButton.getPreferredSize());
buttonPanel.setMaximumSize(new Dimension( // #225246
(int) buttonPanel.getMaximumSize().getWidth(),
(int) buttonPanel.getPreferredSize().getHeight()));

JPanel leftPanel = new JPanel();
leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
leftPanel.add(resultsOutlineSupport.getOutlineView());
leftPanel.add(buttonPanel);

this.splitPane = new JSplitPane();
splitPane.setLeftComponent(leftPanel);
splitPane.setRightComponent(new ContextView(resultModel,
getExplorerManager()));
initSplitDividerLocationHandling();

getContentPanel().add(splitPane);

initResultModelListener();
replaceButton.getAccessibleContext().setAccessibleDescription(
NbBundle.getMessage(ResultView.class,
"ACS_TEXT_BUTTON_REPLACE")); //NOI18N
return leftPanel;
}

private void replace() {
Expand All @@ -107,19 +93,6 @@ private void initResultModelListener() {
resultModel.addPropertyChangeListener(new ModelListener());
}

private void initSplitDividerLocationHandling() {
int location = FindDialogMemory.getDefault().getReplaceResultsDivider();
if (location > 0) {
splitPane.setDividerLocation(location);
}
splitPane.addPropertyChangeListener((PropertyChangeEvent evt) -> {
String pn = evt.getPropertyName();
if (pn.equals(JSplitPane.DIVIDER_LOCATION_PROPERTY)) {
SAVE_TASK.schedule(1000);
}
});
}

@Override
public void searchFinished() {
super.searchFinished();
Expand Down Expand Up @@ -226,14 +199,4 @@ public void showFinishedInfo() {
});
}

private class SaveTask implements Runnable {

@Override
public void run() {
if (splitPane != null) {
FindDialogMemory.getDefault().setReplaceResultsDivider(
splitPane.getDividerLocation());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
*/
package org.netbeans.modules.search.ui;

import java.beans.PropertyChangeEvent;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JComponent;
import javax.swing.JSplitPane;
import org.netbeans.modules.search.BasicComposition;
import org.netbeans.modules.search.ContextView;
Expand All @@ -34,51 +32,37 @@
* @author jhavlin
*/
public class BasicSearchResultsPanel extends BasicAbstractResultsPanel {
private final RequestProcessor.Task SAVE_TASK = RequestProcessor.getDefault().create(new BasicSearchResultsPanel.SaveTask());
private JSplitPane splitPane;

public BasicSearchResultsPanel(ResultModel resultModel,
BasicComposition composition, boolean details, Node infoNode) {
super(resultModel, composition, details,
new ResultsOutlineSupport(false, details, resultModel,
composition, infoNode));
init();
public BasicSearchResultsPanel(ResultModel resultModel, BasicComposition composition, boolean details, Node infoNode) {
this(resultModel, composition, details,
new ResultsOutlineSupport(false, details, resultModel, composition, infoNode));
}

private void init() {
JPanel leftPanel = new JPanel();
leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
leftPanel.add(resultsOutlineSupport.getOutlineView());
BasicSearchResultsPanel(ResultModel resultModel, BasicComposition composition, boolean details, ResultsOutlineSupport resultsOutlineSupport) {
super(resultModel, composition, details, resultsOutlineSupport);

this.splitPane = new JSplitPane();
splitPane.setLeftComponent(leftPanel);
splitPane.setRightComponent(new ContextView(resultModel,
getExplorerManager()));
initSplitDividerLocationHandling();
JSplitPane splitPane = new JSplitPane();
splitPane.setLeftComponent(createLeftComponent());
splitPane.setRightComponent(createRightComponent());
getContentPanel().add(splitPane);
}

private void initSplitDividerLocationHandling() {
// divider persistance
RequestProcessor.Task dividerSaveTask = RequestProcessor.getDefault().create(() ->
FindDialogMemory.getDefault().setReplaceResultsDivider(splitPane.getDividerLocation())
);
int location = FindDialogMemory.getDefault().getReplaceResultsDivider();
if (location > 0) {
splitPane.setDividerLocation(location);
}
splitPane.addPropertyChangeListener((PropertyChangeEvent evt) -> {
String pn = evt.getPropertyName();
if (pn.equals(JSplitPane.DIVIDER_LOCATION_PROPERTY)) {
SAVE_TASK.schedule(1000);
}
});
splitPane.setDividerLocation(Math.max(location, 250));
splitPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, e ->
dividerSaveTask.schedule(1000)
);
}

private class SaveTask implements Runnable {
protected JComponent createLeftComponent() {
return resultsOutlineSupport.getOutlineView();
}

@Override
public void run() {
if (splitPane != null) {
FindDialogMemory.getDefault().setReplaceResultsDivider(
splitPane.getDividerLocation());
}
}
protected JComponent createRightComponent() {
return new ContextView(resultModel, getExplorerManager());
}

}
Loading