blob: 6dcffeb956e983b1f9867fee7748f227c7355554 [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.maven.repository;
import java.beans.PropertyVetoException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.modules.maven.indexer.api.NBVersionInfo;
import org.netbeans.modules.maven.indexer.spi.ui.ArtifactNodeSelector;
import org.openide.explorer.ExplorerManager;
import org.openide.nodes.Node;
import org.openide.nodes.NodeNotFoundException;
import org.openide.nodes.NodeOp;
import org.openide.util.Mutex;
import org.openide.util.RequestProcessor;
import org.openide.util.lookup.ServiceProvider;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
@ServiceProvider(service=ArtifactNodeSelector.class)
public class ArtifactNodeSelectorImpl implements ArtifactNodeSelector {
private static final Logger LOG = Logger.getLogger(ArtifactNodeSelectorImpl.class.getName());
@Override public void select(final NBVersionInfo artifact) {
// copied from hudson module; cf. #7551
Mutex.EVENT.readAccess(new Runnable() {
@Override 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() {
@Override public void run() {
Node _selected;
try {
_selected = NodeOp.findPath(root, new String[] {M2RepositoryBrowser.NAME, artifact.getRepoId(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()});
} catch (NodeNotFoundException x) {
LOG.log(Level.FINE, "Could not find subnode", x);
_selected = x.getClosestNode();
}
final Node selected = _selected;
Mutex.EVENT.readAccess(new Runnable() {
@Override public void run() {
try {
mgr.setSelectedNodes(new Node[] {selected});
} catch (PropertyVetoException x) {
LOG.log(Level.FINE, "Could not select path", x);
}
}
});
}
});
}
});
}
}