Skip to content

Commit 4b862a3

Browse files
committed
Add the feature to add a label #9
1 parent 6cdb48d commit 4b862a3

7 files changed

Lines changed: 540 additions & 9 deletions

File tree

src/main/java/com/junichi11/netbeans/modules/github/issues/GitHubCache.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,20 @@ public List<Milestone> getMilestones() {
154154
* @return labels
155155
*/
156156
public List<Label> getLabels() {
157-
if (labels == null) {
157+
return getLabels(false);
158+
}
159+
160+
/**
161+
* Get labels.
162+
*
163+
* @param force {@code true} if reload labels, otherwise {@code false}
164+
* @return labels
165+
*/
166+
public List<Label> getLabels(boolean force) {
167+
if (labels == null || force) {
168+
if (labels != null) {
169+
labels.clear();
170+
}
158171
GitHubClient client = repository.createGitHubClient();
159172
if (client == null) {
160173
return Collections.emptyList();

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/ui/GitHubIssuePanel.form

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
<Group type="102" alignment="1" attributes="0">
4343
<Component id="headerErrorLabel" min="-2" max="-2" attributes="0"/>
4444
<EmptySpace max="32767" attributes="0"/>
45+
<Component id="addLabelButton" min="-2" max="-2" attributes="0"/>
46+
<EmptySpace max="-2" attributes="0"/>
4547
<Component id="headerSubmitButton" min="-2" max="-2" attributes="0"/>
4648
</Group>
4749
<Group type="102" attributes="0">
@@ -100,6 +102,7 @@
100102
<Group type="103" groupAlignment="3" attributes="0">
101103
<Component id="headerSubmitButton" alignment="3" min="-2" max="-2" attributes="0"/>
102104
<Component id="headerErrorLabel" alignment="3" min="-2" max="-2" attributes="0"/>
105+
<Component id="addLabelButton" alignment="3" min="-2" max="-2" attributes="0"/>
103106
</Group>
104107
</Group>
105108
</Group>
@@ -201,6 +204,16 @@
201204
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="refreshLinkButtonActionPerformed"/>
202205
</Events>
203206
</Component>
207+
<Component class="javax.swing.JButton" name="addLabelButton">
208+
<Properties>
209+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
210+
<ResourceString bundle="com/junichi11/netbeans/modules/github/issues/issue/ui/Bundle.properties" key="GitHubIssuePanel.addLabelButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
211+
</Property>
212+
</Properties>
213+
<Events>
214+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addLabelButtonActionPerformed"/>
215+
</Events>
216+
</Component>
204217
</SubComponents>
205218
</Container>
206219
<Container class="javax.swing.JScrollPane" name="mainScrollPane">

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/ui/GitHubIssuePanel.java

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@
5353
import com.junichi11.netbeans.modules.github.issues.issue.GitHubIssueSupport;
5454
import com.junichi11.netbeans.modules.github.issues.repository.GitHubRepository;
5555
import com.junichi11.netbeans.modules.github.issues.ui.AttributesListCellRenderer;
56+
import com.junichi11.netbeans.modules.github.issues.utils.UiUtils;
5657
import java.awt.Color;
5758
import java.awt.Font;
5859
import java.beans.PropertyChangeListener;
5960
import java.text.DateFormat;
6061
import java.text.SimpleDateFormat;
6162
import java.util.ArrayList;
63+
import java.util.Collections;
64+
import java.util.Enumeration;
6265
import java.util.List;
6366
import java.util.logging.Logger;
6467
import javax.swing.DefaultComboBoxModel;
@@ -150,6 +153,13 @@ public GitHubIssue getIssue() {
150153
return gitHubIssue;
151154
}
152155

156+
private GitHubRepository getRepository() {
157+
if (gitHubIssue == null) {
158+
return null;
159+
}
160+
return gitHubIssue.getRepository();
161+
}
162+
153163
public void update() {
154164
// header
155165
setHeader();
@@ -182,13 +192,7 @@ public void update() {
182192
assigneeComboBoxModel.addElement(collaborator);
183193
}
184194

185-
// label
186-
List<Label> labels = cache.getLabels();
187-
labelsListModel.removeAllElements();
188-
labelsListModel.addElement(null);
189-
for (Label label : labels) {
190-
labelsListModel.addElement(label);
191-
}
195+
updateLables(cache, false);
192196
}
193197

194198
// existing issue
@@ -258,6 +262,15 @@ public void update() {
258262
fireChange();
259263
}
260264

265+
private void updateLables(GitHubCache cache, boolean force) {
266+
List<Label> labels = cache.getLabels(force);
267+
labelsListModel.removeAllElements();
268+
labelsListModel.addElement(null);
269+
for (Label label : labels) {
270+
labelsListModel.addElement(label);
271+
}
272+
}
273+
261274
public void loadComments() {
262275
commentsPanel.loadComments();
263276
fireChange();
@@ -318,6 +331,7 @@ private void setCollaboratorsComponentsVisible(boolean isVisible) {
318331
milestoneComboBox.setVisible(isVisible);
319332
assigneeLabel.setVisible(isVisible);
320333
assigneeComboBox.setVisible(isVisible);
334+
addLabelButton.setVisible(isVisible);
321335
}
322336

323337
@NbBundle.Messages({
@@ -528,6 +542,7 @@ private void initComponents() {
528542
headerShowInBrowserLinkButton = new org.netbeans.modules.bugtracking.commons.LinkButton();
529543
jSeparator1 = new javax.swing.JSeparator();
530544
refreshLinkButton = new org.netbeans.modules.bugtracking.commons.LinkButton();
545+
addLabelButton = new javax.swing.JButton();
531546
mainScrollPane = new javax.swing.JScrollPane();
532547
mainPanel = new javax.swing.JPanel();
533548
assigneeLabel = new javax.swing.JLabel();
@@ -584,6 +599,13 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
584599
}
585600
});
586601

602+
org.openide.awt.Mnemonics.setLocalizedText(addLabelButton, org.openide.util.NbBundle.getMessage(GitHubIssuePanel.class, "GitHubIssuePanel.addLabelButton.text")); // NOI18N
603+
addLabelButton.addActionListener(new java.awt.event.ActionListener() {
604+
public void actionPerformed(java.awt.event.ActionEvent evt) {
605+
addLabelButtonActionPerformed(evt);
606+
}
607+
});
608+
587609
javax.swing.GroupLayout headerPanelLayout = new javax.swing.GroupLayout(headerPanel);
588610
headerPanel.setLayout(headerPanelLayout);
589611
headerPanelLayout.setHorizontalGroup(
@@ -594,6 +616,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
594616
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, headerPanelLayout.createSequentialGroup()
595617
.addComponent(headerErrorLabel)
596618
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
619+
.addComponent(addLabelButton)
620+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
597621
.addComponent(headerSubmitButton))
598622
.addGroup(headerPanelLayout.createSequentialGroup()
599623
.addComponent(headerStatusLabel)
@@ -642,7 +666,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
642666
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
643667
.addGroup(headerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
644668
.addComponent(headerSubmitButton)
645-
.addComponent(headerErrorLabel)))
669+
.addComponent(headerErrorLabel)
670+
.addComponent(addLabelButton)))
646671
);
647672

648673
mainPanel.setAutoscrolls(true);
@@ -797,7 +822,30 @@ public void run() {
797822

798823
}//GEN-LAST:event_refreshLinkButtonActionPerformed
799824

825+
@NbBundle.Messages({
826+
"GitHubIssuePanel.message.addLabel.error=Can't add a label."
827+
})
828+
private void addLabelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addLabelButtonActionPerformed
829+
Enumeration<Label> elements = labelsListModel.elements();
830+
Label label = LabelPanel.showDialog(Collections.list(elements));
831+
if (label != null) {
832+
GitHubRepository repository = getRepository();
833+
if (repository == null) {
834+
return;
835+
}
836+
Label newLable = repository.addLabel(label);
837+
if (newLable == null) {
838+
// show dialog
839+
UiUtils.showErrorDialog(Bundle.GitHubIssuePanel_message_addLabel_error());
840+
return;
841+
}
842+
GitHubCache cache = GitHubCache.create(repository);
843+
updateLables(cache, true);
844+
}
845+
}//GEN-LAST:event_addLabelButtonActionPerformed
846+
800847
// Variables declaration - do not modify//GEN-BEGIN:variables
848+
private javax.swing.JButton addLabelButton;
801849
private javax.swing.JComboBox<User> assigneeComboBox;
802850
private javax.swing.JLabel assigneeLabel;
803851
private com.junichi11.netbeans.modules.github.issues.issue.ui.AttributesViewPanel attributesViewPanel;
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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" attributes="0">
20+
<EmptySpace max="-2" attributes="0"/>
21+
<Group type="103" groupAlignment="0" attributes="0">
22+
<Group type="102" attributes="0">
23+
<Group type="103" groupAlignment="0" attributes="0">
24+
<Component id="nameLabel" min="-2" max="-2" attributes="0"/>
25+
<Component id="colorLabel" alignment="0" min="-2" max="-2" attributes="0"/>
26+
</Group>
27+
<EmptySpace max="-2" attributes="0"/>
28+
<Group type="103" groupAlignment="0" attributes="0">
29+
<Group type="102" attributes="0">
30+
<Component id="colorTextField" pref="257" max="32767" attributes="0"/>
31+
<EmptySpace max="-2" attributes="0"/>
32+
<Component id="selectColorButton" min="-2" max="-2" attributes="0"/>
33+
</Group>
34+
<Component id="nameTextField" max="32767" attributes="0"/>
35+
</Group>
36+
</Group>
37+
<Group type="102" alignment="0" attributes="0">
38+
<Component id="errorLabel" min="-2" max="-2" attributes="0"/>
39+
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
40+
</Group>
41+
</Group>
42+
<EmptySpace max="-2" attributes="0"/>
43+
</Group>
44+
</Group>
45+
</DimensionLayout>
46+
<DimensionLayout dim="1">
47+
<Group type="103" groupAlignment="0" attributes="0">
48+
<Group type="102" alignment="0" attributes="0">
49+
<EmptySpace max="-2" attributes="0"/>
50+
<Group type="103" groupAlignment="3" attributes="0">
51+
<Component id="nameLabel" alignment="3" min="-2" max="-2" attributes="0"/>
52+
<Component id="nameTextField" alignment="3" min="-2" max="-2" attributes="0"/>
53+
</Group>
54+
<EmptySpace max="-2" attributes="0"/>
55+
<Group type="103" groupAlignment="3" attributes="0">
56+
<Component id="selectColorButton" alignment="3" min="-2" max="-2" attributes="0"/>
57+
<Component id="colorTextField" alignment="3" min="-2" max="-2" attributes="0"/>
58+
<Component id="colorLabel" alignment="3" min="-2" max="-2" attributes="0"/>
59+
</Group>
60+
<EmptySpace max="-2" attributes="0"/>
61+
<Component id="errorLabel" min="-2" max="-2" attributes="0"/>
62+
<EmptySpace max="32767" attributes="0"/>
63+
</Group>
64+
</Group>
65+
</DimensionLayout>
66+
</Layout>
67+
<SubComponents>
68+
<Component class="javax.swing.JButton" name="selectColorButton">
69+
<Properties>
70+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
71+
<ResourceString bundle="com/junichi11/netbeans/modules/github/issues/issue/ui/Bundle.properties" key="LabelPanel.selectColorButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
72+
</Property>
73+
</Properties>
74+
<Events>
75+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="selectColorButtonActionPerformed"/>
76+
</Events>
77+
</Component>
78+
<Component class="javax.swing.JLabel" name="nameLabel">
79+
<Properties>
80+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
81+
<ResourceString bundle="com/junichi11/netbeans/modules/github/issues/issue/ui/Bundle.properties" key="LabelPanel.nameLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
82+
</Property>
83+
</Properties>
84+
</Component>
85+
<Component class="javax.swing.JTextField" name="nameTextField">
86+
<Properties>
87+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
88+
<ResourceString bundle="com/junichi11/netbeans/modules/github/issues/issue/ui/Bundle.properties" key="LabelPanel.nameTextField.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
89+
</Property>
90+
</Properties>
91+
</Component>
92+
<Component class="javax.swing.JLabel" name="colorLabel">
93+
<Properties>
94+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
95+
<ResourceString bundle="com/junichi11/netbeans/modules/github/issues/issue/ui/Bundle.properties" key="LabelPanel.colorLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
96+
</Property>
97+
</Properties>
98+
</Component>
99+
<Component class="javax.swing.JTextField" name="colorTextField">
100+
<Properties>
101+
<Property name="editable" type="boolean" value="false"/>
102+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
103+
<ResourceString bundle="com/junichi11/netbeans/modules/github/issues/issue/ui/Bundle.properties" key="LabelPanel.colorTextField.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
104+
</Property>
105+
</Properties>
106+
</Component>
107+
<Component class="javax.swing.JLabel" name="errorLabel">
108+
<Properties>
109+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
110+
<ResourceString bundle="com/junichi11/netbeans/modules/github/issues/issue/ui/Bundle.properties" key="LabelPanel.errorLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
111+
</Property>
112+
</Properties>
113+
</Component>
114+
</SubComponents>
115+
</Form>

0 commit comments

Comments
 (0)