001: /*
002: * Copyright (c) 2007, Sun Microsystems, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * * Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * * Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * * Neither the name of Sun Microsystems, Inc. nor the names of its contributors
015: * may be used to endorse or promote products derived from this software without
016: * specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
028: * THE POSSIBILITY OF SUCH DAMAGE.
029: */
030: package org.myorg.feedreader;
031:
032: import java.awt.BorderLayout;
033: import java.io.Serializable;
034: import javax.swing.ActionMap;
035: import org.openide.explorer.ExplorerManager;
036: import org.openide.explorer.ExplorerUtils;
037: import org.openide.explorer.view.BeanTreeView;
038: import org.openide.loaders.DataObjectNotFoundException;
039: import org.openide.util.Exceptions;
040: import org.openide.util.NbBundle;
041: import org.openide.util.Utilities;
042: import org.openide.windows.TopComponent;
043:
044: final class FeedTopComponent extends TopComponent implements
045: ExplorerManager.Provider {
046:
047: private static FeedTopComponent instance;
048:
049: private final ExplorerManager manager = new ExplorerManager();
050: private final BeanTreeView view = new BeanTreeView();
051:
052: private FeedTopComponent() {
053: setName(NbBundle.getMessage(FeedTopComponent.class,
054: "CTL_FeedTopComponent"));
055: setToolTipText(NbBundle.getMessage(FeedTopComponent.class,
056: "HINT_FeedTopComponent"));
057: setIcon(Utilities.loadImage("org/myorg/feedreader/rss16.gif",
058: true));
059: setLayout(new BorderLayout());
060: add(view, BorderLayout.CENTER);
061: view.setRootVisible(true);
062: try {
063: manager.setRootContext(new RssNode.RootRssNode());
064: } catch (DataObjectNotFoundException ex) {
065: Exceptions.printStackTrace(ex);
066: }
067: ActionMap map = getActionMap();
068: map.put("delete", ExplorerUtils.actionDelete(manager, true));
069: associateLookup(ExplorerUtils.createLookup(manager, map));
070: }
071:
072: public static synchronized FeedTopComponent getDefault() {
073: if (instance == null) {
074: instance = new FeedTopComponent();
075: }
076: return instance;
077: }
078:
079: public int getPersistenceType() {
080: return TopComponent.PERSISTENCE_ALWAYS;
081: }
082:
083: protected String preferredID() {
084: return "FeedTopComponent";
085: }
086:
087: protected Object writeReplace() {
088: return new ResolvableHelper();
089: }
090:
091: private static final class ResolvableHelper implements Serializable {
092:
093: private static final long serialVersionUID = 1L;
094:
095: public Object readResolve() {
096: return FeedTopComponent.getDefault();
097: }
098:
099: }
100:
101: public ExplorerManager getExplorerManager() {
102: return manager;
103: }
104:
105: }
|