insertresourcelinkedit.java

来自「java xml 应用开发」· Java 代码 · 共 91 行

JAVA
91
字号
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;

/*
 * InsertResourceLinkEdit.java
 * @author Elena Skobchenko
 */

public class InsertResourceLinkEdit extends AbstractUndoableEdit 
{
    private static final long serialVersionUID = -2778264565816334345L;
    
    private JDFTreeNode node;
    private JDFNode jdfNode;
    private JDFTreeNode resLinkNode;
    private JDFResourceLink resLink;
    private JDFTreeNode resLinkPoolNode;
    private JDFResourceLinkPool resLinkPool;
    private JDFFrame parFrame;
    private TreePath path = null;
    private TreePath resLinkPath = null; 
    private boolean hasResourceLinkPool;
    private boolean success = true;
    
    public InsertResourceLinkEdit(final JDFFrame parent, final JDFNode jdfNode, final JDFTreeNode node, 
                                  boolean hasResourceLinkPool, final JDFResourceLink resLink, final JDFTreeNode resLinkNode) 
    {
        parFrame = parent;
        this.node = node;
        this.jdfNode = jdfNode;
        this.resLink = resLink;
        this.resLinkNode = resLinkNode;
        this.hasResourceLinkPool = hasResourceLinkPool;
        path = new TreePath(node.getPath());
        
        resLinkPath = new TreePath(resLinkNode.getPath());
        resLinkPoolNode = (JDFTreeNode) resLinkNode.getParent();
        resLinkPool = (JDFResourceLinkPool) resLink.getParentNode_KElement();
                
        parFrame.updateViews(resLinkPath);
    }

    public void undo() throws CannotUndoException 
    {
        success = parFrame.deleteItem(resLinkPath);
        if (!hasResourceLinkPool)
        {
            parFrame.deleteItem(resLinkPath.getParentPath()); // delete ResLinkPool if it did not exist before action started
        }
        else
        {
            path = new TreePath(resLinkPoolNode.getPath()); // path to select in a tree after undo
        }
        parFrame.updateViews(path);
    }

    public void redo() throws CannotRedoException 
    {        
        if (!hasResourceLinkPool)
        {
            parFrame.insertInto(node, resLinkPoolNode, -1);
            jdfNode.appendChild(resLinkPool);
        }
        parFrame.insertInto(resLinkPoolNode, resLinkNode, -1);
        resLinkPool.appendChild(resLink);
        
        parFrame.updateViews(resLinkPath);
    }

    public boolean canUndo() 
    {
        return success;
    }

    public boolean canRedo() 
    {
        return success;
    }
    
    public String getPresentationName() 
    {
        return "Insert ResourceLink";
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?