Cleanup code whitespace
[nbgit.git] / src / org / nbgit / ui / update / UpdatePanel.java
blobf9a874012f8aa65eb366d6b09705f3f24e11a0e5
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
24 * Contributor(s):
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28 * Microsystems, Inc. All Rights Reserved.
29 * Portions Copyright 2008 Alexander Coles (Ikonoklastik Productions).
31 * If you wish your version of this file to be governed by only the CDDL
32 * or only the GPL Version 2, indicate your decision by adding
33 * "[Contributor] elects to include this software in this distribution
34 * under the [CDDL or GPL Version 2] license." If you do not indicate a
35 * single choice of license, a recipient has the option to distribute
36 * your version of this file under either the CDDL, the GPL Version 2 or
37 * to extend the choice of license to its licensees as provided above.
38 * However, if you add GPL Version 2 code and therefore, elected the GPL
39 * Version 2 license, then the option applies only if the new code is
40 * made subject to such option by the copyright holder.
42 package org.nbgit.ui.update;
44 import java.io.File;
45 import java.util.LinkedHashSet;
46 import java.util.List;
47 import java.util.Set;
48 import java.util.Vector;
49 import javax.swing.ComboBoxModel;
50 import javax.swing.DefaultComboBoxModel;
51 import javax.swing.SwingUtilities;
52 import org.netbeans.api.progress.ProgressHandle;
53 import org.netbeans.api.progress.ProgressHandleFactory;
54 import org.nbgit.util.GitCommand;
55 import org.openide.util.NbBundle;
56 import org.openide.util.RequestProcessor;
58 /**
60 * @author Padraig O'Briain
62 public class UpdatePanel extends javax.swing.JPanel {
64 private File repository;
65 private List<String[]> revisionMap;
66 private RequestProcessor.Task refreshViewTask;
67 private static final RequestProcessor rp = new RequestProcessor("GitUpdate", 1); // NOI18N
68 private Thread refreshViewThread;
69 private static final int GIT_REVERT_TARGET_LIMIT = 100;
71 /** Creates new form ReverModificationsPanel */
72 public UpdatePanel(File repo)
74 repository = repo;
75 refreshViewTask = rp.create(new RefreshViewTask());
76 initComponents();
77 refreshViewTask.schedule(0);
80 public String getSelectedRevision()
82 String revStr = (String) revisionsComboBox.getSelectedItem();
83 if (revStr != null)
84 if (revStr.equals(NbBundle.getMessage(RevertModificationsPanel.class, "MSG_Revision_Default")) || // NOI18N
85 revStr.equals(NbBundle.getMessage(RevertModificationsPanel.class, "MSG_Fetching_Revisions"))) // NOI18N
86 revStr = null;
87 else if (revisionMap != null)
88 for (String[] entry : revisionMap) {
89 if (entry[0].equals(revStr)) {
90 revStr = entry[1];
91 break;
94 return revStr;
97 public boolean isForcedUpdateRequested()
99 return forcedUpdateChxBox.isSelected();
102 /** This method is called from within the constructor to
103 * initialize the form.
104 * WARNING: Do NOT modify this code. The content of this method is
105 * always regenerated by the Form Editor.
107 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
108 private void initComponents() {
110 revisionsLabel = new javax.swing.JLabel();
111 revisionsComboBox = new javax.swing.JComboBox();
112 jLabel1 = new javax.swing.JLabel();
113 jLabel2 = new javax.swing.JLabel();
114 jPanel1 = new javax.swing.JPanel();
115 forcedUpdateChxBox = new javax.swing.JCheckBox();
117 revisionsLabel.setLabelFor(revisionsComboBox);
118 org.openide.awt.Mnemonics.setLocalizedText(revisionsLabel, org.openide.util.NbBundle.getMessage(UpdatePanel.class, "UpdatePanel.revisionsLabel.text")); // NOI18N
120 jLabel1.setFont(new java.awt.Font("Dialog", 1, 11));
121 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(UpdatePanel.class, "UpdatePanel.infoLabel.text")); // NOI18N
123 jLabel2.setForeground(new java.awt.Color(153, 153, 153));
124 org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(UpdatePanel.class, "UpdatePanel.infoLabel2.text")); // NOI18N
126 jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(UpdatePanel.class, "UpdatePanel.jPanel1.border.title"))); // NOI18N
128 org.openide.awt.Mnemonics.setLocalizedText(forcedUpdateChxBox, org.openide.util.NbBundle.getMessage(UpdatePanel.class, "UpdatePanel.forcedUpdateChxBox.text")); // NOI18N
130 org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
131 jPanel1.setLayout(jPanel1Layout);
132 jPanel1Layout.setHorizontalGroup(
133 jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
134 .add(jPanel1Layout.createSequentialGroup()
135 .addContainerGap()
136 .add(forcedUpdateChxBox)
137 .addContainerGap(120, Short.MAX_VALUE))
139 jPanel1Layout.setVerticalGroup(
140 jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
141 .add(jPanel1Layout.createSequentialGroup()
142 .add(forcedUpdateChxBox)
143 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
146 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
147 this.setLayout(layout);
148 layout.setHorizontalGroup(
149 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
150 .add(layout.createSequentialGroup()
151 .addContainerGap()
152 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
153 .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
154 .add(jLabel2)
155 .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
156 .add(layout.createSequentialGroup()
157 .add(36, 36, 36)
158 .add(revisionsLabel)
159 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
160 .add(revisionsComboBox, 0, 311, Short.MAX_VALUE)))
161 .addContainerGap())
163 layout.setVerticalGroup(
164 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
165 .add(layout.createSequentialGroup()
166 .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
167 .add(4, 4, 4)
168 .add(jLabel2)
169 .add(29, 29, 29)
170 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
171 .add(revisionsLabel)
172 .add(revisionsComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
173 .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
174 .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
175 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
177 }// </editor-fold>//GEN-END:initComponents
180 * Must NOT be run from AWT.
182 private void setupModels()
184 // XXX attach Cancelable hook
185 final ProgressHandle ph = ProgressHandleFactory.createHandle(NbBundle.getMessage(RevertModificationsPanel.class, "MSG_Refreshing_Update_Versions")); // NOI18N
186 try {
187 Set<String> initialRevsSet = new LinkedHashSet<String>();
188 initialRevsSet.add(NbBundle.getMessage(RevertModificationsPanel.class, "MSG_Fetching_Revisions")); // NOI18N
189 ComboBoxModel targetsModel = new DefaultComboBoxModel(new Vector<String>(initialRevsSet));
190 revisionsComboBox.setModel(targetsModel);
191 refreshViewThread = Thread.currentThread();
192 Thread.interrupted(); // clear interupted status
193 ph.start();
195 refreshRevisions();
196 } finally {
197 SwingUtilities.invokeLater(new Runnable() {
199 public void run()
201 ph.finish();
202 refreshViewThread = null;
209 private void refreshRevisions()
211 revisionMap = GitCommand.getRevisions(repository, GIT_REVERT_TARGET_LIMIT);
213 Set<String> targetRevsSet = new LinkedHashSet<String>();
215 if (revisionMap == null)
216 targetRevsSet.add(NbBundle.getMessage(RevertModificationsPanel.class, "MSG_Revision_Default"));
217 else
218 for (String[] entry : revisionMap) {
219 targetRevsSet.add(entry[0]);
222 ComboBoxModel targetsModel = new DefaultComboBoxModel(new Vector<String>(targetRevsSet));
223 revisionsComboBox.setModel(targetsModel);
225 if (targetRevsSet.size() > 0)
226 revisionsComboBox.setSelectedIndex(0);
229 private class RefreshViewTask implements Runnable {
231 public void run()
233 setupModels();
238 // Variables declaration - do not modify//GEN-BEGIN:variables
239 private javax.swing.JCheckBox forcedUpdateChxBox;
240 private javax.swing.JLabel jLabel1;
241 private javax.swing.JLabel jLabel2;
242 private javax.swing.JPanel jPanel1;
243 private javax.swing.JComboBox revisionsComboBox;
244 private javax.swing.JLabel revisionsLabel;
245 // End of variables declaration//GEN-END:variables