⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 insertresourcelinkedit.java

📁 java xml 应用开发
💻 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;

/*
 * 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -