testmeproject.java.svn-base

来自「cqME :java framework for TCK test.」· SVN-BASE 代码 · 共 444 行 · 第 1/2 页

SVN-BASE
444
字号
/*
 * $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.project;

import com.sun.testme.jtharness.testsuite.JTharnessSuiteUtil;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;
import org.apache.tools.ant.module.api.support.ActionUtils;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectInformation;
import org.netbeans.api.queries.VisibilityQuery;
import org.netbeans.spi.project.ActionProvider;
import org.netbeans.spi.project.ProjectState;
import org.netbeans.spi.project.support.ant.AntProjectHelper;
import org.netbeans.spi.project.ui.LogicalViewProvider;
import org.netbeans.spi.project.ui.ProjectOpenedHook;
import org.netbeans.spi.project.ui.support.CommonProjectActions;
import org.openide.actions.PropertiesAction;
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileObject;
import org.openide.loaders.ChangeableDataFilter;
import org.openide.loaders.DataFilter;
import org.openide.loaders.DataFolder;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.FilterNode;
import org.openide.nodes.Node;
import org.openide.nodes.NodeEvent;
import org.openide.nodes.NodeListener;
import org.openide.nodes.NodeMemberEvent;
import org.openide.nodes.NodeReorderEvent;
import org.openide.nodes.Sheet;
import org.openide.util.Lookup;
import org.openide.util.actions.SystemAction;
import org.openide.util.lookup.Lookups;

public class TestMEProject implements Project {
    
    public TestMEProject(AntProjectHelper helper) throws IOException {
        this.helper = helper;
        this.projectDir = helper.getProjectDirectory();
    }
    
    public org.openide.filesystems.FileObject getProjectDirectory() {
        return helper.getProjectDirectory();
    }
    
    public Lookup getLookup() {
        if (lkp == null) {
            JTharnessSuiteUtil suiteInfo = new JTharnessSuiteUtil(this);
            lkp = Lookups.fixed( new Object[] {
                new TestMEClassPathProvider(this),
                //new TestMEAuxiliaryConfiguration(),
                new TestMESources(this),
                this,
                //state,
                new ActionProviderImpl(),
                //loadProperties(),
                new Info(),
                new TestMEProjectLogicalView(this),
                new TestMEProjectOpenedHook(),
                suiteInfo
            });
        }
        return lkp;
    }
    
    private final class ActionProviderImpl implements ActionProvider {
        
        private final Set/*<String>*/ COMMON_NON_IDE_GLOBAL_ACTIONS = new HashSet(Arrays.asList(new String[] {
            ActionProvider.COMMAND_BUILD,
            //ActionProvider.COMMAND_RUN
        }));
        
        public String[] getSupportedActions() {
            Vector names = new Vector();
            names.addAll(COMMON_NON_IDE_GLOBAL_ACTIONS);
            return (String[])names.toArray(new String[names.size()]);
        }
        
        public void invokeAction(String string, Lookup lookup) throws IllegalArgumentException {
            if (string.equals(ActionProvider.COMMAND_RUN)) {
                //JTUtils.runTest(null);
            } else {
                FileObject buildFile = getProjectDirectory().getFileObject("build/build.xml");
                
                try {
                    ActionUtils.runTarget(buildFile, new String[]{"build"}, null);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        
        public boolean isActionEnabled(String string, Lookup lookup) throws IllegalArgumentException {
            if (string.equals(ActionProvider.COMMAND_RUN) ||
                    string.equals(ActionProvider.COMMAND_BUILD)) {
                return true;
            } else {
                return false;
            }
        }
    }
    
    private final class Info implements ProjectInformation {
        public String getName() {
            return projectDir.getName();
        }
        
        public String getDisplayName() {
            return getName();
        }
        
        public Icon getIcon() {
            return null;
        }
        
        public Project getProject() {
            return TestMEProject.this;
        }
        
        public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) {
        }
        
        public void removePropertyChangeListener(PropertyChangeListener propertyChangeListener) {
        }
    }
    
    private class TestMEProjectOpenedHook extends ProjectOpenedHook {
        protected void projectOpened() {
            System.out.println("Opened...");
            JTharnessSuiteUtil util = (JTharnessSuiteUtil)TestMEProject.this.getLookup().lookup(JTharnessSuiteUtil.class);
            util.openTestSuite();
            //JTViewerTopComponent win = (JTViewerTopComponent)JTViewerTopComponent.findInstance();
            /*
            win.initWD();
            if (!win.isOpened()) {
                win.open();
            }*/
        }
        
        protected void projectClosed() {
            System.out.print("Closed...");
            FileObject fob = TestMEProject.this.getProjectDirectory().getFileObject("build/plugin.properties");
            if (fob == null) {
                return;
            }
            Properties prop = new Properties();
            try {
                InputStream in = fob.getInputStream();
                prop.load(in);
                in.close();
                //File wrkDirFile = JThanessUtils.getWorkDirectory();
                JTharnessSuiteUtil util = (JTharnessSuiteUtil)TestMEProject.this.getLookup().lookup(JTharnessSuiteUtil.class);
                File wrkDirFile = util.getWorkDirectory();
                if (wrkDirFile != null) {
                    prop.put("wrkDir", wrkDirFile.getPath());
                    FileLock lock = fob.lock();
                    prop.store(fob.getOutputStream(lock), "");
                    lock.releaseLock();
                }
                //JTViewerTopComponent win = (JTViewerTopComponent)JTViewerTopComponent.findInstance();
                //win.close();
            } catch (FileNotFoundException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
    
    private class TestMEProjectLogicalView implements LogicalViewProvider {
        
        public TestMEProjectLogicalView(TestMEProject project) {
            this.project = project;
        }
        
        public org.openide.nodes.Node createLogicalView() {
            try {

⌨️ 快捷键说明

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