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

📄 newentrywin.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.ca.directory.jxplorer.tree;

import com.ca.commons.cbutil.*;
import com.ca.commons.naming.*;
import com.ca.directory.jxplorer.*;

import javax.naming.InvalidNameException;
import javax.naming.NamingException;
import javax.naming.directory.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.logging.Logger;
import java.util.logging.Level;

/**
 *   This class allows a user to create the details of a new entry.
 *   These details are then passed to the table editor (usually) 
 *   where the user can make further modifications, before finally
 *   submitting the result to the directory.
 */

// XXX
// XXX    This class is being pressed into service to do two similar
// XXX    things - create new entries, and change the object classes of
// XXX    Existing entries.  It gets a bit ugly, and should probably be
// XXX    Be rewritten.  - Chris
// XXX    


public class NewEntryWin extends CBDialog implements ActionListener, DataListener
{
    JTextField rdnField,parentDNField;
    
    JScrollPane possiblePanel;     // holds the selection list
    JList possibleList;            // list of possible object classes to be selected
    
    JScrollPane selectedPanel;     // holds the results list
    JList selectedList;            // list of user-selected object classes
    
    DefaultListModel selDataModel; // dataModel for selected list
    DefaultListModel posDataModel; // dataModel for possible list

    DataSink entryEditor;          // the table display the larval entry is (finally) displayed within.    
    
    JCheckBox autoSuggest;
    
    CBButton select, remove;
    
    static boolean suggest = true;
    
    Vector suggestedClasses = new Vector();
    
    DataSource dataSource;
    
    /*
     *    Only used in 'new entry' mode.
     */
     
    DN parentDN;
    DN childDN;
    
    /*
     *    Only used in 'change classes' mode.
     */
     
    DN entryDN = null;
    DXAttributes defaultAttributes = null;
    
    protected CBHelpSystem helpBroker;     
        
    String objectClassName = null; // is it 'objectclass' or 'objectClass'

    private static Logger log = Logger.getLogger(NewEntryWin.class.getName());

    /**
     *    this sets whether the window needs to worry about the entry name.
     *    IF we're modifying an existing entry, we don't.
     */
     
    protected boolean simpleMode;  

    /*
     *    Whether the child/parent name fields are disabled (implying that 
     *    they must have been set externally!)
     */
     
    protected boolean disableName = false;
    
	
	boolean virtualEntry = false;		//TE: a flag representing a virtual entry.
	
  	public BasicAttribute newObjectClasses = null;
	
      /**
     *    This creates the GUI, using the passed parameters
     *    to set up the default name and default object classes
     *    (if possible), and the destination of the prepared
     *    data.
     *
     *    @param pDN the parent DN.  This is the DN under which the new entry will
     *               be created.
     *    @param cDN an arbitrary child DN of a sibling of the to-be-created entry.
     *               This may be null, but if present is used to 'guess' what object
     *               classes may be wanted for the new entry.
     *    @param dSource a link to the directory, which is queried to discover
     *               what object classes are available for the new entry.
     *    @param attDisplay where the resulting half-finished entry is sent for the 
     *               user to modify, and finally submit to the directory.
     *    @param parent the usual parent GUI for swing look and feel propogation etc.
     */

         
    public NewEntryWin(DN pDN, DN cDN, DataSource dSource, 
                            DataSink attDisplay, Frame parent)
    {
        this(pDN, cDN, dSource, null, null, attDisplay, parent);
        disableName = false;
        rdnField.setEnabled(true);
        parentDNField.setEnabled(true);
    }

    
    /**
     *    This creates the GUI, using the passed parameters
     *    to set up the default name and default object classes
     *    (if possible), and the destination of the prepared
     *    data.
     *
     *    @param pDN the parent DN.  This is the DN under which the new entry will
     *               be created.
     *    @param cDN an arbitrary child DN of a sibling of the to-be-created entry.
     *               This may be null, but if present is used to 'guess' what object
     *               classes may be wanted for the new entry.
     *    @param dSource a link to the directory, which is queried to discover
     *               what object classes are available for the new entry.
     *    @param defaultValues - sometimes the 'new' entry is really just an update
     *               of an old one, with the object classes changing.  If this is non
     *               null, it is used to initialise the attributes of the new entry.
     *    @param rdn an optional default name for an entry (again, mainly used if 
     *               we're over-hauling an old entry, rather than creating a new one
     *               from scratch.
     *    @param attDisplay where the resulting half-finished entry is sent for the 
     *               user to modify, and finally submit to the directory.
     *    @param parent the usual parent GUI for swing look and feel propogation etc.
     */
         
    public NewEntryWin(DN pDN, DN cDN, 
            DataSource dSource, Attributes defaultValues, 
            String rdn, DataSink attDisplay, Frame parent)
    {
        super(parent, CBIntText.get("Set Entry Object Classes"), HelpIDs.ENTRY_NEW);

        simpleMode = false;
        
        dataSource = dSource;
            
        entryEditor = attDisplay;            
            
        if (defaultValues!=null)  
        {
            if (defaultValues instanceof DXAttributes)
                defaultAttributes = (DXAttributes)defaultValues;
            else
                defaultAttributes = new DXAttributes(defaultAttributes);
        }
        
        // try to figure out what the capitalisation of 'objectClass' is today...
        try
        {
            objectClassName = dataSource.getSchemaOps().getNameOfObjectClassAttribute();
        }
        catch (Exception e)
        {
        } // do nothing...
    
        parentDN = pDN;
        childDN = cDN;
            
        getContentPane().add(display);
 
        autoSuggest = new JCheckBox(CBIntText.get("Suggest Classes?"), suggest);
        display.add(autoSuggest,3,0);
        display.newLine();
        
        display.add(new JLabel(CBIntText.get("Parent DN") + ": "));
        display.addLine(parentDNField = new JTextField(parentDN.toString(), 20));
        
        parentDNField.setEnabled(false);      // disable, (but this is over-ridden if we are called from the other constructor)
        
        display.add(new JLabel(CBIntText.get("Enter RDN") + ": "));
        display.addLine(rdnField = new JTextField("=", 20));

        // try to set some meaningful default values for the rdn field
        if (rdn != null)
        {
            rdnField.setText(rdn);
            rdnField.setEnabled(false);      // disable, (but this is over-ridden if we are called from the other constructor)
        }    
        else if ((suggest == true)&&(childDN != null))
		{
           rdnField.setText(childDN.getLowestRDN().getAtt() + "=");
		}
		
        setupObjectClassPanels(null);
        
    
        
        autoSuggest.addActionListener(this);

        registerMouseListeners();
    }

   /**
     *    This creates the GUI, using the passed parameters
     *    to set up the default name and default object classes
     *    (if possible), and the destination of the prepared
     *    data.
     *
     *    @param dSource a link to the directory, which is queried to discover
     *               what object classes are available for the entry.
     *    @param entryDN the DN of the (existing) entry to be modified.
     *    @param defaultValues - sometimes the 'new' entry is really just an update
     *               of an old one, with the object classes changing.  If this is non
     *               null, it is used to initialise the attributes of the new entry.
     *    @param attDisplay where the resulting half-finished entry is sent for the 
     *               user to modify, and finally submit to the directory.
     *    @param parent the usual parent GUI for swing look and feel propogation etc.
     */
         
    public NewEntryWin(DataSource dSource, DN entryDN, Attributes defaultValues, 
            DataSink attDisplay, Frame parent)
    {
        super(parent, CBIntText.get("Set Entry Object Classes"), HelpIDs.CLASS_CHANGE);

        simpleMode = true;
        
        this.entryDN = entryDN;
        
        dataSource = dSource;
            
        entryEditor = attDisplay;            
            
        if (defaultValues instanceof DXAttributes)
            defaultAttributes = (DXAttributes) defaultValues;
        else
            defaultAttributes = new DXAttributes(defaultAttributes);
        
        // try to figure out what the capitalisation of 'objectClass' is today...
        try
        {
            objectClassName = dataSource.getSchemaOps().getNameOfObjectClassAttribute();
        }
        catch (Exception e) {} // do nothing...
    
        getContentPane().add(display);
 
        setupObjectClassPanels(defaultAttributes);
        
        registerMouseListeners();
    }
	
	
	
   /**
	*   This creates the GUI, using the passed parameters
	*   to set up the default name and default object classes
	*   (if possible), and the destination of the prepared
	*   data.
	*
	*   @param dSource a link to the directory, which is queried to discover
	*           what object classes are available for the entry.
	*   @param entryDN the DN of the (existing) entry to be modified.
	*   @param attDisplay - where the data is to be displayed; usually the entry Editor.
	*   @param parent the usual parent GUI for swing look and feel propogation etc.
	*	@param virtualEntry flag representing if the entry is a virtual entry (should always
	*			be true b/c currently this constructor will only be called under that condition).
	*/
	 	
    public NewEntryWin(DataSource dSource, DN entryDN, DataSink attDisplay, Frame parent, boolean virtualEntry)
    {
        super(parent, CBIntText.get("Set Entry Object Classes"), HelpIDs.CLASS_CHANGE);

		this.virtualEntry = virtualEntry;
		
		simpleMode = true;
        
        this.entryDN = entryDN;
		
		dataSource = dSource;
	
		entryEditor = attDisplay;
		getContentPane().add(display);
		
		setupObjectClassPanels(null);
		registerMouseListeners();		
    }



    protected void setupObjectClassPanels(Attributes currentAtts)            
    {

        display.addWide(new JLabel(CBIntText.get("Available Classes") + ": "),2);
        display.addWide(new JLabel(CBIntText.get("Selected Classes") + ": "),2);
        display.newLine();

        selDataModel = new DefaultListModel();
        selectedList = new JList(selDataModel);
        selectedList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        selectedList.setSelectionModel(new CBSingleSelectionModel(selectedList));   //TE: tries to ensure that the selected item is visible.

        posDataModel = new DefaultListModel();
        possibleList = new JList(posDataModel);
        possibleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        possibleList.setSelectionModel(new CBSingleSelectionModel(possibleList));   //TE: tries to ensure that the selected item is visible.

        possiblePanel = new JScrollPane(possibleList);
        selectedPanel = new JScrollPane(selectedList);

		/*
		 *	If we've passed in an existing entry to get the 'recommended' object
		 *  classes from, then read them off immediately.
		 */

        if (currentAtts != null)
        {
            Attribute objectClasses = currentAtts.get(objectClassName);
            try
            {
                Enumeration recommendedObjectClasses = objectClasses.getAll();
                while (recommendedObjectClasses.hasMoreElements())
                {
                    String oc = (String)recommendedObjectClasses.nextElement();
                    selDataModel.addElement(oc);
                    suggestedClasses.add(oc);
                }
            }
            catch (Exception e) {}
        }

		/*
		 *  If we haven't got a list of ocs, but we know the DN of a sibling
		 *  entry (confusing called 'childDN' here) then we try to copy
		 *  the object classes of that entry (on the grounds that similar
		 *  entries often occupy the same level of a directory.
		 *
		 *  The results of this query are returned (eventually & asynchronously)
		 *  in 'dataReady()' below.
		 */

        else if (childDN != null)
        {
            DataQuery myQuery = dataSource.getRecommendedObjectClasses(childDN);
            myQuery.addDataListener(this);
        }

		/*
		 *  Post a query to get all the available object classes known to the
		 *  directory.
		 *
		 *  The results of this query are returned (eventually & asynchronously)
		 *  in 'dataReady()' below.
		 */
        try
        {
            ArrayList allObjectClasses = dataSource.getSchemaOps().objectClasses();

            for (int i=0; i<allObjectClasses.size(); i++)

⌨️ 快捷键说明

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