📄 attributedisplay.java
字号:
/**
* Starts the print operation. This is quite expensive, and is kicked off
* in a separate thread.
*/
public void print()
{
final PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(this);
// make a local copy of the object to be printed, for use by the print thread
// below...
final Component printMe = getPrintComponent();
Thread worker = new Thread()
{
public void run()
{
if (job.printDialog())
{
try
{
// need to make sure that no other thread tries to
// run a print job and set printCompnent at the same
// time...
synchronized(this)
{
printComponent = printMe;
job.print();
printComponent = null;
}
}
catch (Exception ex)
{ log.warning("error printing: " + ex); }
}
}
};
worker.start();
}
/**
* Used to force Attribute Display to show a particular web page,
* rather than an attribute display.
* This forces it to change view to an HTMLTemplateDisplay
* editor, and then show the desired URL thrugh this display.
*
* @param docURL the web page url to be displayed
*/
public void openDocumentURL(String docURL)
{
if (templateDisplay == null)
initHTMLEditor();
templateDisplay.openDocumentURL(docURL);
setCurrentEditor(templateDisplay);
}
/**
* This is a 'get out of jail free' method that allows an external class
* to force the display of a particular editor. (e.g. for a pluggable
* editor system that wants to be started on an empty directory).
* @param entry the entry to display (may be null)
* @param ds the data source to use for directory info.
* @param editorName the name to display in the editor tab.
*/
public void displaySpecialEntry(DXEntry entry, DataSource ds, String editorName)
{
PluggableEditor ed = getEditor(editorName);
if (ed != null)
{
if (ed.isUnique() == false)
{
setCurrentEditor(ed);
}
else
{
if (currentEditor != ed)
addUniqueEditor(ed);
refreshEditors(entry, ds);
oldOCSig = null;
}
}
}
/**
* <p>Displays data that can be modified by the user.</p>
*
* <p>This method also organises which editors are used to
* display the current entry, searching for pluggable editors
* and so on.</p>
*
* @param dxentry the entry to be displayed by all the editors
* @param ds the datasource the editors may use for more info
*/
// XXX hack alert - entry == null && ds != null is a special flag to load the
// XXX 'null entry editor' (for pki group). This is highly volitile while
// XXX requirements are worked out; if they stabilise we'll want to revisit this
// XXX code and neaten it up (and the calling code from smart tree).
public void displayEntry(DXEntry dxentry, DataSource ds)
{
// Set the local data variables.
dataSource = ds;
entry = dxentry;
// check that the default editors have been initialised.
if (tableDisplay == null)
initTableEditor();
if (templateDisplay == null )
initHTMLEditor();
// check for a 'no data' display - if there is no data, revert
// to the default html 'no data' template.
if (entry == null) // || entry.size() == 0) //TE: This is commented out to allow virtual nodes to be edited.
{
if (oldOCSig != null)
{
clearPluggableEditors();
if (activeEditors.size() == 0)
{
addEditor(templateDisplay);
}
oldOCSig = null;
}
refreshEditors(null, ds);
}
else
{
dataSource = ds; // may be null...
Vector ocs = entry.getOrderedOCs();
// try to create a unique 'signature' for a group of object classes
// This relies on them being delivered in the same order though. (Less
// efficient if they aren't, but otherwise shouldn't be a big problem).
String newOCSig = new String();
if (ocs != null)
for (int i=0; i<ocs.size(); i++)
{
Object ocSig = ocs.get(i);
if (ocSig != null)
newOCSig += ocSig.toString();
}
// Check if signiture hasn't changed. If it *has* changed,
// reset the editors using 'setEditors', and update
// the 'old object class signiture' variable.
if (newOCSig.equals(oldOCSig) == false)
{
setEditors(entry, ds, ocs);
oldOCSig = newOCSig;
}
// Some quick sanity checks...
if (entry.getStatus() == DXEntry.NEW) // check for new entries (but *not* NEW_WRITTEN)...
{
// don't allow editors to appear that can't edit a new entry
trimNonNewEntryEditors();
suggestPluggableEditor();
}
else
{
// make sure that the html template display is around...
// XXX (a bit of a hack - this should really check that *all*
// XXX editor that can't handle new entries have been added back...
// XXX (maybe set flag?)
//TE: added '&& !currentEditor.isUnique()' b/c this code always made sure the HTML
//TE: editor is visible, whereas with a unique plugin we only want that one visible...
//TE: unless of course I am totally confused! See bug 674.
if (activeEditors.contains(templateDisplay) == false && !currentEditor.isUnique())
{
add((PluggableEditor)templateDisplay, 0);
if (currentEditor != null) //XXX hack hack.
setCurrentEditor(currentEditor);
}
}
if (activeEditors.contains(currentEditor) == false)
{
suggestPluggableEditor();
}
// now that the editor set we're using has been sorted out,
// actually go and update the editors!
refreshEditors(entry, ds);
}
}
/**
* Not all editors are capable of displaying new entries. This whips through
* and removes all editors that can't.
*/
private void trimNonNewEntryEditors()
{
int size = activeEditors.size();
for (int i=size-1; i>=0; i--)
{
if (((DataSink)activeEditors.get(i)).canCreateEntry() == false)
{
remove(i);
}
}
suggestTableEditor(); // use table editor as default for new entries...
}
/**
* If a purpose written pluggable editor is available, switch to that,
*/
public boolean suggestPluggableEditor()
{
for (int i=activeEditors.size()-1; i>=0; i--)
{
// try to set to the first 'user written' pluggable editor
// that can be found...
PluggableEditor ed = (PluggableEditor)activeEditors.get(i);
if ( (ed != templateDisplay) && (ed != tableDisplay) )
{
setCurrentEditor(ed);
return true;
}
}
return false;
}
/*
* If the table editor is available (i.e. has not been replaced
* by a pluggable editor) this switches the display to the table editor.
*/
public boolean suggestTableEditor()
{
// if we can't find one of those, relapse to the table editor.
if (activeEditors.contains(tableDisplay) == true)
{
setCurrentEditor(tableDisplay);
return true;
}
return false;
}
/*
* If the html editor is available (i.e. has not been replaced
* by a pluggable editor) this switches the display to the table editor.
*/
public boolean suggestHTMLEditor()
{
// if we can't find one of those, relapse to the table editor.
if (activeEditors.contains(templateDisplay) == true)
{
setCurrentEditor(templateDisplay);
return true;
}
return false;
}
/**
* Sets the current editor to the specified editor,
* loads the current entry,
* and makes sure that it is visible
* to the user.
* @param makeCurrent the editor to select.
*/
protected void setCurrentEditor(PluggableEditor makeCurrent)
{
currentEditor = makeCurrent;
if (currentEditor != null && currentEditor.getDataSink()!= null)
currentEditor.getDataSink().displayEntry(entry, dataSource);
int index = activeEditors.indexOf(makeCurrent);
if (index == -1)
{
clearPluggableEditors();
addEditor(makeCurrent);
setSelectedIndex(activeEditors.indexOf(makeCurrent));
}
else if (index != getSelectedIndex())
{
setSelectedIndex(index);
}
}
/**
* Returns the current editor.
*/
protected PluggableEditor getCurrentEditor()
{
return currentEditor;
}
/**
* Clear out all the old editors, and get new editors corresponding
* to the new object classes.
* @param entry the entry to be displayed by all the editors
* @param ds the datasource the editors may use for more info
* @param ocs the object classes (in order) to find editors for.
*/
protected void setEditors(DXEntry entry, DataSource ds, Vector ocs)
{
try
{
clearPluggableEditors(); // clear all extra editors
// search for unique structural editors...
if ("false".equalsIgnoreCase(JXplorer.getProperty("plugins.ignoreUniqueness")))
{
if(ocs==null) //TE: may happen if virtual entry.
return;
int size = ocs.size();
for (int i=0; i<size; i++)
{
Object objectClass = ocs.get(i);
if (objectClass != null)
{
PluggableEditor ed = getEditor(objectClass.toString());
if (ed != null && ed.isUnique() == true) // found a unique editor
{ // so clear old ones,
addUniqueEditor(ed); // and use the unique one
refreshEditors(entry, ds); // to display the data
setCurrentEditor(ed);
return; // ... and exit.
}
}
}
}
else
log.warning("skipping uniqueness test for pluggable editors");
boolean newEdSet = false;
// search for non-unique structural editors
for (int i=0; i<ocs.size(); i++)
{
Object objectClass = ocs.get(i);
if (objectClass != null)
{
PluggableEditor ed = getEditor(objectClass.toString());
if (ed != null)
{
addEditor(ed);
// Force the displayed editor to be the first pluggable one...
if (newEdSet == false)
{
setCurrentEditor(ed);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -