# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: F:\Sources\MainTrunk\core\navigator # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: src/org/netbeans/modules/navigator/NavigatorController.java *** F:\Sources\MainTrunk\core\navigator\src\org\netbeans\modules\navigator\NavigatorController.java Base (1.11) --- F:\Sources\MainTrunk\core\navigator\src\org\netbeans\modules\navigator\NavigatorController.java Locally Modified (Based On 1.11) *************** *** 56,65 **** import org.openide.windows.WindowManager; /** * * @author Dafe Simonek */ ! final class NavigatorController implements LookupListener, ActionListener, Lookup.Provider, PropertyChangeListener { /** Time in ms to wait before propagating current node changes further * into navigator UI */ --- 56,66 ---- import org.openide.windows.WindowManager; /** + * Listen to user action and handles navigator behaviour. * * @author Dafe Simonek */ ! public final class NavigatorController implements LookupListener, ActionListener, Lookup.Provider, PropertyChangeListener { /** Time in ms to wait before propagating current node changes further * into navigator UI */ *************** *** 144,156 **** return; } NavigatorPanel newPanel = (NavigatorPanel)navigatorTC.getPanels().get(index); NavigatorPanel oldPanel = navigatorTC.getSelectedPanel(); ! if (!newPanel.equals(oldPanel)) { if (oldPanel != null) { oldPanel.panelDeactivated(); } ! newPanel.panelActivated(clientsLookup); ! navigatorTC.setSelectedPanel(newPanel); } } --- 145,167 ---- return; } NavigatorPanel newPanel = (NavigatorPanel)navigatorTC.getPanels().get(index); + activatePanel(newPanel); + } + + /** Activates given panel. Throws IllegalArgumentException if panel is + * not available for activation. + */ + public void activatePanel (NavigatorPanel panel) { + if (!navigatorTC.getPanels().contains(panel)) { + throw new IllegalArgumentException("Panel is not available for activation: " + panel); //NOI18N + } NavigatorPanel oldPanel = navigatorTC.getSelectedPanel(); ! if (!panel.equals(oldPanel)) { if (oldPanel != null) { oldPanel.panelDeactivated(); } ! panel.panelActivated(clientsLookup); ! navigatorTC.setSelectedPanel(panel); } } Index: src/org/netbeans/modules/navigator/NavigatorTC.java *** F:\Sources\MainTrunk\core\navigator\src\org\netbeans\modules\navigator\NavigatorTC.java Base (1.9) --- F:\Sources\MainTrunk\core\navigator\src\org\netbeans\modules\navigator\NavigatorTC.java Locally Modified (Based On 1.9) *************** *** 53,59 **** * * @author Dafe Simonek */ ! final class NavigatorTC extends TopComponent { /** singleton instance */ private static NavigatorTC instance; --- 53,59 ---- * * @author Dafe Simonek */ ! public final class NavigatorTC extends TopComponent { /** singleton instance */ private static NavigatorTC instance; *************** *** 61,67 **** /** Currently active panel in navigator (or null if empty) */ private NavigatorPanel selectedPanel; /** A list of panels currently available (or null if empty) */ ! private List panels; /** Controller, controls behaviour and reacts to user actions */ private NavigatorController controller; /** label signalizing no available providers */ --- 61,67 ---- /** Currently active panel in navigator (or null if empty) */ private NavigatorPanel selectedPanel; /** A list of panels currently available (or null if empty) */ ! private List panels; /** Controller, controls behaviour and reacts to user actions */ private NavigatorController controller; /** label signalizing no available providers */ *************** *** 140,152 **** /** List of panels currently contained in navigator component. * @return List of NavigatorPanel instances or null if navigator is empty */ ! public List getPanels () { return panels; } /** Sets content of navigator to given panels, selecting the first one */ ! public void setPanels (List panels) { this.panels = panels; int panelsCount = panels == null ? -1 : panels.size(); // no panel, so make UI look empty --- 140,152 ---- /** List of panels currently contained in navigator component. * @return List of NavigatorPanel instances or null if navigator is empty */ ! public List getPanels () { return panels; } /** Sets content of navigator to given panels, selecting the first one */ ! public void setPanels (List panels) { this.panels = panels; int panelsCount = panels == null ? -1 : panels.size(); // no panel, so make UI look empty *************** *** 160,170 **** // #63777: hide panel selector when only one panel available panelSelector.setVisible(panelsCount != 1); // fill with new content - NavigatorPanel curPanel = null; JComponent curComp = null; int i = 0; ! for (Iterator iter = panels.iterator(); iter.hasNext(); i++) { ! curPanel = (NavigatorPanel)iter.next(); panelSelector.addItem(curPanel.getDisplayName()); curComp = curPanel.getComponent(); // for better error report in cases like #68544 --- 160,168 ---- // #63777: hide panel selector when only one panel available panelSelector.setVisible(panelsCount != 1); // fill with new content JComponent curComp = null; int i = 0; ! for (NavigatorPanel curPanel : panels) { panelSelector.addItem(curPanel.getDisplayName()); curComp = curPanel.getComponent(); // for better error report in cases like #68544 *************** *** 180,185 **** --- 178,184 ---- if (i == 0) { selectedPanel = curPanel; } + i++; } // show if was hidden resetFromEmpty(); *************** *** 247,265 **** return navTCLookup; } - /*************** private stuff ************/ - /** Accessor for controller which controls UI behaviour */ ! private NavigatorController getController () { if (controller == null) { controller = new NavigatorController(this); } return controller; } /** Removes regular UI content and sets UI to empty state */ private void setToEmpty () { --- 246,262 ---- return navTCLookup; } /** Accessor for controller which controls UI behaviour */ ! public NavigatorController getController () { if (controller == null) { controller = new NavigatorController(this); } return controller; } + + /*************** private stuff ************/ + /** Removes regular UI content and sets UI to empty state */ private void setToEmpty () { if (notAvailLbl.isShowing()) { Index: test/unit/src/org/netbeans/api/navigator/NavigatorHandlerTest.java *** F:\Sources\MainTrunk\core\navigator\test\unit\src\org\netbeans\api\navigator\NavigatorHandlerTest.java No Base Revision --- F:\Sources\MainTrunk\core\navigator\test\unit\src\org\netbeans\api\navigator\NavigatorHandlerTest.java Locally New *************** *** 1,0 **** --- 1,193 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + package org.netbeans.api.navigator; + + import java.io.File; + import java.net.URL; + import java.util.List; + import javax.swing.JComponent; + import javax.swing.JPanel; + import junit.framework.*; + import org.netbeans.modules.navigator.NavigatorTC; + import org.netbeans.modules.navigator.UnitTestUtils; + import org.netbeans.spi.navigator.NavigatorLookupHint; + import org.netbeans.spi.navigator.NavigatorPanel; + import org.openide.filesystems.FileObject; + import org.openide.filesystems.FileUtil; + import org.openide.filesystems.URLMapper; + import org.openide.loaders.DataFolder; + import org.openide.loaders.DataObject; + import org.openide.loaders.DataShadow; + import org.openide.util.ContextGlobalProvider; + import org.openide.util.Lookup; + import org.openide.util.lookup.AbstractLookup; + import org.openide.util.lookup.InstanceContent; + import org.openide.util.lookup.Lookups; + + + /** + * + * @author Dafe Simonek + */ + public class NavigatorHandlerTest extends TestCase { + + public NavigatorHandlerTest(String testName) { + super(testName); + } + + public static void main(java.lang.String[] args) { + junit.textui.TestRunner.run(suite()); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + public static Test suite() { + TestSuite suite = new TestSuite(NavigatorHandlerTest.class); + return suite; + } + + public void testActivatePanel () throws Exception { + System.out.println("Testing NavigatorHandlerTest.activatePanel"); + InstanceContent ic = new InstanceContent(); + GlobalLookup4Test nodesLkp = new GlobalLookup4Test(ic); + UnitTestUtils.prepareTest(new String [] { + "/org/netbeans/modules/navigator/resources/NavigatorHandlerTestProvider.xml" }, + Lookups.singleton(nodesLkp) + ); + + TestLookupHint hint = new TestLookupHint("NavigatorHandlerTest/TestMimeType"); + ic.add(hint); + + NavigatorTC navTC = NavigatorTC.getInstance(); + navTC.componentOpened(); + + NavigatorPanel selPanel = navTC.getSelectedPanel(); + assertNotNull("Selected panel is null", selPanel); + + List panels = navTC.getPanels(); + assertEquals(2, panels.size()); + + int selIndex = panels.indexOf(selPanel); + assertTrue(selIndex >= 0); + + System.out.println("selected panel before: " + navTC.getSelectedPanel().getDisplayName()); + + if (selIndex == 0) { + NavigatorHandler.activatePanel(panels.get(1)); + } else { + NavigatorHandler.activatePanel(panels.get(0)); + } + + assertTrue(selPanel != navTC.getSelectedPanel()); + + System.out.println("selected panel after: " + navTC.getSelectedPanel().getDisplayName()); + + } + + /** Panel implementation 1 + */ + public static final class PanelImpl1 implements NavigatorPanel { + + public String getDisplayName () { + return "Panel Impl 1"; + } + + public String getDisplayHint () { + return null; + } + + public JComponent getComponent () { + return new JPanel(); + } + + public void panelActivated (Lookup context) { + } + + public void panelDeactivated () { + } + + public Lookup getLookup () { + return null; + } + } + + /** Panel implementation 2 + */ + public static final class PanelImpl2 implements NavigatorPanel { + + public String getDisplayName () { + return "Panel Impl 2"; + } + + public String getDisplayHint () { + return null; + } + + public JComponent getComponent () { + return new JPanel(); + } + + public void panelActivated (Lookup context) { + } + + public void panelDeactivated () { + } + + public Lookup getLookup () { + return null; + } + } + + + /** Envelope for textual (mime-type like) content type to be used in + * global lookup + */ + private static final class TestLookupHint implements NavigatorLookupHint { + + private final String contentType; + + public TestLookupHint (String contentType) { + this.contentType = contentType; + } + + public String getContentType () { + return contentType; + } + + } + + + private static final class GlobalLookup4Test extends AbstractLookup implements ContextGlobalProvider { + + public GlobalLookup4Test (AbstractLookup.Content content) { + super(content); + } + + public Lookup createGlobalContext() { + return this; + } + } + + + } Index: src/org/netbeans/api/navigator/NavigatorHandler.java *** F:\Sources\MainTrunk\core\navigator\src\org\netbeans\api\navigator\NavigatorHandler.java No Base Revision --- F:\Sources\MainTrunk\core\navigator\src\org\netbeans\api\navigator\NavigatorHandler.java Locally New *************** *** 1,0 **** --- 1,56 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + package org.netbeans.api.navigator; + + import org.netbeans.modules.navigator.NavigatorTC; + import org.netbeans.spi.navigator.NavigatorPanel; + + /** + * Set of methods for driving navigator behaviour. + * + * @author Dafe Simonek + */ + public final class NavigatorHandler { + + /** No external instantiation allowed. + */ + private NavigatorHandler () { + } + + /** + * Activates and shows given panel in navigator view. Panel must be one of + * available panels at the time this method is called, which means that + * panel must be registered (either through mime type in xml layer or NavigatorLookupHint) + * for currently activated node in the system. + * Previously activated panel is deactivated and hidden. + *

+ * Typical use case is to set preferred navigator panel in a situation + * when multiple panels are registered for multiple data types. + *

+ * This method must be called from EventQueue thread. + * + * @param panel Navigator panel to be activated + * @throws IllegalArgumentException if givwn panel is not available + */ + public static void activatePanel (NavigatorPanel panel) { + NavigatorTC.getInstance().getController().activatePanel(panel); + } + + } Index: nbproject/project.properties *** F:\Sources\MainTrunk\core\navigator\nbproject\project.properties Base (1.6) --- F:\Sources\MainTrunk\core\navigator\nbproject\project.properties Locally Modified (Based On 1.6) *************** *** 17,22 **** --- 17,24 ---- is.autoload=true + javac.compilerargs=-Xlint:unchecked + javac.source=1.5 javadoc.arch=${basedir}/arch.xml test.unit.run.cp.extra=\ Index: test/unit/src/org/netbeans/modules/navigator/resources/NavigatorHandlerTestProvider.xml *** F:\Sources\MainTrunk\core\navigator\test\unit\src\org\netbeans\modules\navigator\resources\NavigatorHandlerTestProvider.xml No Base Revision --- F:\Sources\MainTrunk\core\navigator\test\unit\src\org\netbeans\modules\navigator\resources\NavigatorHandlerTestProvider.xml Locally New *************** *** 1,0 **** --- 1,34 ---- + + + + + + + + + + + + + + + + +