1 19 package org.netbeans.modules.subversion.ui.browser; 20 21 import java.awt.Dimension ; 22 import java.awt.GridBagConstraints ; 23 import java.awt.GridBagLayout ; 24 import java.awt.Insets ; 25 import java.lang.reflect.InvocationTargetException ; 26 import java.util.ResourceBundle ; 27 import javax.swing.AbstractAction ; 28 import javax.swing.BorderFactory ; 29 import javax.swing.JButton ; 30 import javax.swing.JLabel ; 31 import javax.swing.JPanel ; 32 import javax.swing.JTree ; 33 import javax.swing.SwingUtilities ; 34 import javax.swing.UIManager ; 35 import javax.swing.tree.TreePath ; 36 import javax.swing.tree.TreeSelectionModel ; 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 47 public class BrowserPanel extends JPanel implements ExplorerManager.Provider { 48 49 private final BrowserTreeTableView treeView; 50 private final ExplorerManager manager; 51 52 private ControlPanel controlPanel; 53 54 55 public BrowserPanel(String labelText, String browserAcsn, String browserAcsd, boolean singleSelection) { 56 setName(java.util.ResourceBundle.getBundle("org/netbeans/modules/subversion/ui/browser/Bundle").getString("CTL_Browser_Prompt")); 58 manager = new ExplorerManager(); 59 60 setLayout(new GridBagLayout ()); 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")); 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 c = new GridBagConstraints (); 77 int gridY = 0; 78 79 JLabel label = new JLabel (); 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")); } 88 c = new GridBagConstraints (); 89 c.gridx = 0; 90 c.gridy = gridY++; 91 c.insets = new Insets (4,0,4,4); 92 c.fill = GridBagConstraints.HORIZONTAL; 93 c.anchor = GridBagConstraints.WEST; 94 95 add(label, c); 96 97 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 controlPanel = new ControlPanel(); 109 controlPanel.warningLabel.setVisible(false); 110 c = new GridBagConstraints (); 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 (800, 400)); 120 } 121 122 void warning(String 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 [] actions) { 133 if(actions != null) { 134 controlPanel.buttonPanel.removeAll(); 135 for (int i = 0; i < actions.length; i++) { 136 JButton button = new JButton (); 137 button.setAction(actions[i]); 138 button.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(BrowserPanel.class, "CTL_Action_MakeDir")); org.openide.awt.Mnemonics.setLocalizedText(button, org.openide.util.NbBundle.getMessage(BrowserPanel.class, "CTL_Action_MakeDir")); 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 getTree() { 156 return tree; 157 } 158 159 public void startEditingAtPath(TreePath path) { 160 tree.startEditingAtPath(path); 161 } 162 163 public void addNotify() { 164 super.addNotify(); 165 setDefaultColumnSizes(); 166 } 167 168 private void setupColumns() { 169 ResourceBundle loc = NbBundle.getBundle(BrowserPanel.class); 170 Node.Property [] columns = new Node.Property[4]; 171 columns[0] = new ColumnDescriptor<String >(RepositoryPathNode.PROPERTY_NAME_REVISION, String .class, loc.getString("LBL_BrowserTree_Column_Revision"), loc.getString("LBL_BrowserTree_Column_Revision_Desc")); columns[1] = new ColumnDescriptor<String >(RepositoryPathNode.PROPERTY_NAME_DATE, String .class, loc.getString("LBL_BrowserTree_Column_Date"), loc.getString("LBL_BrowserTree_Column_Date_Desc")); columns[2] = new ColumnDescriptor<String >(RepositoryPathNode.PROPERTY_NAME_AUTHOR, String .class, loc.getString("LBL_BrowserTree_Column_Author"), loc.getString("LBL_BrowserTree_Column_Author_Desc")); columns[3] = new ColumnDescriptor<String >(RepositoryPathNode.PROPERTY_NAME_HISTORY, String .class, loc.getString("LBL_BrowserTree_Column_History"), loc.getString("LBL_BrowserTree_Column_History_Desc")); 176 setProperties(columns); 177 } 178 179 private void setDefaultColumnSizes() { 180 SwingUtilities.invokeLater(new Runnable () { 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 name, Class <T> type, String displayName, String shortDescription) { 195 super(name, type, displayName, shortDescription); 196 } 197 198 public T getValue() throws IllegalAccessException , InvocationTargetException { 199 return null; 200 } 201 } 202 } 203 | Popular Tags |