Java源码示例:org.eclipse.core.commands.Category
示例1
private boolean checkDefaults(ArrayList<Category> compareCats) {
boolean result = true;
Category[] newArray = sortCats(compareCats);
if (defaultCats == null) {
defaultCats = sortCats(convertToCats(getPreferenceStore().getDefaultString(getPreferenceName()),
getAllCategories()));
}
if (newArray.length == defaultCats.length) {
for (int i = 0; i < newArray.length; i++) {
if (newArray[i] != defaultCats[i]) {
result = false;
break;
}
}
} else {
result = false;
}
return result;
}
示例2
/**
* @param catIdList is a 'list' of category ids
*
* @see org.eclipse.jface.preference.ListEditor#parseString(java.lang.String)
*/
protected String[] parseString(String catIdList) {
Category[] allCats = this.getAllCategories();
active = convertToCats(catIdList,allCats);
inactive = new ArrayList<Category>();
for (int i=0; i< allCats.length; i++){
if (!active.contains(allCats[i])){
inactive.add(allCats[i]);
}
}
String[] result = new String[active.size()];
for (int i=0; i< result.length; i++){
result[i] = getLabel(active.get(i));
}
return result;
}
示例3
/**
* Get the current set of defined categories corresponding to the included category names
*
* @param ics
* @return the filtered set of categories
*
* @throws NotDefinedException
*/
private HashSet<Category> getCategories(ICommandService ics) throws NotDefinedException
{
if (catHash.isEmpty() && catIncludes != null) {
Category[] cats = ics.getDefinedCategories();
for (int i = 0; i < cats.length; i++) {
for (int j = 0; j < catIncludes.length; j++) {
if (catIncludes[j].equals(cats[i].getId())) {
catHash.add(cats[i]);
break;
}
}
}
}
return catHash;
}
示例4
private void checkCats(){
List myList = this.getListUnchecked();
if (myList != null) {
String[] items = myList.getItems();
if (items.length != active.size()) {
// a remove happened
ArrayList<Category> moveCats = new ArrayList<Category>();
String[] catLabels = new String[active.size()];
for (int i = 0; i < active.size(); i++) {
catLabels[i] = getLabel(active.get(i));
}
for (int i = 0; i < catLabels.length; i++) {
boolean ok = false;
for (int j = 0; j < items.length; j++) {
if (items[j].equals(catLabels[i])) {
ok = true;
break;
}
}
if (!ok) {
moveCats.add(active.get(i));
}
}
if (!moveCats.isEmpty()) {
active.removeAll(moveCats);
inactive.addAll(moveCats);
}
}
}
}
示例5
/**
* Cook up a label that is, hopefully, distinct and useful
* @param cat
* @return
*/
String getLabel(Category cat) {
String result = null;
try {
String desc = cat.getDescription();
result= cat.getName() + DISPLAY_SEPARATOR + (desc != null ? desc : ""); //$NON-NLS-1$
} catch (NotDefinedException e) {}
return result;
}
示例6
/**
* @see org.eclipse.jface.preference.ListEditor#createList(java.lang.String[])
*/
protected String createList(String[] items) {
Category[] orderedCats = sortCats(active);
StringBuilder result = new StringBuilder("");//$NON-NLS-1$
for (int i = 0; i < orderedCats.length; i++) {
result.append(orderedCats[i].getId());
result.append(SEPARATOR);
}
return result.toString();
}
示例7
private ArrayList<Category> convertToCats(String idList, Category[] allCats){
ArrayList<Category> result;
StringTokenizer st = new StringTokenizer(idList, SEPARATOR);
result = new ArrayList<Category>();
while (st.hasMoreElements()) {
String next = ((String) st.nextElement()).trim();
for (int i=0; i< allCats.length; i++){
if (allCats[i].getId().equals(next)){
result.add(allCats[i]);
break;
}
}
}
return result;
}
示例8
Category[] sortCats(java.util.List<Category> sCats) {
Category[] sCatsArray = sCats.toArray(new Category[0]);
Arrays.sort(sCatsArray, new Comparator<Category>() {
public int compare(Category o1, Category o2) {
int result = 0;
try {
result = o1.getName().compareTo(o2.getName());
} catch (NotDefinedException e) {}
return result;
}
});
return sCatsArray;
}
示例9
/**
* Initialize our categories with cats
*
* @param cats
*/
void setCategories(ArrayList<Category> cats){
Category[] orderedCats = sortCats(cats);
categoryArray = new ArrayList<Category>();
for (int i=0; i < orderedCats.length; i++){
categoryArray.add((Category)orderedCats[i]);
}
}
示例10
/**
* Get all the selected categories from the add dialog
* @return
*/
ArrayList<Category> getNewCategories() {
int[] selection = catList.getSelectionIndices();
ArrayList<Category> cats = new ArrayList<Category>();
for (int i = 0; i < selection.length; i++) {
cats.add(categoryArray.get(selection[i]));
}
return cats;
}
示例11
public TreeMap<String, Command> getCommandList(IEditorPart editor, boolean all) {
ICommandService ics = (ICommandService) editor.getSite().getService(ICommandService.class);
Command[] commands = ics.getDefinedCommands();
commandTree = new TreeMap<String, Command>();
try {
HashSet<Category>catHash = (all ? null : getCategories(ics));
boolean isOk = all;
for (int i = 0; i < commands.length; i++) {
if (!isOk && catHash.contains(commands[i].getCategory())) {
IParameter[] params = commands[i].getParameters();
isOk = commands[i].isHandled();
// if the command has parameters, they must all be optional
if (isOk && params != null) {
for (int j = 0; j < params.length; j++) {
if (!(isOk = params[j].isOptional())) {
break;
}
}
}
}
if (isOk) {
commandTree.put(fixName(commands[i].getName()), commands[i]);
}
isOk = all;
}
} catch (NotDefinedException e) {}
// getContexts(editor);
return commandTree;
}
示例12
public CategoryPatternFilter(boolean filterCategories, Category c) {
uncategorized = c;
filterCategories(filterCategories);
}
示例13
public CategoryPatternFilter(boolean filterCategories, Category c) {
uncategorized = c;
filterCategories(filterCategories);
}
示例14
public CategoryPatternFilter(boolean filterCategories, Category c) {
uncategorized = c;
filterCategories(filterCategories);
}
示例15
/**
* Used by preference page to update changes to include categories
* @param newCats
*/
public static void setCategories(String[] newCats){
catIncludes = newCats;
catHash = new HashSet<Category>();
}
示例16
/**
* Receive the results of the add dialog
*
* @param cats
*/
void setOkCategories(ArrayList<Category> cats) {
newOnes = cats;
}
示例17
/**
* Get all the currently defined categories
* @return
*/
private Category[] getAllCategories() {
return ((ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class)).getDefinedCategories();
}