📄 tableattributeeditor.java
字号:
return;
}
virtualEntry = false;
// Isn't a virtual entry...
if(entry != null)
currentDN = entry.getDN();
// May have been changed to 'Add Class'...
changeClass.setText(CBIntText.get("Change Class"));
// Some quick faffing around, to see if we're coming back from a
// change classes operation.
if (classChangedOriginalEntry != null)
{
// If they have the same name, then we're reviewing the same entry - otherwise we've moved on
if (entry == null || entry.getDN().equals(classChangedOriginalEntry.getDN()) == false)
classChangedOriginalEntry = null;
}
/*
* Check that we're not displaying a new entry, and leaving unsaved changes
* behind.
*
* This turns out to be quite tricky, and involves a bunch 'o special cases.
*
* First check whether the table data has changed (if not, do nothing)
* -> if the new entry is null, prompt user to save
* -> OR if the DN has changed, and it wasn't due to a rename, prompt user to save
*
*/
if (tableData.changedByUser()) // user made changes - were they saved? (i.e., are we
{ // displaying the result of those changes?)
boolean prompt = false;
DXEntry oldEntry = tableData.getOldEntry();
if (oldEntry != null)
{
/*
* The code below is simply checking to see if the name of the
* new entry is different from the old entry, and if it is,
* whether that's due to the old entry being renamed.
*/
if (entry == null)
{
prompt = true;
}
//TE: added the isEmpty check see bug: 3194.
else if (!oldEntry.getDN().isEmpty() && entry.getDN().equals(oldEntry.getDN())==false)
{
DN oldParent = oldEntry.getDN().parentDN();
DN newParent = entry.getDN().parentDN();
if (oldParent.equals(newParent) == false)
{
prompt = true;
}
else
{
if (entry.getDN().getLowestRDN().equals(tableData.getRDN()) == false)
{
prompt = true;
}
}
}
if (prompt) // yes, there is a risk of data loss - prompt the user.
{
if (promptForSave(false)) // see if the user wants to save their data
{
//dataSource.getEntry(entry.getDN()); // queue a request to redisplay
return; // this entry (but don't show it this time around).
}
}
}
}
myEditor.setDataSource(ds); // Sets the DataSource in AttributeValueCellEditor used to get the syntax of attributes.
// only enable buttons if DataSource
// is valid *and* we can modify data...
if (dataSource == null || entry == null)
{
submit.setEnabled(false);
reset.setEnabled(false);
changeClass.setEnabled(false);
opAttrs.setEnabled(false);
}
else
{
submit.setEnabled(true);
reset.setEnabled(true);
opAttrs.setEnabled(true);
if (entry.get("objectclass") != null) // only allow class changes if we can find
changeClass.setEnabled(true); // some to start with!
}
myEditor.stopCellEditing();
if (entry != null)
{
entry.expandAllAttributes();
currentDN = entry.getDN();
tableData.insertAttributes(entry);
popupTableTool.setDN(currentDN); // Sets the DN in SmartPopupTableTool.
myEditor.setDN(currentDN); // Sets the DN in the attributeValueCellEditor which can be used to identify the entry that is being modified/
}
else
{
tableData.clear(); // Sets editor to a blank screen.
}
tableScroller.getVerticalScrollBar().setValue(0); // Sets the scroll bar back to the top.
}
public JComponent getDisplayComponent()
{
validate();
repaint();
return this;
}
public String[] getAttributeValuesAsStringArray(Attribute a)
throws NamingException
{
if (a == null) return new String[0];
DXNamingEnumeration e = new DXNamingEnumeration(a.getAll());
if (e == null) return new String[0];
return e.toStringArray();
}
/**
* Test whether the (unordered) object class lists of two
* attributes contain the same
*/
public boolean objectClassesChanged(DXAttributes a, DXAttributes b)
{
boolean result = false;
try
{
String[] A = getAttributeValuesAsStringArray(a.getAllObjectClasses());
String[] B = getAttributeValuesAsStringArray(b.getAllObjectClasses());
Object[] test = CBArray.difference(A,B);
if (test.length>0) result = true;
test = CBArray.difference(B,A);
if (test.length>0) result = true;
return result;
}
catch (NamingException e)
{
log.log(Level.WARNING, "Error in TableAttributeEditor:objectClassesChanged ", e);
return true;
}
}
/**
* Writes the data currently in the table editor to the directory.
*/
public void writeTableData()
{
myEditor.stopCellEditing();
if (dataSource == null) // if ds is null, data is not modifiable...
{CBUtility.error("no datasource to write data to in writeTableData()"); return;} // shouldn't happen
DXEntry oldEntry = tableData.getOldEntry();
DXEntry newEntry = tableData.getNewEntry();
/* Check to see if major surgery is needed - whether the user has been
* messing with the object class list. */
if (classChangedOriginalEntry != null)
{
// use the saved state of the pre-class-changed entry as the 'old entry'
// state.
oldEntry = classChangedOriginalEntry;
classChangedOriginalEntry = null; // this is only used once! (either the object class change will
// now succeed, or fail - either way, the entry state is reset to
// match what's in the directory.)
if (objectClassesChanged(oldEntry, newEntry))
{
oldEntry.removeEmptyAttributes();
newEntry.setStatus(oldEntry.getStatus());
Object[] delSet = CBArray.difference(oldEntry.toIDStringArray(), newEntry.toIDStringArray());
/* if there *are* attributes that should no longer exist, delete them by adding them (blanked)
* to the complete 'newAtts' set of *all* known attributes. */
if ((delSet != null) && (delSet.length > 0))
{
for (int i=0; i<delSet.length; i++)
{
newEntry.put(new DXAttribute(delSet[i].toString())); // overwrite old values with an empty attribute
}
}
}
}
dataSource.modifyEntry(oldEntry, newEntry);
}
/**
* Return the thingumy that should be printed.
*/
public Component getPrintComponent()
{
return attributeTable;
}
/**
* This editor is happy to be used in conjunction with other editors...
*/
public boolean isUnique() { return false; }
public String getName() { return CBIntText.get("Table Editor"); }
public ImageIcon getIcon() { return new ImageIcon("images" + File.separator + "table.gif"); } //TE: returns an icon.
public String getToolTip() { return CBIntText.get("The table editor is generally used for editing data, it also functions perfectly well as a simple, but robust, entry viewer."); } //TE: returns a tool tip.
public DataSink getDataSink() { return this; }
public boolean canCreateEntry() { return true; }
public void registerComponents(JMenuBar menu, JToolBar buttons, JTree tree, JPopupMenu treeMenu, JFrame jx) {}
public void unload() {}
/**
* Use the default tree icon system based on naming value
* or object class.
*/
public ImageIcon getTreeIcon(String rdn) { return null; }
/**
* Use the default popupmenu.
*/
public JPopupMenu getPopupMenu(String rdn) { return null; }
/**
* Don't hide sub entries.
*/
public boolean hideSubEntries(String rdn) { return false; }
/**
* Optionally register a new class loader for atribute value viewers to use.
*/
public void registerClassLoader(ClassLoader loader)
{
myLoader = loader;
myEditor.registerClassLoader(loader);
}
public void setVisible(boolean state)
{
super.setVisible(state);
// has to be *after* previous call for SwingMagic reasons.
if (state == false && tableData.changedByUser()) // user made changes - were they saved? (i.e., are we
{
/*
* The setVisible() method may be called multiple time. Only prompt
* the user the first time.
*/
promptForSave(false);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -