KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > copy > CopyDialog


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.copy;
20
21 import java.awt.Dialog JavaDoc;
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.Vector JavaDoc;
29 import javax.swing.ComboBoxModel JavaDoc;
30 import javax.swing.DefaultComboBoxModel JavaDoc;
31 import javax.swing.JButton JavaDoc;
32 import javax.swing.JComboBox JavaDoc;
33 import javax.swing.JPanel JavaDoc;
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 /**
43  *
44  * @author Tomas Stupka
45  */

46 public abstract class CopyDialog {
47
48     private DialogDescriptor dialogDescriptor;
49     private JButton JavaDoc okButton, cancelButton;
50     private JPanel JavaDoc panel;
51
52     private Map JavaDoc<String JavaDoc, JComboBox JavaDoc> urlComboBoxes;
53     
54     public CopyDialog(JPanel JavaDoc panel, String JavaDoc title, String JavaDoc okLabel) {
55         this.panel = panel;
56         dialogDescriptor = new DialogDescriptor(panel, title);
57         
58         okButton = new JButton JavaDoc(okLabel);
59         okButton.getAccessibleContext().setAccessibleDescription(okLabel);
60         okButton.setEnabled(false);
61         cancelButton = new JButton JavaDoc(org.openide.util.NbBundle.getMessage(CopyDialog.class, "CTL_Copy_Cancel")); // NOI18N
62
cancelButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CopyDialog.class, "CTL_Copy_Cancel")); // NOI18N
63
dialogDescriptor.setOptions(new Object JavaDoc[] {okButton, cancelButton});
64         
65         dialogDescriptor.setModal(true);
66         dialogDescriptor.setHelpCtx(new HelpCtx(this.getClass()));
67         dialogDescriptor.setValid(false);
68         Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
69         dialog.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CopyDialog.class, "CTL_Title")); // NOI18N
70
}
71
72     protected void resetUrlComboBoxes() {
73         getUrlComboBoxes().clear();
74     }
75     
76     protected void setupUrlComboBox(JComboBox JavaDoc cbo, String JavaDoc key) {
77         if(cbo==null) {
78             return;
79         }
80         List JavaDoc<String JavaDoc> recentFolders = Utils.getStringList(SvnModuleConfig.getDefault().getPreferences(), key);
81         ComboBoxModel JavaDoc rootsModel = new DefaultComboBoxModel JavaDoc(new Vector JavaDoc<String JavaDoc>(recentFolders));
82         cbo.setModel(rootsModel);
83                 
84         getUrlComboBoxes().put(key, cbo);
85     }
86     
87     private Map JavaDoc<String JavaDoc, JComboBox JavaDoc> getUrlComboBoxes() {
88         if(urlComboBoxes == null) {
89             urlComboBoxes = new HashMap JavaDoc<String JavaDoc, JComboBox JavaDoc>();
90         }
91         return urlComboBoxes;
92     }
93     
94     protected JPanel JavaDoc getPanel() {
95         return panel;
96     }
97     
98     public boolean showDialog() {
99         Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
100         dialog.setVisible(true);
101         dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CopyDialog.class, "CTL_Title")); // NOI18N
102
boolean ret = dialogDescriptor.getValue()==okButton;
103         if(ret) {
104             storeValidValues();
105         }
106         return ret;
107     }
108     
109     private void storeValidValues() {
110         for (Iterator JavaDoc it = urlComboBoxes.keySet().iterator(); it.hasNext();) {
111             String JavaDoc key = (String JavaDoc) it.next();
112             JComboBox JavaDoc cbo = (JComboBox JavaDoc) urlComboBoxes.get(key);
113             Object JavaDoc item = cbo.getEditor().getItem();
114             if(item != null && !item.equals("")) { // NOI18N
115
Utils.insert(SvnModuleConfig.getDefault().getPreferences(), key, (String JavaDoc) item, 8);
116             }
117         }
118     }
119     
120     protected JButton JavaDoc getOKButton() {
121         return okButton;
122     }
123
124 }
125
Popular Tags