?? attributedisplay.java
字號:
newEdSet = true;
}
}
}
}
// search for non-structural editors
try
{
Attribute allOCs = entry.getAllObjectClasses();
if (allOCs != null)
{
Enumeration vals = allOCs.getAll();
while (vals.hasMoreElements())
{
Object oc = vals.nextElement();
if (oc != null)
{
String ocName = oc.toString();
if (ocs.contains(ocName) == false) // don't bother with struct objectclasses dealt with above
{
PluggableEditor ed = getEditor(ocName);
if (ed != null)
{
addEditor(ed);
if (ed.isUnique()) // a special service to users...
log.warning("WARNING: Illegal unique editor defined for oc: " + ocName + " not allowed - (oc not in primary structural inheritance chain)");
}
}
}
}
}
}
catch (NamingException e)
{
log.log(Level.WARNING, "WARNING: non-fatal exception getting object classes for plugin editors. ", e);
}
addEditor(templateDisplay); // and always add old faithfulls...
//XXX
if (entry.getStatus() != DXEntry.NEW) // well, almost always...
addEditor(tableDisplay);
}
catch (Exception e)
{
log.warning("Unexpected Exception in AttributeDisplay\n" + e);
e.printStackTrace();
}
}
/**
* Removes all extra editors, leaves only the default html editor...
*/
//TODO: figure this out...
public void clearEditors()
{
removeAll();
activeEditors.removeAllElements();
templateDisplay.setToDefault();
addEditor(templateDisplay);
tableDisplay.displayEntry(null, null);
addEditor(tableDisplay);
}
/**
* Removes all transient editors, and ensures that the table editor
* and the html editor are available.
*/
void clearPluggableEditors()
{
ignoreChangeEvents = true;
for (int i=activeEditors.size()-1; i>=0; i--)
{
PluggableEditor ed = (PluggableEditor)activeEditors.get(i);
if ( (ed != templateDisplay) && (ed != tableDisplay) )
{
remove(i);
}
}
if (activeEditors.contains(templateDisplay)==false)
{
addEditor(templateDisplay);
}
if (activeEditors.contains(tableDisplay)==false)
{
addEditor(tableDisplay);
}
if (currentEditor != tableDisplay && currentEditor != templateDisplay)
{
suggestHTMLEditor();
}
ignoreChangeEvents = false;
}
/**
* This looks through a list of object classes in an attribute
* until it finds a unique editor corresponding to a particular
* value. If no editor is found 'null' is returned. Note that
* If multiple unique editors exist, which one is returned is
* undefined.<p>
*
* @param oc the objectClass attribute; a list of object classes
* @return the unique pluggable editor corresponding to one particular
* object class value, or null if none is found.
*
*/
public PluggableEditor getUniqueEditor(Attribute oc)
{
try
{
Enumeration values = oc.getAll();
while (values.hasMoreElements())
{
String objectClassName = (String)values.nextElement();
PluggableEditor editor = getEditor(objectClassName);
if (editor != null)
{
if (editor.isUnique())
return editor;
}
}
return null;
}
catch (Exception e)
{
log.log(Level.FINE, "Unable to find unique pluggable editor: ", e);
return null;
}
}
/**
* Gets a pluggable editor for a particular object class name.
* @param ocName the object class name to look up
* @return a corresponding editor, or null if none exists.
*/
PluggableEditor getEditor(String ocName)
{
ocName = ocName.toLowerCase();
Object editorFromHash = editors.get(PACKAGEPREFIX + ocName);
if (editorFromHash != null)
return castToPluggableEditor(editorFromHash, ocName); // get it from storage
return loadEditorFromDisk(PACKAGEPREFIX + ocName ); // may be null
}
/**
* Try to cast the object to a PluggableEditor, or return null if it is a placeholder.
* @param rawEditor the editor to cast (or a 'NONE' object placeholder)
* @param ocName the name of the editor (for error print out)
*/
private PluggableEditor castToPluggableEditor(Object rawEditor, String ocName)
{
if (rawEditor == NONE) // we have no editor for this entry, and we've already looked.
return null;
if (rawEditor instanceof PluggableEditor) // already have an editor for that oc
{
return (PluggableEditor)rawEditor;
}
else
{
log.warning("Unexpected Class Cast Error loading plugin editor '"+PACKAGEPREFIX + ocName + "' from hashtable");
return null;
}
}
/**
* Look on disk for an editor with the class name 'ocName'.
*/
PluggableEditor loadEditorFromDisk(String ocName)
{
// if here, we need to look on disk for a pluggable editor class...
log.finer("looking for ocName: " + ocName);
try
{
Class c = myLoader.loadClass(ocName);
Constructor constructor = c.getConstructor(new Class[0]);
// XXX If the pluggable editor has an error in the constructor, under some
// XXX circumstances it can fail so badly that this call never returns, and
// XXX the thread hangs! It doesn't even get to the exception handler below...
// XXX but sometimes if the constructor fails everything works as expected. Wierd.
PluggableEditor editor = (PluggableEditor) constructor.newInstance(new Object[0]);
editors.put(ocName, editor); // add the new editor to our list
return editor;
}
catch (Exception e) // expected condition - just means no pluggable editor available
{
if (e instanceof InvocationTargetException) // rare exception - an error was encountered in the plugin's constructor.
{
log.warning("unable to load special editor for: '" + ocName + "' " + e);
if (JXplorer.debugLevel >= 1)
{
log.warning("Error loading plugin class: ");
((InvocationTargetException)e).getTargetException().printStackTrace();
}
}
log.log(Level.FINEST, "'Expected' Error loading " + ocName, e);
editors.put(ocName, NONE); // add a blank place holder - we can't load
// an editor for this, and there's no point looking again. (change if want dynamic loading, i.e. look *every* time)
}
return null; // only here if an error has occured.
}
/**
* This can be used to register Swing components that may be
* used by sub editors to affect the outside environment.
*/
public void registerComponents(JMenuBar menu, JToolBar buttons, JTree tree, JPopupMenu treeMenu, JFrame jxplorer)
{
registerMenu = menu;
registerButtons = buttons;
registerTree = tree;
registerTreeMenu = treeMenu;
registerJX = jxplorer;
// reset the sub editors as well.
for (int i=0; i<activeEditors.size(); i++)
{
((PluggableEditor)activeEditors.get(i)).registerComponents(menu, buttons, tree, treeMenu, jxplorer);
}
}
/**
* Adds an editor to the current collection of active editors,
* and makes it a tab pane.
*/
void addEditor(PluggableEditor ed)
{
if (activeEditors.contains(ed) == false) // don't add editors twice!
{
add(ed);
ed.registerComponents(registerMenu, registerButtons, registerTree, registerTreeMenu, registerJX);
}
}
/**
* Adds a particular editor to the tab pane and collection of
* active editors, while removing all others.
*/
void addUniqueEditor(PluggableEditor ed)
{
ignoreChangeEvents = true; // don't bother the change listener until we've settled everything
removeAll();
addEditor(ed);
setCurrentEditor(ed);
ignoreChangeEvents = false; // start the change listener listening again.
}
/**
* Refreshes the currently visible editor with new info.
* .
*/
public void refreshEditors()
{
//TE: This method is in response to bug 367 re the fields in the
// HTML templates disappearing when the look and feel changes.
// Forcing a refresh of the page seems to solve the problem.
// Currently is is only being used by AdvancedOptions (yea...a bit
// of a lame fix).
if(dataSource != null)
refreshEditors(entry, dataSource);
}
/**
* Refreshes the currently visible editor with new info.
*/
public void refreshEditors(DXEntry entry, DataSource ds)
{
if (currentEditor != null)
{
this.entry = entry; //TE: make sure everything is in sink.
dataSource = ds;
currentEditor.getDataSink().displayEntry(entry, ds);
// check that the editor hasn't changed display component
JComponent display = currentEditor.getDisplayComponent();
// XXX hack alert - some editor writers change their display component
// XXX mid-flight, and expect JX to magically notice, and change the
// XXX the display. This code attempts to do this.
if (indexOfComponent(display) == -1) // we have a problem - the display component has changed
{
String title = currentEditor.getName();
ImageIcon icon = currentEditor.getIcon();
String toolTip = currentEditor.getToolTip();
int index = getSelectedIndex(); // find the index of the editor (XXX - this relies on the activeEditor vector tracking the inherent tab pane order)
super.remove(index);
super.insertTab(title, icon, display, toolTip, index);
super.setSelectedIndex(index);
}
}
else
log.warning("internal error - no editor available in AttributeDisplay");
}
/**
* Return the thingumy that should be printed.
*/
public Component getPrintComponent()
{
return currentEditor.getPrintComponent();
}
public boolean canCreateEntry() { return true; }
public void add(PluggableEditor ed)
{
add(ed, getTabCount());
}
public void add(PluggableEditor ed, int index)
{
//add(ed.getName(), ed.getDisplayComponent()); // wierd array bounds error thrown here?
insertTab(ed.getName(), ed.getIcon(), ed.getDisplayComponent(), ed.getToolTip(), index);
activeEditors.add(index, ed);
}
public void remove(int index)
{
if (activeEditors.size() == 0) return; // it can get a bit excitable about removing element 0 ...
PluggableEditor ed = (PluggableEditor) activeEditors.remove(index);
ed.unload();
super.remove(index);
}
public void removeAll()
{
int size = activeEditors.size();
for (int i=size-1; i>=0; i--)
remove(i);
super.removeAll(); // XXX this really shouldn't be necessary.
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -