[Ejtools-cvs] applications/jndi.browser/src/main/org/ejtools/jndi/browser AboutDialog.java,1.3,1.4 B
Brought to you by:
letiemble
From: <let...@us...> - 2003-11-27 01:31:02
|
Update of /cvsroot/ejtools/applications/jndi.browser/src/main/org/ejtools/jndi/browser In directory sc8-pr-cvs1:/tmp/cvs-serv17169/jndi.browser/src/main/org/ejtools/jndi/browser Modified Files: AboutDialog.java Browser.java Main.java Log Message: Address Todo #755528 Address Todo #800902 Index: AboutDialog.java =================================================================== RCS file: /cvsroot/ejtools/applications/jndi.browser/src/main/org/ejtools/jndi/browser/AboutDialog.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AboutDialog.java 3 Mar 2003 20:34:53 -0000 1.3 --- AboutDialog.java 27 Nov 2003 01:30:28 -0000 1.4 *************** *** 1,92 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser; ! ! import java.awt.BorderLayout; ! import java.awt.Color; ! import java.awt.Container; ! import java.awt.GridLayout; ! import java.util.ResourceBundle; ! ! import javax.swing.ImageIcon; ! import javax.swing.JLabel; ! import javax.swing.JPanel; ! ! import org.ejtools.adwt.service.AboutService; ! ! /** ! * Custom AboutService that shows the EJTools logo and some informations about the virtual machine. ! * ! * @author letiemble ! * @created 2 novembre 2001 ! * @version $Revision$ ! */ ! public class AboutDialog implements AboutService ! { ! /** The main panel */ ! protected JPanel panel = null; ! /** Bundle for I18N */ ! private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.jndi.browser.Resources"); ! ! ! /** Constructor for the AboutServiceProvider object */ ! public AboutDialog() { } ! ! ! /** ! * Implementation of AboutService. Return the main panel to show. ! * ! * @return The main panel ! */ ! public Container getPanel() ! { ! // Lazy creation ! if (this.panel == null) ! { ! this.createPanel(); ! } ! return this.panel; ! } ! ! ! /** ! * Implementation of AboutService. Return the title of the About box. ! * ! * @return The String to display as title ! */ ! public String getTitle() ! { ! return resources.getString("about.dialog.title"); ! } ! ! ! /** Creation of the panel to show */ ! protected void createPanel() ! { ! this.panel = new JPanel(new BorderLayout()); ! ! String display = null; ! JLabel label = null; ! ! // North part of the panel ! this.panel.add("North", new JLabel(new ImageIcon(getClass().getResource("/images/logo.png")))); ! ! // Center part of the panel ! this.panel.add("Center", new JLabel(" ")); ! ! // South part of the panel ! JPanel info = new JPanel(new GridLayout(2, 1)); ! JLabel java = new JLabel(resources.getString("about.dialog.text.javaVersion") + " : " + System.getProperty("java.version"), JLabel.CENTER); ! java.setForeground(Color.black); ! info.add(java); ! JLabel vm = new JLabel(resources.getString("about.dialog.text.virtualMachine") + " : " + System.getProperty("java.vm.name") + ", " + System.getProperty("java.vm.version"), JLabel.CENTER); ! vm.setForeground(Color.black); ! info.add(vm); ! this.panel.add("South", info); ! } ! } ! --- 1,107 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser; ! ! import java.awt.BorderLayout; ! import java.awt.Color; ! import java.awt.Container; ! import java.awt.GridLayout; ! import java.util.ResourceBundle; ! ! import javax.swing.ImageIcon; ! import javax.swing.JLabel; ! import javax.swing.JPanel; ! import javax.swing.SwingConstants; ! import javax.swing.UIManager; ! ! import org.ejtools.adwt.service.AboutService; ! ! /** ! * Custom AboutService that shows the EJTools logo and some informations about the virtual machine. ! * ! * @author letiemble ! * @created 2 novembre 2001 ! * @version $Revision$ ! */ ! public class AboutDialog implements AboutService ! { ! /** The main panel */ ! protected JPanel panel = null; ! /** Bundle for I18N */ ! private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.jndi.browser.Resources"); ! ! ! /** Constructor for the AboutServiceProvider object */ ! public AboutDialog() { } ! ! ! /** ! * Implementation of AboutService. Return the main panel to show. ! * ! * @return The main panel ! */ ! public Container getPanel() ! { ! // Lazy creation ! if (this.panel == null) ! { ! this.createPanel(); ! } ! return this.panel; ! } ! ! ! /** ! * Implementation of AboutService. Return the title of the About box. ! * ! * @return The String to display as title ! */ ! public String getTitle() ! { ! return resources.getString("about.dialog.title"); ! } ! ! ! /** Creation of the panel to show */ ! protected void createPanel() ! { ! this.panel = new JPanel(new BorderLayout()); ! ! // North part of the panel ! this.panel.add("North", new JLabel(new ImageIcon(getClass().getResource("/images/logo.png")))); ! ! // Center part of the panel ! this.panel.add("Center", new JLabel(" ")); ! ! // South part of the panel ! JPanel info = new JPanel(new GridLayout(3, 1)); ! ! JLabel java = new JLabel( ! resources.getString("about.dialog.text.javaVersion") ! + " : " ! + System.getProperty("java.version"), SwingConstants.LEADING); ! java.setForeground(Color.black); ! info.add(java); ! ! JLabel vm = new JLabel( ! resources.getString("about.dialog.text.virtualMachine") ! + " : " ! + System.getProperty("java.vm.name") ! + ", " ! + System.getProperty("java.vm.version"), SwingConstants.LEADING); ! vm.setForeground(Color.black); ! info.add(vm); ! ! JLabel laf = new JLabel( ! resources.getString("about.dialog.text.lookAndFeel") ! + " : " ! + UIManager.getLookAndFeel().getName(), SwingConstants.LEADING); ! vm.setForeground(Color.black); ! info.add(laf); ! this.panel.add("South", info); ! } ! } Index: Browser.java =================================================================== RCS file: /cvsroot/ejtools/applications/jndi.browser/src/main/org/ejtools/jndi/browser/Browser.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Browser.java 3 Mar 2003 20:34:52 -0000 1.2 --- Browser.java 27 Nov 2003 01:30:28 -0000 1.3 *************** *** 10,29 **** --- 10,41 ---- import java.awt.event.WindowEvent; import java.beans.beancontext.BeanContextServicesSupport; + import java.io.File; + import java.net.URL; import java.util.Arrays; import java.util.List; import java.util.ResourceBundle; + import javax.swing.JFileChooser; import javax.swing.JOptionPane; + import javax.swing.filechooser.FileFilter; import org.apache.log4j.Logger; + import org.ejtools.adwt.LookAndFeelUtil; import org.ejtools.adwt.action.Command; import org.ejtools.adwt.action.file.ExitAction; import org.ejtools.adwt.action.file.NewAction; + import org.ejtools.adwt.action.file.OpenWorkspaceAction; + import org.ejtools.adwt.action.file.SaveAsWorkspaceAction; + import org.ejtools.adwt.action.file.SaveWorkspaceAction; import org.ejtools.adwt.service.AboutServiceProvider; + import org.ejtools.adwt.service.HistoryService; + import org.ejtools.adwt.service.HistoryServiceProvider; import org.ejtools.adwt.service.MDIFrameServiceProvider; import org.ejtools.adwt.service.MenuBarServiceProvider; import org.ejtools.adwt.service.ToolBarServiceProvider; import org.ejtools.jndi.browser.frame.ServerInternalFrame; + import org.ejtools.jndi.browser.model.Server; import org.ejtools.jndi.browser.model.service.ConnectionMetaData; + import org.ejtools.jndi.browser.state.WorkbenchState; import org.ejtools.util.service.Profile; import org.ejtools.util.service.ProfileServiceProvider; *************** *** 33,52 **** * * @author letiemble - * @created 21 mars 2002 * @version $Revision$ */ ! public class Browser extends BeanContextServicesSupport { - /** Description of the Field */ protected AboutServiceProvider aboutService; - /** Description of the Field */ protected ProfileServiceProvider factoryProvider; - /** Description of the Field */ protected MDIFrameServiceProvider frameService; - /** Description of the Field */ protected MenuBarServiceProvider menuBarService; - /** Description of the Field */ protected ToolBarServiceProvider toolBarService; /** Description of the Field */ private static Logger logger = Logger.getLogger(Browser.class); /** Bundle for I18N */ --- 45,78 ---- * * @author letiemble * @version $Revision$ + * @created 21 mars 2002 */ ! public class Browser extends BeanContextServicesSupport implements HistoryService.Holder { protected AboutServiceProvider aboutService; protected ProfileServiceProvider factoryProvider; protected MDIFrameServiceProvider frameService; protected MenuBarServiceProvider menuBarService; protected ToolBarServiceProvider toolBarService; + protected WorkbenchState stateManager; + protected HistoryServiceProvider historyService; + /** Description of the Field */ + private FileFilter WORKSPACE_FILE_FILTER = + new FileFilter() + { + public boolean accept(File file) + { + return file.getName().endsWith(".xml"); + } + + + public String getDescription() + { + return Browser.resources.getString("file.dialog.extension.description"); + } + }; + + /** Default logger */ private static Logger logger = Logger.getLogger(Browser.class); /** Bundle for I18N */ *************** *** 59,62 **** --- 85,91 ---- logger.debug("JNDI Browser starting..."); + // Search for custom Look and Feel + LookAndFeelUtil.setLookAndFeel(); + this.frameService = new MDIFrameServiceProvider(); this.aboutService = new AboutServiceProvider(new AboutDialog()); *************** *** 64,67 **** --- 93,98 ---- this.toolBarService = new ToolBarServiceProvider(); this.factoryProvider = new ProfileServiceProvider(new ConnectionMetaData()); + this.historyService = new HistoryServiceProvider(this, 4); + this.stateManager = new WorkbenchState(this); try *************** *** 96,104 **** if (idx >= 0) { ! Browser.this.add(new ServerInternalFrame(Browser.this.factoryProvider.getProfile(idx))); } } } ! )); this.add(new ExitAction( --- 127,215 ---- if (idx >= 0) { ! Profile profile = Browser.this.factoryProvider.getProfile(idx); ! ServerInternalFrame frame = new ServerInternalFrame(); ! frame.setProfile(profile); ! frame.setServer(new Server()); ! Browser.this.add(frame); } } } ! )); ! ! this.add(this.stateManager); ! ! this.add(new OpenWorkspaceAction( ! new Command() ! { ! public void execute() ! { ! try ! { ! URL selectedURL = selectWorkspaceFile(resources.getString("file.dialog.title.load"), JFileChooser.OPEN_DIALOG); ! if (selectedURL != null) ! { ! loadResource(selectedURL, null); ! } ! } ! catch (Exception e) ! { ! // JOptionPane.showMessageDialog(null, "Could not load file:" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); ! logger.error("Error while loading workspace", e); ! } ! } ! } ! )); ! ! this.add(new SaveWorkspaceAction( ! new Command() ! { ! public void execute() ! { ! try ! { ! if (Browser.this.stateManager.getWorkbenchURL() == null) ! { ! URL selectedURL = selectWorkspaceFile(resources.getString("file.dialog.title.save"), JFileChooser.SAVE_DIALOG); ! if (selectedURL != null) ! { ! Browser.this.stateManager.setWorkbenchURL(selectedURL); ! } ! } ! if (Browser.this.stateManager.getWorkbenchURL() != null) ! { ! Browser.this.stateManager.store(); ! } ! } ! catch (Exception e) ! { ! logger.error("Error while saving workspace", e); ! } ! } ! } ! )); ! ! this.add(new SaveAsWorkspaceAction( ! new Command() ! { ! public void execute() ! { ! try ! { ! URL selectedURL = selectWorkspaceFile(resources.getString("file.dialog.title.save"), JFileChooser.SAVE_DIALOG); ! if (selectedURL != null) ! { ! Browser.this.stateManager.setWorkbenchURL(selectedURL); ! Browser.this.stateManager.store(); ! } ! } ! catch (Exception e) ! { ! logger.error("Error while saving workspace", e); ! } ! } ! } ! )); ! ! this.add(this.historyService); this.add(new ExitAction( *************** *** 110,114 **** } } ! )); this.add(this.frameService); --- 221,225 ---- } } ! )); this.add(this.frameService); *************** *** 139,142 **** --- 250,267 ---- + /** + * Description of the Method + * + * @param url Description of the Parameter + * @param context Description of the Parameter + */ + public void loadResource(URL url, Object context) + { + this.stateManager.setWorkbenchURL(url); + this.stateManager.load(); + this.historyService.push(url, context); + } + + /** Quit method */ public void quit() *************** *** 144,146 **** --- 269,304 ---- System.exit(0); } + + + /** + * Description of the Method + * + * @param title Description of the Parameter + * @param type Description of the Parameter + * @return Description of the Return Value + * @exception Exception Description of the Exception + */ + private URL selectWorkspaceFile(String title, int type) + throws Exception + { + // Fix for JFileChooser/SecurityManager bug (#4264750) + SecurityManager s = System.getSecurityManager(); + System.setSecurityManager(null); + + // Choose file + JFileChooser chooser = new JFileChooser(System.getProperty("user.dir")); + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + chooser.setDialogTitle(title); + chooser.setDialogType(type); + chooser.setFileFilter(WORKSPACE_FILE_FILTER); + + int returnVal = chooser.showDialog(null, title); + System.setSecurityManager(s); + if (returnVal != JFileChooser.APPROVE_OPTION) + { + return null; + } + + return chooser.getSelectedFile().toURL(); + } } Index: Main.java =================================================================== RCS file: /cvsroot/ejtools/applications/jndi.browser/src/main/org/ejtools/jndi/browser/Main.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Main.java 24 Feb 2003 22:32:15 -0000 1.2 --- Main.java 27 Nov 2003 01:30:28 -0000 1.3 *************** *** 1,115 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser; ! ! import java.beans.Beans; ! import java.io.File; ! import java.net.URL; ! import java.net.URLClassLoader; ! import java.security.AccessController; ! import java.security.Permission; ! import java.security.PrivilegedExceptionAction; ! import java.util.LinkedList; ! ! import org.apache.log4j.Logger; ! ! /** ! * Main class for the JNDI Browser. Construct the classloader dynamically by scanning directories. Once the classloader has been built, launch the Browser with ! * a custom security manager. ! * ! * @author letiemble ! * @created 21 mars 2002 ! * @version $Revision$ ! */ ! public class Main ! { ! /** Log4j logger */ ! static Logger logger = Logger.getLogger(Main.class); ! ! ! /** ! * The main method ! * ! * @param args The command line arguments ! * @exception Exception Exception ! */ ! public static void main(String[] args) ! throws Exception ! { ! logger.debug("========================================"); ! logger.debug("JAVA_HOME : " + System.getProperty("java.home")); ! logger.debug("Vendor : " + System.getProperty("java.vendor")); ! logger.debug("Version : " + System.getProperty("java.version")); ! logger.debug("Operating Sys. : " + System.getProperty("os.name")); ! logger.debug("Architecture : " + System.getProperty("os.arch")); ! logger.debug("Version : " + System.getProperty("os.version")); ! logger.debug("========================================"); ! ! File pluginDir; ! File[] plugins; ! LinkedList list = new LinkedList(); ! ! logger.debug("Building classpath..."); ! ! // Store the files from lib directory ! logger.debug("Scanning lib directory..."); ! pluginDir = new File("../lib"); ! plugins = pluginDir.listFiles(); ! if (plugins != null) ! { ! for (int i = 0; i < plugins.length; i++) ! { ! logger.debug("Found " + plugins[i].toURL()); ! list.add(plugins[i].toURL()); ! } ! } ! ! // Store the files from lib/ext directory ! logger.debug("Scanning lib/ext directory..."); ! pluginDir = new File("../lib/ext"); ! plugins = pluginDir.listFiles(); ! if (plugins != null) ! { ! for (int i = 0; i < plugins.length; i++) ! { ! logger.debug("Found " + plugins[i].toURL()); ! list.add(plugins[i].toURL()); ! } ! } ! logger.debug("========================================"); ! ! // Create a custom classloader ! URL[] pluginURLs = (URL[]) list.toArray(new URL[list.size()]); ! Thread.currentThread().setContextClassLoader( ! new URLClassLoader(pluginURLs, Thread.currentThread().getContextClassLoader()) ! ); ! ! // Custom security manager ! System.setSecurityManager( ! new SecurityManager() ! { ! public void checkPermission(Permission p) { } ! ! ! public void checkPermission(Permission perm, Object context) { } ! }); ! ! // Create the JNDI Browser JavaBean ! logger.debug("Launching EJTools JNDI Browser"); ! AccessController.doPrivileged( ! new PrivilegedExceptionAction() ! { ! public Object run() ! throws Exception ! { ! Beans.instantiate(Thread.currentThread().getContextClassLoader(), "org.ejtools.jndi.browser.Browser"); ! return null; ! } ! }); ! } ! } ! --- 1,115 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser; ! ! import java.beans.Beans; ! import java.io.File; ! import java.net.URL; ! import java.net.URLClassLoader; ! import java.security.AccessController; ! import java.security.Permission; ! import java.security.PrivilegedExceptionAction; ! import java.util.LinkedList; ! ! import org.apache.log4j.Logger; ! ! /** ! * Main class for the JNDI Browser. Construct the classloader dynamically by scanning directories. Once the classloader has been built, launch the Browser with ! * a custom security manager. ! * ! * @author letiemble ! * @created 21 mars 2002 ! * @version $Revision$ ! */ ! public class Main ! { ! /** Log4j logger */ ! static Logger logger = Logger.getLogger(Main.class); ! ! ! /** ! * The main method ! * ! * @param args The command line arguments ! * @exception Exception Exception ! */ ! public static void main(String[] args) ! throws Exception ! { ! logger.debug("========================================"); ! logger.debug("JAVA_HOME : " + System.getProperty("java.home")); ! logger.debug("Vendor : " + System.getProperty("java.vendor")); ! logger.debug("Version : " + System.getProperty("java.version")); ! logger.debug("Operating Sys. : " + System.getProperty("os.name")); ! logger.debug("Architecture : " + System.getProperty("os.arch")); ! logger.debug("Version : " + System.getProperty("os.version")); ! logger.debug("========================================"); ! ! File pluginDir; ! File[] plugins; ! LinkedList list = new LinkedList(); ! ! logger.debug("Building classpath..."); ! ! // Store the files from lib directory ! logger.debug("Scanning lib directory..."); ! pluginDir = new File("../lib"); ! plugins = pluginDir.listFiles(); ! if (plugins != null) ! { ! for (int i = 0; i < plugins.length; i++) ! { ! logger.debug("Found " + plugins[i].toURL()); ! list.add(plugins[i].toURL()); ! } ! } ! ! // Store the files from lib/ext directory ! logger.debug("Scanning lib/ext directory..."); ! pluginDir = new File("../lib/ext"); ! plugins = pluginDir.listFiles(); ! if (plugins != null) ! { ! for (int i = 0; i < plugins.length; i++) ! { ! logger.debug("Found " + plugins[i].toURL()); ! list.add(plugins[i].toURL()); ! } ! } ! logger.debug("========================================"); ! ! // Create a custom classloader ! URL[] pluginURLs = (URL[]) list.toArray(new URL[list.size()]); ! Thread.currentThread().setContextClassLoader( ! new URLClassLoader(pluginURLs, Thread.currentThread().getContextClassLoader()) ! ); ! ! // Custom security manager ! System.setSecurityManager( ! new SecurityManager() ! { ! public void checkPermission(Permission p) { } ! ! ! public void checkPermission(Permission perm, Object context) { } ! }); ! ! // Create the JNDI Browser JavaBean ! logger.debug("Launching EJTools JNDI Browser"); ! AccessController.doPrivileged( ! new PrivilegedExceptionAction() ! { ! public Object run() ! throws Exception ! { ! Beans.instantiate(Thread.currentThread().getContextClassLoader(), "org.ejtools.jndi.browser.Browser"); ! return null; ! } ! }); ! } ! } ! |