📄 smartpopuptool.java
字号:
br.setItemEnabled(br.PASTE_ALIAS, false);
}
/**
* 'Copies' a subtree by registering the DN of the copied
* branch, which is accessed by the paste ftn. - the @paste
* ftn then has responsibility for copying the subtree.
*/
public void copy()
{
DN activeDN = getActiveDN();
log.fine("Copy "+ activeDN);
copyDN = activeDN;
cutDN = null;
selectDN = null;
br.setItemEnabled(br.PASTE, true);
br.setItemEnabled(br.PASTE_ALIAS, true);
}
/**
* This checks to see if the 'confirm tree operations' option is on. If it is,
* it sticks up an annoying dialog box to ask the user whether they actually want
* to do what they just asked to do.
* @param operationType the type of operation being performed e.g. delete, copy etc.
*/
protected boolean checkAction(String operationType)
{
// String prop = com.ca.directory.jxplorer.JXplorer.myProperties.getProperty("option.confirmTreeOperations");
String prop = JXplorer.getProperty("option.confirmTreeOperations");
if ("false".equalsIgnoreCase(prop)) // the user has wisely decided not to bother with this mis-feature.
return true;
return (JOptionPane.showConfirmDialog(this, CBIntText.get("The {0} operation will modify the directory - continue?", new String[] {operationType}),
CBIntText.get("Confirm Tree Operation"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE)
== JOptionPane.OK_OPTION);
}
/**
* The paste ftn either copies or moves a pre-selected subtree
* depending
*/
public void paste()
{
// make sure we're not pasting something into itself...
DN activeDN = getActiveDN();
if ((activeDN==null)||(cutDN == null && copyDN == null)) // should never happen...
return; // so ignore it.
String from = (copyDN==null)?cutDN.toString():copyDN.toString();
String to = activeDN.toString();
log.fine("pasting: \n" + from + "\n" + to);
if (to.endsWith(from))
{
CBUtility.error(this, CBIntText.get("Unable to paste an object into itself!"));
return;
}
if (copyDN != null)
{
copy(copyDN, activeDN);
}
else if (cutDN != null)
{
move(cutDN, activeDN);
}
}
/**
* Move the node to another location (performs a cut operation).
* Currently this is being used by the drag functionality - the difference
* between this method and the move(DN moveFrom, DN moveTo) method is purely
* that this method does NOT show a confirmation message even if that option is
* set to true by the user.
* @param moveFrom the DN of the entry to be moved (or cut).
* @param moveTo the new DN of the entry i.e. where it will be cut to.
* .
*/
//TE: XXXXXXX A TEMP FIX FOR BUG 2742 - WE STILL NEED A CONFIRMATION DIALOG...THIS IS
// JUST A WORK AROUND FOR JX CRASHING WHEN DISPLAYING THE CONFIRMATION DIALOG.
public void dragMove(DN moveFrom, DN moveTo)
{
try
{
moveTo.addChildRDN(moveFrom.getLowestRDN().toString());
}
catch (javax.naming.InvalidNameException e)
{
CBUtility.error(tree, CBIntText.get("Unable to add {0} to {1} due to bad name", new String[] {moveFrom.toString(),moveTo.toString()}),e);
return;
}
tree.modifyEntry(new DXEntry(moveFrom), new DXEntry(moveTo));
cutDN = null;
br.setItemEnabled(br.PASTE, false);
br.setItemEnabled(br.PASTE_ALIAS, false);
}
/**
* Move the node to another location (performs a cut operation).
* @param moveFrom the DN of the entry to be moved (or cut).
* @param moveTo the new DN of the entry i.e. where it will be cut to.
*/
public void move(DN moveFrom, DN moveTo)
{
// 'move'ing a tree means placing the old tree *under*
// the newly selected tree... hence deepen 'activeDN' by
// one new level. (i.e. ou=eng,o=uni,c=au moved to o=biz,c=au
// requires activeDN extended to ou=eng,o=biz,c=au before move
if (checkAction("cut") == false)
return;
try
{
moveTo.addChildRDN(moveFrom.getLowestRDN().toString());
}
catch (javax.naming.InvalidNameException e)
{
CBUtility.error(tree, CBIntText.get("Unable to add {0} to {1} due to bad name", new String[] {moveFrom.toString(),moveTo.toString()}),e);
return;
}
tree.modifyEntry(new DXEntry(moveFrom), new DXEntry(moveTo));
cutDN = null;
br.setItemEnabled(br.PASTE, false);
br.setItemEnabled(br.PASTE_ALIAS, false);
}
/**
* Copys (in the directory) the selected DN to the new
* destination. The copied entry/subtree is placed *under*
* the destination node.
* Currently this is being used by the drag functionality - the difference
* between this method and the copy(DN copyFrom, DN copyTo) method is purely
* that this method does NOT show a confirmation message even if that option is
* set to true by the user.
* @param copyFrom the DN of an entry or subtree apex to copy entries from
* @param copyTo the location to copy to.
* .
*/
//TE: XXXXXXX A TEMP FIX FOR BUG 2742 - WE STILL NEED A CONFIRMATION DIALOG...THIS IS
// JUST A WORK AROUND FOR JX CRASHING WHEN DISPLAYING THE CONFIRMATION DIALOG.
public void dragCopy(DN copyFrom, DN copyTo)
{
tree.copyTree(copyFrom, copyTo);
}
/**
* Copys (in the directory) the selected Dn to the new
* destination. The copied entry/subtree is placed *under*
* the destination node.
* @param copyFrom the DN of an entry or subtree apex to copy entries from
* @param copyTo the location to copy to.
*/
public void copy(DN copyFrom, DN copyTo)
{
if (checkAction("paste") == false)
return;
tree.copyTree(copyFrom, copyTo);
}
/**
* Deletes the currently <i>selected</i> entry.
*/
public void delete()
{
DN activeDN = getActiveDN();
// If a delete is performed with a null DN, the whole DIT is deleted. Check for a null DN...
if(activeDN == null || activeDN.isEmpty())
{
log.warning("An invalid DN was requested to be deleted: " + activeDN);
JOptionPane.showMessageDialog(this, CBIntText.get("Please select a valid entry to delete."),
CBIntText.get("No Entry Selected"), JOptionPane.WARNING_MESSAGE);
return;
}
if (checkAction("delete") == false)
return;
log.fine("deleting " + activeDN);
tree.modifyEntry(new DXEntry(activeDN), null);
br.setItemEnabled(br.PASTE_ALIAS, false);
tree.clearEntry(); //TE: display a null entry.
}
/**
* Starts the tree cell editor on the currently <i>selected</i> entry.
*/
public void rename()
{
if (checkAction("rename") == false) return;
tree.getTree().startEditingAtPath(getActivePath()); // renameSubTree called by the TreeCellListener
br.setItemEnabled(br.PASTE_ALIAS, false);
}
/**
* Uses the tree to start the process of creating a new entry.
*/
public void newEntry()
{
if (newEnabled==false)
{
CBUtility.warning(this,CBIntText.get("Browser unable to add new entries using ldap 2 connection"), CBIntText.get("reduced funcitonality in ldap 2"));
}
else
{
setVisible(false);
repaint();
tree.makeNewEntry(getActiveDN());
}
}
/**
* Creates an alias of the currently copied or copyDN-ed entry
*/
public void pasteAlias()
{
if (checkAction("paste alias") == false)
return;
DN aliasedObject = selectDN;
if (aliasedObject == null)
aliasedObject = copyDN;
if (aliasedObject == null)
{
log.warning("no DN selected for aliasing.");
br.setItemEnabled(br.PASTE_ALIAS, false);
return;
}
DN newAlias = new DN(getActiveDN());
RDN newAliasName = aliasedObject.getLowestRDN();
newAlias.add(newAliasName);
DXEntry alias = new DXEntry(newAlias);
DXAttribute oc = new DXAttribute("objectClass", "top");
oc.add("alias");
alias.put(oc);
alias.put(new DXAttribute("aliasedObjectName", aliasedObject.toString()));
alias.put(new DXAttribute(newAliasName.getAtt(), newAliasName.getRawVal()));
tree.modifyEntry(null, alias);
}
/**
* Reads the directory to refresh the currently selected entry's data
* and it's immediate children.
*/
public void refresh()
{
tree.refresh(getActiveDN());
}
/**
* Copies a previously selected entry (and it's children) to
* the new position, <i>under</i> the current selection.
*/
public void copyDN()
{
selectDN = new DN(getActiveDN());
StringSelection ss = new StringSelection(selectDN.toString());
Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
clip.setContents(ss,ss);
tree.fireJXplorerEvent(new JXplorerEvent(this, JXplorerEvent.EventType.DNSELECTED, selectDN.toString()));
if(!tree.getName().equalsIgnoreCase("Schema"))
br.setItemEnabled(br.PASTE_ALIAS, true);
br.setItemEnabled(br.PASTE, false);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -