001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * Portions Copyrighted 2007 Sun Microsystems, Inc.
016: */
017: package org.netbeans.modules.xslt.tmap.navigator;
018:
019: import java.awt.Component;
020: import javax.swing.JComboBox;
021: import javax.swing.SwingUtilities;
022: import org.netbeans.core.api.multiview.MultiViewHandler;
023: import org.netbeans.core.api.multiview.MultiViewPerspective;
024: import org.netbeans.core.api.multiview.MultiViews;
025: import org.openide.windows.TopComponent;
026: import org.openide.windows.WindowManager;
027:
028: /**Щ
029: *
030: * @author Vitaly Bychkov
031: */
032: public class TMapNavigatorController {
033:
034: private TMapNavigatorController() {
035: }
036:
037: public static TopComponent getNavigatorTC() {
038: return WindowManager.getDefault().findTopComponent(
039: "navigatorTC"); // NOI18N
040: }
041:
042: public static void activateLogicalPanel() {
043: // System.out.println("try to activate logical panel");
044: switchNavPanel(TMapLogicalNavigatorPanel.getUName());
045: }
046:
047: public static void switchNavPanel(final Object navPanelUid) {
048: if (navPanelUid == null) {
049: return;
050: }
051: SwingUtilities.invokeLater(new Runnable() {
052: public void run() {
053: TopComponent navigatorTC = getNavigatorTC();
054: if (navigatorTC == null) {
055: return;
056: }
057:
058: JComboBox navComboBox = getNavigatorComboBox(navigatorTC);
059: if (navComboBox == null) {
060: return;
061: }
062:
063: int selIndex = navComboBox.getSelectedIndex();
064: int numPanels = navComboBox.getItemCount();
065: // System.out.println("navPanelUID: "+navPanelUid);
066: for (int i = 0; i < numPanels; i++) {
067: // System.out.println(i+ " navComboBox.getItemAt(i): "+navComboBox.getItemAt(i));
068: if (navPanelUid.equals(navComboBox.getItemAt(i))) {
069: if (i != selIndex) {
070: navComboBox.setSelectedIndex(i);
071: }
072: break;
073: }
074: }
075: }
076: });
077:
078: }
079:
080: private static JComboBox getNavigatorComboBox(
081: TopComponent navigatorTC) {
082: assert navigatorTC != null;
083: JComboBox comboBox = null;
084: Component[] components = navigatorTC.getComponents();
085: for (Component elem : components) {
086: if (elem instanceof JComboBox) {
087: comboBox = (JComboBox) elem;
088: break;
089: }
090: }
091: return comboBox;
092: }
093:
094: private static String getMVEditorActivePanelPrefferedId() {
095: TopComponent activeTC = WindowManager.getDefault()
096: .getRegistry().getActivated();
097: MultiViewHandler mvh = MultiViews
098: .findMultiViewHandler(activeTC);
099: if (mvh == null) {
100: return null;
101: }
102:
103: MultiViewPerspective mvp = mvh.getSelectedPerspective();
104: if (mvp != null) {
105: return mvp.preferredID();
106: }
107:
108: return null;
109: }
110: }
|