- try {
- final MetadataRepositoryElement element = new MetadataRepositoryElement(null, new URI(updateSite), true);
- element.setNickname(updateSiteName);
- ElementUtils.updateRepositoryUsingElements(ProvisioningUI.getDefaultUI(),new MetadataRepositoryElement[] {element}, null);
- } catch (URISyntaxException e) {
- MessagingUtils.errorDialog("Invalid update site URI",
- P2Util.class,
- "The update site URI has an invalid syntax",
- TaxonomicEditorPlugin.PLUGIN_ID,
- e,
- false);
+ List<MetadataRepositoryElement> repoElements = new ArrayList<MetadataRepositoryElement>();
+ List<MetadataRepositoryElement> savedRepoElements = PreferencesUtil.getP2Repositories();
+ if(savedRepoElements.isEmpty()) {
+ // we always need an update site, so we add the default one
+ try {
+ MetadataRepositoryElement element = new MetadataRepositoryElement(null, new URI(updateSite), true);
+ element.setNickname(updateSiteName);
+ repoElements.add(element);
+ } catch (URISyntaxException e) {
+ MessagingUtils.errorDialog("Invalid update site URI",
+ P2Util.class,
+ "The update site URI has an invalid syntax",
+ TaxonomicEditorPlugin.PLUGIN_ID,
+ e,
+ false);
+ }
+ }
+ repoElements.addAll(savedRepoElements);
+
+ ElementUtils.updateRepositoryUsingElements(ProvisioningUI.getDefaultUI(),repoElements
+ .toArray(new MetadataRepositoryElement[]{} ), null);
+
+ }
+
+ /**
+ * {@link org.eclipse.equinox.p2.ui.RepositoryManipulationPage} which handles the repsitory site list
+ * in preferences does not create a preference store and hence the changes are not saved. This means
+ * that we need to save it ourselves.
+ *
+ * This method saves the list of current repositories in the preference store as a string with
+ * specific delimiters.
+ */
+
+ public static void saveP2RepositoryPreferences() {
+
+ IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ProvisioningUI.getDefaultUI().getSession());
+
+ URI[] currentlyEnabled = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
+ URI[] currentlyDisabled = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_DISABLED);
+
+ List<MetadataRepositoryElement> repoElements = new ArrayList<MetadataRepositoryElement>();
+
+ for(URI repo : currentlyEnabled) {
+ boolean enabled = true;
+ String nickname = metaManager.getRepositoryProperty(repo, IRepository.PROP_NICKNAME);
+ MetadataRepositoryElement element = new MetadataRepositoryElement(null, repo, true);
+ element.setNickname(nickname);
+ element.setEnabled(enabled);
+ repoElements.add(element);