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