📄 searchgui.java
字号:
package com.ca.directory.jxplorer.search;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import com.ca.directory.jxplorer.*;
import com.ca.commons.naming.*;
import com.ca.commons.cbutil.*;
/**
* This class creates a dialog that has currently three tabs on it. The first one is for
* creating or building filters, the second on is for joining already created filters and the third
* one allows the user to enter or paste in a text filter. This class acts as a
* a controller between the view (build, join & text tabs) and the model (SearchModel) as well as being a part of
* the view itself.
* <p>
* This class, in brief, sets up a search dialog that can be used to build, load, view, edit, join or save filters aswell
* as search an LDAP directory with the filter that the user has created.
* @author Trudi.
*/
public class SearchGUI extends CBDialog
{
final JXplorer jx;
protected JTabbedPane tabbedPane;
JCheckBox aliasSearchCheckBox, aliasFindingCheckBox;
JTextField baseDNTextField, filterNameTextField;
CBJComboBox andOrCombo, searchLevelCombo, returnAttributesCombo;
static final String[] andOrArray = new String[] {CBIntText.get("And"), CBIntText.get("Or")};
static final String[] searchLevelArray = new String[] {CBIntText.get("Search Base Object"), CBIntText.get("Search Next Level"), CBIntText.get("Search Full Subtree"),};
static final int BASEOBJECTSEARCH=0, ONELEVELSEARCH=1, FULLSUBTREESEARCH=2;
CBButton btnSave, btnLoad, btnMore, btnLess, btnView;
BuildFilterPanel build;
JoinFilterPanel join;
TextFilterPanel text;
SearchModel searchModel;
String buildName = "Untitled", joinName = "Untitled", textName = "Untitled", dirImages;
CBButton[] btnEdit = new CBButton[50];
int buttonCounter = 0; //TE: a counter that keeps track of the number of created 'edit' buttons and is used when recalling buttons from the button array..
String[] returnAttrs = null;
private static Logger log = Logger.getLogger(SearchGUI.class.getName());
//private static ReturnAttributesDisplay rat = null;
/**
* Contructor that sets up the display and initiates the main search objects: SearchModel,
* BuildFilterPanel, JoinFilterPanel and TextFilterPanel.
* @param baseDN the DN of the currently selected entry (i.e. unless changed is where the search will be conducted from).
* @param jxplorer JXplorer.
*/
public SearchGUI(DN baseDN, JXplorer jxplorer)
{
super(jxplorer, CBIntText.get("Search"), HelpIDs.SEARCH);
jx = jxplorer;
dirImages = JXplorer.getProperty("dir.images");
build = new BuildFilterPanel(jx);
join = new JoinFilterPanel(getEditButton());
text = new TextFilterPanel();
buttonCounter++;
searchModel = new SearchModel();
CBPanel panel = getMainPanel(baseDN);
tabbedPane = new JTabbedPane();
tabbedPane.addTab(CBIntText.get("Build Filter"), new ImageIcon(dirImages+"build.gif"), build, CBIntText.get("Build a filter from scratch."));
tabbedPane.addTab(CBIntText.get("Join Filters"), new ImageIcon(dirImages+"join.gif"), join, CBIntText.get("Join filters that have been made in the Build tab."));
tabbedPane.addTab(CBIntText.get("Text Filter"), new ImageIcon(dirImages+"text.gif"), text, CBIntText.get("Type or paste a filter into the field in plain text."));
OK.setText(CBIntText.get("Search"));
display.makeHeavy();
display.addln(panel);
display.add(tabbedPane);
display.makeLight();
display.add(getButtonPanel());
CBButton btnAttrs = new CBButton(CBIntText.get("Return Attrs"), CBIntText.get("Select Returning Attributes."));
btnAttrs.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
ArrayList list = CBListSelector.getSelectedValues(jx, build.getAttributes(), CBIntText.get("Select Returning Attributes"), HelpIDs.SEARCH);
if(list!=null)
returnAttrs = (String[])list.toArray(new String[list.size()]);
}});
setSize(550, 400);
CBUtility.center(this, jx);
/**
* This change listener is intended to listen for tab changes.
* Updates the filter name as the user flicks between tabs &
* enables or disables the controller buttons depending on which
* tab is visible.
*/
tabbedPane.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent e)
{
int index = tabbedPane.getSelectedIndex();
if (index == 0)
{
filterNameTextField.setText(buildName);
setButtons(true);
}
else if (index == 1)
{
filterNameTextField.setText(joinName);
setButtons(true);
}
else if (index ==2)
{
filterNameTextField.setText(textName);
setButtons(false);
}
}
});
}
/**
* Sets up a panel with the components which display the name of the filter, the base DN,
* aliase prefs, search level prefs and the button panel.
* @param baseDN the Distinguished Name where the searching is done from. This is added to a text field on this panel.
* @return the panel with the components added.
*/
public CBPanel getMainPanel(DN baseDN)
{
CBPanel panel = new CBPanel();
//TE: adds a label & text field for the name of the filter...
panel.add(new JLabel(CBIntText.get("Filter Name") + ": "));
panel.makeWide();
panel.add(filterNameTextField = new JTextField("Untitled"));
panel.makeLight();
panel.newLine();
//TE: adds a label & text field for the name of the DN being searched from...
panel.add(new JLabel(CBIntText.get("Start Searching From") + ": "));
panel.makeWide();
if(baseDN == null)
panel.add(baseDNTextField = new JTextField(""));
else
panel.add(baseDNTextField = new JTextField(baseDN.toString()));
panel.makeLight();
panel.newLine();
CBPanel optionsPanel = new CBPanel(); //TE: panel for adding the alias & search level panels to (for layout).
//TE: alias check boxes...
CBPanel aliasPanel = new CBPanel();
aliasPanel.setBorder(new TitledBorder(CBIntText.get(" Alias Options ")));
aliasPanel.makeWide();
aliasPanel.addln(aliasSearchCheckBox = new JCheckBox(CBIntText.get("Resolve aliases while searching.")));
aliasSearchCheckBox.setToolTipText(CBIntText.get("Resolve aliases while searching."));
aliasPanel.addln(aliasFindingCheckBox = new JCheckBox(CBIntText.get("Resolve aliases when finding base object.")));
aliasFindingCheckBox.setToolTipText(CBIntText.get("Resolve aliases when finding base object."));
//TE: search level combo...
CBPanel searchLevelPanel = new CBPanel();
searchLevelPanel.setBorder(new TitledBorder(CBIntText.get(" Search Level ")));
searchLevelPanel.addln(new JLabel(CBIntText.get("Select Search Level: ")));
searchLevelPanel.makeWide();
searchLevelPanel.addln(searchLevelCombo = new CBJComboBox(searchLevelArray));
searchLevelCombo.setSelectedIndex(FULLSUBTREESEARCH);
//TE: put the alias & search level panels on the options panel then add the options panel to the main panel...
optionsPanel.add(aliasPanel);
optionsPanel.makeWide();
optionsPanel.addln(searchLevelPanel);
panel.makeWide();
panel.addln(optionsPanel);
//TE: return attributes combo...
CBPanel returnAttrsPanel = new CBPanel();
returnAttributesCombo = new CBJComboBox(ReturnAttributesDialog.getSavedListNames());
returnAttributesCombo.setSelectedItem(ReturnAttributesDialog.DEFAULT_RETURN_ATTRS);
returnAttrsPanel.makeLight();
returnAttrsPanel.add(new JLabel(CBIntText.get("Information to retrieve: ")));
returnAttrsPanel.makeWide();
returnAttrsPanel.addln(returnAttributesCombo);
panel.addln(returnAttrsPanel);
return panel;
}
/**
* Sets the base DN in the base DN text field.
* @param baseDN the DN to search from.
*/
public void setBaseDN(DN baseDN)
{
if(baseDN != null)
baseDNTextField.setText(baseDN.toString());
}
/**
* Returns a panel with four buttons on it: More, Less, Save & View. The buttons are set up
* with listeners and are placed one above the other.
* @return the panel with the buttons on it.
*/
public CBPanel getButtonPanel()
{
CBPanel panel = new CBPanel();
btnMore = new CBButton(CBIntText.get("More"), CBIntText.get("Add a Line to the search window."));
btnMore.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if (isFilterValid())
{
if (tabbedPane.getSelectedIndex()==0) //TE: make sure that you are adding rows to the tab that is visible, not to both tabs!
{
build.addFilterRow();
}
else if (tabbedPane.getSelectedIndex()==1 && buttonCounter<50)
{
join.addFilterRow(getEditButton());
buttonCounter++; //TE: a counter that keeps track of the number of created 'edit' buttons.
}
}
else
{
showMessage(CBIntText.get("There is an error in the filter; there appears to be missing information.\nPlease make sure you have entered all the information for the filter correctly,\nthen try to add more rows."), CBIntText.get("Missing Information"));
}
}});
btnLess = new CBButton(CBIntText.get("Less"), CBIntText.get("Remove a Line from the search window."));
btnLess.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if (tabbedPane.getSelectedIndex()==0) //TE: make sure that you are removing rows from the tab that is visible, not from both tabs!
{
build.removeFilterRow();
}
else if (tabbedPane.getSelectedIndex()==1 && buttonCounter>1)
{
buttonCounter--;
join.removeFilterRow(btnEdit[buttonCounter]);
}
}});
btnSave = new CBButton(CBIntText.get("Save"), CBIntText.get("Save this filter."));
btnSave.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if (isFilterValid())
save();
else
showMessage(CBIntText.get("The filter cannot be constructed; there appears to be missing information.\nPlease make sure you have entered all the information for the filter correctly."), CBIntText.get("Missing Information"));
}});
btnLoad = new CBButton(CBIntText.get("Load"), CBIntText.get("Load a previously saved filter."));
btnLoad.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(tabbedPane.getSelectedIndex()==0)
loadBuild();
else if(tabbedPane.getSelectedIndex()==1)
loadJoin();
else if(tabbedPane.getSelectedIndex()==2)
loadText();
}});
btnView = new CBButton(CBIntText.get("View"), CBIntText.get("View this search filter as text."));
btnView.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if (!isFilterValid())
showMessage(CBIntText.get("The filter cannot be constructed; there appears to be missing information.\nPlease make sure you have entered all the information for the filter correctly."), CBIntText.get("Missing Information"));
else if(tabbedPane.getSelectedIndex()==1 && recursiveFilterCheck(null, join.getFilter(), "View")) // We don't care about the name of this filter b/c we are just viewing it.
return;
else
showDialog(CBIntText.get("Current Filter"), getLDAPFilter());
}});
panel.makeHigh(); //TE: add a label that it takes up the any remaining space above the buttons, so that the buttons are at the bottom of the panel.
panel.addln(new JLabel(" "));
panel.makeLight();
panel.addln(btnMore);
panel.addln(btnLess);
panel.addln(btnSave);
panel.addln(btnLoad);
panel.addln(btnView);
return panel;
}
/**
* Enables or disables the More, Less and View buttons. We basically don't
* want these buttons enabled if the user has selected the Text Filter tab.
* @param state the state of the buttons (enabled=true or disabled=false).
*/
protected void setButtons(boolean state)
{
btnMore.setEnabled(state);
btnLess.setEnabled(state);
btnView.setEnabled(state);
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -