📄 deleteitemedit.java
字号:
import javax.swing.tree.TreePath;
import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;
import org.cip4.jdflib.core.JDFElement;
import org.cip4.jdflib.util.StringUtil;
/*
* InsertElementAfterEdit.java
* @author Elena Skobchenko
*/
public class DeleteItemEdit extends AbstractUndoableEdit
{
private static final long serialVersionUID = -2778264565816334345L;
private TreePath path;
private JDFTreeNode delNode;
private JDFTreeNode parentNode;
private JDFElement delElement;
private String attributeName;
private String attributeValue;
private JDFElement parElement;
private JDFFrame parFrame;
private int pos;
private boolean success = true;
public DeleteItemEdit(final JDFFrame parentFrame, final TreePath treePath)
{
parFrame = parentFrame;
path = treePath;
delNode = (JDFTreeNode) treePath.getLastPathComponent();
if (!delNode.isElement())
{
attributeName = StringUtil.token(delNode.toString(), 0, "=");
attributeValue = StringUtil.token(delNode.toString(), 1, "=");
if (attributeValue.indexOf("\"") != -1)
{
attributeValue = attributeValue.substring(1,attributeValue.length()-1);
}
}
else
{
delElement = (JDFElement) ((Wrapper) delNode.getUserObject()).getElement();
}
parentNode = (JDFTreeNode) treePath.getParentPath().getLastPathComponent();
parElement = (JDFElement) ((Wrapper) parentNode.getUserObject()).getElement();
pos = parentNode.getIndex(delNode);
success = parFrame.deleteItem(treePath);
parFrame.updateViews(treePath.getParentPath());
}
public void undo() throws CannotUndoException
{
if (!delNode.isElement())
{
parElement.setAttribute(attributeName, attributeValue);
}
else
{
parElement.appendChild(delElement);
}
parFrame.insertInto(parentNode, delNode, pos);
if (delNode == null)
{
success = false;
}
parFrame.updateViews(path);
}
public void redo() throws CannotRedoException
{
success = parFrame.deleteItem(path);
parFrame.updateViews(path.getParentPath());
}
public boolean canUndo()
{
return success && delNode != null;
}
public boolean canRedo()
{
return success && delNode != null;
}
public String getPresentationName()
{
return "Delete";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -