📄 addrequiredattredit.java
字号:
import java.util.Vector;
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;
/*
* AddRequiredAttrEdit.java
* @author Elena Skobchenko
*/
public class AddRequiredAttrEdit extends AbstractUndoableEdit
{
private static final long serialVersionUID = -2778264565816334345L;
private TreePath path;
private JDFTreeNode intoNode;
private JDFElement intoElement;
private JDFFrame parFrame;
private Vector addedVector;
private boolean success = true;
public AddRequiredAttrEdit(final JDFFrame parentFrame, final TreePath treePath,
final JDFTreeNode intoNod, final JDFElement intoElem, final Vector addedVect )
{
parFrame = parentFrame;
path = treePath;
this.intoNode = intoNod;
this.intoElement = intoElem;
this.addedVector = addedVect;
JDFTreeNode attrNode = (JDFTreeNode) addedVect.elementAt(0);
parFrame.updateViews(new TreePath(attrNode.getPath()));
}
public void undo() throws CannotUndoException
{
for (int i=0; i < addedVector.size(); i++)
{
JDFTreeNode attrNode = (JDFTreeNode) addedVector.elementAt(i);
TreePath attrPath = new TreePath(attrNode.getPath());
success = parFrame.deleteItem(attrPath);
}
parFrame.updateViews(path);
}
public void redo() throws CannotRedoException
{
TreePath attrPath = null;
for (int i=0; i < addedVector.size(); i++)
{
JDFTreeNode attrNode = (JDFTreeNode) addedVector.elementAt(i);
String attributeName = StringUtil.token(attrNode.toString(), 0, "=");
String attributeValue = StringUtil.token(attrNode.toString(), 1, "=");
if (attributeValue.indexOf("\"") != -1)
{
attributeValue = attributeValue.substring(1,attributeValue.length()-1);
}
intoElement.setAttribute(attributeName, attributeValue);
final Vector vAttNames = intoElement.getAttributeVector_KElement();
for (int j = 0; j < vAttNames.size(); j++)
{
final String attNameStr = vAttNames.elementAt(j).toString();
if (attNameStr.equals(attributeName))
{
parFrame.insertInto(intoNode, attrNode, j);
}
}
attrPath = new TreePath(attrNode.getPath());
}
parFrame.updateViews(attrPath);
}
public boolean canUndo()
{
return success && addedVector.size()>0;
}
public boolean canRedo()
{
return success && addedVector.size()>0;
}
public String getPresentationName()
{
return "AddRequiredAttributes";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -