Lines 35-40
Link Here
|
35 |
*/ |
35 |
*/ |
36 |
package org.nbgit.ui.browser; |
36 |
package org.nbgit.ui.browser; |
37 |
|
37 |
|
|
|
38 |
import java.util.Collection; |
39 |
import javax.swing.JComponent; |
40 |
import javax.swing.JOptionPane; |
38 |
import javax.swing.ListSelectionModel; |
41 |
import javax.swing.ListSelectionModel; |
39 |
import javax.swing.SwingUtilities; |
42 |
import javax.swing.SwingUtilities; |
40 |
import javax.swing.event.DocumentEvent; |
43 |
import javax.swing.event.DocumentEvent; |
Lines 43-90
Link Here
|
43 |
import javax.swing.event.ListSelectionListener; |
46 |
import javax.swing.event.ListSelectionListener; |
44 |
|
47 |
|
45 |
import org.eclipse.jgit.awtui.CommitGraphPane; |
48 |
import org.eclipse.jgit.awtui.CommitGraphPane; |
|
|
49 |
import org.eclipse.jgit.lib.Constants; |
50 |
import org.netbeans.modules.versioning.spi.VCSContext; |
51 |
import org.openide.nodes.Node; |
46 |
import org.openide.util.NbBundle; |
52 |
import org.openide.util.NbBundle; |
47 |
import org.openide.windows.TopComponent; |
53 |
import org.openide.windows.TopComponent; |
48 |
import org.openide.util.ImageUtilities; |
54 |
import org.openide.util.ImageUtilities; |
|
|
55 |
import org.openide.util.Lookup.Result; |
56 |
import org.openide.util.LookupEvent; |
57 |
import org.openide.util.LookupListener; |
58 |
import org.openide.util.Utilities; |
49 |
|
59 |
|
50 |
/** |
60 |
/** |
51 |
* Repository browser top component. |
61 |
* Repository browser top component. |
52 |
*/ |
62 |
*/ |
53 |
public final class BrowserTopComponent extends TopComponent { |
63 |
public final class BrowserTopComponent extends TopComponent implements LookupListener { |
54 |
|
64 |
|
55 |
private static final String ICON_PATH = "org/nbgit/resources/icons/gitvcs-icon.png"; // NOI18N |
65 |
private static final String ICON_PATH = "org/nbgit/resources/icons/gitvcs-icon.png"; // NOI18N |
56 |
private static final String PREFERRED_ID = "org-nbgit-ui-browser"; // NOI18N |
66 |
private static final String PREFERRED_ID = "org-nbgit-ui-browser"; // NOI18N |
57 |
private int commitIndex = -1; |
67 |
private int commitIndex = -1; |
|
|
68 |
private Result<Node> lookupResult; |
58 |
|
69 |
|
59 |
public BrowserTopComponent(BrowserModel model) { |
70 |
public BrowserTopComponent(BrowserModel model) { |
60 |
initComponents(); |
71 |
initComponents(); |
61 |
setName(_("CTL_BrowserTopComponent")); // NOI18N |
72 |
setName(_("CTL_BrowserTopComponent")); // NOI18N |
62 |
setToolTipText(_("HINT_BrowserTopComponent")); // NOI18N |
73 |
setToolTipText(_("HINT_BrowserTopComponent")); // NOI18N |
63 |
setIcon(ImageUtilities.loadImage(ICON_PATH, true)); |
74 |
setIcon(ImageUtilities.loadImage(ICON_PATH, true)); |
64 |
model.setCommitList(commitGraphPane.getCommitList()); |
75 |
setModel(model); |
65 |
textArea.setDocument(model.getDocument()); |
|
|
66 |
model.getDocument().addDocumentListener(new DocumentListener() { |
67 |
|
68 |
public void updateId(DocumentEvent e) { |
69 |
String id = e.getDocument().getProperty(BrowserModel.CONTENT_ID).toString(); |
70 |
idField.setText(id); |
71 |
scrollTextToStart(); |
72 |
} |
73 |
|
74 |
public void insertUpdate(DocumentEvent e) { |
75 |
updateId(e); |
76 |
} |
77 |
|
78 |
public void removeUpdate(DocumentEvent e) { |
79 |
updateId(e); |
80 |
} |
81 |
|
82 |
public void changedUpdate(DocumentEvent e) { |
83 |
updateId(e); |
84 |
} |
85 |
}); |
86 |
commitGraphPane.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
76 |
commitGraphPane.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
87 |
|
|
|
88 |
public void valueChanged(ListSelectionEvent event) { |
77 |
public void valueChanged(ListSelectionEvent event) { |
89 |
ListSelectionModel listModel = (ListSelectionModel) event.getSource(); |
78 |
ListSelectionModel listModel = (ListSelectionModel) event.getSource(); |
90 |
for (int i = event.getFirstIndex(); i <= event.getLastIndex(); i++) { |
79 |
for (int i = event.getFirstIndex(); i <= event.getLastIndex(); i++) { |
Lines 95-112
Link Here
|
95 |
break; |
84 |
break; |
96 |
} |
85 |
} |
97 |
} |
86 |
} |
98 |
|
|
|
99 |
}); |
87 |
}); |
100 |
} |
88 |
} |
101 |
|
89 |
|
102 |
private void scrollTextToStart() { |
90 |
private void scrollTextToStart() { |
103 |
SwingUtilities.invokeLater(new Runnable() { |
91 |
SwingUtilities.invokeLater(new Runnable() { |
104 |
|
|
|
105 |
public void run() { |
92 |
public void run() { |
106 |
idField.setCaretPosition(0); |
93 |
idField.setCaretPosition(0); |
107 |
textArea.setCaretPosition(0); |
94 |
textArea.setCaretPosition(0); |
108 |
} |
95 |
} |
109 |
|
|
|
110 |
}); |
96 |
}); |
111 |
} |
97 |
} |
112 |
|
98 |
|
Lines 128-137
Link Here
|
128 |
return NbBundle.getMessage(BrowserTopComponent.class, id, args); |
114 |
return NbBundle.getMessage(BrowserTopComponent.class, id, args); |
129 |
} |
115 |
} |
130 |
|
116 |
|
131 |
/** This method is called from within the constructor to |
117 |
/** |
132 |
* initialize the form. |
118 |
* This method is called from within the constructor to initialize the form. |
133 |
* WARNING: Do NOT modify this code. The content of this method is |
119 |
* WARNING: Do NOT modify this code. The content of this method is always |
134 |
* always regenerated by the Form Editor. |
120 |
* regenerated by the Form Editor. |
135 |
*/ |
121 |
*/ |
136 |
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents |
122 |
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents |
137 |
private void initComponents() { |
123 |
private void initComponents() { |
Lines 188-194
Link Here
|
188 |
.add(browserSplitPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE) |
174 |
.add(browserSplitPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE) |
189 |
); |
175 |
); |
190 |
}// </editor-fold>//GEN-END:initComponents |
176 |
}// </editor-fold>//GEN-END:initComponents |
191 |
|
|
|
192 |
// Variables declaration - do not modify//GEN-BEGIN:variables |
177 |
// Variables declaration - do not modify//GEN-BEGIN:variables |
193 |
private final javax.swing.JSplitPane browserSplitPane = new javax.swing.JSplitPane(); |
178 |
private final javax.swing.JSplitPane browserSplitPane = new javax.swing.JSplitPane(); |
194 |
private final CommitGraphPane commitGraphPane = new CommitGraphPane(); |
179 |
private final CommitGraphPane commitGraphPane = new CommitGraphPane(); |
Lines 200-203
Link Here
|
200 |
private final javax.swing.JScrollPane textScrollPane = new javax.swing.JScrollPane(); |
185 |
private final javax.swing.JScrollPane textScrollPane = new javax.swing.JScrollPane(); |
201 |
private final javax.swing.JToolBar toolBar = new javax.swing.JToolBar(); |
186 |
private final javax.swing.JToolBar toolBar = new javax.swing.JToolBar(); |
202 |
// End of variables declaration//GEN-END:variables |
187 |
// End of variables declaration//GEN-END:variables |
|
|
188 |
|
189 |
public void resultChanged(LookupEvent le) { |
190 |
this.setDisplayName(lookupResult.allInstances().toString()); |
191 |
Collection<? extends Node> nodes = lookupResult.allInstances(); |
192 |
updateViewForNodes(nodes); |
193 |
} |
194 |
|
195 |
@Override |
196 |
protected void componentOpened() { |
197 |
lookupResult = Utilities.actionsGlobalContext().lookupResult(Node.class); |
198 |
lookupResult.addLookupListener(this); |
199 |
} |
200 |
|
201 |
@Override |
202 |
protected void componentClosed() { |
203 |
lookupResult.removeLookupListener(this); |
204 |
} |
205 |
|
206 |
private void setModel(BrowserModel model) { |
207 |
model.setCommitList(commitGraphPane.getCommitList()); |
208 |
textArea.setDocument(model.getDocument()); |
209 |
model.getDocument().addDocumentListener(new DocumentListener() { |
210 |
public void updateId(DocumentEvent e) { |
211 |
String id = e.getDocument().getProperty(BrowserModel.CONTENT_ID).toString(); |
212 |
idField.setText(id); |
213 |
scrollTextToStart(); |
214 |
} |
215 |
|
216 |
public void insertUpdate(DocumentEvent e) { |
217 |
updateId(e); |
218 |
} |
219 |
|
220 |
public void removeUpdate(DocumentEvent e) { |
221 |
updateId(e); |
222 |
} |
223 |
|
224 |
public void changedUpdate(DocumentEvent e) { |
225 |
updateId(e); |
226 |
} |
227 |
}); |
228 |
} |
229 |
|
230 |
public void updateViewForNodes(Collection<? extends Node> nodeColl) { |
231 |
final BrowserTopComponent comp = this; |
232 |
final Node[] nodes = nodeColl.toArray(new Node[nodeColl.size()]); |
233 |
SwingUtilities.invokeLater(new Runnable() { |
234 |
public void run() { |
235 |
|
236 |
final VCSContext ctx = VCSContext.forNodes(nodes); |
237 |
if (ctx != null && ctx.getRootFiles() != null && !ctx.getRootFiles().isEmpty()) { |
238 |
|
239 |
BrowserModel model = new BrowserModel(ctx.getRootFiles(), Constants.HEAD); |
240 |
setModel(model); |
241 |
System.out.println("model" + model); |
242 |
|
243 |
BrowserController controller = new BrowserController(comp, model); |
244 |
controller.show(); |
245 |
|
246 |
SwingUtilities.updateComponentTreeUI(comp); |
247 |
} |
248 |
} |
249 |
}); |
250 |
} |
203 |
} |
251 |
} |