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;
042:
043: import java.awt.BorderLayout;
044: import java.awt.Dimension;
045: import java.awt.Frame;
046: import java.beans.PropertyVetoException;
047:
048: import javax.swing.BorderFactory;
049: import javax.swing.JPanel;
050: import javax.swing.JSplitPane;
051:
052: import org.netbeans.modules.mashup.db.ui.model.FlatfileTreeTableModel;
053: import org.openide.explorer.ExplorerManager;
054: import org.openide.explorer.propertysheet.PropertySheet;
055: import org.openide.explorer.propertysheet.PropertySheetView;
056: import org.openide.explorer.view.BeanTreeView;
057: import org.openide.nodes.Node;
058: import org.openide.windows.WindowManager;
059:
060: /**
061: * @author Ritesh Adval
062: * @author Ahimanikya Satapathy
063: * @version $Revision$
064: */
065: public class FlatfileTreeTableView extends JPanel implements
066: ExplorerManager.Provider {
067:
068: private FlatfileTreeView treeView;
069: private PropertySheetView propertyView;
070: private Node selectedNode;
071: private JSplitPane splitPane;
072: private ExplorerManager etlExplorerManager = new ExplorerManager();
073:
074: /**
075: * Creates a new instance of FlatfileTableView
076: *
077: * @param model is the model to create this object with.
078: */
079: public FlatfileTreeTableView() {
080: treeView = new FlatfileTreeView();
081: treeView.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
082:
083: JPanel leftPanel = new JPanel();
084: leftPanel.setLayout(new BorderLayout());
085: leftPanel
086: .setBorder(BorderFactory
087: .createCompoundBorder(
088: BorderFactory
089: .createTitledBorder("Flat File Database Definition"),
090: BorderFactory.createEmptyBorder(0, 0,
091: 0, 0)));
092: leftPanel.add(treeView);
093: leftPanel.setPreferredSize(new Dimension(75, 200));
094: propertyView = new PropertySheetView();
095: propertyView.setBorder(BorderFactory.createEmptyBorder(0, 0, 0,
096: 0));
097: try {
098: propertyView.setSortingMode(PropertySheet.UNSORTED);
099: } catch (PropertyVetoException ignore) {
100: // ignore
101: }
102:
103: JPanel rightPanel = new JPanel();
104: rightPanel.setLayout(new BorderLayout());
105: rightPanel.setBorder(BorderFactory.createCompoundBorder(
106: BorderFactory.createTitledBorder("Properties"),
107: BorderFactory.createEmptyBorder(0, 0, 0, 0)));
108: rightPanel.add(propertyView);
109:
110: splitPane = new JSplitPane();
111: splitPane.setOneTouchExpandable(true);
112: splitPane.setLeftComponent(leftPanel);
113: splitPane.setRightComponent(rightPanel);
114:
115: Frame f = WindowManager.getDefault().getMainWindow();
116: Dimension d = f.getSize();
117: int divLocation = d.width / 3;
118: splitPane.setDividerLocation(divLocation);
119: this .add(splitPane);
120: }
121:
122: /**
123: * Sets model for this view to the given instance.
124: *
125: * @param model FlatfileTreeTableModel providing content for this view.
126: */
127: public void setModel(FlatfileTreeTableModel model) {
128: this .getExplorerManager().setRootContext(model.getRootNode());
129: if (selectedNode == null) { // set root default selected node
130: selectedNode = model.getRootNode();
131: }
132: }
133:
134: public void setDividerLocation(int size) {
135: splitPane.setDividerLocation(size);
136: }
137:
138: public Node getCurrentNode() {
139: return selectedNode;
140: }
141:
142: public ExplorerManager getExplorerManager() {
143: return etlExplorerManager;
144: }
145:
146: class FlatfileTreeView extends BeanTreeView {
147: public FlatfileTreeView() {
148: super ();
149: }
150:
151: protected void selectionChanged(Node[] nodes, ExplorerManager em)
152: throws PropertyVetoException {
153: super .selectionChanged(nodes, em);
154: if (nodes != null && nodes.length != 0) {
155: selectedNode = nodes[0];
156: propertyView.setNodes(new Node[] { selectedNode });
157: firePropertyChange(
158: FlatfileTreeTableView.this.getName(),
159: selectedNode, selectedNode);
160: }
161: }
162: }
163: }
|