KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > browser > BrowserPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.subversion.ui.browser;
20
21 import java.awt.Dimension JavaDoc;
22 import java.awt.GridBagConstraints JavaDoc;
23 import java.awt.GridBagLayout JavaDoc;
24 import java.awt.Insets JavaDoc;
25 import java.lang.reflect.InvocationTargetException JavaDoc;
26 import java.util.ResourceBundle JavaDoc;
27 import javax.swing.AbstractAction JavaDoc;
28 import javax.swing.BorderFactory JavaDoc;
29 import javax.swing.JButton JavaDoc;
30 import javax.swing.JLabel JavaDoc;
31 import javax.swing.JPanel JavaDoc;
32 import javax.swing.JTree JavaDoc;
33 import javax.swing.SwingUtilities JavaDoc;
34 import javax.swing.UIManager JavaDoc;
35 import javax.swing.tree.TreePath JavaDoc;
36 import javax.swing.tree.TreeSelectionModel JavaDoc;
37 import org.openide.explorer.ExplorerManager;
38 import org.openide.explorer.view.TreeTableView;
39 import org.openide.nodes.Node;
40 import org.openide.nodes.PropertySupport;
41 import org.openide.util.NbBundle;
42
43 /**
44  *
45  * @author Tomas Stupka
46  */

47 public class BrowserPanel extends JPanel JavaDoc implements ExplorerManager.Provider {
48
49     private final BrowserTreeTableView treeView;
50     private final ExplorerManager manager;
51
52     private ControlPanel controlPanel;
53     
54     /** Creates new form BrowserPanel */
55     public BrowserPanel(String JavaDoc labelText, String JavaDoc browserAcsn, String JavaDoc browserAcsd, boolean singleSelection) {
56         setName(java.util.ResourceBundle.getBundle("org/netbeans/modules/subversion/ui/browser/Bundle").getString("CTL_Browser_Prompt")); // NOI18N
57

58         manager = new ExplorerManager();
59         
60         setLayout(new GridBagLayout JavaDoc());
61         
62         treeView = new BrowserTreeTableView();
63         treeView.setDragSource(true);
64         treeView.setDropTarget(true);
65               
66         treeView.setDefaultActionAllowed (false);
67         treeView.setBorder(UIManager.getBorder("Nb.ScrollPane.border")); // NOI18N
68
treeView.getAccessibleContext().setAccessibleDescription(browserAcsd);
69         treeView.getAccessibleContext().setAccessibleName(browserAcsn);
70         if(singleSelection) {
71             treeView.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
72         }
73         treeView.setPopupAllowed(true);
74         treeView.getTree().setShowsRootHandles(true);
75
76         GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
77         int gridY = 0;
78                 
79         // title label
80
JLabel JavaDoc label = new JLabel JavaDoc();
81         label.setLabelFor(treeView.getTree());
82         label.setToolTipText(browserAcsd);
83         if(labelText != null && !labelText.trim().equals("")) {
84             org.openide.awt.Mnemonics.setLocalizedText(label, labelText);
85         } else {
86             org.openide.awt.Mnemonics.setLocalizedText(label, org.openide.util.NbBundle.getMessage(BrowserPanel.class, "BK2003")); // NOI18N
87
}
88         c = new GridBagConstraints JavaDoc();
89         c.gridx = 0;
90         c.gridy = gridY++;
91         c.insets = new Insets JavaDoc(4,0,4,4);
92         c.fill = GridBagConstraints.HORIZONTAL;
93         c.anchor = GridBagConstraints.WEST;
94         
95         add(label, c);
96         
97         // treetable
98
c.gridx = 0;
99         c.gridy = gridY++;
100         c.fill = GridBagConstraints.BOTH;
101         c.weighty = 1;
102         c.weightx = 1;
103         c.anchor = GridBagConstraints.WEST;
104         c.gridwidth = 1;
105         add(treeView, c);
106                 
107         // buttons
108
controlPanel = new ControlPanel();
109         controlPanel.warningLabel.setVisible(false);
110         c = new GridBagConstraints JavaDoc();
111         c.gridx = 0;
112         c.gridy = gridY++;
113         c.fill = GridBagConstraints.HORIZONTAL;
114         c.anchor = GridBagConstraints.EAST;
115         add(controlPanel, c);
116         
117         setBorder(BorderFactory.createEmptyBorder(12,12,0,12));
118         
119         setPreferredSize(new Dimension JavaDoc(800, 400));
120     }
121     
122     void warning(String JavaDoc warningText) {
123         if(warningText != null) {
124             controlPanel.warningLabel.setText(warningText);
125             controlPanel.warningLabel.setVisible(true);
126         } else {
127             controlPanel.warningLabel.setText("");
128             controlPanel.warningLabel.setVisible(false);
129         }
130     }
131     
132     public void setActions(AbstractAction JavaDoc[] actions) {
133         if(actions != null) {
134             controlPanel.buttonPanel.removeAll();
135             for (int i = 0; i < actions.length; i++) {
136                 JButton JavaDoc button = new JButton JavaDoc();
137                 button.setAction(actions[i]);
138                 button.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(BrowserPanel.class, "CTL_Action_MakeDir")); // NOI18N
139
org.openide.awt.Mnemonics.setLocalizedText(button, org.openide.util.NbBundle.getMessage(BrowserPanel.class, "CTL_Action_MakeDir")); // NOI18N
140
controlPanel.buttonPanel.add(button);
141             }
142             revalidate();
143         }
144     }
145     
146     public ExplorerManager getExplorerManager() {
147         return manager;
148     }
149     
150     private class BrowserTreeTableView extends TreeTableView {
151         BrowserTreeTableView() {
152             setupColumns();
153         }
154         
155         public JTree JavaDoc getTree() {
156             return tree;
157         }
158         
159         public void startEditingAtPath(TreePath JavaDoc path) {
160             tree.startEditingAtPath(path);
161         }
162         
163         public void addNotify() {
164             super.addNotify();
165             setDefaultColumnSizes();
166         }
167         
168         private void setupColumns() {
169             ResourceBundle JavaDoc loc = NbBundle.getBundle(BrowserPanel.class);
170             Node.Property [] columns = new Node.Property[4];
171             columns[0] = new ColumnDescriptor<String JavaDoc>(RepositoryPathNode.PROPERTY_NAME_REVISION, String JavaDoc.class, loc.getString("LBL_BrowserTree_Column_Revision"), loc.getString("LBL_BrowserTree_Column_Revision_Desc")); // NOI18N
172
columns[1] = new ColumnDescriptor<String JavaDoc>(RepositoryPathNode.PROPERTY_NAME_DATE, String JavaDoc.class, loc.getString("LBL_BrowserTree_Column_Date"), loc.getString("LBL_BrowserTree_Column_Date_Desc")); // NOI18N
173
columns[2] = new ColumnDescriptor<String JavaDoc>(RepositoryPathNode.PROPERTY_NAME_AUTHOR, String JavaDoc.class, loc.getString("LBL_BrowserTree_Column_Author"), loc.getString("LBL_BrowserTree_Column_Author_Desc")); // NOI18N
174
columns[3] = new ColumnDescriptor<String JavaDoc>(RepositoryPathNode.PROPERTY_NAME_HISTORY, String JavaDoc.class, loc.getString("LBL_BrowserTree_Column_History"), loc.getString("LBL_BrowserTree_Column_History_Desc")); // NOI18N
175

176             setProperties(columns);
177         }
178     
179         private void setDefaultColumnSizes() {
180             SwingUtilities.invokeLater(new Runnable JavaDoc() {
181                 public void run() {
182                     int width = getWidth();
183                     treeTable.getColumnModel().getColumn(0).setPreferredWidth(width * 50 / 100);
184                     treeTable.getColumnModel().getColumn(1).setPreferredWidth(width * 10 / 100);
185                     treeTable.getColumnModel().getColumn(2).setPreferredWidth(width * 20 / 100);
186                     treeTable.getColumnModel().getColumn(3).setPreferredWidth(width * 10 / 100);
187                     treeTable.getColumnModel().getColumn(4).setPreferredWidth(width * 10 / 100);
188                 }
189             });
190         }
191     }
192
193     private static class ColumnDescriptor<T> extends PropertySupport.ReadOnly<T> {
194         public ColumnDescriptor(String JavaDoc name, Class JavaDoc<T> type, String JavaDoc displayName, String JavaDoc shortDescription) {
195             super(name, type, displayName, shortDescription);
196         }
197
198         public T getValue() throws IllegalAccessException JavaDoc, InvocationTargetException JavaDoc {
199             return null;
200         }
201     }
202 }
203
Popular Tags