001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.compapp.casaeditor.navigator;
043:
044: import java.beans.PropertyChangeEvent;
045: import java.util.Collection;
046: import javax.swing.JComponent;
047: import org.netbeans.modules.compapp.casaeditor.CasaDataObject;
048: import org.openide.loaders.DataObject;
049: import org.openide.util.Lookup;
050: import org.openide.util.LookupEvent;
051: import org.openide.util.LookupListener;
052: import org.openide.util.NbBundle;
053: import org.netbeans.spi.navigator.NavigatorPanel;
054: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaWrapperModel;
055: import org.openide.windows.TopComponent;
056:
057: /**
058: *
059: * @author Vitaly Bychkov
060: * @version 6 December 2005
061: */
062: public class CasaNavigatorView implements LookupListener,
063: NavigatorPanel {
064:
065: private static String navPanelName = NbBundle.getMessage(
066: CasaNavigatorView.class, "LBL_LOGICAL_VIEW"); // NOI18N
067:
068: private CasaNavigatorContentPanel mNavigatorPanel;
069: private Lookup.Result mLookupResult;
070: private CasaWrapperModel mCasaModel;
071:
072: public CasaNavigatorView() {
073: }
074:
075: public static String getUName() {
076: return navPanelName;
077: }
078:
079: public String getDisplayName() {
080: return navPanelName;
081: }
082:
083: public String getDisplayHint() {
084: return NbBundle.getMessage(CasaNavigatorView.class,
085: "LBL_LOGICAL_VIEW_TOOLTIP"); // NOI18N
086: }
087:
088: public JComponent getComponent() {
089: if (mNavigatorPanel == null) {
090: mNavigatorPanel = new CasaNavigatorContentPanel();
091: }
092: return mNavigatorPanel;
093: }
094:
095: public void panelActivated(Lookup context) {
096: getComponent();
097: TopComponent.getRegistry().addPropertyChangeListener(
098: mNavigatorPanel);
099: mLookupResult = context.lookup(new Lookup.Template<DataObject>(
100: DataObject.class));
101: mLookupResult.addLookupListener(this );
102: resultChanged(null);
103:
104: // hack to init selection if any
105: mNavigatorPanel.propertyChange(new PropertyChangeEvent(this ,
106: TopComponent.getRegistry().PROP_ACTIVATED_NODES, false,
107: true));
108: }
109:
110: public void panelDeactivated() {
111: TopComponent.getRegistry().removePropertyChangeListener(
112: mNavigatorPanel);
113: if (mLookupResult != null) {
114: mLookupResult.removeLookupListener(this );
115: mLookupResult = null;
116: }
117: }
118:
119: public Lookup getLookup() {
120: // go with default activated Node strategy
121: //Default mechanism chooses first Node from Utilities.actionsGlobalContext()
122: //as activated Node for Navigator's TopComponent.
123: return null;
124: }
125:
126: public void resultChanged(LookupEvent ev) {
127: // lookup result may be null
128: if (mLookupResult != null) {
129: Collection selected = mLookupResult.allInstances();
130: if (selected.size() == 1) {
131: Object result = selected.iterator().next();
132: if (result instanceof CasaDataObject) {
133: mNavigatorPanel.navigate((CasaDataObject) result);
134: } else {
135: mNavigatorPanel.navigate(null);
136: }
137: }
138: }
139: }
140: }
|