📄 attributevaluecelleditor.java
字号:
if (att.isEmpty())
{
label.setText(" ");
}
else
{
label.setText(att.getStringValue()); //TE: sets the table label to reflect the changes.
}
editorComponent = label;
}
/**
* Sets the postal address editor in the table cell whose attribute is
* a postalAddress ["1.3.6.1.4.1.1466.115.121.1.7"].
* @param att the attribute value to be set in the editor.
*/
private void setBooleanEditor(AttributeValue att)
{
booleaneditor booleanEditor = new booleaneditor(owner, att);
specialStringEditor = true;
CBUtility.center(booleanEditor, owner); //TE: centres the attribute editor.
booleanEditor.setStringValue(att);
booleanEditor.setVisible(true);
if (att.isEmpty())
{
label.setText(" ");
}
else
{
label.setText(att.getStringValue()); //TE: sets the table label to reflect the changes.
}
editorComponent = label;
}
/**
* Returns the syntax of the attribute value that is supplied
* @param att the attribute value for example 'Fred' from 'cn=Fred'.
* @return the syntax of the attribute for example for postalAddress the return string would be:
* 'SYNTAX: 1.3.6.1.4.1.1466.115.121.1.41'. If it fails to find the schema, it returns
* '1.3.6.1.4.1.1466.115.121.1.15' (DirectoryString) as a default.
*/
public String getAttributeSyntax(AttributeValue att)
{
String attID = att.getID();
return getAttributeSyntaxFromName(attID);
}
/**
* This looks up the attribute syntax using the name of the attribute.
* If none is found, it also checks to see if it is a 'SUP' of another
* attribute, and tries to recursively get the schema from that.
* @param attID the name of the attribute to look up; e.g. 'cn'
* @return the syntax of the attribute (usually an OID, e.g. "1.3.6.1.4.1.1466.115.121.1.15")
*/
private String getAttributeSyntaxFromName(String attID)
{
if (attID.indexOf(';') > 0)
attID = attID.substring(0, attID.indexOf(';')); //TE: for example: userCertificate;binary.
try
{
if (datasource == null)
throw new NamingException("No datasource!");
SchemaOps schema = datasource.getSchemaOps();
if (schema == null)
throw new NamingException("No schema!");
//TE: gets the schema.
Attributes attSchema = schema.getAttributes("AttributeDefinition/" + attID); //TE: gets the attribute definition.
if (attSchema == null)
throw new NamingException("No schema for AttributeDefinition/"+attID);
Attribute attSyntax = attSchema.get("SYNTAX"); //TE: gets the Syntax of the attribute .
if (attSyntax == null) // maybe it's a 'SUP' entry...
{
Attribute supSchema = attSchema.get("SUP");
if (supSchema == null)
throw new NamingException("Error processing attribute definition for " + attID + " no schema and no sup entry found");
if (supSchema.get().toString().equals(attID)) // 'SUP' is always single valued
throw new NamingException("recursive schema definition: " + attID + " sup of itself");
return getAttributeSyntaxFromName(supSchema.get().toString()); // recursively find the syntax of the sup entry
}
else
{
String syntax = attSyntax.toString();
if (syntax.startsWith("SYNTAX: "))
syntax = syntax.substring(8);
return syntax;
}
}
catch (NamingException e)
{
log.log(Level.WARNING, "Problem processing attribute definition: ", e);
return "1.3.6.1.4.1.1466.115.121.1.15"; // default to 'DirectoryString'
}
}
/**
* Does a quick check to make the binary handling sane (if necessary)
* before calling the super class stopCellEditing.
*/
// Enough casts to fill a hindu temple.
public boolean stopCellEditing()
{
if (binaryEditFlag)
{
return super.stopCellEditing();
}
else if (specialStringEditor)
{
return super.stopCellEditing();
}
Object o = getCellEditorValue();
if (o == null) return true; // not actually editing - redundant call.
if (o instanceof AttributeValue)
{
AttributeValue v = (AttributeValue)o;
if (editorComponent instanceof JTextField)
{
String userData = ((JTextField)editorComponent).getText();
// Bug 4891 - limit the user to entering only a single space.
int len = userData.length();
if (len > 0)
{
userData.trim();
if (userData.length() == 0)
userData = " "; // multiple spaces are shortened to a single space. Technically we should
if (userData.length() != len)
((JTextField)editorComponent).setText(userData);
}
v.update(userData);
}
else if (editorComponent instanceof CBJComboBox)
v.update(((CBJComboBox)editorComponent).getSelectedItem());
else
log.warning("unknown editorComponent = " + editorComponent.getClass());
}
else
log.warning("(AttValCellEdit) Not an Att Val: is " + o.getClass());
setCellEditorValue(o);
return super.stopCellEditing();
}
/**
* Checks if the user has clicked sufficient times to make the cell
* editable.
*/
public boolean isCellEditable(EventObject e)
{
boolean editable = true;
if (e instanceof MouseEvent)
{
editable = ((MouseEvent)e).getClickCount() >= clickCountToStart;
}
return editable;
}
/**
* Kicks of a separate binary editor by looking for a Java class with
* name of the attribute, plus the word 'Editor', and starting that
* up if it can be found. (Otherwise it uses the default editor).
*/
public void startBinaryEditor(AttributeValue att)
{
if (abstractEditor != null &&
(abstractEditor instanceof Component) &&
((Component)abstractEditor).isVisible() ) //TE: checks if an editor is already open (i.e. if multiple clicks on a value in the table editor).
{
return; //TE: do nothing...there is already an editor open.
}
if (att.isBinary()==false) // should never happen!
{log.warning("Error: non binary value passed to binary editor!"); return; }
String attName = att.getID();
int trim = attName.indexOf(";binary");
if (trim>0)
attName = attName.substring(0,trim);
String className = "com.ca.directory.jxplorer.editor." + attName + "editor";
try
{
Class c = null;
if (myLoader == null)
{
System.out.println("using default loader for "+className );
c = Class.forName(className);
}
else
{
System.out.println("looking for: " + className.toLowerCase());
c = myLoader.loadClass(className.toLowerCase());
}
if (abstractbinaryeditor.class.isAssignableFrom(c))
{
Constructor constructor;
if (owner instanceof Frame)
{
constructor = c.getConstructor(new Class[] {java.awt.Frame.class});
abstractEditor = (abstractbinaryeditor) constructor.newInstance(new Object[] {owner});
}
else
{
constructor = c.getConstructor(new Class[0]);
abstractEditor = (abstractbinaryeditor) constructor.newInstance(new Object[0]);
}
abstractEditor.setValue(att);
if(abstractEditor instanceof basicbinaryeditor) //TE: set the current DN in the editor.
((basicbinaryeditor)abstractEditor).setDN(currentDN);
else if(abstractEditor instanceof defaultbinaryeditor) //TE: set the current DN in the editor.
((defaultbinaryeditor)abstractEditor).setDN(currentDN);
if (abstractEditor instanceof defaultbinaryeditor)
{
((defaultbinaryeditor)abstractEditor).showDialog(); //todo: TE:seems that the abstractEditor doesn't get set to null after it is closed...
abstractEditor = null; //todo: TE: so this is a hack to kill the dialog so that it opens the next time a user clicks on that attribute value. It would be nice to fix this!
}
else if (abstractEditor instanceof Component)
{
((Component)abstractEditor).setVisible(true);
}
fireEditingStopped(); // everything is now being done by the separate binary editor window...
return; // ...and don't load default editor (below)
}
else
{
log.warning("error: can't load editor class " + className + " since it is not inherited from AbstractBinaryEditor\n");
}
}
catch (NoSuchMethodException e)
{
log.log(Level.WARNING, "coding error in editor " + className+ " - using default binary editor instead.", e);
}
catch (ClassNotFoundException e)
{
log.info("(expected) can not find editor " + className + "\n" + e.toString()); // 'expected' error
try
{
defaultbinaryeditor dbe = new defaultbinaryeditor(owner); // kick off the default editor (creates an option dialog)
dbe.setDN(currentDN);
CBUtility.center(dbe, owner); //TE: centers the window.
dbe.setValue(att);
dbe.showDialog();
}
catch (Exception e2)
{
log.log(Level.WARNING, "unable to start backup editor", e2);
e2.printStackTrace();
}
}
catch (Exception e3)
{
log.log(Level.WARNING, "error loading editor " + className, e3);
e3.printStackTrace();
}
}
/**
* Optionally register a new class loader for atribute value viewers to use.
*/
public void registerClassLoader(ClassLoader loader)
{
myLoader = loader;
}
/**
* Returns the datasource.
* @param ds the datasource.
*/
public void setDataSource(DataSource ds)
{
datasource = ds;
}
/**
* Sets the dn of the entry being modified.
* @param dn the DN of the entry being modified.
*/
public void setDN(DN dn)
{
currentDN = dn;
}
/**
* Sets the the abstract editor (display editor for binary data - e.g. the audio player, or photo viewer), to null.
*/
public void cleanupEditor()
{
abstractEditor = null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -