Renamed constants, local variables and member variables using "hg" to "git".
[nbgit.git] / src / org / netbeans / modules / git / ui / update / UpdatePanel.java
blobd4ab91f3bbc3d431bc199117a78d598ae3ec3a26
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.netbeans.modules.git.ui.update;
44 import java.io.File;
45 import java.util.LinkedHashSet;
46 import java.util.Set;
47 import java.util.Vector;
48 import javax.swing.ComboBoxModel;
49 import javax.swing.DefaultComboBoxModel;
50 import javax.swing.SwingUtilities;
51 import org.netbeans.api.progress.ProgressHandle;
52 import org.netbeans.api.progress.ProgressHandleFactory;
53 import org.netbeans.modules.git.util.GitCommand;
54 import org.openide.util.NbBundle;
55 import org.openide.util.RequestProcessor;
57 /**
59 * @author Padraig O'Briain
61 public class UpdatePanel extends javax.swing.JPanel {
63 private File repository;
64 private RequestProcessor.Task refreshViewTask;
65 private static final RequestProcessor rp = new RequestProcessor("GitUpdate", 1); // NOI18N
66 private Thread refreshViewThread;
68 private static final int GIT_REVERT_TARGET_LIMIT = 100;
70 /** Creates new form ReverModificationsPanel */
71 public UpdatePanel(File repo) {
72 repository = repo;
73 refreshViewTask = rp.create(new RefreshViewTask());
74 initComponents();
75 refreshViewTask.schedule(0);
78 public String getSelectedRevision() {
79 String revStr = (String) revisionsComboBox.getSelectedItem();
80 if(revStr != null){
81 if (revStr.equals(NbBundle.getMessage(RevertModificationsPanel.class, "MSG_Revision_Default")) || // NOI18N
82 revStr.equals(NbBundle.getMessage(RevertModificationsPanel.class, "MSG_Fetching_Revisions"))) { // NOI18N
83 revStr = null;
84 } else {
85 revStr = revStr.substring(0, revStr.indexOf(" ")); // NOI18N
88 return revStr;
91 public boolean isForcedUpdateRequested() {
92 return forcedUpdateChxBox.isSelected();
95 /** This method is called from within the constructor to
96 * initialize the form.
97 * WARNING: Do NOT modify this code. The content of this method is
98 * always regenerated by the Form Editor.
100 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
101 private void initComponents() {
103 revisionsLabel = new javax.swing.JLabel();
104 revisionsComboBox = new javax.swing.JComboBox();
105 jLabel1 = new javax.swing.JLabel();
106 jLabel2 = new javax.swing.JLabel();
107 jPanel1 = new javax.swing.JPanel();
108 forcedUpdateChxBox = new javax.swing.JCheckBox();
110 revisionsLabel.setLabelFor(revisionsComboBox);
111 org.openide.awt.Mnemonics.setLocalizedText(revisionsLabel, org.openide.util.NbBundle.getMessage(UpdatePanel.class, "UpdatePanel.revisionsLabel.text")); // NOI18N
113 jLabel1.setFont(new java.awt.Font("Dialog", 1, 11));
114 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(UpdatePanel.class, "UpdatePanel.infoLabel.text")); // NOI18N
116 jLabel2.setForeground(new java.awt.Color(153, 153, 153));
117 org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(UpdatePanel.class, "UpdatePanel.infoLabel2.text")); // NOI18N
119 jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(UpdatePanel.class, "UpdatePanel.jPanel1.border.title"))); // NOI18N
121 org.openide.awt.Mnemonics.setLocalizedText(forcedUpdateChxBox, org.openide.util.NbBundle.getMessage(UpdatePanel.class, "UpdatePanel.forcedUpdateChxBox.text")); // NOI18N
123 org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
124 jPanel1.setLayout(jPanel1Layout);
125 jPanel1Layout.setHorizontalGroup(
126 jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
127 .add(jPanel1Layout.createSequentialGroup()
128 .addContainerGap()
129 .add(forcedUpdateChxBox)
130 .addContainerGap(120, Short.MAX_VALUE))
132 jPanel1Layout.setVerticalGroup(
133 jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
134 .add(jPanel1Layout.createSequentialGroup()
135 .add(forcedUpdateChxBox)
136 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
139 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
140 this.setLayout(layout);
141 layout.setHorizontalGroup(
142 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
143 .add(layout.createSequentialGroup()
144 .addContainerGap()
145 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
146 .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
147 .add(jLabel2)
148 .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
149 .add(layout.createSequentialGroup()
150 .add(36, 36, 36)
151 .add(revisionsLabel)
152 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
153 .add(revisionsComboBox, 0, 311, Short.MAX_VALUE)))
154 .addContainerGap())
156 layout.setVerticalGroup(
157 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
158 .add(layout.createSequentialGroup()
159 .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
160 .add(4, 4, 4)
161 .add(jLabel2)
162 .add(29, 29, 29)
163 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
164 .add(revisionsLabel)
165 .add(revisionsComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
166 .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
167 .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
168 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
170 }// </editor-fold>//GEN-END:initComponents
174 * Must NOT be run from AWT.
176 private void setupModels() {
177 // XXX attach Cancelable hook
178 final ProgressHandle ph = ProgressHandleFactory.createHandle(NbBundle.getMessage(RevertModificationsPanel.class, "MSG_Refreshing_Update_Versions")); // NOI18N
179 try {
180 Set<String> initialRevsSet = new LinkedHashSet<String>();
181 initialRevsSet.add(NbBundle.getMessage(RevertModificationsPanel.class, "MSG_Fetching_Revisions")); // NOI18N
182 ComboBoxModel targetsModel = new DefaultComboBoxModel(new Vector<String>(initialRevsSet));
183 revisionsComboBox.setModel(targetsModel);
184 refreshViewThread = Thread.currentThread();
185 Thread.interrupted(); // clear interupted status
186 ph.start();
188 refreshRevisions();
189 } finally {
190 SwingUtilities.invokeLater(new Runnable() {
191 public void run() {
192 ph.finish();
193 refreshViewThread = null;
199 private void refreshRevisions() {
200 java.util.List<String> targetRevsList = GitCommand.getRevisions(repository, GIT_REVERT_TARGET_LIMIT);
202 Set<String> targetRevsSet = new LinkedHashSet<String>();
204 int size;
205 if( targetRevsList == null){
206 size = 0;
207 targetRevsSet.add(NbBundle.getMessage(RevertModificationsPanel.class, "MSG_Revision_Default")); // NOI18N
208 }else{
209 size = targetRevsList.size();
210 int i = 0 ;
211 while(i < size){
212 targetRevsSet.add(targetRevsList.get(i));
213 i++;
216 ComboBoxModel targetsModel = new DefaultComboBoxModel(new Vector<String>(targetRevsSet));
217 revisionsComboBox.setModel(targetsModel);
219 if (targetRevsSet.size() > 0 ) {
220 revisionsComboBox.setSelectedIndex(0);
224 private class RefreshViewTask implements Runnable {
225 public void run() {
226 setupModels();
230 // Variables declaration - do not modify//GEN-BEGIN:variables
231 private javax.swing.JCheckBox forcedUpdateChxBox;
232 private javax.swing.JLabel jLabel1;
233 private javax.swing.JLabel jLabel2;
234 private javax.swing.JPanel jPanel1;
235 private javax.swing.JComboBox revisionsComboBox;
236 private javax.swing.JLabel revisionsLabel;
237 // End of variables declaration//GEN-END:variables