| /* |
| * 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.java.debug; |
| |
| import com.sun.source.util.TreePath; |
| import java.awt.BorderLayout; |
| import java.beans.PropertyChangeEvent; |
| import java.beans.PropertyChangeListener; |
| import javax.swing.ActionMap; |
| import javax.swing.JComponent; |
| import javax.swing.JPanel; |
| import javax.swing.ListSelectionModel; |
| import org.netbeans.api.java.source.CancellableTask; |
| import org.netbeans.api.java.source.CompilationInfo; |
| import org.netbeans.spi.navigator.NavigatorPanel; |
| import org.openide.explorer.ExplorerManager; |
| import org.openide.explorer.ExplorerUtils; |
| import org.openide.explorer.view.BeanTreeView; |
| import org.openide.util.Lookup; |
| import org.openide.util.NbBundle; |
| |
| /** |
| * |
| * @author Jan Lahoda |
| */ |
| public class ElementNavigatorProviderImpl implements NavigatorPanel { |
| |
| private JComponent panel; |
| private final ExplorerManager manager = new ExplorerManager(); |
| |
| /** |
| * Default constructor for layer instance. |
| */ |
| public ElementNavigatorProviderImpl() { |
| manager.addPropertyChangeListener(new PropertyChangeListener() { |
| public void propertyChange(PropertyChangeEvent evt) { |
| if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { |
| TreeNavigatorProviderImpl.setHighlights(ElementNavigatorJavaSourceFactory.getInstance().getFile(), manager); |
| } |
| } |
| }); |
| } |
| |
| public String getDisplayName() { |
| return NbBundle.getMessage(ElementNavigatorProviderImpl.class, "NM_Elements"); |
| } |
| |
| public String getDisplayHint() { |
| return NbBundle.getMessage(ElementNavigatorProviderImpl.class, "SD_Elements"); |
| } |
| |
| public JComponent getComponent() { |
| if (panel == null) { |
| final BeanTreeView view = new BeanTreeView(); |
| view.setRootVisible(true); |
| view.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
| class Panel extends JPanel implements ExplorerManager.Provider, Lookup.Provider { |
| // Make sure action context works correctly: |
| private final Lookup lookup = ExplorerUtils.createLookup(manager, new ActionMap()); |
| { |
| setLayout(new BorderLayout()); |
| add(view, BorderLayout.CENTER); |
| } |
| public ExplorerManager getExplorerManager() { |
| return manager; |
| } |
| public Lookup getLookup() { |
| return lookup; |
| } |
| } |
| panel = new Panel(); |
| } |
| return panel; |
| } |
| |
| public Lookup getLookup() { |
| return null; |
| } |
| |
| public void panelActivated(Lookup context) { |
| ElementNavigatorJavaSourceFactory.getInstance().setLookup(context, new TaskImpl()); |
| } |
| |
| public void panelDeactivated() { |
| ElementNavigatorJavaSourceFactory.getInstance().setLookup(Lookup.EMPTY, null); |
| } |
| |
| private final class TaskImpl implements CancellableTask<CompilationInfo> { |
| |
| public void cancel() { |
| } |
| |
| public void run(CompilationInfo info) { |
| manager.setRootContext(ElementNode.getTree(info, info.getTrees().getElement(new TreePath(info.getCompilationUnit())))); |
| } |
| |
| } |
| |
| } |