1 package eu
.etaxonomy
.taxeditor
.handler
.update
;
4 import java
.net
.URISyntaxException
;
5 import java
.util
.ArrayList
;
8 import org
.eclipse
.equinox
.internal
.p2
.ui
.ProvUI
;
9 import org
.eclipse
.equinox
.internal
.p2
.ui
.model
.ElementUtils
;
10 import org
.eclipse
.equinox
.internal
.p2
.ui
.model
.MetadataRepositoryElement
;
11 import org
.eclipse
.equinox
.p2
.repository
.IRepository
;
12 import org
.eclipse
.equinox
.p2
.repository
.IRepositoryManager
;
13 import org
.eclipse
.equinox
.p2
.repository
.metadata
.IMetadataRepositoryManager
;
14 import org
.eclipse
.equinox
.p2
.ui
.ProvisioningUI
;
16 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
17 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
18 import eu
.etaxonomy
.taxeditor
.util
.ApplicationUtil
;
21 * This class is a utility class for updating the editor from a p2 update site,
22 * greatly inspired by the links given below.
26 * - Allow configurable update sites
31 * @see http://wiki.eclipse.org/Equinox/p2/Adding_Self-Update_to_an_RCP_Application
32 * @see http://bugs.eclipse.org/281226
33 * @see http://www.vogella.com/tutorials/EclipseP2Update/article.html
37 private static String EDIT_NIGHTLY_UPDATE_SITE
= "http://cybertaxonomy.eu/download/taxeditor/update/nightly/";
38 private static String EDIT_NIGHTLY_UPDATE_SITE_NAME
= "Taxonomic Editor Nightly";
40 private static String EDIT_STABLE_UPDATE_SITE
= "http://cybertaxonomy.eu/download/taxeditor/update/stable/";
41 private static String EDIT_STABLE_UPDATE_SITE_NAME
= "Taxonomic Editor Stable";
44 * Retrieve and load the saved list of repositories from the preference store,
45 * making sure that at least the default repository is always loaded.
47 @SuppressWarnings("restriction")
48 public static void setP2UpdateRepositories() {
49 List
<MetadataRepositoryElement
> repoElements
= new ArrayList
<MetadataRepositoryElement
>();
50 List
<MetadataRepositoryElement
> savedRepoElements
= new ArrayList
<>();
52 MetadataRepositoryElement mre
= new MetadataRepositoryElement(null, getP2UpdateRepository(), true);
53 mre
.setNickname(getP2UpdateRepositoryName());
54 savedRepoElements
.add(mre
);
56 repoElements
.addAll(savedRepoElements
);
58 ElementUtils
.updateRepositoryUsingElements(ProvisioningUI
.getDefaultUI(),repoElements
59 .toArray(new MetadataRepositoryElement
[]{} ));
63 public static String
getP2UpdateRepositoryName(){
64 return ApplicationUtil
.isStable()?EDIT_STABLE_UPDATE_SITE_NAME
:EDIT_NIGHTLY_UPDATE_SITE_NAME
;
67 public static URI
getP2UpdateRepository(){
69 return ApplicationUtil
.isStable()?
new URI(EDIT_STABLE_UPDATE_SITE
):new URI(EDIT_NIGHTLY_UPDATE_SITE
);
70 } catch (URISyntaxException e
) {
71 MessagingUtils
.error(P2Util
.class, e
);
77 * {@link org.eclipse.equinox.p2.ui.RepositoryManipulationPage} which handles the repsitory site list
78 * in preferences does not create a preference store and hence the changes are not saved. This means
79 * that we need to save it ourselves.
81 * This method saves the list of current repositories in the preference store as a string with
82 * specific delimiters.
85 public static void saveP2RepositoryPreferences() {
87 IMetadataRepositoryManager metaManager
= ProvUI
.getMetadataRepositoryManager(ProvisioningUI
.getDefaultUI().getSession());
89 URI
[] currentlyEnabled
= metaManager
.getKnownRepositories(IRepositoryManager
.REPOSITORIES_ALL
);
90 URI
[] currentlyDisabled
= metaManager
.getKnownRepositories(IRepositoryManager
.REPOSITORIES_DISABLED
);
92 List
<MetadataRepositoryElement
> repoElements
= new ArrayList
<MetadataRepositoryElement
>();
94 for(URI repo
: currentlyEnabled
) {
95 boolean enabled
= true;
96 String nickname
= metaManager
.getRepositoryProperty(repo
, IRepository
.PROP_NICKNAME
);
97 MetadataRepositoryElement element
= new MetadataRepositoryElement(null, repo
, true);
98 element
.setNickname(nickname
);
99 element
.setEnabled(enabled
);
100 repoElements
.add(element
);
103 for(URI repo
: currentlyDisabled
) {
104 boolean enabled
= false;
105 String nickname
= metaManager
.getRepositoryProperty(repo
, IRepository
.PROP_NICKNAME
);
106 MetadataRepositoryElement element
= new MetadataRepositoryElement(null, repo
, true);
107 element
.setNickname(nickname
);
108 element
.setEnabled(enabled
);
109 repoElements
.add(element
);
111 PreferencesUtil
.setP2Repositories(repoElements
);