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.mashup.db.ui.wizard;
042:
043: import java.awt.BorderLayout;
044: import java.util.MissingResourceException;
045:
046: import javax.swing.JPanel;
047:
048: import net.java.hulp.i18n.Logger;
049: import org.netbeans.modules.etl.logger.Localizer;
050: import org.netbeans.modules.etl.logger.LogUtil;
051: import org.netbeans.modules.mashup.db.model.FlatfileDatabaseModel;
052: import org.netbeans.modules.mashup.db.ui.FlatfileTreeTableView;
053: import org.netbeans.modules.mashup.db.ui.model.FlatfileTreeTableModel;
054:
055: /**
056: * Descriptor for single panel to select tables and columns to be included in an Flatfile
057: * Database definition instance.
058: *
059: * @author Jonathan Giron
060: * @author Ahimanikya Satapathy
061: * @version $Revision$
062: */
063: public class PreviewDatabaseVisualPanel extends JPanel {
064:
065: private static transient final Logger mLogger = LogUtil
066: .getLogger(PreviewDatabaseVisualPanel.class.getName());
067:
068: private static transient final Localizer mLoc = Localizer.get();
069: /* Container to hold configuration components */
070: private JPanel contentPanel;
071:
072: /* Model used to supply content to FlatfileTreeTableView instance */
073: private FlatfileTreeTableModel mTreeModel;
074:
075: /* Component which displays content to be configured. */
076: private FlatfileTreeTableView mTreeView;
077:
078: /**
079: * Constructs a new instance of PreviewDatabaseVisualPanel with the given
080: * PreviewDatabasePanel instance as its owner.
081: *
082: * @param panelHost owner of this new instance
083: */
084: public PreviewDatabaseVisualPanel(PreviewDatabasePanel panelHost) {
085: mTreeModel = new FlatfileTreeTableModel();
086: mTreeView = new FlatfileTreeTableView();
087:
088: setLayout(new BorderLayout());
089: String nbBundle1 = mLoc
090: .t("PRSR001: Preview Flat File Database Definition");
091: try {
092: setName(Localizer.parse(nbBundle1));
093: } catch (MissingResourceException e) {
094: setName("*** Preview Flatfile Database ***");
095: }
096: }
097:
098: /**
099: * Constructs a new instance of PreviewDatabaseVisualPanel
100: *
101: * @param panelHost owner of this new instance
102: */
103: public PreviewDatabaseVisualPanel() {
104: mTreeModel = new FlatfileTreeTableModel();
105: mTreeView = new FlatfileTreeTableView();
106:
107: setLayout(new BorderLayout());
108: String nbBundle2 = mLoc
109: .t("PRSR001: Preview Flat File Database Definition");
110: try {
111: setName(Localizer.parse(nbBundle2));
112: } catch (MissingResourceException e) {
113: setName("*** Preview Flatfile Database ***");
114: }
115: }
116:
117: /**
118: * Gets FlatfileDatabaseModel representing current contents of this visual component.
119: *
120: * @return FlatfileDatabaseModel representing the contents of this visual component
121: */
122: public FlatfileDatabaseModel getModel() {
123: if (mTreeModel != null) {
124: FlatfileDatabaseModel modFolder = mTreeModel.getModel();
125: return modFolder;
126: }
127: return null;
128: }
129:
130: /**
131: * Indicates whether the controls in this panel all have sufficient valid data to
132: * advance the wizard to the next panel.
133: *
134: * @return true if data are valid, false otherwise
135: */
136: public boolean hasValidData() {
137: return true;
138: }
139:
140: /**
141: * Sets data model of this visual component to the contents of the given
142: * FlatfileDatabaseModel.
143: *
144: * @param newModel FlatfileDatabaseModel whose contents will be rendered by this
145: * component
146: */
147: public void setModel(FlatfileDatabaseModel newModel) {
148: mTreeModel.configureModel(newModel);
149: mTreeView.setModel(mTreeModel);
150:
151: if (contentPanel == null) {
152: contentPanel = createContentPanel(newModel, mTreeView);
153: add(contentPanel, BorderLayout.CENTER);
154: }
155:
156: mTreeView.revalidate();
157: mTreeView.repaint();
158: }
159:
160: private JPanel createContentPanel(FlatfileDatabaseModel folder,
161: FlatfileTreeTableView view) {
162: JPanel outermost = new JPanel(new BorderLayout());
163:
164: mTreeView.setModel(mTreeModel);
165: mTreeView.setDividerLocation(190);
166: outermost.add(mTreeView, BorderLayout.CENTER);
167: outermost.setSize(300, 200);
168: return outermost;
169: }
170: }
|