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

📄 tableattributeeditor.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			userData.setSize(400,250);
			CBUtility.center(userData, owner);    // TE: centres window.
            userData.setVisible(true);
		}
	}

   /**
    * Kicks off the entry modify/update & checks for manditory attributes.
	*/
	public void doSubmit()
	{
		if (dataSource == null)
		{
		    CBUtility.error("No dataSource available to write changes to in Table Attribute Editor");
		    return;
		}

		myEditor.stopCellEditing();

		// If schema checking is on, make sure that all mandatory attributes are filled in.
		if ("false".equalsIgnoreCase(JXplorer.getProperty("option.ignoreSchemaOnSubmission"))
		    && (tableData.checkMandatoryAttributesSet()==false))
		{
		    CBUtility.error(TableAttributeEditor.this, CBIntText.get("All Mandatory Attributes must have values!"), null);
		    return;
		}

		writeTableData();
	}

   /**
    * Opens a dialog that displays the operational attributes of the current entry.
	*/
	public void displayOperationalAttributes()
	{
		JXplorer jx = null;

		if(owner instanceof JXplorer)
			jx = (JXplorer)owner;
		else
			return;

		String[] opAttrs = new String[]{"createTimestamp","modifyTimestamp","creatorsName","modifiersName","subschemaSubentry"} ;
		int size = opAttrs.length;
        DXEntry entry = null;
        try
        {
            entry = (jx.getSearchBroker()).unthreadedReadEntry(currentDN, opAttrs);
        }
        catch (NamingException e)
        {
            CBUtility.error(TableAttributeEditor.this, CBIntText.get("Unable to read entry " + currentDN), e);
        }
        StringBuffer buffy = new StringBuffer("DN: "+currentDN.toString()+"\n\n");

		// Get the attribute values...
		for(int i=0;i<size;i++)
		{
			DXAttribute att = (DXAttribute)entry.get(opAttrs[i]);

		    try
			{
				if (att!=null)
				{
					buffy.append(opAttrs[i]+ ": "+ att.get().toString()+"\n\n");
				}
			}
		    catch (NamingException ee)
			{
				log.log(Level.WARNING, "Problem accessing Operational Attributes via Table Editor\n", ee);
			}
		}

		// Dialog setup...
		JTextArea area = new JTextArea(buffy.toString());
		area.setFont(new Font("SansSerif", Font.PLAIN, 11));
		area.setLineWrap(true);
		area.setWrapStyleWord(true);
		JScrollPane scrollPane = new JScrollPane(area);
		scrollPane.setPreferredSize(new Dimension(300,125));
		scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		JOptionPane.showMessageDialog(jx, scrollPane, CBIntText.get("Properties (Operational Attributes)"), JOptionPane.INFORMATION_MESSAGE);
	}

    /**
     *    This notifies the user that they are about to lose entered data (i.e. they've
     *    made changes and are about to a) change classes or b) go to another entry).
     *    @param reset usually prompt for save keeps an internal check to prevent the
     *           user being prompted twice for the same entry.  If this parameter is
     *           true, that prompt is reset.
     *    @return true if data is saved, false if discarded.
     */
    public boolean promptForSave(boolean reset)
    {
        return false;
/* TEMPORARY REMOVAL
        if (dataSource == null || dataSource.isActive() == false)
        {
            return false;  // no point prompting - nothing to save with!
        }
*/
        /*
         *    Only ever check the entry once (sometimes promptForSave can be called
         *    multiple time - remember that the 'save' function gets called by a
         *    separate thread).
         */
/* TEMPORARY REMOVAL
        if (reset)
            checkedDN = null;  // force the prompt to be used.

        if (checkedDN == null || checkedDN.equals(tableData.getOldEntry().getDN()) == false)
        {
            checkedDN = tableData.getOldEntry().getDN();

            //Thread.currentThread().dumpStack();

            String save = CBIntText.get("Save");
            String discard = CBIntText.get("Discard");

            int result = JOptionPane.showOptionDialog(CBUtility.getDefaultDisplay(),
                                                 CBIntText.get("Submit changes to the Directory?"),
                                                 CBIntText.get("Save Data"), JOptionPane.DEFAULT_OPTION,
                                                 JOptionPane.QUESTION_MESSAGE, null,
                                                 new Object[] {save, discard}, save);
            if (result == 0)
            {
                writeTableData();  // nb - this queues a request to the directory
                return true;
            }
        }
        else
        {
            // do nothing - don't prompt, don't save...
        }
        return false;
*/
    }

   /**
    *	Opens a dialog that asks the user if they want to make a virtual entry a non
	*	virtual entry.  If the user clicks 'Yes' the 'change class' dialog opens.
	*/
	public void doVirtualEntryDisplay()
	{
		virtualEntryDialog = new JDialog(owner, CBIntText.get("Virtual Entry"), true);

		CBButton btnYes = new CBButton(CBIntText.get("Yes"), CBIntText.get("Click yes to make a Virtual Entry."));
		CBButton btnNo = new CBButton(CBIntText.get("No"), CBIntText.get("Click no to cancel without making a Virtual Entry."));

		//TE: layout stuff...
		Container pane = virtualEntryDialog.getContentPane();
        pane.setLayout(new BorderLayout());
		CBPanel panel1 = new CBPanel();
		CBPanel panel2 = new CBPanel();
		CBPanel panel3 = new CBPanel();

		panel1.add(new JLabel(CBIntText.get("This entry is a Virtual Entry.  Are you sure you want to give this entry an object class?")));
		panel2.add(btnYes);
		panel2.add(btnNo);

		panel3.makeWide();
		panel3.addln(panel1);
		panel3.addln(panel2);

		pane.add(panel3);

		btnYes.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
				processVirtualEntry();
            }
        });

		btnNo.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
				shutVirtualEntryDialog();
            }
        });
		virtualEntryDialog.setSize(475, 125);
		CBUtility.center(virtualEntryDialog, owner);
		virtualEntryDialog.setVisible(true);
	}

   /**
    * 	Normally called by the 'Yes' button listener of the virtual entry dialog.
	*	This method opens the New Entry dialog in simple mode (or Change Classes dialog).
	*	If the user selects one or more object classes they are added to the entry and
	*	displayed in the table editor.
	*/
	public void processVirtualEntry()
	{

		NewEntryWin userData = null;
		if (dataSource.getSchemaOps()==null)
		{
			JOptionPane.showMessageDialog(owner, CBIntText.get("Because there is no schema currently published by the\ndirectory, changing an entry's object class is unavailable."), CBIntText.get("No Schema"), JOptionPane.INFORMATION_MESSAGE );
			return;
		}
		else
		{
			shutVirtualEntryDialog();				//TE: kill the prompt window.
		    userData = new NewEntryWin(dataSource, currentEntry.getDN(), this, owner, true);
			userData.setSize(400,250);
			CBUtility.center(userData, owner);    	//TE: centres window.
		    userData.setVisible(true);

			while (userData.isVisible())			//TE: don't do anything until the New Entry window is closed.
			{
				try
				{
					wait();
				}
				catch(Exception e)
				{
					userData.dispose();
				}
			}
		}

		if (userData.newObjectClasses!=null)		//TE: if the user has selected one or more object classes - add them to the entry in the directory.
		{
            try
            {
                DXOps dxOps = new DXOps(dataSource.getDirContext());
                dxOps.addAttribute(currentEntry.getDN(), userData.newObjectClasses);
                dataSource.getEntry(currentEntry.getDN());			//TE: hack??  forces the entry to be read again - otherwise we don't display the naming value.
            }
            catch (NamingException e)
            {
                CBUtility.error(TableAttributeEditor.this, CBIntText.get("Unable to add new object classes to {0}.", new String[] {currentEntry.getDN().toString()}), e);
            }
        }
	}

   /**
    *	Disposes of the virtual entry dialog that is opened as a prompt
	*	when the user may want to edit a virtual entry.
	*/
	public void shutVirtualEntryDialog()
	{
		if (virtualEntryDialog!=null)
		{
			virtualEntryDialog.setVisible(false);
			virtualEntryDialog.dispose();
		}
	}

    //
//    DN checkedDN;

    /**
     *    <p>Displays data that can be modified by the user in a table.</p>
     *    @param entry the entry to be displayed by all the editors
     *    @param ds the datasource the editors may use for more info
     */
    public void displayEntry(DXEntry entry, DataSource ds)
    {
//        checkedDN = null; // hack - resets promptForSave.

        // Set the globals...
		currentEntry = entry;
		dataSource = ds;

		if (entry!=null && entry.size()==0)
		{
            // If there is an entry and it's size is zero - it's probably is a virtual entry.
            // We need to give the user the option of adding an object class to it i.e. so that
            // it can be added to the directory as a real entry.
            //
            // Disable all the buttons except the 'Change Class' button - but rename this button
            // to 'Add Class' so the user hopefully has a bit more of an idea about what is going on.

            // Sets editor to a blank screen...
			tableData.clear();

            // Disable all buttons except the 'Change Class' button - rename this one...
			submit.setEnabled(false);
	        reset.setEnabled(false);
			changeClass.setText(CBIntText.get("Add Class"));
	        changeClass.setEnabled(true);
			opAttrs.setEnabled(false);

			virtualEntry = true;

⌨️ 快捷键说明

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