org.eclipse.core.commands.Category Java Examples

The following examples show how to use org.eclipse.core.commands.Category. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommandSupport.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: CommandCategoryEditor.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
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;
	}
 
Example #3
Source File: CommandCategoryEditor.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @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;
}
 
Example #4
Source File: CommandCategoryEditor.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #5
Source File: CommandSupport.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
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;
	}
 
Example #6
Source File: CommandCategoryEditor.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: CommandCategoryEditor.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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]);
	}
}
 
Example #8
Source File: CommandCategoryEditor.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #9
Source File: CommandCategoryEditor.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @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();
}
 
Example #10
Source File: CommandCategoryEditor.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
   * 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;
  }
 
Example #11
Source File: CommandCategoryEditor.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
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);
		}
	}
}
  }
 
Example #12
Source File: CategoryPatternFilter.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public CategoryPatternFilter(boolean filterCategories, Category c) {
	uncategorized = c;
	filterCategories(filterCategories);
}
 
Example #13
Source File: CommandSupport.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Used by preference page to update changes to include categories
 * @param newCats
 */
public static void setCategories(String[] newCats){
	catIncludes = newCats;
	catHash = new HashSet<Category>();		
}
 
Example #14
Source File: CategoryPatternFilter.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public CategoryPatternFilter(boolean filterCategories, Category c) {
	uncategorized = c;
	filterCategories(filterCategories);
}
 
Example #15
Source File: CategoryPatternFilter.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public CategoryPatternFilter(boolean filterCategories, Category c) {
	uncategorized = c;
	filterCategories(filterCategories);
}
 
Example #16
Source File: CommandCategoryEditor.java    From e4macs with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Receive the results of the add dialog
 * 
 * @param cats
 */
void setOkCategories(ArrayList<Category> cats) {
	newOnes = cats;
}
 
Example #17
Source File: CommandCategoryEditor.java    From e4macs with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Get all the currently defined categories
 * @return
 */
private Category[] getAllCategories() {
	return ((ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class)).getDefinedCategories();
}