use of org.talend.core.runtime.services.IMavenUIService in project tdi-studio-se by Talend.
the class ProjectSettingDialog method getNodeManager.
/**
* get all projectsettingPage node dynamic. need get the different result each time. because the tester will calc
* dymamic.
*
* @return PreferenceManager
*/
private PreferenceManager getNodeManager() {
// PreferenceManager manager = new PreferenceManager(WorkbenchPlugin.PREFERENCE_PAGE_CATEGORY_SEPARATOR);
PreferenceManager manager = new PreferenceManager('/');
IExtensionRegistry registry = Platform.getExtensionRegistry();
IConfigurationElement[] configurationElements = registry.getConfigurationElementsFor(//$NON-NLS-1$
"org.talend.repository.projectsetting_page");
Map<String, List<IPreferenceNode>> hasCategoriesNodes = new HashMap<String, List<IPreferenceNode>>();
for (IConfigurationElement element : configurationElements) {
ProjectSettingNode node = new ProjectSettingNode(element);
try {
//$NON-NLS-1$
IPreferencePage page = (IPreferencePage) element.createExecutableExtension("class");
node.setPage(page);
//$NON-NLS-1$
String id = element.getAttribute("id");
IConfigurationElement[] testers = element.getChildren("tester");
if (testers != null && testers.length == 1) {
// currently, only one tester is supported.
try {
IProjectSettingPageTester pageTester = (IProjectSettingPageTester) testers[0].createExecutableExtension("class");
if (pageTester != null) {
if (!pageTester.valid(element, node)) {
// don't add this page node.
continue;
}
}
} catch (CoreException ex) {
// can't create the tester
log.log(Level.WARN, "can't create the project setting tester for " + id, ex);
}
}
//$NON-NLS-1$
page.setDescription(element.getAttribute("description"));
//$NON-NLS-1$
page.setTitle(element.getAttribute("title"));
} catch (CoreException e) {
ExceptionHandler.process(e);
}
// add all into root.
manager.addToRoot(node);
// has category
String category = node.getCategory();
if (category != null && category.length() > 0) {
List<IPreferenceNode> list = hasCategoriesNodes.get(category);
if (list == null) {
list = new ArrayList<IPreferenceNode>();
hasCategoriesNodes.put(category, list);
}
list.add(node);
}
}
// add the speciall node for maven custom
if (GlobalServiceRegister.getDefault().isServiceRegistered(IMavenUIService.class)) {
IMavenUIService mavenUIService = (IMavenUIService) GlobalServiceRegister.getDefault().getService(IMavenUIService.class);
IPreferenceNode mavenCostomSetup = manager.find("projectsetting.MavenCustomSetup");
mavenUIService.addCustomMavenSettingChildren(mavenCostomSetup);
}
// find parent nodes for category
Map<String, IPreferenceNode> parentNodesMap = new HashMap<String, IPreferenceNode>();
for (String category : hasCategoriesNodes.keySet()) {
IPreferenceNode parent = manager.find(category);
if (parent != null) {
parentNodesMap.put(category, parent);
}
}
// process children nodes
for (String category : hasCategoriesNodes.keySet()) {
List<IPreferenceNode> list = hasCategoriesNodes.get(category);
if (list != null) {
IPreferenceNode parent = parentNodesMap.get(category);
Collections.sort(list, COMPARATOR);
for (IPreferenceNode node : list) {
// if the parent is not valid or not existed. the node won't show also.
// remove from root node.
manager.remove(node);
if (parent != null) {
// the parent existed.
parent.add(node);
}
}
}
}
// sort the root nodes
List<IPreferenceNode> rootSubNodesList = new ArrayList<IPreferenceNode>(Arrays.asList(manager.getRootSubNodes()));
Collections.sort(rootSubNodesList, COMPARATOR);
// clean all to re-add for order
manager.removeAll();
// add the sorted list to manager
for (IPreferenceNode rootSubNode : rootSubNodesList) {
manager.addToRoot(rootSubNode);
}
return manager;
}
Aggregations