if (item != null)
item.setExpanded(!item.getExpanded());
}
});
} catch (Exception e) {
Logger.log(new LogEvent(LOGID, "Error initializing ConfigView", e));
}
scResizeListener = new Listener() {
public void handleEvent(Event event) {
setupSC((ScrolledComposite)event.widget);
}
};
// Add sections
/** How to add a new section
* 1) Create a new implementation of ConfigSectionSWT in a new file
* (Use the ConfigSectionTMP.java as a template if it's still around)
* 2) import it into here
* 3) add it to the internal sections list
*/
pluginSections = ConfigSectionRepository.getInstance().getList();
ConfigSection[] internalSections = {
new ConfigSectionMode(),
new ConfigSectionStartShutdown(),
new ConfigSectionConnection(),
new ConfigSectionConnectionProxy(),
new ConfigSectionConnectionAdvanced(),
new ConfigSectionConnectionEncryption(),
new ConfigSectionTransfer(),
new ConfigSectionTransferAutoSpeedSelect(),
new ConfigSectionTransferAutoSpeed(),
new ConfigSectionTransferAutoSpeedBeta(),
new ConfigSectionTransferLAN(),
new ConfigSectionFile(),
new ConfigSectionFileMove(),
new ConfigSectionFileTorrents(),
new ConfigSectionFileTorrentsDecoding(),
new ConfigSectionFilePerformance(),
new ConfigSectionInterface(),
new ConfigSectionInterfaceLanguage(),
new ConfigSectionInterfaceStart(),
new ConfigSectionInterfaceDisplay(),
new ConfigSectionInterfaceTables(),
new ConfigSectionInterfaceColor(),
new ConfigSectionInterfaceAlerts(),
new ConfigSectionInterfacePassword(),
new ConfigSectionInterfaceLegacy(),
new ConfigSectionIPFilter(),
new ConfigSectionPlugins(this),
new ConfigSectionStats(),
new ConfigSectionTracker(),
new ConfigSectionTrackerClient(),
new ConfigSectionTrackerServer(),
new ConfigSectionSecurity(),
new ConfigSectionSharing(),
new ConfigSectionLogging()
};
pluginSections.addAll(0, Arrays.asList(internalSections));
for (int i = 0; i < pluginSections.size(); i++) {
// slip the non-standard "plugins" initialisation inbetween the internal ones
// and the plugin ones so plugin ones can be children of it
boolean plugin_section = i >= internalSections.length;
ConfigSection section = pluginSections.get(i);
if (section instanceof ConfigSectionSWT || section instanceof UISWTConfigSection ) {
String name;
try {
name = section.configSectionGetName();
} catch (Exception e) {
Logger.log(new LogEvent(LOGID, "A ConfigSection plugin caused an "
+ "error while trying to call its "
+ "configSectionGetName function", e));
name = "Bad Plugin";
}
String section_key = name;
if ( plugin_section ){
// if resource exists without prefix then use it as plugins don't
// need to start with the prefix
if ( !MessageText.keyExists(section_key)){
section_key = sSectionPrefix + name;
}
}else{
section_key = sSectionPrefix + name;
}
String section_name = MessageText.getString( section_key );
try {
TreeItem treeItem;
String location = section.configSectionGetParentSection();
if ( location.length() == 0 || location.equalsIgnoreCase(ConfigSection.SECTION_ROOT)){
//int position = findInsertPointFor(section_name, tree);
//if ( position == -1 ){
treeItem = new TreeItem(tree, SWT.NULL);
// }else{
// treeItem = new TreeItem(tree, SWT.NULL, position);
//}
}else{
TreeItem treeItemFound = findTreeItem(tree, location);
if (treeItemFound != null){
if (location.equalsIgnoreCase(ConfigSection.SECTION_PLUGINS)) {
// Force ordering by name here.
int position = findInsertPointFor(section_name, treeItemFound);
if (position == -1) {
treeItem = new TreeItem(treeItemFound, SWT.NULL);
}
else {
treeItem = new TreeItem(treeItemFound, SWT.NULL, position);
}
}
else {
treeItem = new TreeItem(treeItemFound, SWT.NULL);
}
}else{
treeItem = new TreeItem(tree, SWT.NULL);
}
}
ScrolledComposite sc = new ScrolledComposite(cConfigSection, SWT.H_SCROLL | SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setLayoutData(new GridData(GridData.FILL_BOTH));
sc.getVerticalBar().setIncrement(16);
sc.addListener(SWT.Resize, scResizeListener);
if(i == 0) {
Composite c;
if ( section instanceof ConfigSectionSWT ){
c = ((ConfigSectionSWT)section).configSectionCreate(sc);
}else{
c = ((UISWTConfigSection)section).configSectionCreate(sc);
}
sectionsCreated.add(section);
sc.setContent(c);
}
Messages.setLanguageText(treeItem, section_key);
treeItem.setData("Panel", sc);
treeItem.setData("ID", name);
treeItem.setData("ConfigSectionSWT", section);
sections.put(treeItem, section);
// ConfigSectionPlugins is special because it has to handle the
// PluginConfigModel config pages
if (section instanceof ConfigSectionPlugins)
((ConfigSectionPlugins)section).initPluginSubSections();
} catch (Exception e) {
Logger.log(new LogEvent(LOGID, "ConfigSection plugin '" + name
+ "' caused an error", e));
}
}
}