📄 tableattributeeditor.java
字号:
package com.ca.directory.jxplorer.viewer;
import com.ca.commons.cbutil.*;
import com.ca.commons.naming.*;
import com.ca.directory.jxplorer.*;
import com.ca.directory.jxplorer.tree.NewEntryWin;
import com.ca.directory.jxplorer.viewer.tableviewer.*;
import com.ca.directory.jxplorer.viewer.tableviewer.AttributeValue;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.util.logging.Logger;
import java.util.logging.Level;
/**
* This class displays attributes in a table (currently string attributes
* only). The user can modify the table values, and submit the
* results, which are passed to the registered DataSource (obtained from
* the registered DataSource)...
*/
/* PROGRAMMING NOTE:
*
* Some rather unpleasent stuff happens with object class changing. The state
* of the unmodified entry is maintained between displayEntry() calls using
* the classChangedOriginalEntry variable.
*/
public class TableAttributeEditor extends JPanel
implements DataSink, PluggableEditor //, TreeEntryCreator
{
private static Logger log = Logger.getLogger(TableAttributeEditor.class.getName());
JTable attributeTable;
AttributeTableModel tableData;
JScrollPane tableScroller;
CBButton submit, reset, changeClass, opAttrs; //, help;
JFrame owner;
JDialog virtualEntryDialog = null;
/**
* Flag for a virtual entry.
*/
boolean virtualEntry = false;
/**
* Copy of the current entry.
*/
DXEntry currentEntry = null;
/**
* Copy of the current DN.
*/
DN currentDN = null;
/**
* The data source directory data is read from.
*/
public DataSource dataSource;
/**
* A rare operation is for the user to change the classes of an entry. This
* backs up the original state of that entry.
*/
DXEntry classChangedOriginalEntry = null;
SmartPopupTableTool popupTableTool;
ClassLoader myLoader;
final AttributeValueCellEditor myEditor;
/**
* Constructor initialises the table and a popup tool,
* as well as initialising the required GUI elements.
* It adds action listeners for the three main buttons,
* which include basic user input validation checking.
*/
public TableAttributeEditor(JFrame MyOwner)
{
// As usual, it is insanely hard to get the swing components to display
// and work properly. If JTable is not displayed in a scroll pane no headers are
// displayed, and you have to do it manually. (If you *do* display it
// in a scrollbar, in this instance, it screws up sizing)
// The broken header mis-feature is only mentioned in the tutorial,
// not in the api doco - go figure.
super();
owner = MyOwner;
// final JPanel mainPanel = (JPanel)this;
tableData = new AttributeTableModel();
attributeTable = new JTable(tableData);
//attributeTable.setRowHeight(20); // This may be needed, depends on how fussy people get about the bottom of letters like 'y' getting cut off when the cell is selected - bug 3013.
popupTableTool = new SmartPopupTableTool(attributeTable, tableData);
// Set the renderer for the attribute type...
final AttributeTypeCellRenderer typeRenderer = new AttributeTypeCellRenderer();
attributeTable.setDefaultRenderer(AttributeType.class, typeRenderer);
// Set the renderer for the attribute value...
final AttributeValueCellRenderer valueRenderer = new AttributeValueCellRenderer();
attributeTable.setDefaultRenderer(AttributeValue.class, valueRenderer);
// Set the editor for the attribute value...
myEditor = new AttributeValueCellEditor(owner);
attributeTable.setDefaultEditor(AttributeValue.class, myEditor);
attributeTable.getTableHeader().setReorderingAllowed(false);
currentDN = null;
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
buttonPanel.add(submit = new CBButton(CBIntText.get("Submit"), CBIntText.get("Submit your changes to the Directory.")));
buttonPanel.add(reset = new CBButton(CBIntText.get("Reset"), CBIntText.get("Reset this entry i.e. cancels any changes.")));
buttonPanel.add(changeClass = new CBButton(CBIntText.get("Change Classes"), CBIntText.get("Change the Object Class of this entry.")));
buttonPanel.add(opAttrs = new CBButton(CBIntText.get("Properties"), CBIntText.get("View the Operational Attributes of this entry.")));
// I don't really understand why we have to do this...
// but without it these buttons over ride the default
// button (Search Bar's search button), if they have
// been clicked and the user hits the enter key?
opAttrs.setDefaultCapable(false);
submit.setDefaultCapable(false);
reset.setDefaultCapable(false);
changeClass.setDefaultCapable(false);
setLayout(new BorderLayout(10,10));
tableScroller = new JScrollPane();
attributeTable.setBackground(Color.white);
tableScroller.setPreferredSize(new Dimension(300,285));
tableScroller.setViewportView(attributeTable);
add(tableScroller, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
setVisible(true);
// Opens a dialog that displays any operational attributes of the current entry.
opAttrs.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
displayOperationalAttributes();
}
});
reset.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
myEditor.stopCellEditing();
//XXX??? if (attributeTable.isEditing()) myEditor.stopCellEditing();
tableData.reset();
}
});
submit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
doSubmit();
}
});
// This allows the user to change the objectclass attribute.
// This is pretty tricky, because it changes what attributes are available.
changeClass.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
changeClass();
}
});
attributeTable.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e) { if (!doPopupStuff(e)) super.mousePressed(e); }
public void mouseReleased(MouseEvent e) { if (!doPopupStuff(e)) super.mouseReleased(e); }
//TODO need to have a way to call this from a keystroke...
public boolean doPopupStuff(MouseEvent e)
{
if (e.isPopupTrigger()==false) return false;
int row = attributeTable.rowAtPoint(new Point(e.getX(), e.getY()));
attributeTable.clearSelection();
attributeTable.addRowSelectionInterval(row,row);
attributeTable.repaint();
popupTableTool.registerCurrentRow((AttributeType)attributeTable.getValueAt(row,0), (AttributeValue)attributeTable.getValueAt(row,1), row, tableData.getRDN()); // active path also set by valueChanged
popupTableTool.show(attributeTable, e.getX(), e.getY());
popupTableTool.registerCellEditor(myEditor); //TE: for bug fix 3107.
return true;
}
});
}
/**
* Opens the change class dialog.
*/
public void changeClass()
{ //JPanel mainPanel
/*
* MINOR MAGIC
*
* This code reuses the 'new entry window'. In order to make things
* sane, we prompt the user to save any serious changes before continuing.
* (Things can get really wierd if the user changes the name and then
* tries to change the objectclass - best to avoid the whole issue.)
*/
myEditor.stopCellEditing();
if (virtualEntry)
{
doVirtualEntryDisplay();
return;
}
/*
* classChangedOriginalEntry saves the original state of the entry
* between visits to NewEntryWin. (- I wonder if it would be neater
* to just reset the 'oldEntry' state of the table every time? ).
* Check it's not been set already (i.e. Pathological User is paying
* multiple visits to the NewEntryWin.)
*/
if (classChangedOriginalEntry == null)
classChangedOriginalEntry = tableData.getOldEntry();
DXEntry newEntry = tableData.getNewEntry();
DN newDN = newEntry.getDN();
/*
* Pathalogical user has messed with the name, *and* wants to
* change the object classes...
*/
if (newDN.equals(classChangedOriginalEntry.getDN()) == false)
{
if (promptForSave(false) == false) // we may need to reset the 'newEntry' data
{ // if the user discards their changes.
tableData.reset(); // resets the table before going on.
newEntry = tableData.getNewEntry();
newDN = newEntry.getDN();
}
else // user has saved data - so now we need to reset the 'classChangedOriginalEntry'
{ // to the changed (and hopefully saved!) data.
// NB: If the directory write fails, then the change classes will also fail...
classChangedOriginalEntry = tableData.getNewEntry();
}
}
/*
* Open NewEntryWin, allowing the user to reset the objectclass attribute.
*/
/*
NewEntryWin userData = new NewEntryWin(newDN.parentDN(), newDN,
dataSource,
newEntry.getAsNonNullAttributes(),
newDN.getLowestRDN().toString(), TableAttributeEditor.this,
CBUtility.getParentFrame(mainPanel));
*/
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
{
NewEntryWin userData = new NewEntryWin(dataSource, newDN, newEntry.getAsNonNullAttributes(),
this, CBUtility.getParentFrame(this));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -