testresulteditorsupport.java.svn-base

来自「cqME :java framework for TCK test.」· SVN-BASE 代码 · 共 154 行

SVN-BASE
154
字号
/*
 * $Id$
 *
 * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version
 * 2 only, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License version 2 for more details (a copy is
 * included at /legal/license.txt).
 *
 * You should have received a copy of the GNU General Public License
 * version 2 along with this work; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
 * Clara, CA 95054 or visit www.sun.com if you need additional
 * information or have any questions.
 *
 */

package com.sun.testme.jtviewer.jtrsupport.editor;

import com.sun.testme.jtviewer.jtrsupport.JTRDataObject;
import java.io.IOException;
import java.io.Serializable;
import org.netbeans.core.spi.multiview.CloseOperationHandler;
import org.netbeans.core.spi.multiview.CloseOperationState;
import org.netbeans.core.spi.multiview.MultiViewDescription;
import org.netbeans.core.spi.multiview.MultiViewFactory;
import org.openide.cookies.CloseCookie;
import org.openide.cookies.EditCookie;
import org.openide.cookies.EditorCookie;
import org.openide.cookies.OpenCookie;
import org.openide.cookies.SaveCookie;
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataObject;
import org.openide.text.CloneableEditorSupport;
import org.openide.text.DataEditorSupport;
import org.openide.windows.CloneableOpenSupport;
import org.openide.windows.CloneableTopComponent;
import org.openide.windows.Mode;
import org.openide.windows.WindowManager;

/**
 *
 * @author Alexander Glasman
 */
public class TestResultEditorSupport extends DataEditorSupport implements OpenCookie, EditorCookie, EditCookie, CloseCookie {

    protected CloneableEditorSupport.Pane createPane() {
        MultiViewDescription[] descriptions = {
            new TestResultTextDescription((JTRDataObject)getDataObject()),
            new TestResultSectionDescription((JTRDataObject)getDataObject())
        };
        CloneableTopComponent mvtc = MultiViewFactory.
                createCloneableMultiView(descriptions, descriptions[1], new CloseHandler((JTRDataObject)getDataObject()));
        Mode editorMode = WindowManager.getDefault().findMode(CloneableEditorSupport.EDITOR_MODE);
        if (editorMode != null) {
            editorMode.dockInto(mvtc);
        }
        return (CloneableEditorSupport.Pane) mvtc;
    }
   
    private TestResultEditorSupport(JTRDataObject obj) {
        super(obj, new TestResultEnv(obj));
    }

    public static TestResultEditorSupport create(JTRDataObject obj) {
        return new TestResultEditorSupport(obj);
    }    

    protected boolean notifyModified() {
        boolean retValue;
        retValue = super.notifyModified();
        if (retValue) {
            JTRDataObject obj = (JTRDataObject)getDataObject();
            obj.ic.add(env);
        }
        return retValue;
    }

    protected void notifyUnmodified() {
        super.notifyUnmodified();
        JTRDataObject obj = (JTRDataObject)getDataObject();
        obj.ic.remove(env);
    }    

    
    private static final class TestResultEnv extends DataEditorSupport.Env implements SaveCookie {
        private static final long serialVersionUID = -1L;
        private JTRDataObject jtrDataObject;
           
        public TestResultEnv(JTRDataObject obj) {
            super(obj);
            jtrDataObject = obj;
        }

        public void save() throws IOException {
            TestResultEditorSupport ed = (TestResultEditorSupport)this.findCloneableOpenSupport();
            ed.saveDocument();
        }

        protected FileObject getFile() {
            return jtrDataObject.getPrimaryFile();
        }

        protected FileLock takeLock() throws IOException {
            return jtrDataObject.getPrimaryEntry().takeLock();
        }

        
//        public void writeExternal(ObjectOutput out) throws IOException {
//            out.writeObject(jtrDataObject);
//        }
//
//        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
//        {
//            Object firstObject = in.readObject();
//            if (firstObject instanceof JTRDataObject)
//                jtrDataObject = (JTRDataObject) firstObject;
//        }

         public CloneableOpenSupport findCloneableOpenSupport() {
            return (TestResultEditorSupport)getDataObject().getCookie(TestResultEditorSupport.class);
        }
    }
    
    private static class CloseHandler implements CloseOperationHandler, Serializable {
        private static final long serialVersionUID =-3126744315424172415L;        
        private DataObject dataObject;

        private CloseHandler() {
        }

        public CloseHandler(DataObject jtrDO) {
            dataObject = jtrDO;
        }

        public boolean resolveCloseOperation(CloseOperationState[] elements) {
            TestResultEditorSupport editorSupport = (TestResultEditorSupport) dataObject.getCookie(TestResultEditorSupport.class);
            return editorSupport != null ? editorSupport.canClose() : true;
        }
    }


}

⌨️ 快捷键说明

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