1 19 package org.netbeans.modules.subversion.ui.copy; 20 21 import java.awt.Dialog ; 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Map ; 28 import java.util.Vector ; 29 import javax.swing.ComboBoxModel ; 30 import javax.swing.DefaultComboBoxModel ; 31 import javax.swing.JButton ; 32 import javax.swing.JComboBox ; 33 import javax.swing.JPanel ; 34 import org.netbeans.modules.subversion.ui.browser.RepositoryPaths; 35 import org.netbeans.modules.subversion.SvnModuleConfig; 36 import org.netbeans.modules.versioning.util.Utils; 37 import org.openide.DialogDescriptor; 38 import org.openide.DialogDisplayer; 39 import org.openide.util.HelpCtx; 40 import org.openide.util.NbBundle; 41 42 46 public abstract class CopyDialog { 47 48 private DialogDescriptor dialogDescriptor; 49 private JButton okButton, cancelButton; 50 private JPanel panel; 51 52 private Map <String , JComboBox > urlComboBoxes; 53 54 public CopyDialog(JPanel panel, String title, String okLabel) { 55 this.panel = panel; 56 dialogDescriptor = new DialogDescriptor(panel, title); 57 58 okButton = new JButton (okLabel); 59 okButton.getAccessibleContext().setAccessibleDescription(okLabel); 60 okButton.setEnabled(false); 61 cancelButton = new JButton (org.openide.util.NbBundle.getMessage(CopyDialog.class, "CTL_Copy_Cancel")); cancelButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CopyDialog.class, "CTL_Copy_Cancel")); dialogDescriptor.setOptions(new Object [] {okButton, cancelButton}); 64 65 dialogDescriptor.setModal(true); 66 dialogDescriptor.setHelpCtx(new HelpCtx(this.getClass())); 67 dialogDescriptor.setValid(false); 68 Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor); 69 dialog.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CopyDialog.class, "CTL_Title")); } 71 72 protected void resetUrlComboBoxes() { 73 getUrlComboBoxes().clear(); 74 } 75 76 protected void setupUrlComboBox(JComboBox cbo, String key) { 77 if(cbo==null) { 78 return; 79 } 80 List <String > recentFolders = Utils.getStringList(SvnModuleConfig.getDefault().getPreferences(), key); 81 ComboBoxModel rootsModel = new DefaultComboBoxModel (new Vector <String >(recentFolders)); 82 cbo.setModel(rootsModel); 83 84 getUrlComboBoxes().put(key, cbo); 85 } 86 87 private Map <String , JComboBox > getUrlComboBoxes() { 88 if(urlComboBoxes == null) { 89 urlComboBoxes = new HashMap <String , JComboBox >(); 90 } 91 return urlComboBoxes; 92 } 93 94 protected JPanel getPanel() { 95 return panel; 96 } 97 98 public boolean showDialog() { 99 Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor); 100 dialog.setVisible(true); 101 dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CopyDialog.class, "CTL_Title")); boolean ret = dialogDescriptor.getValue()==okButton; 103 if(ret) { 104 storeValidValues(); 105 } 106 return ret; 107 } 108 109 private void storeValidValues() { 110 for (Iterator it = urlComboBoxes.keySet().iterator(); it.hasNext();) { 111 String key = (String ) it.next(); 112 JComboBox cbo = (JComboBox ) urlComboBoxes.get(key); 113 Object item = cbo.getEditor().getItem(); 114 if(item != null && !item.equals("")) { Utils.insert(SvnModuleConfig.getDefault().getPreferences(), key, (String ) item, 8); 116 } 117 } 118 } 119 120 protected JButton getOKButton() { 121 return okButton; 122 } 123 124 } 125 | Popular Tags |