blob: 360443955945d8037b2c8fb09241cb36d066b890 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.hudson.ui.api;
import java.beans.PropertyVetoException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Action;
import org.netbeans.modules.hudson.api.HudsonJobBuild;
import org.netbeans.modules.hudson.api.HudsonMavenModuleBuild;
import org.netbeans.modules.hudson.ui.actions.ShowBuildConsole;
import org.netbeans.modules.hudson.ui.actions.ShowChanges;
import org.netbeans.modules.hudson.ui.actions.ShowFailures;
import org.netbeans.modules.hudson.ui.nodes.HudsonRootNode;
import org.openide.explorer.ExplorerManager;
import org.openide.nodes.Node;
import org.openide.nodes.NodeNotFoundException;
import org.openide.nodes.NodeOp;
import org.openide.util.ContextAwareAction;
import org.openide.util.Mutex;
import org.openide.util.RequestProcessor;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
/**
* Utility class for manipulating Hudson-related UI elements.
*/
public class UI {
private UI() {}
private static final Logger LOG = Logger.getLogger(UI.class.getName());
/**
* Try to select a node somewhere beneath the root node in the Services tab.
* @param path a path as in {@link NodeOp#findPath(Node, String[])}
*/
public static void selectNode(final String... path) {
Mutex.EVENT.readAccess(new Runnable() {
public void run() {
TopComponent tab = WindowManager.getDefault().findTopComponent("services"); // NOI18N
if (tab == null) {
// XXX have no way to open it, other than by calling ServicesTabAction
LOG.fine("No ServicesTab found");
return;
}
tab.open();
tab.requestActive();
if (!(tab instanceof ExplorerManager.Provider)) {
LOG.fine("ServicesTab not an ExplorerManager.Provider");
return;
}
final ExplorerManager mgr = ((ExplorerManager.Provider) tab).getExplorerManager();
final Node root = mgr.getRootContext();
RequestProcessor.getDefault().post(new Runnable() {
public void run() {
Node hudson = NodeOp.findChild(root, HudsonRootNode.HUDSON_NODE_NAME);
if (hudson == null) {
LOG.fine("ServicesTab does not contain " + HudsonRootNode.HUDSON_NODE_NAME);
return;
}
Node _selected;
try {
_selected = NodeOp.findPath(hudson, path);
} catch (NodeNotFoundException x) {
LOG.log(Level.FINE, "Could not find subnode", x);
_selected = x.getClosestNode();
}
final Node selected = _selected;
Mutex.EVENT.readAccess(new Runnable() {
public void run() {
try {
mgr.setSelectedNodes(new Node[] {selected});
} catch (PropertyVetoException x) {
LOG.log(Level.FINE, "Could not select path", x);
}
}
});
}
});
}
});
}
/**
* Action to show changes in a build.
*/
public static Action showChangesAction(HudsonJobBuild build) {
return new ShowChanges(build);
}
/**
* Action to show console of a build.
*/
public static Action showConsoleAction(HudsonJobBuild build) {
return new ShowBuildConsole(build);
}
/**
* Action to show console of a Maven module build.
*/
public static Action showConsoleAction(HudsonMavenModuleBuild build) {
return new ShowBuildConsole(build);
}
/**
* Action to show test failures of a build.
*/
public static ContextAwareAction showFailuresAction() {
return ShowFailures.getInstance();
}
}