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: package org.netbeans.modules.etl.ui.navigator;
042:
043: import org.netbeans.modules.etl.ui.*;
044: import java.util.Collection;
045: import java.util.Iterator;
046: import javax.swing.JComponent;
047: import javax.swing.JPanel;
048:
049: import org.netbeans.spi.navigator.NavigatorPanel;
050: import org.netbeans.spi.navigator.NavigatorLookupHint;
051: import org.openide.util.Lookup;
052: import org.openide.util.LookupEvent;
053: import org.openide.util.LookupListener;
054:
055: public class ETLNavigatorComponent implements NavigatorPanel,
056: NavigatorLookupHint {
057:
058: /** holds UI of this panel */
059: private JComponent panelUI;
060:
061: /** template for finding data in given context.
062: * Object used as example, replace with your own data source, for example JavaDataObject etc */
063: @SuppressWarnings("unchecked")
064: private static final Lookup.Template ETL_DATA = new Lookup.Template(
065: ETLDataObject.class);
066: /** current context to work on */
067: private Lookup.Result curContext;
068: /** listener to context changes */
069: private LookupListener contextL;
070:
071: /** public no arg constructor needed for system to instantiate provider well */
072: public ETLNavigatorComponent() {
073: }
074:
075: public String getDisplayHint() {
076: return null;
077: }
078:
079: public String getDisplayName() {
080: return null;
081: }
082:
083: public JComponent getComponent() {
084: if (panelUI == null) {
085: panelUI = new JPanel();
086: }
087: return panelUI;
088: }
089:
090: @SuppressWarnings("unchecked")
091: public void panelActivated(Lookup context) {
092: // lookup context and listen to result to get notified about context changes
093: curContext = context.lookup(ETL_DATA);
094: curContext.addLookupListener(getContextListener());
095: // get actual data and recompute content
096: Collection data = curContext.allInstances();
097: setNewContent(data);
098: }
099:
100: public void panelDeactivated() {
101: curContext.removeLookupListener(getContextListener());
102: curContext = null;
103: panelUI = null;
104: }
105:
106: public Lookup getLookup() {
107: // go with default activated Node strategy
108: return null;
109: }
110:
111: /************* non - public part ************/
112:
113: private void setNewContent(Collection newData) {
114: // put your code here that grabs information you need from given
115: // collection of data, recompute UI of your panel and show it.
116: // Note - be sure to compute the content OUTSIDE event dispatch thread,
117: // just final repainting of UI should be done in event dispatch thread.
118: // Please use RequestProcessor and Swing.invokeLater to achieve this.
119: Iterator it = newData.iterator();
120: while (it.hasNext()) {
121: ETLDataObject dObj = (ETLDataObject) it.next();
122: if (panelUI == null) {
123: panelUI = new JPanel();
124: panelUI.setBorder(javax.swing.BorderFactory
125: .createEmptyBorder(50, 50, 50, 50));//, left, bottom, right)createTitledBorder("Navigator Panel Title"));
126: panelUI.setSize(150, 150);
127: }
128:
129: while (true) {
130: try {
131: //panelUI = dObj.getETLEditorTopPanel().getSatelliteView();
132: //panelUI.add((JComponent)dObj.getETLEditorTopPanel().getGraphView());
133: //dObj.getETLEditorTopPanel().getGraphView().getObserved();
134: panelUI.add(dObj.getETLEditorTopPanel()
135: .getSatelliteView());
136: panelUI.updateUI();
137: panelUI.requestFocus();
138: break;
139: } catch (Exception exception) {
140: // wait till scene is loaded
141: }
142: }
143: panelUI.revalidate();
144: break;
145: }
146: }
147:
148: /** Accessor for listener to context */
149: private LookupListener getContextListener() {
150: if (contextL == null) {
151: contextL = new ContextListener();
152: }
153: return contextL;
154: }
155:
156: /** Listens to changes of context and triggers proper action */
157: private class ContextListener implements LookupListener {
158:
159: public void resultChanged(LookupEvent ev) {
160: Collection data = ((Lookup.Result) ev.getSource())
161: .allInstances();
162: setNewContent(data);
163: }
164:
165: } // end of ContextListener
166:
167: public String getContentType() {
168: return "x-etl+xml";
169: }
170: }
|