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]"
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
;
45 import java
.util
.LinkedHashSet
;
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
.GitModuleConfig
;
54 import org
.netbeans
.modules
.git
.util
.GitCommand
;
55 import org
.openide
.util
.NbBundle
;
56 import org
.openide
.util
.RequestProcessor
;
60 * @author Padraig O'Briain
62 public class RevertModificationsPanel
extends javax
.swing
.JPanel
{
64 private File repository
;
65 private File
[] revertFiles
;
66 private RequestProcessor
.Task refreshViewTask
;
67 private Thread refreshViewThread
;
68 private static final RequestProcessor rp
= new RequestProcessor("GitRevert", 1); // NOI18N
70 private static final int GIT_REVERT_TARGET_LIMIT
= 100;
72 /** Creates new form ReverModificationsPanel */
73 public RevertModificationsPanel(File repo
, File
[] files
) {
76 refreshViewTask
= rp
.create(new RefreshViewTask());
78 refreshViewTask
.schedule(0);
81 public File
[] getRevertFiles() {
85 public boolean isBackupRequested() {
86 return doBackupChxBox
.isSelected();
89 public String
getSelectedRevision() {
90 String revStr
= (String
) revisionsComboBox
.getSelectedItem();
92 if (revStr
.equals(NbBundle
.getMessage(RevertModificationsPanel
.class, "MSG_Revision_Default")) || // NOI18N
93 revStr
.equals(NbBundle
.getMessage(RevertModificationsPanel
.class, "MSG_Fetching_Revisions"))) { // NOI18N
96 revStr
= revStr
.substring(0, revStr
.indexOf(" ")); // NOI18N
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 doBackupChxBox
= new javax
.swing
.JCheckBox();
117 revisionsLabel
.setLabelFor(revisionsComboBox
);
118 org
.openide
.awt
.Mnemonics
.setLocalizedText(revisionsLabel
, org
.openide
.util
.NbBundle
.getMessage(RevertModificationsPanel
.class, "RevertModificationsPanel.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(RevertModificationsPanel
.class, "RevertModificationsPanel.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(RevertModificationsPanel
.class, "RevertModificationsPanel.infoLabel2.text")); // NOI18N
126 jPanel1
.setBorder(javax
.swing
.BorderFactory
.createTitledBorder("Options"));
128 org
.openide
.awt
.Mnemonics
.setLocalizedText(doBackupChxBox
, org
.openide
.util
.NbBundle
.getMessage(RevertModificationsPanel
.class, "RevertModificationsPanel.doBackupChxBox.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()
137 .addContainerGap(159, Short
.MAX_VALUE
))
139 jPanel1Layout
.setVerticalGroup(
140 jPanel1Layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
141 .add(jPanel1Layout
.createSequentialGroup()
143 .addContainerGap(org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, Short
.MAX_VALUE
))
146 doBackupChxBox
.getAccessibleContext().setAccessibleDescription(org
.openide
.util
.NbBundle
.getMessage(RevertModificationsPanel
.class, "ACSD_doBackupChxBox")); // NOI18N
148 org
.jdesktop
.layout
.GroupLayout layout
= new org
.jdesktop
.layout
.GroupLayout(this);
149 this.setLayout(layout
);
150 layout
.setHorizontalGroup(
151 layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
152 .add(layout
.createSequentialGroup()
153 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.TRAILING
)
154 .add(org
.jdesktop
.layout
.GroupLayout
.LEADING
, layout
.createSequentialGroup()
157 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
158 .add(revisionsComboBox
, 0, 334, Short
.MAX_VALUE
))
159 .add(org
.jdesktop
.layout
.GroupLayout
.LEADING
, layout
.createSequentialGroup()
161 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
163 .add(jLabel1
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 515, Short
.MAX_VALUE
)
164 .add(jPanel1
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, Short
.MAX_VALUE
))))
167 layout
.setVerticalGroup(
168 layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
169 .add(layout
.createSequentialGroup()
170 .add(jLabel1
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, 25, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
)
174 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.BASELINE
)
176 .add(revisionsComboBox
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
))
177 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.UNRELATED
)
178 .add(jPanel1
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
)
179 .addContainerGap(org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, Short
.MAX_VALUE
))
182 revisionsComboBox
.getAccessibleContext().setAccessibleDescription(org
.openide
.util
.NbBundle
.getMessage(RevertModificationsPanel
.class, "ACSD_revisionsComboBox")); // NOI18N
183 }// </editor-fold>//GEN-END:initComponents
187 * Must NOT be run from AWT.
189 private void setupModels() {
190 // XXX attach Cancelable hook
191 final ProgressHandle ph
= ProgressHandleFactory
.createHandle(NbBundle
.getMessage(RevertModificationsPanel
.class, "MSG_Refreshing_Revert_Versions")); // NOI18N
193 boolean doBackup
= GitModuleConfig
.getDefault().getBackupOnRevertModifications();
194 doBackupChxBox
.setSelected(doBackup
);
196 Set
<String
> initialRevsSet
= new LinkedHashSet
<String
>();
197 initialRevsSet
.add(NbBundle
.getMessage(RevertModificationsPanel
.class, "MSG_Fetching_Revisions")); // NOI18N
198 ComboBoxModel targetsModel
= new DefaultComboBoxModel(new Vector
<String
>(initialRevsSet
));
199 revisionsComboBox
.setModel(targetsModel
);
200 refreshViewThread
= Thread
.currentThread();
201 Thread
.interrupted(); // clear interupted status
206 SwingUtilities
.invokeLater(new Runnable() {
209 refreshViewThread
= null;
215 private void refreshRevisions() {
216 java
.util
.List
<String
> targetRevsList
= GitCommand
.getRevisionsForFile(repository
, revertFiles
, GIT_REVERT_TARGET_LIMIT
);
218 Set
<String
> targetRevsSet
= new LinkedHashSet
<String
>();
221 if( targetRevsList
== null){
223 targetRevsSet
.add(NbBundle
.getMessage(RevertModificationsPanel
.class, "MSG_Revision_Default")); // NOI18N
225 size
= targetRevsList
.size();
228 targetRevsSet
.add(targetRevsList
.get(i
));
232 ComboBoxModel targetsModel
= new DefaultComboBoxModel(new Vector
<String
>(targetRevsSet
));
233 revisionsComboBox
.setModel(targetsModel
);
235 if (targetRevsSet
.size() > 0 ) {
236 revisionsComboBox
.setSelectedIndex(0);
240 private class RefreshViewTask
implements Runnable
{
246 // Variables declaration - do not modify//GEN-BEGIN:variables
247 private javax
.swing
.JCheckBox doBackupChxBox
;
248 private javax
.swing
.JLabel jLabel1
;
249 private javax
.swing
.JLabel jLabel2
;
250 private javax
.swing
.JPanel jPanel1
;
251 private javax
.swing
.JComboBox revisionsComboBox
;
252 private javax
.swing
.JLabel revisionsLabel
;
253 // End of variables declaration//GEN-END:variables