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.sql.framework.ui.output;
042:
043: import org.netbeans.modules.sql.framework.ui.view.*;
044: import org.netbeans.modules.etl.ui.view.*;
045: import java.awt.BorderLayout;
046: import java.awt.Component;
047: import java.beans.PropertyChangeEvent;
048: import java.beans.PropertyChangeListener;
049: import java.util.HashSet;
050: import java.util.Iterator;
051: import java.util.Set;
052: import javax.swing.JTabbedPane;
053: import javax.swing.SwingUtilities;
054: import net.java.hulp.i18n.Logger;
055: import org.netbeans.modules.etl.logger.Localizer;
056: import org.netbeans.modules.etl.logger.LogUtil;
057: import org.netbeans.modules.sql.framework.ui.view.conditionbuilder.IConditionGraphViewContainer;
058: import org.openide.awt.TabbedPaneFactory;
059: import org.openide.util.Lookup;
060: import org.openide.windows.TopComponent;
061: import org.openide.windows.WindowManager;
062:
063: /**
064: * Top component which displays something.
065: */
066: public final class SQLOutputConditionView extends TopComponent
067: implements PropertyChangeListener, Lookup.Provider {
068:
069: private static SQLOutputConditionView instance;
070: private static final String PREFERRED_ID = "ETLOutputWindowTopComponent";
071: private static IConditionGraphViewContainer sqlView;
072: private Set<Component> components = new HashSet<Component>(1);
073: private JTabbedPane tabbedPane = TabbedPaneFactory
074: .createCloseButtonTabbedPane();
075: private static transient final Logger mLogger = LogUtil
076: .getLogger(SQLOutputConditionView.class.getName());
077: private static transient final Localizer mLoc = Localizer.get();
078:
079: public SQLOutputConditionView(IConditionGraphViewContainer view) {
080: this .sqlView = view;
081: initComponents();
082: // setIcon(org.openide.util.Utilities.loadImage("org/netbeans/modules/etl/ui/resources/images/ETLCollab.gif"));
083: setLayout(new BorderLayout());
084: String nbBundle1 = mLoc
085: .t("PRSR001: Conditional Builder Output View");
086: setName(Localizer.parse(nbBundle1));
087: String nbBundle2 = mLoc
088: .t("PRSR001: Conditional Builder Output View");
089: getAccessibleContext().setAccessibleDescription(
090: Localizer.parse(nbBundle2));
091: String nbBundle3 = mLoc
092: .t("PRSR001: Conditional Builder Output View");
093: setToolTipText(Localizer.parse(nbBundle3));
094: tabbedPane.addPropertyChangeListener(this );
095: }
096:
097: /** This method is called from within the constructor to
098: * initialize the form.
099: * WARNING: Do NOT modify this code. The content of this method is
100: * always regenerated by the Form Editor.
101: */
102: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
103: private void initComponents() {
104:
105: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
106: this );
107: this .setLayout(layout);
108: layout.setHorizontalGroup(layout.createParallelGroup(
109: org.jdesktop.layout.GroupLayout.LEADING).add(0, 400,
110: Short.MAX_VALUE));
111: layout.setVerticalGroup(layout.createParallelGroup(
112: org.jdesktop.layout.GroupLayout.LEADING).add(0, 300,
113: Short.MAX_VALUE));
114: }// </editor-fold>//GEN-END:initComponents
115:
116: // Variables declaration - do not modify//GEN-BEGIN:variables
117: // End of variables declaration//GEN-END:variables
118: /**
119: * Gets default instance. Do not use directly: reserved for *.settings files only,
120: * i.e. deserialization routines; otherwise you could get a non-deserialized instance.
121: * To obtain the singleton instance, use {@link findInstance}.
122: * @return ETLOutputWindowTopComponent defaultInstance
123: */
124: public static synchronized SQLOutputConditionView getDefault() {
125: if (instance == null) {
126: instance = new SQLOutputConditionView(sqlView);
127: }
128: return instance;
129: }
130:
131: /**
132: * Obtain the ETLOutputWindowTopComponent instance. Never call {@link #getDefault} directly!
133: * @return ETLOutputWindowTopComponent defaultInstance
134: */
135: public static synchronized SQLOutputConditionView findInstance() {
136: TopComponent win = WindowManager.getDefault().findTopComponent(
137: PREFERRED_ID);
138: if (win == null) {
139: mLogger
140: .infoNoloc(mLoc
141: .t(
142: "PRSR180: Cannot find{0}component. It will not be located properly in the window system.in{1}",
143: PREFERRED_ID,
144: SQLOutputConditionView.class
145: .getName()));
146: return getDefault();
147: }
148: if (win instanceof SQLOutputConditionView) {
149: return (SQLOutputConditionView) win;
150: }
151: mLogger
152: .infoNoloc(mLoc
153: .t(
154: "PRSR181: There seem to be multiple components with the '{0}' ID. That is a potential source of errors and unexpected behavior.",
155: PREFERRED_ID,
156: SQLOutputConditionView.class.getName()));
157: return getDefault();
158: }
159:
160: public void addComponent(Component c) {
161: assert SwingUtilities.isEventDispatchThread();
162: if (!components.add(c)) {
163: return;
164: }
165: if (components.size() == 1) {
166: assert getComponentCount() == 0;
167: add(c);
168: } else if (components.size() == 2) {
169: assert getComponentCount() == 1;
170: removeAll();
171: Iterator<Component> it = components.iterator();
172: tabbedPane.add(it.next());
173: tabbedPane.add(it.next());
174: tabbedPane.setSelectedComponent(c);
175: add(tabbedPane);
176: } else {
177: assert getComponentCount() == 1;
178: tabbedPane.add(c);
179: tabbedPane.setSelectedComponent(c);
180: }
181: //updateName();
182: revalidate();
183: }
184:
185: public void propertyChange(PropertyChangeEvent evt) {
186: if (TabbedPaneFactory.PROP_CLOSE.equals(evt.getPropertyName())) {
187: Component c = (Component) evt.getNewValue();
188: removeComponent(c);
189: }
190: }
191:
192: //remove Component
193: private void removeComponent(Component c) {
194: assert SwingUtilities.isEventDispatchThread();
195: assert components.remove(c);
196: if (components.size() == 0) {
197: removeAll();
198: } else if (components.size() == 1) {
199: tabbedPane.removeAll();
200: removeAll();
201: add(components.iterator().next());
202: } else {
203: tabbedPane.remove(c);
204: }
205: // updateName();
206: revalidate();
207: }
208: }
|