Skip to content

Commit 1550040

Browse files
committed
Add Add Repository button
1 parent 4c49e53 commit 1550040

6 files changed

Lines changed: 342 additions & 53 deletions

File tree

src/main/java/com/junichi11/netbeans/modules/github/issues/repository/GitHubRepository.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,4 +790,15 @@ private void fireQueryListChanged() {
790790
private void fireUnsubmittedIssueChanged() {
791791
propertyChangeSupport.firePropertyChange(RepositoryProvider.EVENT_UNSUBMITTED_ISSUES_CHANGED, null, null);
792792
}
793+
794+
public static List<Repository> getRepositories(String oauthToken) {
795+
GitHubClient client = new GitHubClient().setOAuth2Token(oauthToken);
796+
RepositoryService repositoryService = new RepositoryService(client);
797+
try {
798+
return repositoryService.getRepositories();
799+
} catch (IOException ex) {
800+
LOGGER.log(Level.INFO, ex.getMessage());
801+
}
802+
return Collections.emptyList();
803+
}
793804
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4+
<AuxValues>
5+
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
6+
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
7+
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
8+
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
9+
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
10+
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
11+
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
12+
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
13+
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
14+
</AuxValues>
15+
16+
<Layout>
17+
<DimensionLayout dim="0">
18+
<Group type="103" groupAlignment="0" attributes="0">
19+
<Group type="102" alignment="0" attributes="0">
20+
<EmptySpace max="-2" attributes="0"/>
21+
<Component id="repositoryComboBox" max="32767" attributes="0"/>
22+
<EmptySpace max="-2" attributes="0"/>
23+
</Group>
24+
</Group>
25+
</DimensionLayout>
26+
<DimensionLayout dim="1">
27+
<Group type="103" groupAlignment="0" attributes="0">
28+
<Group type="102" alignment="0" attributes="0">
29+
<EmptySpace max="-2" attributes="0"/>
30+
<Component id="repositoryComboBox" min="-2" max="-2" attributes="0"/>
31+
<EmptySpace max="32767" attributes="0"/>
32+
</Group>
33+
</Group>
34+
</DimensionLayout>
35+
</Layout>
36+
<SubComponents>
37+
<Component class="javax.swing.JComboBox" name="repositoryComboBox">
38+
<Properties>
39+
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
40+
<StringArray count="0"/>
41+
</Property>
42+
</Properties>
43+
<AuxValues>
44+
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;Repository&gt;"/>
45+
</AuxValues>
46+
</Component>
47+
</SubComponents>
48+
</Form>
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7+
* Other names may be trademarks of their respective owners.
8+
*
9+
* The contents of this file are subject to the terms of either the GNU
10+
* General Public License Version 2 only ("GPL") or the Common
11+
* Development and Distribution License("CDDL") (collectively, the
12+
* "License"). You may not use this file except in compliance with the
13+
* License. You can obtain a copy of the License at
14+
* http://www.netbeans.org/cddl-gplv2.html
15+
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16+
* specific language governing permissions and limitations under the
17+
* License. When distributing the software, include this License Header
18+
* Notice in each file and include the License file at
19+
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20+
* particular file as subject to the "Classpath" exception as provided
21+
* by Oracle in the GPL Version 2 section of the License file that
22+
* accompanied this code. If applicable, add the following below the
23+
* License Header, with the fields enclosed by brackets [] replaced by
24+
* your own identifying information:
25+
* "Portions Copyrighted [year] [name of copyright owner]"
26+
*
27+
* If you wish your version of this file to be governed by only the CDDL
28+
* or only the GPL Version 2, indicate your decision by adding
29+
* "[Contributor] elects to include this software in this distribution
30+
* under the [CDDL or GPL Version 2] license." If you do not indicate a
31+
* single choice of license, a recipient has the option to distribute
32+
* your version of this file under either the CDDL, the GPL Version 2 or
33+
* to extend the choice of license to its licensees as provided above.
34+
* However, if you add GPL Version 2 code and therefore, elected the GPL
35+
* Version 2 license, then the option applies only if the new code is
36+
* made subject to such option by the copyright holder.
37+
*
38+
* Contributor(s):
39+
*
40+
* Portions Copyrighted 2014 Sun Microsystems, Inc.
41+
*/
42+
package com.junichi11.netbeans.modules.github.issues.repository.ui;
43+
44+
import java.awt.Component;
45+
import java.awt.Dialog;
46+
import java.util.List;
47+
import javax.swing.DefaultComboBoxModel;
48+
import javax.swing.DefaultListCellRenderer;
49+
import javax.swing.JList;
50+
import javax.swing.ListCellRenderer;
51+
import org.eclipse.egit.github.core.Repository;
52+
import org.openide.DialogDescriptor;
53+
import org.openide.DialogDisplayer;
54+
import org.openide.util.NbBundle;
55+
56+
/**
57+
*
58+
* @author junichi11
59+
*/
60+
public class GitHubRepositoryListPanel extends javax.swing.JPanel {
61+
62+
private static final long serialVersionUID = -6030255526517952671L;
63+
64+
private final DefaultComboBoxModel<Repository> repositoryComboBoxModel = new DefaultComboBoxModel<>();
65+
66+
/**
67+
* Creates new form GitHubRepositoryListPanel
68+
*/
69+
private GitHubRepositoryListPanel(List<Repository> repositories) {
70+
initComponents();
71+
init(repositories);
72+
}
73+
74+
private void init(List<Repository> repositories) {
75+
repositoryComboBoxModel.removeAllElements();
76+
for (Repository repository : repositories) {
77+
repositoryComboBoxModel.addElement(repository);
78+
}
79+
repositoryComboBox.setRenderer(new RepositoryListCellRenderer(repositoryComboBox.getRenderer()));
80+
repositoryComboBox.setModel(repositoryComboBoxModel);
81+
}
82+
83+
@NbBundle.Messages({
84+
"GitHubRepositoryListPanel.title=Repositories"
85+
})
86+
public static Repository showDialog(List<Repository> repositories) {
87+
GitHubRepositoryListPanel panel = new GitHubRepositoryListPanel(repositories);
88+
DialogDescriptor dialogDescriptor = new DialogDescriptor(panel, Bundle.GitHubRepositoryListPanel_title(), true, DialogDescriptor.OK_CANCEL_OPTION, null, null);
89+
Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
90+
dialog.pack();
91+
dialog.setVisible(true);
92+
dialog.dispose();
93+
if (dialogDescriptor.getValue() == DialogDescriptor.OK_OPTION) {
94+
return panel.getSelectedRepository();
95+
}
96+
return null;
97+
}
98+
99+
private Repository getSelectedRepository() {
100+
return (Repository) repositoryComboBox.getSelectedItem();
101+
}
102+
103+
/**
104+
* This method is called from within the constructor to initialize the form.
105+
* WARNING: Do NOT modify this code. The content of this method is always
106+
* regenerated by the Form Editor.
107+
*/
108+
@SuppressWarnings("unchecked")
109+
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
110+
private void initComponents() {
111+
112+
repositoryComboBox = new javax.swing.JComboBox<Repository>();
113+
114+
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
115+
this.setLayout(layout);
116+
layout.setHorizontalGroup(
117+
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
118+
.addGroup(layout.createSequentialGroup()
119+
.addContainerGap()
120+
.addComponent(repositoryComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
121+
.addContainerGap())
122+
);
123+
layout.setVerticalGroup(
124+
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
125+
.addGroup(layout.createSequentialGroup()
126+
.addContainerGap()
127+
.addComponent(repositoryComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
128+
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
129+
);
130+
}// </editor-fold>//GEN-END:initComponents
131+
132+
// Variables declaration - do not modify//GEN-BEGIN:variables
133+
private javax.swing.JComboBox<Repository> repositoryComboBox;
134+
// End of variables declaration//GEN-END:variables
135+
136+
private static class RepositoryListCellRenderer extends DefaultListCellRenderer {
137+
138+
private static final long serialVersionUID = -8530867911076509797L;
139+
140+
private final ListCellRenderer renderer;
141+
142+
public RepositoryListCellRenderer(ListCellRenderer renderer) {
143+
this.renderer = renderer;
144+
}
145+
146+
@Override
147+
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
148+
String text = " "; // NOI18N
149+
if (value instanceof Repository) {
150+
Repository repository = (Repository) value;
151+
text = repository.getName();
152+
}
153+
return renderer.getListCellRendererComponent(list, text, index, isSelected, cellHasFocus);
154+
}
155+
156+
}
157+
}

src/main/java/com/junichi11/netbeans/modules/github/issues/repository/ui/GitHubRepositoryPanel.form

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,42 @@
1919
<Group type="102" attributes="0">
2020
<EmptySpace min="-2" max="-2" attributes="0"/>
2121
<Group type="103" groupAlignment="0" attributes="0">
22-
<Group type="102" alignment="0" attributes="0">
23-
<Component id="propertyFileCheckBox" min="-2" max="-2" attributes="0"/>
24-
<EmptySpace pref="135" max="32767" attributes="0"/>
25-
<Component id="connectButton" min="-2" max="-2" attributes="0"/>
22+
<Group type="102" attributes="0">
23+
<Component id="oauthTokenLabel" min="-2" max="-2" attributes="0"/>
24+
<EmptySpace min="-2" max="-2" attributes="0"/>
25+
<Component id="oauthTokenTextField" max="32767" attributes="0"/>
2626
<EmptySpace max="-2" attributes="0"/>
27+
<Component id="addRepositoryButton" min="-2" max="-2" attributes="0"/>
28+
<EmptySpace min="-2" pref="12" max="-2" attributes="0"/>
2729
</Group>
2830
<Group type="102" alignment="0" attributes="0">
2931
<Group type="103" groupAlignment="0" attributes="0">
30-
<Component id="oauthTokenLabel" alignment="0" min="-2" max="-2" attributes="0"/>
31-
<Component id="userNameLabel" alignment="0" min="-2" max="-2" attributes="0"/>
32-
<Component id="displayNameLabel" alignment="0" min="-2" max="-2" attributes="0"/>
33-
<Component id="repositoryLabel" alignment="0" min="-2" max="-2" attributes="0"/>
34-
</Group>
35-
<EmptySpace min="-2" max="-2" attributes="0"/>
36-
<Group type="103" groupAlignment="0" attributes="0">
37-
<Group type="102" attributes="0">
32+
<Group type="102" alignment="0" attributes="0">
33+
<Component id="propertyFileCheckBox" min="-2" max="-2" attributes="0"/>
34+
<EmptySpace pref="112" max="32767" attributes="0"/>
35+
<Component id="connectButton" min="-2" max="-2" attributes="0"/>
36+
</Group>
37+
<Group type="102" alignment="0" attributes="0">
38+
<Group type="103" groupAlignment="0" attributes="0">
39+
<Component id="userNameLabel" alignment="0" min="-2" max="-2" attributes="0"/>
40+
<Component id="displayNameLabel" alignment="0" min="-2" max="-2" attributes="0"/>
41+
<Component id="repositoryLabel" alignment="0" min="-2" max="-2" attributes="0"/>
42+
</Group>
43+
<EmptySpace min="-2" pref="28" max="-2" attributes="0"/>
3844
<Group type="103" groupAlignment="0" attributes="0">
39-
<Component id="oauthTokenTextField" alignment="0" max="32767" attributes="0"/>
45+
<Group type="102" alignment="0" attributes="0">
46+
<Component id="repositoryAuthorTextField" max="32767" attributes="0"/>
47+
<EmptySpace min="-2" max="-2" attributes="0"/>
48+
<Component id="repositorySeparationLabel" min="-2" max="-2" attributes="0"/>
49+
<EmptySpace min="-2" max="-2" attributes="0"/>
50+
<Component id="repositoryNameTextField" max="32767" attributes="0"/>
51+
</Group>
52+
<Component id="displayNameTextField" max="32767" attributes="0"/>
4053
<Component id="userNameTextField" max="32767" attributes="0"/>
41-
<Component id="displayNameTextField" alignment="0" max="32767" attributes="0"/>
4254
</Group>
43-
<EmptySpace min="-2" pref="12" max="-2" attributes="0"/>
44-
</Group>
45-
<Group type="102" attributes="0">
46-
<Component id="repositoryAuthorTextField" min="-2" pref="143" max="-2" attributes="0"/>
47-
<EmptySpace max="-2" attributes="0"/>
48-
<Component id="repositorySeparationLabel" min="-2" max="-2" attributes="0"/>
49-
<EmptySpace min="-2" max="-2" attributes="0"/>
50-
<Component id="repositoryNameTextField" max="32767" attributes="0"/>
51-
<EmptySpace min="-2" max="-2" attributes="0"/>
5255
</Group>
5356
</Group>
57+
<EmptySpace min="-2" max="-2" attributes="0"/>
5458
</Group>
5559
</Group>
5660
</Group>
@@ -59,6 +63,12 @@
5963
<DimensionLayout dim="1">
6064
<Group type="103" groupAlignment="0" attributes="0">
6165
<Group type="102" alignment="1" attributes="0">
66+
<EmptySpace max="-2" attributes="0"/>
67+
<Group type="103" groupAlignment="3" attributes="0">
68+
<Component id="oauthTokenLabel" alignment="3" min="-2" max="-2" attributes="0"/>
69+
<Component id="oauthTokenTextField" alignment="3" min="-2" max="-2" attributes="0"/>
70+
<Component id="addRepositoryButton" alignment="3" min="-2" max="-2" attributes="0"/>
71+
</Group>
6272
<EmptySpace max="-2" attributes="0"/>
6373
<Group type="103" groupAlignment="3" attributes="0">
6474
<Component id="displayNameLabel" alignment="3" min="-2" max="-2" attributes="0"/>
@@ -70,11 +80,6 @@
7080
<Component id="userNameTextField" alignment="3" min="-2" max="-2" attributes="0"/>
7181
</Group>
7282
<EmptySpace max="-2" attributes="0"/>
73-
<Group type="103" groupAlignment="3" attributes="0">
74-
<Component id="oauthTokenLabel" alignment="3" min="-2" max="-2" attributes="0"/>
75-
<Component id="oauthTokenTextField" alignment="3" min="-2" max="-2" attributes="0"/>
76-
</Group>
77-
<EmptySpace max="-2" attributes="0"/>
7883
<Group type="103" groupAlignment="3" attributes="0">
7984
<Component id="repositoryAuthorTextField" alignment="3" min="-2" max="-2" attributes="0"/>
8085
<Component id="repositoryLabel" alignment="3" min="-2" max="-2" attributes="0"/>
@@ -182,5 +187,15 @@
182187
</Property>
183188
</Properties>
184189
</Component>
190+
<Component class="javax.swing.JButton" name="addRepositoryButton">
191+
<Properties>
192+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
193+
<ResourceString bundle="com/junichi11/netbeans/modules/github/issues/repository/ui/Bundle.properties" key="GitHubRepositoryPanel.addRepositoryButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
194+
</Property>
195+
</Properties>
196+
<Events>
197+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addRepositoryButtonActionPerformed"/>
198+
</Events>
199+
</Component>
185200
</SubComponents>
186201
</Form>

0 commit comments

Comments
 (0)