Revision 185662d8
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java | ||
---|---|---|
13 | 13 |
import java.io.FileInputStream; |
14 | 14 |
import java.io.FileOutputStream; |
15 | 15 |
import java.io.IOException; |
16 |
import java.net.URI; |
|
17 |
import java.net.URISyntaxException; |
|
16 | 18 |
import java.util.ArrayList; |
17 | 19 |
import java.util.Arrays; |
18 | 20 |
import java.util.Collections; |
... | ... | |
21 | 23 |
import java.util.Map; |
22 | 24 |
import java.util.Properties; |
23 | 25 |
import java.util.Set; |
26 |
import java.util.StringTokenizer; |
|
24 | 27 |
import java.util.UUID; |
25 | 28 |
|
26 | 29 |
import org.apache.commons.lang.StringUtils; |
27 | 30 |
import org.apache.log4j.Logger; |
31 |
import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement; |
|
28 | 32 |
import org.eclipse.jface.preference.IPreferenceStore; |
29 | 33 |
import org.eclipse.jface.window.Window; |
30 | 34 |
import org.eclipse.swt.widgets.Composite; |
... | ... | |
76 | 80 |
*/ |
77 | 81 |
public class PreferencesUtil implements IPreferenceKeys { |
78 | 82 |
|
83 |
/** |
|
84 |
* |
|
85 |
*/ |
|
79 | 86 |
public static final String PREFERRED_TERMS_CHANGE = "preferred_terms"; |
80 | 87 |
|
88 |
public static final String P2_REPOSITORIES_DELIM = ","; |
|
89 |
public static final String P2_REPOSITORY_FIELDS_DELIM = ";"; |
|
90 |
|
|
81 | 91 |
private final static Logger logger = Logger.getLogger(PreferencesUtil.class); |
82 | 92 |
|
83 | 93 |
/** |
... | ... | |
868 | 878 |
fos.close(); |
869 | 879 |
} |
870 | 880 |
|
881 |
/** |
|
882 |
* Saves a list of P2 Metadata Repositories as string with specified delimiters |
|
883 |
* |
|
884 |
* @param p2Repos |
|
885 |
*/ |
|
886 |
public static void setP2Repositories(List<MetadataRepositoryElement> p2Repos) { |
|
887 |
StringBuilder sb = new StringBuilder(); |
|
888 |
for(MetadataRepositoryElement p2Repo : p2Repos) { |
|
889 |
sb.append(P2_REPOSITORIES_DELIM); |
|
890 |
if(p2Repo.getName() == null || p2Repo.getName().isEmpty()) { |
|
891 |
sb.append("-"); |
|
892 |
} else { |
|
893 |
sb.append(p2Repo.getName()); |
|
894 |
} |
|
895 |
sb.append(P2_REPOSITORY_FIELDS_DELIM); |
|
896 |
sb.append(p2Repo.getLocation().toString()); |
|
897 |
sb.append(P2_REPOSITORY_FIELDS_DELIM); |
|
898 |
sb.append(String.valueOf(p2Repo.isEnabled())); |
|
899 |
} |
|
900 |
getPreferenceStore().setValue(P2_REPOSITORY_LIST, sb.toString()); |
|
901 |
} |
|
902 |
|
|
903 |
|
|
904 |
/** |
|
905 |
* Retrieves a list of previously saved P2 repositories |
|
906 |
* |
|
907 |
* @return |
|
908 |
*/ |
|
909 |
public static List<MetadataRepositoryElement> getP2Repositories() { |
|
910 |
List<MetadataRepositoryElement> p2Repos = new ArrayList<MetadataRepositoryElement>(); |
|
911 |
String p2ReposPref = getPreferenceStore().getString(P2_REPOSITORY_LIST); |
|
912 |
if(p2ReposPref != null && !p2ReposPref.isEmpty()) { |
|
913 |
StringTokenizer p2ReposPrefST = new StringTokenizer(p2ReposPref,P2_REPOSITORIES_DELIM); |
|
914 |
|
|
915 |
while(p2ReposPrefST.hasMoreTokens()) { |
|
916 |
String p2RepoStr = p2ReposPrefST.nextToken(); |
|
917 |
StringTokenizer p2ReposStrST = new StringTokenizer(p2RepoStr,P2_REPOSITORY_FIELDS_DELIM); |
|
918 |
if(p2ReposStrST.countTokens()==3) { |
|
919 |
String nickname = p2ReposStrST.nextToken(); |
|
920 |
URI uri = null; |
|
921 |
try { |
|
922 |
uri = new URI(p2ReposStrST.nextToken()); |
|
923 |
} catch (URISyntaxException e) { |
|
924 |
continue; |
|
925 |
} |
|
926 |
boolean enabled = Boolean.parseBoolean(p2ReposStrST.nextToken()); |
|
927 |
MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri, true); |
|
928 |
mre.setNickname(nickname); |
|
929 |
mre.setEnabled(enabled); |
|
930 |
p2Repos.add(mre); |
|
931 |
} |
|
932 |
} |
|
933 |
} |
|
934 |
|
|
935 |
return p2Repos; |
|
936 |
} |
|
871 | 937 |
|
872 | 938 |
/** |
873 | 939 |
* enables/disables nested composite. <br> |
Also available in: Unified diff
Revert "ref #7268, #6913 Remove p2 related code"
This reverts commit 598845be674417e5a4d79cc533f3ff3b1a0b4cdb.