📄 searchgui.java
字号:
* Displays a JOptionPane message with a text area containing the current filter.
* The text area is set to do line wrapping and only vertical scrolling.
* @param title the heading of the dialog that appears in the title bar.
* @param filter the current LDAP filter (or any string to be displayed).
*/
protected void showDialog(String title, String filter)
{
JTextArea area = new JTextArea(filter);
area.setLineWrap(true);
area.setWrapStyleWord(true);
JScrollPane scrollPane = new JScrollPane(area);
scrollPane.setPreferredSize(new Dimension(300,60));
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JOptionPane.showMessageDialog(this, scrollPane, title, JOptionPane.INFORMATION_MESSAGE);
}
/**
* Returns an edit button, i.e. a button labelled "Edit", has a dimension of 55x21, has a tooltip "Edit
* this filter.", and has an action listener that calls the edit method with it's position (or row number).
* @return the configured button.
*/
protected CBButton getEditButton()
{
btnEdit[buttonCounter] = new CBButton(CBIntText.get("Edit"), CBIntText.get("Edit this filter."));
btnEdit[buttonCounter].setPreferredSize(new Dimension(55,21));
btnEdit[buttonCounter].addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
CBButton item = (CBButton)e.getSource();
for(int i=0; i<buttonCounter; i++)
{
if (item == btnEdit[i])
edit(i);
}
}
});
return btnEdit[buttonCounter];
}
/**
* Displays the filter(s) corresponding to the edit button that the user has selected.
* The edit buttons live on the join panel. If a user wants to edit a raw filter the raw filter
* is displayed in the build panel otherwise if the user wants to edit a filter that is a combination
* of filters, the filter is displayed in the join panel.
* @param row the row number that the filter name is to be taken from.
*/
protected void edit(int row)
{
ArrayList list = searchModel.getFilterNames(SearchModel.BUILDFILTER); //TE: get all the raw filter names.
String filter = join.getFilterComboValue(row);
if (filter==null) //TE: will equal null if nothing to edit.
{
showMessage(CBIntText.get("There are no filters available to edit"), CBIntText.get("Nothing to Edit"));
return;
}
else
{
try
{
if (list.contains(filter)) //TE: the filter is a raw filter which needs to be displayed in the build filter panel.
{
buildName = filter; //TE: set the global variable so that the correct name of the filter is displayed when tabs are changed.
tabbedPane.setSelectedIndex(0); //TE: change tabs.
build.displayFilter(searchModel.getFilter(filter)); //TE: send the raw filter off to get displayed.
}
else //TE: the filter is a combination of filters which need to be displayed in the join filter panel.
{
String value = searchModel.getFilter(filter); //TE: get the value of the filter.
setNumberOfRows(build.getOccurrences(searchModel.getFilter(filter), "JXFilter")); //TE: ...set up that many number of rows.
ArrayList aList = searchModel.getJoinFilterNames(value); //TE: get the names of these filters.
if (!join.displayFilter(aList, value))
{
showMessage(CBIntText.get("Your filter cannot be edited."), CBIntText.get("Edit Unsuccessful"));
}
else
{
joinName = filter;
filterNameTextField.setText(joinName); //TE: set the global variable so that the correct name of the filter is displayed.
}
}
}
catch(Exception e) //TE: the user has somehow selected nothing in either the attribute or the function combo.
{
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"));
return;
}
}
}
/**
* Currently used by the loadJoin() and edit() methods to prompt the JoinFilterPanel class to either add or remove
* rows. If adding rows is required, the extra number of edit buttons are created before the hand-balling goes off
* to the JoinFilterPanel class.
* @param rows the number of rows that need to be added.
*/
protected void setNumberOfRows(int rows)
{
if (buttonCounter > rows) //TE: if there are more buttons than rows required...
{
while (buttonCounter > rows) //TE: ...delete these buttons and any other components on that row until the correct number of rows are displayed.
{
buttonCounter--; //TE: make sure the button counter is updated.
join.removeFilterRow(btnEdit[buttonCounter]);
}
}
else if (buttonCounter < rows) //TE: if there are less buttons than rows required...
{
while (buttonCounter < rows) //TE: ...create and add these buttons and any other required components on that row until the correct number of rows are displayed.
{
join.addFilterRow(getEditButton());
buttonCounter++; //TE: make sure the button counter is updated.
}
}
}
/**
* Save the filter to the property file 'search_filter.txt". Checks first to see if the filter exists. If
* it does a JOptionPane message asks the user if they want to replace it. If the filter is saved successfully
* a confirmation message is displayed again using JOptionPane. This also updates the filter combo of the join
* tab so that a user can see changes straight away.
*/
protected void save()
{
String name = filterNameTextField.getText(); //TE: get the user defined name for the filter.
boolean exists = false; //TE: true if the name exists, false otherwise.
if (name == null || name.trim().length()<=0 || name.equalsIgnoreCase("Untitled"))
{
showMessage(CBIntText.get("Please enter a name in the 'Filter Name' field for the filter that you are trying to save."), CBIntText.get("Name Required"));
return;
}
else if (name.startsWith("JXFilter"))
{
showMessage(CBIntText.get("The name ''{0}'' is a reserved name. Please enter a different name.", new String[] {name}), CBIntText.get("Naming Error"));
return;
}
if (searchModel.exists(name)) //TE: if the name exists ask the user if they want to replace it...
{
int response = JOptionPane.showConfirmDialog(this, CBIntText.get("The name ''{0}'' already exists. Do you want to replace it?", new String[] { name }),
CBIntText.get("Select Filter"), JOptionPane.YES_NO_OPTION );
if(response != JOptionPane.YES_OPTION)
return;
exists = true;
}
try
{
if (tabbedPane.getSelectedIndex()==0)
{
buildName = name; //TE: update the name of the build filter so the tab change listener knows the correct name of the filter.
searchModel.saveFilter(name, getLDAPFilter());
}
else if (tabbedPane.getSelectedIndex()==1)
{
String filter = join.getFilter();
if(recursiveFilterCheck(name, filter, "Save")) //TE: stop the user from constructing a filter that is recursive.
return;
joinName = name; //TE: update the name of the join filter so the tab change listener knows the correct name of the filter.
searchModel.saveFilter(name, filter);
}
else if (tabbedPane.getSelectedIndex()==2)
{
textName = name; //TE: update the name of the text filter so the tab change listener knows the correct name of the filter.
searchModel.saveTextFilter(name, text.getFilter());
}
}
catch(Exception e) //TE: the user has somehow selected nothing in either the attribute or the function combo.
{
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"));
return;
}
save(name); //TE: save search levels, baseDN etc.
if(!exists) //TE: update the filter combo if the filter doesn't exist. Otherwise you would need to close the search dialog to see any changes??
join.updateFilterCombo(name);
jx.getMainMenu().updateSearchMenu(); //TE: updates the Search menu items.
showMessage(CBIntText.get("Your filter ''{0}'' was saved successfully.", new String[] {name}), CBIntText.get("Successful Save."));
}
/**
* Saves the base DN, return attribute list name, the search level and the alias
* state to the property file so they can be loaded similar to the filter.
* @param name the name of the filter, will be used in the key (e.g. name.baseDN=whatever).
*/
protected void save(String name)
{
String baseDN = ((baseDNTextField.getText()).trim()).length()<=0 ? ((jx.getTree()).getRootDN()).toString() : baseDNTextField.getText();
searchModel.saveValue(name, SearchModel.BASEDN, baseDN);
searchModel.saveValue(name, SearchModel.RETATTRS, (returnAttributesCombo.getSelectedItem()).toString());
searchModel.saveSearchLevel(name, searchLevelCombo.getSelectedIndex());
searchModel.saveAlias(name, SearchModel.FIND, aliasFindingCheckBox.isSelected());
searchModel.saveAlias(name, SearchModel.SEARCH, aliasSearchCheckBox.isSelected());
}
/**
* Displays a JOptionPane message which has a combo box containing all the possible filters that can be
* loaded into the build display. Gets the user selection and hand-balls the loading off to the BuildFilterPanel class.
*/
protected void loadBuild()
{
ArrayList list = searchModel.getFilterNames(SearchModel.BUILDFILTER); //TE: get the names of raw filters (i.e. (cn=f*)).
if (list.size()==0)
{
showMessage(CBIntText.get("There are no filters available to load.") , CBIntText.get("Nothing to Load"));
return;
}
Object listOb[] = list.toArray();
Arrays.sort(listOb, new SearchModel.StringComparator()); //TE: sort the list alphabetically.
CBJComboBox loadCombo = new CBJComboBox(listOb);
loadCombo.setRenderer(new CBBasicComboBoxRenderer(listOb));
loadCombo.setPreferredSize(new Dimension(140, 20));
int response = JOptionPane.showConfirmDialog(this, loadCombo, CBIntText.get("Select Filter"), JOptionPane.OK_CANCEL_OPTION);
if (response != JOptionPane.OK_OPTION)
return; //TE: the user has probably decided not to load a filter i.e. has clicked 'cancel'.
if (loadCombo.getSelectedItem()!=null)
{
String filter=null;
try
{
filter = searchModel.getFilter(loadCombo.getSelectedItem().toString()); //TE: gets the filter that the user selected.
}
catch(Exception e) //TE: the user has somehow selected nothing in either the attribute or the function combo.
{
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"));
return;
}
if (!build.displayFilter(filter)) //TE: display the filter. If unsuccessful show message.
{
showMessage(CBIntText.get("Your filter cannot be displayed."), CBIntText.get("Load Unsuccessful"));
}
else
{
buildName = loadCombo.getSelectedItem().toString(); //TE: update the name of the join filter so the tab change listener knows the correct name of the filter.
filterNameTextField.setText(buildName); //TE: set the name of the filter in the filter name field.
}
}
else
showMessage(CBIntText.get("Problem loading; there are no filters selected.") , CBIntText.get("Nothing to Load"));
load(loadCombo.getSelectedItem().toString());
}
/**
* Displays a JOptionPane message which has a combo box containing all the possible filters that can be
* loaded into the join display. Gets the user selection and creates the edit buttons before hand-balling
* the loading off to the JoinFilterPanel class.
*/
protected void loadJoin()
{
ArrayList list = searchModel.getFilterNames(SearchModel.JOINFILTER); //TE: get the names of filters that are made up of other filters (i.e. not raw filters).
if (list.size()==0)
{
showMessage(CBIntText.get("There are no filters available to load.") , CBIntText.get("Nothing to Load"));
return;
}
CBJComboBox loadCombo = new CBJComboBox(list.toArray());
loadCombo.setRenderer(new CBBasicComboBoxRenderer(list.toArray()));
loadCombo.setPreferredSize(new Dimension(140, 20));
int response = JOptionPane.showConfirmDialog(this, loadCombo,
CBIntText.get("Select Filter"), JOptionPane.OK_CANCEL_OPTION);
if (response != JOptionPane.OK_OPTION)
return; //TE: the user has probably decided not to load a filter i.e. has clicked 'cancel'.
if (loadCombo.getSelectedItem()!=null)
{
String filter = loadCombo.getSelectedItem().toString(); //TE: get the user selected filter from the combo box.
try
{
setNumberOfRows(build.getOccurrences(searchModel.getFilter(filter), "JXFilter")); //TE: add the right number of rows for displaying the filter.
list = searchModel.getJoinFilterNames(searchModel.getFilter(filter)); //TE: get a list of the subfilter names.
if(!join.displayFilter(list, searchModel.getFilter(filter))) //TE: display the filter. If unsuccessful show message.
showMessage(CBIntText.get("Your filter cannot be displayed."), CBIntText.get("Load Unsuccessful"));
else
{
joinName = loadCombo.getSelectedItem().toString(); //TE: update the name of the join filter so the tab change listener knows the correct name of the filter.
filterNameTextField.setText(joinName); //TE: set the name of the filter in the filter name field.
}
}
catch(Exception e) //TE: the user has somehow selected nothing in either the attribute or the function combo.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -