1
package org.herac.tuxguitar.gui.system.plugins;
3
import java.util.ArrayList;
4
import java.util.Iterator;
7
import org.herac.tuxguitar.gui.util.MessageDialog;
8
import org.herac.tuxguitar.util.TGClassLoader;
9
import org.herac.tuxguitar.util.TGServiceReader;
11
public class TGPluginManager {
15
public TGPluginManager(){
16
this.plugins = new ArrayList();
20
public List getPlugins(){
24
public void initPLugins(){
26
//Search available providers
27
Iterator it = TGServiceReader.lookupProviders(TGPlugin.class,TGClassLoader.instance().getClassLoader());
30
TGPlugin plugin = (TGPlugin)it.next();
32
this.plugins.add(plugin);
33
}catch(TGPluginException exception){
34
MessageDialog.errorMessage(exception);
35
}catch(Throwable throwable){
36
MessageDialog.errorMessage(new TGPluginException("An error ocurred when trying to init plugin",throwable));
39
}catch(Throwable throwable){
40
MessageDialog.errorMessage(new TGPluginException("An error ocurred when trying to init plugin",throwable));
44
public void closePLugins(){
45
Iterator it = this.plugins.iterator();
48
((TGPlugin)it.next()).close();
49
}catch(TGPluginException exception){
50
MessageDialog.errorMessage(exception);
51
}catch(Throwable throwable){
52
MessageDialog.errorMessage(new TGPluginException("An error ocurred when trying to close plugin",throwable));
57
public void openPlugins(){
58
Iterator it = this.plugins.iterator();
61
TGPlugin plugin = (TGPlugin)it.next();
62
plugin.setEnabled(isEnabled(plugin));
63
}catch(TGPluginException exception){
64
MessageDialog.errorMessage(exception);
65
}catch(Throwable throwable){
66
MessageDialog.errorMessage(new TGPluginException("An error ocurred when trying to set plugin status",throwable));
71
public void setEnabled(TGPlugin plugin,boolean enabled){
73
TGPluginProperties.instance().setProperty(getEnabledProperty(plugin),enabled);
74
TGPluginProperties.instance().save();
75
plugin.setEnabled(enabled);
76
}catch(TGPluginException exception){
77
MessageDialog.errorMessage(exception);
78
}catch(Throwable throwable){
79
MessageDialog.errorMessage(new TGPluginException("An error ocurred when trying to set plugin status",throwable));
83
public boolean isEnabled(TGPlugin plugin){
85
return TGPluginProperties.instance().getBooleanConfigValue(getEnabledProperty(plugin),true);
86
}catch(Throwable throwable){
87
MessageDialog.errorMessage(new TGPluginException("An error ocurred when trying to get plugin status",throwable));
92
public String getEnabledProperty(TGPlugin plugin){
93
return (plugin.getClass().getName() + ".enabled");