📄 insertresourceandlinkedit.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.JDFResourceLink;
import org.cip4.jdflib.node.JDFNode;
import org.cip4.jdflib.pool.JDFResourceLinkPool;
import org.cip4.jdflib.pool.JDFResourcePool;
import org.cip4.jdflib.resource.JDFResource;
/*
* InsertResourceAndLinkEdit.java
* @author Elena Skobchenko
*/
public class InsertResourceAndLinkEdit extends AbstractUndoableEdit
{
private static final long serialVersionUID = -2778264565816334345L;
private JDFTreeNode node;
private JDFNode jdfNode;
private JDFTreeNode resNode;
private JDFResource res;
private JDFTreeNode resLinkNode;
private JDFResourceLink resLink;
private JDFTreeNode resPoolNode;
private JDFResourcePool resPool;
private JDFTreeNode resLinkPoolNode;
private JDFResourceLinkPool resLinkPool;
private JDFFrame parFrame;
private TreePath path = null;
private TreePath resPath = null;
private TreePath resLinkPath = null;
private boolean hasResourcePool;
private boolean hasResourceLinkPool;
private boolean resSuccess = true;
private boolean resLinkSuccess = true;
public InsertResourceAndLinkEdit(final JDFFrame parent,
final JDFNode jdfNode, final JDFTreeNode node,
boolean hasResourcePool, boolean hasResourceLinkPool,
final JDFTreeNode resNode, final JDFTreeNode resLinkNode)
{
parFrame = parent;
this.node = node;
this.jdfNode = jdfNode;
this.resNode = resNode;
this.resLinkNode = resLinkNode;
this.hasResourcePool = hasResourcePool;
this.hasResourceLinkPool = hasResourceLinkPool;
path = new TreePath(node.getPath());
res = (JDFResource) ((ResourceWrapper)resNode.getUserObject()).getElement();
resPath = new TreePath(resNode.getPath());
resPoolNode = (JDFTreeNode) resNode.getParent();
resPool = (JDFResourcePool) res.getParentNode_KElement();
if (resLinkNode != null)
{
resLink = (JDFResourceLink) ((ResourceLinkWrapper)resLinkNode.getUserObject()).getElement();
resLinkPath = new TreePath(resLinkNode.getPath());
resLinkPoolNode = (JDFTreeNode) resLinkNode.getParent();
resLinkPool = (JDFResourceLinkPool) resLink.getParentNode_KElement();
}
parFrame.updateViews(resPath);
}
public void undo() throws CannotUndoException
{
resSuccess = parFrame.deleteItem(resPath);
if (!hasResourcePool)
{
parFrame.deleteItem(resPath.getParentPath()); // delete ResPool if it did not exist before action started
}
if (resLinkPath != null)
{
resLinkSuccess = parFrame.deleteItem(resLinkPath);
if (!hasResourceLinkPool)
{
parFrame.deleteItem(resLinkPath.getParentPath()); // delete ResLinkPool if it did not exist before action started
}
}
if (hasResourcePool)
{
path = new TreePath(resPoolNode.getPath()); // path to select in a tree after undo
}
parFrame.updateViews(path);
}
public void redo() throws CannotRedoException
{
if (!hasResourcePool)
{
parFrame.insertInto(node, resPoolNode, -1);
jdfNode.appendChild(resPool);
}
parFrame.insertInto(resPoolNode, resNode, -1);
resPool.appendChild(res);
if (resLink != null)
{
if (!hasResourceLinkPool)
{
parFrame.insertInto(node, resLinkPoolNode, -1);
jdfNode.appendChild(resLinkPool);
}
parFrame.insertInto(resLinkPoolNode, resLinkNode, -1);
resLinkPool.appendChild(resLink);
parFrame.updateViews(resLinkPath);
}
parFrame.updateViews(resPath);
}
public boolean canUndo()
{
return resSuccess && resLinkSuccess;
}
public boolean canRedo()
{
return resSuccess && resLinkSuccess;
}
public String getPresentationName()
{
return "Insert Resource";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -