|
41 | 41 | */ |
42 | 42 | package com.junichi11.netbeans.modules.github.issues; |
43 | 43 |
|
| 44 | +import com.junichi11.netbeans.modules.github.issues.issue.GitHubIssue; |
44 | 45 | import com.junichi11.netbeans.modules.github.issues.query.GitHubQuery; |
45 | 46 | import com.junichi11.netbeans.modules.github.issues.repository.GitHubRepository; |
46 | 47 | import com.junichi11.netbeans.modules.github.issues.utils.StringUtils; |
| 48 | +import java.text.DateFormat; |
| 49 | +import java.text.ParseException; |
| 50 | +import java.text.SimpleDateFormat; |
| 51 | +import java.util.Date; |
47 | 52 | import java.util.prefs.BackingStoreException; |
48 | 53 | import java.util.prefs.Preferences; |
49 | 54 | import org.openide.util.Exceptions; |
|
56 | 61 | public final class GitHubIssuesConfig { |
57 | 62 |
|
58 | 63 | private static final GitHubIssuesConfig INSTANCE = new GitHubIssuesConfig(); |
| 64 | + private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd"); // NOI18N |
59 | 65 | private static final String QUERY = "query"; // NOI18N |
60 | 66 | private static final String QUERY_PARAMS = "query.params"; // NOI18N |
| 67 | + private static final String SCHEDULE = "schedule"; // NOI18N |
| 68 | + private static final String SCHEDULE_DUE_DATE = "schedule.due"; // NOI18N |
| 69 | + private static final String SCHEDULE_INTERVAL = "schedule.interval"; // NOI18N |
61 | 70 |
|
62 | 71 | private GitHubIssuesConfig() { |
63 | 72 | } |
@@ -125,7 +134,80 @@ public void removeQuery(GitHubRepository repository, GitHubQuery query) { |
125 | 134 | } |
126 | 135 | } |
127 | 136 |
|
| 137 | + public void setScheduleDueDate(GitHubRepository repository, GitHubIssue issue, Date dueDate) { |
| 138 | + Preferences preferences = getPreferences(repository); |
| 139 | + String id = issue.getID(); |
| 140 | + if (StringUtils.isEmpty(id)) { |
| 141 | + return; |
| 142 | + } |
| 143 | + preferences.node(SCHEDULE).node(id).put(SCHEDULE_DUE_DATE, DATE_FORMAT.format(dueDate)); |
| 144 | + } |
| 145 | + |
| 146 | + public Date getScheduleDueDate(GitHubRepository repository, GitHubIssue issue) { |
| 147 | + Preferences preferences = getPreferences(repository); |
| 148 | + String id = issue.getID(); |
| 149 | + if (StringUtils.isEmpty(id)) { |
| 150 | + return null; |
| 151 | + } |
| 152 | + String dateString = preferences.node(SCHEDULE).node(id).get(SCHEDULE_DUE_DATE, null); |
| 153 | + if (StringUtils.isEmpty(dateString)) { |
| 154 | + return null; |
| 155 | + } |
| 156 | + try { |
| 157 | + return DateFormat.getDateInstance().parse(dateString); |
| 158 | + } catch (ParseException ex) { |
| 159 | + Exceptions.printStackTrace(ex); |
| 160 | + } |
| 161 | + return null; |
| 162 | + } |
| 163 | + |
| 164 | + public void setScheduleInterval(GitHubRepository repository, GitHubIssue issue, int interval) { |
| 165 | + Preferences preferences = getPreferences(repository); |
| 166 | + String id = issue.getID(); |
| 167 | + if (StringUtils.isEmpty(id)) { |
| 168 | + return; |
| 169 | + } |
| 170 | + preferences.node(SCHEDULE).node(id).putInt(SCHEDULE_INTERVAL, interval); |
| 171 | + } |
| 172 | + |
| 173 | + public int getScheduleInterval(GitHubRepository repository, GitHubIssue issue) { |
| 174 | + Preferences preferences = getPreferences(repository); |
| 175 | + String id = issue.getID(); |
| 176 | + if (StringUtils.isEmpty(id)) { |
| 177 | + return -1; |
| 178 | + } |
| 179 | + return preferences.node(SCHEDULE).node(id).getInt(SCHEDULE_INTERVAL, -1); |
| 180 | + } |
| 181 | + |
| 182 | + public void removeSchedule(GitHubRepository repository, GitHubIssue issue) { |
| 183 | + Preferences preferences = getPreferences(repository); |
| 184 | + String id = issue.getID(); |
| 185 | + if (StringUtils.isEmpty(id)) { |
| 186 | + return; |
| 187 | + } |
| 188 | + preferences = preferences.node(SCHEDULE).node(id); |
| 189 | + try { |
| 190 | + preferences.removeNode(); |
| 191 | + } catch (BackingStoreException ex) { |
| 192 | + Exceptions.printStackTrace(ex); |
| 193 | + } |
| 194 | + } |
| 195 | + |
| 196 | + public void removeRepository(GitHubRepository repository) { |
| 197 | + Preferences preferences = getPreferences(repository); |
| 198 | + try { |
| 199 | + preferences.removeNode(); |
| 200 | + } catch (BackingStoreException ex) { |
| 201 | + Exceptions.printStackTrace(ex); |
| 202 | + } |
| 203 | + } |
| 204 | + |
128 | 205 | private Preferences getPreferences() { |
129 | 206 | return NbPreferences.forModule(GitHubIssuesConfig.class); |
130 | 207 | } |
| 208 | + |
| 209 | + private Preferences getPreferences(GitHubRepository repository) { |
| 210 | + String id = repository.getID(); |
| 211 | + return getPreferences().node(id); |
| 212 | + } |
131 | 213 | } |
0 commit comments