138 |
138 |
private static HashMap classesExtensions = new HashMap();
|
139 |
139 |
private static String andamiConfigPath;
|
140 |
140 |
private static String pluginsPersistencePath;
|
141 |
|
|
|
141 |
private static final String nonWinDefaultLookAndFeel = "com.jgoodies.looks.plastic.PlasticXPLookAndFeel";
|
|
142 |
|
142 |
143 |
private static ArrayList pluginsOrdered = new ArrayList();
|
143 |
144 |
|
144 |
145 |
/**
|
... | ... | |
159 |
160 |
if (!validJVM()){
|
160 |
161 |
System.exit(-1);
|
161 |
162 |
}
|
162 |
|
|
|
163 |
|
163 |
164 |
if (args.length < 1) {
|
164 |
165 |
System.err.println("Uso: Launcher appName plugins-directory [language=locale]");
|
165 |
166 |
}
|
... | ... | |
200 |
201 |
// Directorio de las extensiones
|
201 |
202 |
andamiConfigFromXML(andamiConfigPath);
|
202 |
203 |
andamiConfig.setPluginsDirectory(args[1]);
|
203 |
|
|
|
204 |
|
204 |
205 |
// Hacemos visibles los argumentos como una propiedad est?tica
|
205 |
206 |
// de plugin services para quien lo quiera usar (por ejemplo, para
|
206 |
207 |
// cargar un proyecto por l?nea de comandos)
|
... | ... | |
210 |
211 |
String localeStr = null;
|
211 |
212 |
for (int i=2; i < args.length; i++)
|
212 |
213 |
{
|
213 |
|
int index = args[i].indexOf("language=");
|
|
214 |
int index = args[i].indexOf("language=");
|
214 |
215 |
if (index != -1)
|
215 |
216 |
localeStr = args[i].substring(index+9);
|
216 |
217 |
}
|
... | ... | |
240 |
241 |
Locale.setDefault(locale);
|
241 |
242 |
JComponent.setDefaultLocale(locale);
|
242 |
243 |
|
|
244 |
|
243 |
245 |
//Se pone el lookAndFeel
|
244 |
246 |
try {
|
245 |
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
|
247 |
String lookAndFeel = getAndamiConfig().getLookAndFeel();
|
|
248 |
if (lookAndFeel == null)
|
|
249 |
lookAndFeel = getDefaultLookAndFeel();
|
|
250 |
UIManager.setLookAndFeel(lookAndFeel);
|
246 |
251 |
} catch (Exception e) {
|
247 |
252 |
logger.warn(Messages.getString("Launcher.look_and_feel"), e);
|
248 |
253 |
}
|
... | ... | |
252 |
257 |
|
253 |
258 |
// TODO Buscar actualizaciones de los plugins
|
254 |
259 |
downloadExtensions(andamiConfig.getPluginsDirectory());
|
255 |
|
|
|
260 |
|
256 |
261 |
validate();
|
257 |
262 |
|
258 |
263 |
// Se leen los config.xml de los plugins -----++++
|
... | ... | |
314 |
319 |
|
315 |
320 |
//Se muestra el frame principal
|
316 |
321 |
frame.show();
|
317 |
|
|
|
322 |
|
318 |
323 |
// Definimos un KeyEventDispatcher global para que las extensiones
|
319 |
324 |
// puedan registrar sus "teclas r?pidas".
|
320 |
325 |
GlobalKeyEventDispatcher keyDispatcher = GlobalKeyEventDispatcher.getInstance();
|
... | ... | |
329 |
334 |
logger.error("excepci?n al arrancar", e);
|
330 |
335 |
System.exit(-1);
|
331 |
336 |
}
|
332 |
|
|
|
337 |
|
333 |
338 |
}
|
334 |
|
|
|
339 |
|
335 |
340 |
/**
|
336 |
341 |
* Recupera la geometr?a (tama?o, posici?n y estado) de la ventana principal de Andami.
|
337 |
342 |
* TODO Pendiente de ver como se asigna un pluginServices para el launcher.
|
... | ... | |
354 |
359 |
pos = new Point(xy[0], xy[1]);
|
355 |
360 |
}
|
356 |
361 |
frame.setLocation(pos);
|
357 |
|
|
|
362 |
|
358 |
363 |
// restore frame status (Maximized, minimized, etc);
|
359 |
364 |
int state = java.awt.Frame.MAXIMIZED_BOTH;
|
360 |
365 |
if (xml.contains("MDIFrameState")) {
|
... | ... | |
362 |
367 |
}
|
363 |
368 |
frame.setExtendedState(state);
|
364 |
369 |
}
|
365 |
|
|
|
370 |
|
366 |
371 |
private static XMLEntity saveMDIStatus() {
|
367 |
372 |
XMLEntity xml = new XMLEntity();
|
368 |
373 |
// save frame size
|
... | ... | |
414 |
419 |
}
|
415 |
420 |
}
|
416 |
421 |
}
|
417 |
|
|
|
422 |
|
418 |
423 |
/**
|
419 |
424 |
* Salva la persistencia de los plugins.
|
420 |
425 |
* @author LWS
|
... | ... | |
586 |
591 |
try {
|
587 |
592 |
Class extensionClass = ps.getClassLoader().loadClass(extension.getClassName());
|
588 |
593 |
extensionInstance = (com.iver.andami.plugins.IExtension) extensionClass.newInstance();
|
589 |
|
|
590 |
|
// CON DECORATOR
|
|
594 |
|
|
595 |
// CON DECORATOR
|
591 |
596 |
// ANTES: classesExtensions.put(extensionClass, extensionInstance);
|
592 |
597 |
// AHORA: CREAMOS UNA ExtensionDecorator y asignamos esta instancia para
|
593 |
598 |
// poder ampliar con nuevas propiedades (AlwaysVisible, por ejemplo)
|
... | ... | |
699 |
704 |
|
700 |
705 |
/**
|
701 |
706 |
* Installs the menus, toolbars, actiontools and selectable toolbars.
|
702 |
|
* The order in which they are shown is determined here.
|
|
707 |
* The order in which they are shown is determined here.
|
703 |
708 |
*/
|
704 |
709 |
private static void installPluginsControls() {
|
705 |
710 |
Iterator i = pluginsConfig.keySet().iterator();
|
... | ... | |
708 |
713 |
HashMap extensionPluginConfig = new HashMap();
|
709 |
714 |
TreeMap orderedExtensions = new TreeMap(new ExtensionComparator());
|
710 |
715 |
Object previous;
|
711 |
|
|
|
716 |
|
712 |
717 |
// First of all, sort the extensions.
|
713 |
718 |
// We need to iterate on the plugins, and iterate on each plugin's extensions
|
714 |
|
// (each plugin may contain one or more extensions)
|
|
719 |
// (each plugin may contain one or more extensions)
|
715 |
720 |
while (i.hasNext()) { // iterate on the plugins
|
716 |
721 |
String pName = (String) i.next();
|
717 |
722 |
PluginConfig pc = (PluginConfig) pluginsConfig.get(pName);
|
718 |
723 |
PluginServices ps = (PluginServices) pluginsServices.get(pName);
|
719 |
|
|
|
724 |
|
720 |
725 |
Extension[] exts = pc.getExtensions().getExtension();
|
721 |
|
|
|
726 |
|
722 |
727 |
for (int j = 0; j < exts.length; j++) { // iterate on the extensions
|
723 |
728 |
if (exts[j].getActive()) {
|
724 |
729 |
if (orderedExtensions.containsKey(exts[j])) {
|
... | ... | |
726 |
731 |
"Launcher.Two_extensions_with_the_same_priority") +
|
727 |
732 |
exts[j].getClassName());
|
728 |
733 |
}
|
729 |
|
|
|
734 |
|
730 |
735 |
orderedExtensions.put(exts[j], null);
|
731 |
736 |
extensionPluginServices.put(exts[j], ps);
|
732 |
737 |
extensionPluginConfig.put(exts[j], pc);
|
... | ... | |
737 |
742 |
///try {
|
738 |
743 |
TreeMap orderedTools = new TreeMap(new ToolComparator());
|
739 |
744 |
Iterator e = orderedExtensions.keySet().iterator();
|
740 |
|
|
|
745 |
|
741 |
746 |
// Ahora se ordenan las herramientas (actiontools y selectabletools) de las extensiones
|
742 |
747 |
while (e.hasNext()) {
|
743 |
748 |
Extension ext = (Extension) e.next();
|
744 |
|
|
|
749 |
|
745 |
750 |
ToolBar[] toolbars = ext.getToolBar();
|
746 |
|
|
|
751 |
|
747 |
752 |
for (int k = 0; k < toolbars.length; k++) {
|
748 |
753 |
ActionTool[] tools = toolbars[k].getActionTool();
|
749 |
|
|
|
754 |
|
750 |
755 |
for (int t = 0; t < tools.length; t++) {
|
751 |
756 |
SortableToolBar sm = new SortableToolBar(((PluginServices)extensionPluginServices.get(ext)).getClassLoader(), ext,
|
752 |
757 |
toolbars[k], tools[t]);
|
... | ... | |
754 |
759 |
///frame.addTool(((PluginServices)extensionPluginServices.get(ext)).getClassLoader(), ext,
|
755 |
760 |
/// toolbars[k], tools[t]);
|
756 |
761 |
}
|
757 |
|
|
|
762 |
|
758 |
763 |
SelectableTool[] sTools = toolbars[k].getSelectableTool();
|
759 |
|
|
|
764 |
|
760 |
765 |
for (int t = 0; t < sTools.length; t++) {
|
761 |
766 |
SortableToolBar sm=new SortableToolBar(((PluginServices)extensionPluginServices.get(ext)).getClassLoader(), ext,
|
762 |
767 |
toolbars[k], sTools[t]);
|
... | ... | |
773 |
778 |
String pName = (String) i.next();
|
774 |
779 |
PluginConfig pc = (PluginConfig) pluginsConfig.get(pName);
|
775 |
780 |
PluginServices ps = (PluginServices) pluginsServices.get(pName);
|
776 |
|
|
|
781 |
|
777 |
782 |
SkinExtension skinExt = pc.getExtensions().getSkinExtension();
|
778 |
|
|
|
783 |
|
779 |
784 |
if (skinExt != null) {
|
780 |
785 |
ToolBar[] toolbars = skinExt.getToolBar();
|
781 |
|
|
|
786 |
|
782 |
787 |
for (int k = 0; k < toolbars.length; k++) {
|
783 |
788 |
ActionTool[] tools = toolbars[k].getActionTool();
|
784 |
|
|
|
789 |
|
785 |
790 |
for (int t = 0; t < tools.length; t++) {
|
786 |
791 |
SortableToolBar stb=new SortableToolBar(ps.getClassLoader(), skinExt,
|
787 |
792 |
toolbars[k], tools[t]);
|
... | ... | |
789 |
794 |
///frame.addTool(ps.getClassLoader(), skinExt,
|
790 |
795 |
/// toolbars[k], tools[t]);
|
791 |
796 |
}
|
792 |
|
|
|
797 |
|
793 |
798 |
SelectableTool[] sTools = toolbars[k].getSelectableTool();
|
794 |
|
|
|
799 |
|
795 |
800 |
for (int t = 0; t < sTools.length; t++) {
|
796 |
801 |
SortableToolBar stb=new SortableToolBar(ps.getClassLoader(), skinExt,
|
797 |
802 |
toolbars[k], sTools[t]);
|
... | ... | |
803 |
808 |
}
|
804 |
809 |
//Se instalan los popup menus
|
805 |
810 |
PopupMenus pus = pc.getPopupMenus();
|
806 |
|
|
|
811 |
|
807 |
812 |
if (pus != null) {
|
808 |
813 |
PopupMenu[] menus = pus.getPopupMenu();
|
809 |
|
|
|
814 |
|
810 |
815 |
for (int j = 0; j < menus.length; j++) {
|
811 |
816 |
frame.addPopupMenu(ps.getClassLoader(), menus[j]);
|
812 |
817 |
}
|
813 |
818 |
}
|
814 |
819 |
}
|
815 |
820 |
|
816 |
|
Iterator tt = orderedTools.keySet().iterator();
|
|
821 |
Iterator tt = orderedTools.keySet().iterator();
|
817 |
822 |
while (tt.hasNext()) {
|
818 |
823 |
SortableToolBar kk = (SortableToolBar) tt.next();
|
819 |
824 |
kk.getClass();
|
820 |
825 |
}
|
821 |
|
|
822 |
|
|
|
826 |
|
|
827 |
|
823 |
828 |
// Se itera por las herramientas ordenadas, para
|
824 |
829 |
// a?adirlas a la interfaz de forma ordenada
|
825 |
|
Iterator t = orderedTools.keySet().iterator();
|
|
830 |
Iterator t = orderedTools.keySet().iterator();
|
826 |
831 |
while (t.hasNext()) {
|
827 |
832 |
try {
|
828 |
833 |
SortableToolBar stb = (SortableToolBar) t.next();
|
... | ... | |
953 |
958 |
pluginsServices.put(ps.getPluginName(), ps);
|
954 |
959 |
|
955 |
960 |
instalados.add(pluginName);
|
956 |
|
// FJP: Los metemos ordenados para luego no cargar uno que necesita de otro antes de tiempo. Esto lo usaremos al
|
|
961 |
// FJP: Los metemos ordenados para luego no cargar uno que necesita de otro antes de tiempo. Esto lo usaremos al
|
957 |
962 |
// inicializar los plugins
|
958 |
963 |
pluginsOrdered.add(pluginName);
|
959 |
964 |
|
... | ... | |
986 |
991 |
pluginsConfig.remove(pluginName);
|
987 |
992 |
i = pluginsConfig.keySet().iterator();
|
988 |
993 |
}
|
989 |
|
}
|
|
994 |
}
|
990 |
995 |
}
|
991 |
996 |
|
992 |
997 |
/**
|
993 |
998 |
* DOCUMENT ME!
|
994 |
999 |
*/
|
995 |
1000 |
private static void pluginsMessages() {
|
996 |
|
/* add gvsig translations first. This should be done using a generic "appPlugin" variable, instead
|
|
1001 |
/* add gvsig translations first. This should be done using a generic "appPlugin" variable, instead
|
997 |
1002 |
* of using "com.iver.cit.gvsig" directly, but I'll do it when we use the new appgvSIG launcher.
|
998 |
|
* I keep this workaround for the moment.
|
|
1003 |
* I keep this workaround for the moment.
|
999 |
1004 |
*/
|
1000 |
1005 |
PluginConfig config = (PluginConfig) pluginsConfig.get("com.iver.cit.gvsig");
|
1001 |
1006 |
PluginServices ps = (PluginServices) pluginsServices.get("com.iver.cit.gvsig");
|
... | ... | |
1005 |
1010 |
|
1006 |
1011 |
//Iteramos por todos los plugins
|
1007 |
1012 |
Iterator i = pluginsConfig.keySet().iterator();
|
1008 |
|
|
|
1013 |
|
1009 |
1014 |
while (i.hasNext()) {
|
1010 |
1015 |
String pluginName = (String) i.next();
|
1011 |
1016 |
if (!pluginName.equals("com.iver.cit.gvsig")) { // we've already loaded com.iver.cit.gvsig
|
1012 |
1017 |
config = (PluginConfig) pluginsConfig.get(pluginName);
|
1013 |
1018 |
ps = (PluginServices) pluginsServices.get(pluginName);
|
1014 |
|
|
|
1019 |
|
1015 |
1020 |
if (config.getResourceBundle() != null && !config.getResourceBundle().getName().equals("")) {
|
1016 |
1021 |
// add the locale files associated with the plugin
|
1017 |
1022 |
org.gvsig.i18n.Messages.addResourceFamily(config.getResourceBundle().getName(), ps.getClassLoader(), pluginName);
|
... | ... | |
1314 |
1319 |
|
1315 |
1320 |
//Persistencia de los plugins
|
1316 |
1321 |
savePluginPersistence();
|
1317 |
|
|
|
1322 |
|
1318 |
1323 |
//Finalize all the extensions
|
1319 |
1324 |
finalizeExtensions();
|
1320 |
|
|
|
1325 |
|
1321 |
1326 |
// Clean any temp data created
|
1322 |
1327 |
Utilities.cleanUpTempFiles();
|
1323 |
|
|
|
1328 |
|
1324 |
1329 |
//Para la depuraci?n de memory leaks
|
1325 |
1330 |
System.gc();
|
1326 |
1331 |
|
1327 |
1332 |
System.exit(0);
|
1328 |
1333 |
}
|
1329 |
|
|
|
1334 |
|
1330 |
1335 |
/**
|
1331 |
1336 |
* Exectutes the finalize method for all the extensions
|
1332 |
1337 |
*
|
1333 |
1338 |
*/
|
1334 |
1339 |
private static void finalizeExtensions() {
|
1335 |
1340 |
Set extensions = getClassesExtensions().keySet();
|
1336 |
|
Object[] keys = extensions.toArray();
|
1337 |
|
|
|
1341 |
Object[] keys = extensions.toArray();
|
|
1342 |
|
1338 |
1343 |
for (int i=0 ; i<keys.length ; i++){
|
1339 |
|
ExtensionDecorator extensionDecorator =
|
|
1344 |
ExtensionDecorator extensionDecorator =
|
1340 |
1345 |
(ExtensionDecorator) getClassesExtensions().get(keys[i]);
|
1341 |
1346 |
extensionDecorator.getExtension().finalize();
|
1342 |
|
}
|
|
1347 |
}
|
1343 |
1348 |
}
|
1344 |
1349 |
|
1345 |
1350 |
|
... | ... | |
1714 |
1719 |
public int compare(Object o1, Object o2) {
|
1715 |
1720 |
SortableToolBar e1 = (SortableToolBar) o1;
|
1716 |
1721 |
SortableToolBar e2 = (SortableToolBar) o2;
|
1717 |
|
|
|
1722 |
|
1718 |
1723 |
// if the toolbars have the same name, they are considered to be
|
1719 |
1724 |
// the same toolbar, so we don't need to do further comparing
|
1720 |
1725 |
if (e1.toolbar.getName().equals(e2.toolbar.getName()))
|
1721 |
1726 |
return 0;
|
1722 |
|
|
|
1727 |
|
1723 |
1728 |
if (!e1.toolbar.hasPosition() && !e2.toolbar.hasPosition()) {
|
1724 |
1729 |
if (e1.extension instanceof SkinExtensionType) {
|
1725 |
1730 |
return 1;
|
... | ... | |
1739 |
1744 |
}
|
1740 |
1745 |
if (e1.toolbar.getPosition() != e2.toolbar.getPosition())
|
1741 |
1746 |
return e1.toolbar.getPosition() - e2.toolbar.getPosition();
|
1742 |
|
|
|
1747 |
|
1743 |
1748 |
if (e1.toolbar.getActionTool().equals(e2.toolbar.getActionTool()) && e1.toolbar.getSelectableTool().equals(e2.toolbar.getSelectableTool())){
|
1744 |
1749 |
return 0;
|
1745 |
1750 |
}
|
1746 |
1751 |
return (e1.toolbar.toString().compareTo(e2.toolbar.toString()));
|
1747 |
1752 |
}
|
1748 |
1753 |
}
|
1749 |
|
|
|
1754 |
|
1750 |
1755 |
/**
|
1751 |
1756 |
* <p>This class is used to compare tools (selectabletool and actiontool),
|
1752 |
1757 |
* using the "position"
|
... | ... | |
1793 |
1798 |
if (e1.selectabletool.hasPosition())
|
1794 |
1799 |
e1Position = e1.selectabletool.getPosition();
|
1795 |
1800 |
}
|
1796 |
|
|
|
1801 |
|
1797 |
1802 |
if (e2.actiontool!=null) {
|
1798 |
1803 |
if (e2.actiontool.hasPosition())
|
1799 |
1804 |
e2Position = e2.actiontool.getPosition();
|
... | ... | |
1802 |
1807 |
if (e2.selectabletool.hasPosition())
|
1803 |
1808 |
e2Position = e2.selectabletool.getPosition();
|
1804 |
1809 |
}
|
1805 |
|
|
|
1810 |
|
1806 |
1811 |
if (e1Position==-1 && e2Position!=-1) {
|
1807 |
1812 |
return 1;
|
1808 |
1813 |
}
|
... | ... | |
1821 |
1826 |
return e1.toString().compareTo(e2.toString());
|
1822 |
1827 |
}
|
1823 |
1828 |
}
|
1824 |
|
|
1825 |
|
|
|
1829 |
|
|
1830 |
|
1826 |
1831 |
/**
|
1827 |
1832 |
* validates the user before starting gvsig
|
1828 |
1833 |
*
|
1829 |
1834 |
*/
|
1830 |
1835 |
private static void validate(){
|
1831 |
|
|
|
1836 |
|
1832 |
1837 |
IAuthentication session = null;
|
1833 |
1838 |
try {
|
1834 |
|
|
|
1839 |
|
1835 |
1840 |
//String location = getClassLocation(Class.forName("com.iver.andami.authentication.Session"));
|
1836 |
1841 |
session = (IAuthentication)Class.forName("com.iver.andami.authentication.Session").newInstance();
|
1837 |
1842 |
|
... | ... | |
1848 |
1853 |
//e.printStackTrace();
|
1849 |
1854 |
return;
|
1850 |
1855 |
}
|
1851 |
|
|
|
1856 |
|
1852 |
1857 |
session.setPluginDirectory( andamiConfig.getPluginsDirectory() );
|
1853 |
1858 |
if (session.validationRequired()){
|
1854 |
|
|
|
1859 |
|
1855 |
1860 |
//opens the login dialog for the user to validate
|
1856 |
1861 |
//session.loging does not need arguments: they are read in the internal hashtable
|
1857 |
1862 |
session.getUser();
|
1858 |
1863 |
if(session.Login((String)session.get("user"),(String)session.get("pwd"))){
|
1859 |
1864 |
System.out.println("You are logged in");
|
1860 |
|
//PluginServices.setSession( session );
|
|
1865 |
//PluginServices.setSession( session );
|
1861 |
1866 |
}
|
1862 |
1867 |
else{
|
1863 |
1868 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
|
1864 |
|
"You are not logged in");
|
|
1869 |
"You are not logged in");
|
1865 |
1870 |
System.exit(0);
|
1866 |
1871 |
}
|
1867 |
1872 |
PluginServices.setAuthentication(session);
|
1868 |
|
}
|
|
1873 |
}
|
1869 |
1874 |
}
|
|
1875 |
|
|
1876 |
public static String getDefaultLookAndFeel() {
|
|
1877 |
String osName = (String) System.getProperty("os.name");
|
|
1878 |
|
|
1879 |
if (osName.substring(0,3).toLowerCase().equals("win"))
|
|
1880 |
return UIManager.getSystemLookAndFeelClassName();
|
|
1881 |
else
|
|
1882 |
return nonWinDefaultLookAndFeel;
|
|
1883 |
}
|
1870 |
1884 |
}
|