--- spi.navigator/apichanges.xml +++ spi.navigator/apichanges.xml @@ -108,6 +108,21 @@ + + + Added SPI interface @NavigatorPanelWithToolbar + + + + + +

+ Added SPI interface @NavigatorPanelWithToolbar. Clients will implement this interface when they need a toolbar for their Navigator view/panel. +

+
+ + +
Added @NavigatorPanel.Registration --- spi.navigator/manifest.mf +++ spi.navigator/manifest.mf @@ -2,4 +2,4 @@ OpenIDE-Module: org.netbeans.spi.navigator/1 OpenIDE-Module-Layer: org/netbeans/modules/navigator/resources/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/navigator/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 1.24 +OpenIDE-Module-Specification-Version: 1.25 --- spi.navigator/src/org/netbeans/modules/navigator/LazyPanel.java +++ spi.navigator/src/org/netbeans/modules/navigator/LazyPanel.java @@ -45,6 +45,7 @@ import java.util.Map; import javax.swing.JComponent; import org.netbeans.spi.navigator.NavigatorPanel; +import org.netbeans.spi.navigator.NavigatorPanelWithToolbar; import org.netbeans.spi.navigator.NavigatorPanelWithUndo; import org.openide.awt.UndoRedo; import org.openide.util.Lookup; @@ -52,7 +53,7 @@ /** * Delegating panel for use from {@link NavigatorPanel.Registration}. */ -public class LazyPanel implements NavigatorPanelWithUndo { +public class LazyPanel implements NavigatorPanelWithToolbar { /** * Referenced from generated layer. @@ -112,4 +113,9 @@ return p instanceof NavigatorPanelWithUndo ? ((NavigatorPanelWithUndo) p).getUndoRedo() : UndoRedo.NONE; } + @Override + public JComponent getToolbarComponent() { + NavigatorPanel p = initialize(); + return p instanceof NavigatorPanelWithToolbar ? ((NavigatorPanelWithToolbar) p).getToolbarComponent() : null; + } } --- spi.navigator/src/org/netbeans/modules/navigator/NavigatorTC.form +++ spi.navigator/src/org/netbeans/modules/navigator/NavigatorTC.form @@ -7,6 +7,7 @@ + @@ -22,15 +23,32 @@ - + + + + + + - - + + + + + + + + + + + + + + --- spi.navigator/src/org/netbeans/modules/navigator/NavigatorTC.java +++ spi.navigator/src/org/netbeans/modules/navigator/NavigatorTC.java @@ -46,6 +46,7 @@ import java.awt.BorderLayout; import java.awt.Color; +import java.awt.GridBagConstraints; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; @@ -59,6 +60,7 @@ import javax.swing.UIManager; import org.netbeans.spi.navigator.NavigatorDisplayer; import org.netbeans.spi.navigator.NavigatorPanel; +import org.netbeans.spi.navigator.NavigatorPanelWithToolbar; import org.netbeans.spi.navigator.NavigatorPanelWithUndo; import org.openide.ErrorManager; import org.openide.awt.UndoRedo; @@ -214,6 +216,19 @@ } else { contentArea.removeAll(); contentArea.add(panel.getComponent(), BorderLayout.CENTER); + + pnlToolbar.removeAll(); + if (panel instanceof NavigatorPanelWithToolbar && ((NavigatorPanelWithToolbar)panel).getToolbarComponent() != null) { + JComponent toolbar = ((NavigatorPanelWithToolbar)panel).getToolbarComponent(); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.anchor = GridBagConstraints.WEST; + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.weightx = 1.0; + pnlToolbar.add(toolbar, gbc); + pnlToolbar.setVisible(true); + } else { + pnlToolbar.setVisible(false); + } revalidate(); repaint(); } @@ -372,16 +387,37 @@ */ // //GEN-BEGIN:initComponents private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; holderPanel = new javax.swing.JPanel(); panelSelector = new javax.swing.JComboBox(); + pnlToolbar = new javax.swing.JPanel(); contentArea = new javax.swing.JPanel(); setLayout(new java.awt.BorderLayout()); - holderPanel.setLayout(new java.awt.BorderLayout()); - holderPanel.add(panelSelector, java.awt.BorderLayout.CENTER); + holderPanel.setLayout(new java.awt.GridBagLayout()); + panelSelector.setMinimumSize(new java.awt.Dimension(100, 20)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE; + gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.weightx = 1.0; + holderPanel.add(panelSelector, gridBagConstraints); + + pnlToolbar.setOpaque(false); + pnlToolbar.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE; + gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; + gridBagConstraints.weightx = 1.5; + gridBagConstraints.insets = new java.awt.Insets(0, 3, 0, 0); + holderPanel.add(pnlToolbar, gridBagConstraints); + add(holderPanel, java.awt.BorderLayout.NORTH); contentArea.setLayout(new java.awt.BorderLayout()); @@ -393,6 +429,7 @@ private javax.swing.JPanel contentArea; private javax.swing.JPanel holderPanel; private javax.swing.JComboBox panelSelector; + private javax.swing.JPanel pnlToolbar; // End of variables declaration//GEN-END:variables --- spi.navigator/src/org/netbeans/spi/navigator/NavigatorPanelWithToolbar.java +++ spi.navigator/src/org/netbeans/spi/navigator/NavigatorPanelWithToolbar.java @@ -0,0 +1,67 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.spi.navigator; + +import javax.swing.JComponent; + +/** Description of navigation view with a toolbar component on top of basic + * NavigatorPanel and NavigatorPanelWithUndo features. + * + * Clients will implement this interface when they need a toolbar for their Navigator view/panel. + * + * Implementors of this interface will be plugged into Navigator UI. + * @see NavigatorPanel.Registration + * + * @since 1.25 + * + * @author jpeska + */ +public interface NavigatorPanelWithToolbar extends NavigatorPanelWithUndo { + + /** Returns a JComponent which represents panel toolbar. + * + * It allows clients to display a toolbar on top of the Navigator window, next to the panel chooser (ComboBox). + * + * @return Instance of JComponent. + */ + public JComponent getToolbarComponent(); +}