Skip to content

Commit f4cbcac

Browse files
committed
Add GitHubRepositoryManager
1 parent 8134076 commit f4cbcac

5 files changed

Lines changed: 122 additions & 18 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.junichi11.netbeans.modules.github.issues.issue.GitHubIssue;
4545
import com.junichi11.netbeans.modules.github.issues.query.GitHubQuery;
4646
import com.junichi11.netbeans.modules.github.issues.repository.GitHubRepository;
47+
import com.junichi11.netbeans.modules.github.issues.repository.GitHubRepositoryManager;
4748
import org.netbeans.modules.bugtracking.api.Repository;
4849
import org.netbeans.modules.bugtracking.spi.BugtrackingConnector;
4950
import org.netbeans.modules.bugtracking.spi.BugtrackingSupport;
@@ -81,6 +82,7 @@ public Repository createRepository(RepositoryInfo info) {
8182
}
8283

8384
private Repository createRepository(GitHubRepository repository) {
85+
GitHubRepositoryManager.getInstance().add(repository);
8486
GitHubIssues githubIssues = GitHubIssues.getInstance();
8587
BugtrackingSupport<GitHubRepository, GitHubQuery, GitHubIssue> bugtrackingSupport = githubIssues.getBugtrackingSupport();
8688
return bugtrackingSupport.createRepository(

src/main/java/com/junichi11/netbeans/modules/github/issues/options/GitHubIssuesOptionsPanelController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
*/
4242
package com.junichi11.netbeans.modules.github.issues.options;
4343

44+
import com.junichi11.netbeans.modules.github.issues.repository.GitHubRepository;
45+
import com.junichi11.netbeans.modules.github.issues.repository.GitHubRepositoryManager;
4446
import java.beans.PropertyChangeListener;
4547
import java.beans.PropertyChangeSupport;
4648
import javax.swing.JComponent;
@@ -79,6 +81,10 @@ public void applyChanges() {
7981
@Override
8082
public void run() {
8183
getPanel().store();
84+
GitHubRepositoryManager manager = GitHubRepositoryManager.getInstance();
85+
for (GitHubRepository repository : manager.getRepositories()) {
86+
repository.optionsChanged();
87+
}
8288
changed = false;
8389
}
8490
});

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

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.junichi11.netbeans.modules.github.issues.egit.SearchService;
4949
import com.junichi11.netbeans.modules.github.issues.issue.CreateIssueParams;
5050
import com.junichi11.netbeans.modules.github.issues.issue.GitHubIssue;
51+
import com.junichi11.netbeans.modules.github.issues.options.GitHubIssuesOptions;
5152
import com.junichi11.netbeans.modules.github.issues.query.GitHubDefaultQueries;
5253
import com.junichi11.netbeans.modules.github.issues.query.GitHubDefaultQueries.Type;
5354
import com.junichi11.netbeans.modules.github.issues.query.GitHubQuery;
@@ -674,24 +675,31 @@ public void saveQuery(GitHubQuery query) {
674675
addQuery(query);
675676
fireQueryListChanged();
676677
}
677-
// TODO add options?
678-
// public void optionsChanged() {
679-
// GitHubOptions options = GitHubOptions.getInstance();
680-
// setDefaultQuery(getAssignedToMeQuery(), options.isAssignedToMeQuery());
681-
// setDefaultQuery(getCreatedByMeQuery(), options.isCreatedByMeQuery());
682-
// fireQueryListChanged();
683-
// }
684-
// private void setDefaultQuery(GitHubQuery query, boolean isEnabled) {
685-
// if (isEnabled) {
686-
// if (!queries.contains(query)) {
687-
// queries.add(query);
688-
// }
689-
// } else {
690-
// if (queries.contains(query)) {
691-
// queries.remove(query);
692-
// }
693-
// }
694-
// }
678+
679+
// options
680+
public void optionsChanged() {
681+
GitHubIssuesOptions options = GitHubIssuesOptions.getInstance();
682+
Map<Type, Boolean> defaultQueryOptions = options.getDefaultQueryOptions();
683+
for (Map.Entry<Type, Boolean> entrySet : defaultQueryOptions.entrySet()) {
684+
Type type = entrySet.getKey();
685+
Boolean isEnabled = entrySet.getValue();
686+
GitHubQuery query = GitHubDefaultQueries.create(this, type);
687+
setDefaultQuery(query, isEnabled);
688+
}
689+
fireQueryListChanged();
690+
}
691+
692+
private void setDefaultQuery(GitHubQuery query, boolean isEnabled) {
693+
if (isEnabled) {
694+
if (!queries.contains(query)) {
695+
queries.add(query);
696+
}
697+
} else {
698+
if (queries.contains(query)) {
699+
queries.remove(query);
700+
}
701+
}
702+
}
695703

696704
void removed() {
697705
// remove all queries
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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;
43+
44+
import java.util.Collection;
45+
import java.util.Collections;
46+
import java.util.HashMap;
47+
import java.util.Map;
48+
49+
/**
50+
*
51+
* @author junichi11
52+
*/
53+
public class GitHubRepositoryManager {
54+
55+
private static final GitHubRepositoryManager INSTANCE = new GitHubRepositoryManager();
56+
private static final Map<String, GitHubRepository> REPOSITORIES = Collections.synchronizedMap(new HashMap<String, GitHubRepository>());
57+
58+
private GitHubRepositoryManager() {
59+
}
60+
61+
public static final GitHubRepositoryManager getInstance() {
62+
return INSTANCE;
63+
}
64+
65+
public synchronized Collection<GitHubRepository> getRepositories() {
66+
return REPOSITORIES.values();
67+
}
68+
69+
public synchronized GitHubRepository getRepository(String repositoryId) {
70+
return REPOSITORIES.get(repositoryId);
71+
}
72+
73+
public synchronized void add(GitHubRepository repository) {
74+
if (repository == null) {
75+
return;
76+
}
77+
REPOSITORIES.put(repository.getID(), repository);
78+
}
79+
80+
synchronized void remove(GitHubRepository repository) {
81+
if (repository == null) {
82+
return;
83+
}
84+
REPOSITORIES.remove(repository.getID());
85+
}
86+
87+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public Collection<GitHubIssue> getIssues(GitHubRepository repository, String...
8181
@Override
8282
public void removed(GitHubRepository repository) {
8383
repository.removed();
84+
GitHubRepositoryManager.getInstance().remove(repository);
8485
}
8586

8687
@Override

0 commit comments

Comments
 (0)