diff options
Diffstat (limited to 'plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProfileElement.java')
| -rw-r--r-- | plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProfileElement.java | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProfileElement.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProfileElement.java new file mode 100644 index 0000000..02626ad --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProfileElement.java | |||
| @@ -0,0 +1,104 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2012 BMW Car IT GmbH. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * BMW Car IT - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide; | ||
| 12 | |||
| 13 | import java.util.Comparator; | ||
| 14 | import java.util.StringTokenizer; | ||
| 15 | import java.util.TreeSet; | ||
| 16 | |||
| 17 | import org.yocto.sdk.ide.preferences.PreferenceConstants; | ||
| 18 | |||
| 19 | public class YoctoProfileElement { | ||
| 20 | private TreeSet<String> profiles = new TreeSet<String>(new Comparator<String>() { | ||
| 21 | |||
| 22 | @Override | ||
| 23 | public int compare(String o1, String o2) { | ||
| 24 | int strcompare = o1.compareTo(o2); | ||
| 25 | |||
| 26 | if (strcompare == 0) { | ||
| 27 | return strcompare; | ||
| 28 | } | ||
| 29 | |||
| 30 | // Standard profile always less than anything else | ||
| 31 | if (o1.equals(PreferenceConstants.STANDARD_PROFILE_NAME)) { | ||
| 32 | return -1; | ||
| 33 | } | ||
| 34 | |||
| 35 | if (o2.equals(PreferenceConstants.STANDARD_PROFILE_NAME)) { | ||
| 36 | return 1; | ||
| 37 | } | ||
| 38 | |||
| 39 | return strcompare; | ||
| 40 | } | ||
| 41 | }); | ||
| 42 | |||
| 43 | private String selectedProfile; | ||
| 44 | |||
| 45 | public YoctoProfileElement(String profilesString, String selectedProfile) { | ||
| 46 | setProfilesFromString(profilesString); | ||
| 47 | this.selectedProfile = selectedProfile; | ||
| 48 | } | ||
| 49 | |||
| 50 | public void addProfile(String profile) { | ||
| 51 | this.profiles.add(profile); | ||
| 52 | } | ||
| 53 | |||
| 54 | public boolean contains(String newText) { | ||
| 55 | return profiles.contains(newText); | ||
| 56 | } | ||
| 57 | |||
| 58 | public TreeSet<String> getProfiles() { | ||
| 59 | return profiles; | ||
| 60 | } | ||
| 61 | |||
| 62 | public String getProfilesAsString() { | ||
| 63 | String profileString = ""; | ||
| 64 | |||
| 65 | for (String profile : profiles) { | ||
| 66 | profileString += "\"" + profile + "\","; | ||
| 67 | } | ||
| 68 | return profileString.substring(0, profileString.length() - 1); | ||
| 69 | } | ||
| 70 | |||
| 71 | public String getSelectedProfile() { | ||
| 72 | return selectedProfile; | ||
| 73 | } | ||
| 74 | |||
| 75 | public void remove(String profile) { | ||
| 76 | this.profiles.remove(profile); | ||
| 77 | } | ||
| 78 | |||
| 79 | public void rename(String oldProfileName, String newProfileName) { | ||
| 80 | this.remove(oldProfileName); | ||
| 81 | this.addProfile(newProfileName); | ||
| 82 | |||
| 83 | if (selectedProfile.equals(oldProfileName)) { | ||
| 84 | selectedProfile = newProfileName; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | public void setProfiles(TreeSet<String> profiles) { | ||
| 89 | this.profiles = profiles; | ||
| 90 | } | ||
| 91 | |||
| 92 | public void setProfilesFromString(String profilesString) { | ||
| 93 | StringTokenizer tokenizer = new StringTokenizer(profilesString, ","); | ||
| 94 | |||
| 95 | while (tokenizer.hasMoreElements()) { | ||
| 96 | String config = (String) tokenizer.nextElement(); | ||
| 97 | profiles.add(config.replace("\"", "")); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 101 | public void setSelectedProfile(String selectedProfile) { | ||
| 102 | this.selectedProfile = selectedProfile; | ||
| 103 | } | ||
| 104 | } | ||
