Revision 43658
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/Launcher.java | ||
---|---|---|
1899 | 1899 |
*/ |
1900 | 1900 |
private void installPluginsControls() { |
1901 | 1901 |
logger.info("installPluginsControls (toolbars)"); |
1902 |
installPluginsControlsToToolsbar(); |
|
1903 |
installPluginsControlsToStatusbar(); |
|
1904 |
} |
|
1905 |
|
|
1906 |
private void installPluginsControlsToToolsbar() { |
|
1902 | 1907 |
|
1908 |
Map<String,List<SortableTool>> toolsByToolbar = new HashMap<>(); |
|
1909 |
// A?ade primero las toolbars ordenadas para garantizar el orden de estas |
|
1910 |
// Y inicializa las listas del Map. |
|
1911 |
for( ToolBar toolbar : getOrderedToolBars() ) { |
|
1912 |
frame.addToolBar(toolbar.getName(), toolbar.getDescription(), toolbar.getPosition()); |
|
1913 |
ArrayList<SortableTool> tools = new ArrayList<>(); |
|
1914 |
toolsByToolbar.put(toolbar.getName(),tools); |
|
1915 |
} |
|
1916 |
for( Entry<String, PluginConfig> entry : pluginsConfig.entrySet() ) { |
|
1917 |
String pluginName = entry.getKey(); |
|
1918 |
PluginConfig pluginConfig = entry.getValue(); |
|
1919 |
PluginServices plugin = pluginsServices.get(pluginName); |
|
1920 |
PluginClassLoader loader = plugin.getClassLoader(); |
|
1921 |
Extension[] pluginExtensions = pluginConfig.getExtensions().getExtension(); |
|
1922 |
for( Extension pluginExtension : pluginExtensions ) { |
|
1923 |
ToolBar[] pluginToolbars = pluginExtension.getToolBar(); |
|
1924 |
for( ToolBar pluginToolbar : pluginToolbars ) { |
|
1925 |
ActionTool[] actionTools = pluginToolbar.getActionTool(); |
|
1926 |
for( ActionTool actionTool : actionTools ) { |
|
1927 |
List<SortableTool> toolbar = toolsByToolbar.get(pluginToolbar.getName()); |
|
1928 |
toolbar.add(new SortableTool(loader, pluginExtension, pluginToolbar, actionTool)); |
|
1929 |
} |
|
1930 |
SelectableTool[] selectableTools = pluginToolbar.getSelectableTool(); |
|
1931 |
for( SelectableTool selectableTool : selectableTools ) { |
|
1932 |
List<SortableTool> toolbar = toolsByToolbar.get(pluginToolbar.getName()); |
|
1933 |
toolbar.add(new SortableTool(loader, pluginExtension, pluginToolbar, selectableTool)); |
|
1934 |
} |
|
1935 |
} |
|
1936 |
} |
|
1937 |
} |
|
1938 |
for( Entry<String, List<SortableTool>> entry : toolsByToolbar.entrySet() ) { |
|
1939 |
String toolbarName = entry.getKey(); |
|
1940 |
List<SortableTool> tools = entry.getValue(); |
|
1941 |
tools.sort(new Comparator<SortableTool>() { |
|
1942 |
@Override |
|
1943 |
public int compare(SortableTool o1, SortableTool o2) { |
|
1944 |
return Long.compare(o1.getPosition(), o2.getPosition()); |
|
1945 |
} |
|
1946 |
}); |
|
1947 |
for( SortableTool tool : tools ) { |
|
1948 |
try { |
|
1949 |
if (tool.actiontool != null) { |
|
1950 |
frame.addTool(tool.loader, tool.extension, |
|
1951 |
tool.toolbar, tool.actiontool |
|
1952 |
); |
|
1953 |
} else { |
|
1954 |
frame.addTool(tool.loader, tool.extension, |
|
1955 |
tool.toolbar, tool.selectabletool |
|
1956 |
); |
|
1957 |
} |
|
1958 |
} catch (Exception ex) { |
|
1959 |
} |
|
1960 |
} |
|
1961 |
} |
|
1962 |
} |
|
1963 |
|
|
1964 |
private void installPluginsControlsToStatusbar() { |
|
1903 | 1965 |
Iterator<String> pluginNames = pluginsConfig.keySet().iterator(); |
1904 | 1966 |
|
1905 | 1967 |
Map<Extension, PluginServices> extensionPluginServices = new HashMap<Extension, PluginServices>(); |
1906 |
Map<Extension, PluginConfig> extensionPluginConfig = new HashMap<Extension, PluginConfig>(); |
|
1907 |
Set<Extension> orderedExtensions = new TreeSet<Extension>( |
|
1908 |
new ExtensionComparator()); |
|
1968 |
Set<Extension> orderedExtensions = new TreeSet<Extension>(new ExtensionComparator()); |
|
1909 | 1969 |
|
1910 |
// First of all, sort the extensions. |
|
1911 |
// We need to iterate on the plugins, and iterate on each plugin's |
|
1912 |
// extensions |
|
1913 |
// (each plugin may contain one or more extensions) |
|
1914 |
while (pluginNames.hasNext()) { // iterate on the plugins |
|
1970 |
while (pluginNames.hasNext()) { |
|
1915 | 1971 |
String pluginName = pluginNames.next(); |
1916 | 1972 |
try { |
1917 | 1973 |
PluginConfig pc = pluginsConfig.get(pluginName); |
... | ... | |
1919 | 1975 |
|
1920 | 1976 |
Extension[] exts = pc.getExtensions().getExtension(); |
1921 | 1977 |
|
1922 |
for (int j = 0; j < exts.length; j++) { // iterate on the |
|
1923 |
// extensions |
|
1978 |
for (int j = 0; j < exts.length; j++) { |
|
1924 | 1979 |
String cname = "unknow"; |
1925 | 1980 |
try { |
1926 | 1981 |
cname = exts[j].getClassName(); |
1927 |
if (exts[j].getActive() |
|
1928 |
&& !cname.equals(LibraryExtension.class |
|
1929 |
.getName())) { |
|
1982 |
if (exts[j].getActive() && !cname.equals(LibraryExtension.class.getName())) { |
|
1930 | 1983 |
if (orderedExtensions.contains(exts[j])) { |
1931 |
this |
|
1932 |
.addError(Messages
|
|
1933 |
.getString("Launcher.Two_extensions_with_the_same_priority")
|
|
1934 |
+ cname);
|
|
1984 |
this.addError(
|
|
1985 |
Messages.getString("Launcher.Two_extensions_with_the_same_priority")
|
|
1986 |
+ cname
|
|
1987 |
); |
|
1935 | 1988 |
} |
1936 | 1989 |
|
1937 | 1990 |
orderedExtensions.add(exts[j]); |
1938 | 1991 |
extensionPluginServices.put(exts[j], ps); |
1939 |
extensionPluginConfig.put(exts[j], pc); |
|
1940 | 1992 |
} |
1941 | 1993 |
} catch (Throwable e) { |
1942 | 1994 |
addError("Error initializing controls of plugin '" |
... | ... | |
1949 | 2001 |
} |
1950 | 2002 |
} |
1951 | 2003 |
|
1952 |
|
|
1953 |
// A?ade primero las toolbars ordenadas para garantizar el orden de estas |
|
1954 |
for( ToolBar toolbar : getOrderedToolBars() ) { |
|
1955 |
frame.addToolBar(toolbar.getName(), toolbar.getDescription(), toolbar.getPosition()); |
|
1956 |
} |
|
1957 |
|
|
1958 |
TreeSet<SortableTool> orderedTools = new TreeSet<SortableTool>( |
|
1959 |
new ToolComparator()); |
|
1960 | 2004 |
Iterator<Extension> e = orderedExtensions.iterator(); |
1961 | 2005 |
|
1962 |
// sort the toolbars and tools from 'normal' extensions (actiontools, |
|
1963 |
// selectabletools) |
|
1964 |
// and load the combo-scales and combo-buttons for the status bar |
|
2006 |
// load the combo-scales and combo-buttons for the status bar |
|
1965 | 2007 |
while (e.hasNext()) { |
1966 | 2008 |
Extension ext = e.next(); |
1967 | 2009 |
String extName = "unknow"; |
1968 | 2010 |
try { |
1969 | 2011 |
extName = ext.getClassName(); |
1970 |
ToolBar[] toolbars = ext.getToolBar(); |
|
1971 | 2012 |
|
1972 |
// get tools from toolbars |
|
1973 |
for (int k = 0; k < toolbars.length; k++) { |
|
1974 |
ActionTool[] tools = toolbars[k].getActionTool(); |
|
1975 |
|
|
1976 |
for (int t = 0; t < tools.length; t++) { |
|
1977 |
SortableTool sm = new SortableTool( |
|
1978 |
(extensionPluginServices.get(ext)) |
|
1979 |
.getClassLoader(), ext, toolbars[k], |
|
1980 |
tools[t]); |
|
1981 |
orderedTools.add(sm); |
|
1982 |
} |
|
1983 |
|
|
1984 |
SelectableTool[] sTools = toolbars[k].getSelectableTool(); |
|
1985 |
|
|
1986 |
for (int t = 0; t < sTools.length; t++) { |
|
1987 |
SortableTool sm = new SortableTool( |
|
1988 |
(extensionPluginServices.get(ext)) |
|
1989 |
.getClassLoader(), ext, toolbars[k], |
|
1990 |
sTools[t]); |
|
1991 |
orderedTools.add(sm); |
|
1992 |
} |
|
1993 |
} |
|
1994 |
|
|
1995 |
// get controls for statusBar |
|
2013 |
// get controls for statusBar |
|
1996 | 2014 |
PluginServices ps = extensionPluginServices.get(ext); |
1997 | 2015 |
PluginClassLoader loader = ps.getClassLoader(); |
1998 | 2016 |
|
1999 |
// ArrayList componentList = new ArrayList(); |
|
2000 | 2017 |
ComboScale[] comboScaleArray = ext.getComboScale(); |
2001 | 2018 |
for (int k = 0; k < comboScaleArray.length; k++) { |
2002 | 2019 |
org.gvsig.gui.beans.controls.comboscale.ComboScale combo = new org.gvsig.gui.beans.controls.comboscale.ComboScale(); |
... | ... | |
2090 | 2107 |
} |
2091 | 2108 |
} |
2092 | 2109 |
|
2093 |
// Add the tools from MDI extensions to the ordered tool-list, so that |
|
2094 |
// we get a sorted list containing all the tools |
|
2095 |
pluginNames = pluginsConfig.keySet().iterator(); |
|
2096 |
while (pluginNames.hasNext()) { |
|
2097 |
String pName = (String) pluginNames.next(); |
|
2098 |
try { |
|
2099 |
PluginConfig pc = (PluginConfig) pluginsConfig.get(pName); |
|
2100 |
PluginServices ps = (PluginServices) pluginsServices.get(pName); |
|
2101 |
|
|
2102 |
SkinExtension[] skinExts = pc.getExtensions() |
|
2103 |
.getSkinExtension(); |
|
2104 |
for (int j = 0; j < skinExts.length; j++) { |
|
2105 |
|
|
2106 |
if (skinExts[j] != null) { |
|
2107 |
ToolBar[] toolbars = skinExts[j].getToolBar(); |
|
2108 |
|
|
2109 |
for (int k = 0; k < toolbars.length; k++) { |
|
2110 |
ActionTool[] tools = toolbars[k].getActionTool(); |
|
2111 |
|
|
2112 |
for (int t = 0; t < tools.length; t++) { |
|
2113 |
SortableTool stb = new SortableTool(ps |
|
2114 |
.getClassLoader(), skinExts[j], |
|
2115 |
toolbars[k], tools[t]); |
|
2116 |
orderedTools.add(stb); |
|
2117 |
} |
|
2118 |
|
|
2119 |
SelectableTool[] sTools = toolbars[k] |
|
2120 |
.getSelectableTool(); |
|
2121 |
|
|
2122 |
for (int t = 0; t < sTools.length; t++) { |
|
2123 |
SortableTool stb = new SortableTool(ps |
|
2124 |
.getClassLoader(), skinExts[j], |
|
2125 |
toolbars[k], sTools[t]); |
|
2126 |
orderedTools.add(stb); |
|
2127 |
} |
|
2128 |
} |
|
2129 |
} |
|
2130 |
} |
|
2131 |
// Install popup menus |
|
2132 |
PopupMenus pus = pc.getPopupMenus(); |
|
2133 |
if (pus != null) { |
|
2134 |
PopupMenu[] menus = pus.getPopupMenu(); |
|
2135 |
for (int j = 0; j < menus.length; j++) { |
|
2136 |
String menuName = "(unknow)"; |
|
2137 |
try { |
|
2138 |
menuName = menus[j].getName(); |
|
2139 |
frame.addPopupMenu(ps.getClassLoader(), menus[j]); |
|
2140 |
} catch (Throwable ex) { |
|
2141 |
addError("Error adding popup menu' " + menuName + "' in plugin '" + pName + "'."); |
|
2142 |
} |
|
2143 |
} |
|
2144 |
} |
|
2145 |
} catch (Throwable e3) { |
|
2146 |
addError("Error initializing skins of the plugin '" + pName |
|
2147 |
+ "'", e3); |
|
2148 |
} |
|
2149 |
} |
|
2150 |
|
|
2151 |
// loop on the ordered extension list, to add them to the interface in |
|
2152 |
// an ordered way |
|
2153 |
Iterator<SortableTool> t = orderedTools.iterator(); |
|
2154 |
while (t.hasNext()) { |
|
2155 |
SortableTool stb = t.next(); |
|
2156 |
try { |
|
2157 |
if (stb.actiontool != null) { |
|
2158 |
frame.addTool(stb.loader, stb.extension, stb.toolbar, |
|
2159 |
stb.actiontool); |
|
2160 |
} else { |
|
2161 |
frame.addTool(stb.loader, stb.extension, stb.toolbar, |
|
2162 |
stb.selectabletool); |
|
2163 |
} |
|
2164 |
} catch (ClassNotFoundException ex) { |
|
2165 |
this |
|
2166 |
.addError( |
|
2167 |
Messages |
|
2168 |
.getString("Launcher.No_se_encontro_la_clase_de_la_extension"), |
|
2169 |
ex); |
|
2170 |
} catch (Throwable e2) { |
|
2171 |
addError("Error adding tools to the interface of extension '" |
|
2172 |
+ stb.extension.getClassName() + "'", e2); |
|
2173 |
} |
|
2174 |
} |
|
2175 | 2110 |
} |
2176 |
|
|
2111 |
|
|
2177 | 2112 |
/** |
2178 | 2113 |
* Adds new plugins to the the andami-config file. |
2179 | 2114 |
*/ |
... | ... | |
2894 | 2829 |
selectabletool = selectabletool2; |
2895 | 2830 |
this.loader = loader; |
2896 | 2831 |
} |
2832 |
|
|
2833 |
public long getPosition() { |
|
2834 |
if( this.actiontool!=null ) { |
|
2835 |
return this.actiontool.getPosition(); |
|
2836 |
} |
|
2837 |
if( this.selectabletool!=null ) { |
|
2838 |
return this.selectabletool.getPosition(); |
|
2839 |
} |
|
2840 |
return 0; |
|
2841 |
} |
|
2897 | 2842 |
} |
2898 | 2843 |
|
2899 | 2844 |
private static class ToolBarComparator implements Comparator<SortableTool> { |
Also available in: Unified diff