statusnode.java
来自「cqME :java framework for TCK test.」· Java 代码 · 共 123 行
JAVA
123 行
/*
* $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;
import com.sun.javatest.Status;
import com.sun.javatest.TestDescription;
import com.sun.testme.jtviewer.cookies.ClearCookie;
import com.sun.testme.jtviewer.cookies.RefreshCookie;
import java.io.File;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.nodes.Sheet;
import org.openide.util.Lookup;
import org.openide.util.lookup.Lookups;
/**
*
* @author ag155795
*/
public class StatusNode extends AbstractNode{
public StatusNode(Children children, Object [] objects) {
super(children, new MyProxyLookup());
((MyProxyLookup) getLookup()).setMyLookups(new Lookup[] {
Lookups.fixed(objects),
Lookups.singleton(new RefreshCookie() {
public void refresh() {
getRootNode().updateStatus(true);
}}),
});
updateStatus(false);
}
public Status getStatus() {
Status status = null;
try {
status = (Status) getProperty(StatusProperty.PropertyName).getValue();
} catch (Throwable e) {
e.printStackTrace();
}
return status;
}
private Node.Property getProperty(String name) {
return getSheet().get(Sheet.PROPERTIES).get(name);
}
private StatusNode getRootNode() {
Node parent = this;
while ((parent.getParentNode() != null) && (parent.getParentNode() instanceof StatusNode)) {
parent = parent.getParentNode();
}
return (StatusNode) parent;
}
public void updateStatus(boolean propagate) {
StatusCookie cookie = (StatusCookie) getLookup().lookup(StatusCookie.class);
if (cookie == null) {
return;
}
Status status = cookie.getStatus();
setStatus(status);
if (propagate) {
Node [] children = getChildren().getNodes(true);
for (Node child : children) {
if ((child != null) && (child instanceof StatusNode)) {
((StatusNode) child).updateStatus(true);
}
}
}
}
public void setStatus(Status status) {
try {
Status oldStatus = getStatus();
getProperty(StatusProperty.PropertyName).setValue(status);
if ((oldStatus == null) || (oldStatus.getType() != status.getType())) {
firePropertyChange(StatusProperty.PropertyName, oldStatus, status);
fireIconChange();
fireOpenedIconChange();
}
} catch (Throwable e) {
e.printStackTrace();
}
}
protected Sheet createSheet() {
Sheet result = super.createSheet();
Sheet.Set set = result.createPropertiesSet();
set.put (new StatusProperty(null));
result.put(set);
return result;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?