⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchgui.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			{
				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;
			}
		}
		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 text display.  Gets the user selection and hand-balls 
	*	the loading off to the JoinFilterPanel class.  
	*/
	//TE: Perhaps allow the user to load any filter into the text area, not just text filters???
	protected void loadText()
	{
		ArrayList list = searchModel.getFilterNames(SearchModel.TEXTFILTER);	//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;	
			
		if (loadCombo.getSelectedItem()!=null)
		{    
			textName = loadCombo.getSelectedItem().toString();					//TE: get the user selected filter from the combo box.				
			text.displayFilter(searchModel.getTextFilter(textName));
			filterNameTextField.setText(textName);								//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());	
	}
	
   /**
    *	Gets the values of the base dn, search level, return attributes and alias state from the
	*	property file that pertain to the filter being loaded and sets these values in
	*	the GUI.
	*	@param name the name of the filter that is being loaded.
	*/
	protected void load(String name)
	{
		//TE: load search level...
		int searchLevel = 2;
		try
		{
			searchLevel = Integer.parseInt(searchModel.getValue(name + "." + SearchModel.SEARCHLEVEL));
			searchLevelCombo.setSelectedIndex(searchLevel);
		}
		catch(NumberFormatException  e)
		{
			searchLevelCombo.setSelectedIndex(2);
		}		
				
		
		//TE: load base dn...
		String dn = searchModel.getValue(name + "." + SearchModel.BASEDN);
		if(dn!=null)
			baseDNTextField.setText(dn);

		//TE: get the name of the return attribute list.  Check that the list name exists then
		//		set it in the combo...	
		String retAttrs = searchModel.getValue(name + "." + SearchModel.RETATTRS);
		if (retAttrs!=null)
		{
			Object temp[] = ReturnAttributesDialog.getSavedListNames();
			
			for(int i=0; i<temp.length;i++)
			{
				if (((String)temp[i]).equalsIgnoreCase(retAttrs))
				{
					returnAttributesCombo.setSelectedItem(temp[i]);
					break;
				}
			}
		}

		//TE: select finding alias checkboxes...
		String find = searchModel.getValue(name + "." + SearchModel.FIND);
		if (find!=null)
		{			
			if(find.equalsIgnoreCase("true"))
				aliasFindingCheckBox.setSelected(true);
			else
				aliasFindingCheckBox.setSelected(false);
		}			
		
		//TE: select searching alias checkboxes...
		String search = searchModel.getValue(name + "." + SearchModel.SEARCH);
		if (search!=null)
		{
			if(search.equalsIgnoreCase("true"))
				aliasSearchCheckBox.setSelected(true);
			else
				aliasSearchCheckBox.setSelected(false);
		}	
	}
	
   /**
    *	Does a check to see if the filter is valid i.e. it check if there is a value in
	*	each of the combo boxes.  
	*	@return false if one or more of the combo boxes does not contain a value, true otherwise.
	*/
	protected boolean isFilterValid()
	{
		if (tabbedPane.getSelectedIndex()==0)
			return build.isFilterValid();
		else if (tabbedPane.getSelectedIndex()==1)	
			return join.isFilterValid();
		else if(tabbedPane.getSelectedIndex()==2)
			return text.isFilterValid();	
			
		return false;	//TE: something weird with the tabbed panes.
	}

   /**
    *	Returns the LDAP filter of the currently displayed tabbed pane.  This assumes that the build tab is at
	*	position 0, the join tab is at position 1 and the text tab is at position 2.
	*	@return the LDAP filter for example (cn=f*)
	*/
	protected String getLDAPFilter()
	{
		if (tabbedPane.getSelectedIndex()==0)			
			return build.getFilter();
		else if(tabbedPane.getSelectedIndex()==1)
			return searchModel.getJoinFilter(join.getFilter());
		else if(tabbedPane.getSelectedIndex()==2)
			return text.getFilter();		
			
		return "";	
	}

   /**
    *	Displays a information message dialog with the text that is supplied and titles the dialog with the title supplied.
	*	@param message the text to be displayed.
	*	@param title the title of this information message dialog.
	*/
	protected void showMessage(String message, String title)
	{
		JOptionPane.showMessageDialog(this, message, title, JOptionPane.INFORMATION_MESSAGE );			
	}	

   /**
    *	Sets the search Alias Behaviour in the property file, gets the filter and executes the search & display
	*	before closing the window.
	*/
	public void doOK()
	{		
		if (isFilterValid())
		{
            // Check if the filter is safe to use (we don't care about the name to begin with b/c we aren't saving)...
			if(tabbedPane.getSelectedIndex()==1 && recursiveFilterCheck(null, join.getFilter(), "Search"))
				return;		
			setAliasOptions();
			
			String returnAttrs = (returnAttributesCombo.getSelectedItem()).toString();
			if (!returnAttrs.equalsIgnoreCase(ReturnAttributesDialog.DEFAULT_RETURN_ATTRS))
			{
				closeSearchGUI();
				String[] attrNames = ReturnAttributesDialog.getReturnAttributes(returnAttrs);
				searchModel.openRetAttrDisplay(jx, attrNames, (jx.getSearchTree()).getDataSource());														
				SearchExecute.run(jx.getSearchTree(), new DN(baseDNTextField.getText()), getLDAPFilter(), attrNames, searchLevelCombo.getSelectedIndex(), jx.getSearchBroker());	//TE: the search details.				
			}			
			else
			{
				closeSearchGUI();
				SearchExecute.run(jx.getSearchTree(), new DN(baseDNTextField.getText()), getLDAPFilter(),
                        new String[] {"objectClass"}, searchLevelCombo.getSelectedIndex(), jx.getSearchBroker());	//TE: the search details.			SearchExecute.run(jx.getSearchTree(), new DN(baseDNTextField.getText()), getLDAPFilter(), attrNames, searchLevelCombo.getSelectedIndex(), jx.getSearchBroker());	//TE: the search details.
			}	
			jx.getTreeTabPane().setSelectedComponent(jx.getResultsPanel());	
		}		
		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"));							
		}		
	}

    /**
     * Over writes the parent method to call the closeSearchGUI method.
     */
    public void doCancel()
    {
        closeSearchGUI();
    }

    /**
     * Sets the filter name text to 'Untitled' then
     * sets the visibility of the dialog to false.
     */
    public void closeSearchGUI()
    {
        filterNameTextField.setText("Untitled");        //TE: bug 4896.
        setVisible(false);
    }

   /**
    *	Determines which search alias behaviour the user has selected in the search GUI.
	*	The combinations are:
	*	<p>
	*	<b>always</b> - both alias check boxes are checked.<br>
	*	<b>never</b> - neither alias check boxes are checked.<br>
	* 	<b>finding</b> - only the 'Resolve aliases when finding base object' check box is checked.<br>
	*	<b>searching</b> - only the 'Resolve aliases while searching' check box is checked.
	*	</p>
	*	The search alias option is set in JXplorer's property file under 'option.ldap.searchAliasBehaviour'.
	*/
	public void setAliasOptions()
	{
		String aliasOption = "always";
		
		if (!aliasSearchCheckBox.isSelected() && !aliasFindingCheckBox.isSelected())
			aliasOption = "never";
		else if (aliasSearchCheckBox.isSelected() && !aliasFindingCheckBox.isSelected())
			aliasOption = "searching";
		else if (!aliasSearchCheckBox.isSelected() && aliasFindingCheckBox.isSelected())
			aliasOption = "finding";
		
		log.fine("Setting search alias option to: ["+aliasOption+"]");
		JXplorer.setProperty("option.ldap.searchAliasBehaviour", aliasOption);
	}

   /**
    *	Checks if the user is trying to save a copy of the filter into itself, for example
	*	if a filter named t3 contains the filter t3 as part of a join.  This check applies only
	*	for the join tab.  Constructs an info dialog if the filter is recursive.
	*	@param filterName the user specified name for the filter that is currently being saved.
	*	@param filter the value of the filter for example 'JXFilter.t1JXFilter.t1'.
	*	@param type the source of the filter being constructed for example: view, save or search (used in the info dialog).
	*	@return true if the filter contains itself, false otherwise.
	*/
	protected boolean recursiveFilterCheck(String filterName, String filter, String type)
	{		
		if(recursiveFilterCheck(filterName, filter))	//TE: stop the user from constructing a filter that is recursive.
		{
			showMessage(CBIntText.get("The filter you are trying to {0} is not valid.  You may be trying to construct a filter within itself which will cause an infinite loop.", new String[] {type.toLowerCase()}), CBIntText.get(type + " Error"));
			return true;
		}				
		return false;
	}
	
   /**
    *	Checks if the user is trying to save a copy of the filter into itself, for example
	*	if a filter named t3 contains the filter t3 as part of a join.  This check applies only
	*	for the join tab.
	*	@param filterName the user specified name for the filter that is currently being saved.
	*	@param filter the value of the filter for example 'JXFilter.t1JXFilter.t1'.
	*	@return true if the filter contains itself, false otherwise.
	*/
	protected boolean recursiveFilterCheck(String filterName, String filter)
    {
		boolean recursive = false;
		String temp;
		ArrayList list = searchModel.getJoinFilterNames(filter);

		for(int i=0;i<list.size();i++)
	    {
		    temp = list.get(i).toString();
		    
			if(filterName != null && filterName.compareTo(temp) == 0)
		    {
				recursive = true;
				break;
		    }
			
		    // Go down each level that check there is the same name in the filter to be saved and the children fiters...
		    String value = searchModel.getFilter(temp);

            // check if it is joint filter or not...
            if(value != null && value.indexOf("JXFilter") != -1)
				recursive = recursiveFilterCheck(filterName, value);

		    if(recursive)
				return true;
		}
					
		return recursive;     
    }
}


//TE:  ONE DAY..........

//	class TreeFilterPanel extends CBPanel
//	{
//		public TreeFilterPanel()	
//		{	
//			setBackground(new Color(235,255,255));
//		}		
//	}


	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -