/** * See the NOTICE file distributed with this work for additional * information regarding copyright ownership. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.ut.biolab.medsavant.client.plugin; import java.awt.BorderLayout; import java.awt.Dialog; import java.io.File; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JScrollPane; import org.ut.biolab.medsavant.client.app.MedSavantAppFetcher; import org.ut.biolab.medsavant.client.settings.DirectorySettings; import org.ut.biolab.medsavant.client.util.ClientNetworkUtils; import org.ut.biolab.medsavant.client.util.ClientMiscUtils; import org.ut.biolab.medsavant.client.view.util.DialogUtils; import org.ut.biolab.medsavant.shared.util.NetworkUtils; import org.ut.biolab.medsavant.shared.util.VersionSettings; import org.ut.biolab.medsavant.shared.util.WebResources; /** * * @author mfiume */ public class PluginManagerDialog extends JDialog { private static PluginManagerDialog instance; private PluginBrowser browser; private PluginRepositoryDialog repositoryBrowser; public static PluginManagerDialog getInstance() { if (instance == null) { instance = new PluginManagerDialog(); } return instance; } /** Creates new form PluginManager */ private PluginManagerDialog() { super(DialogUtils.getFrontWindow(), "Plugin Manager", Dialog.ModalityType.APPLICATION_MODAL); initComponents(); ClientMiscUtils.registerCancelButton(closeButton); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setLocationRelativeTo(getParent()); setResizable(false); browser = new PluginBrowser(); browserPanel.add(new JScrollPane(browser), BorderLayout.CENTER); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { javax.swing.JLabel pluginsCaption = new javax.swing.JLabel(); javax.swing.JButton fromFileButton = new javax.swing.JButton(); javax.swing.JButton fromRepositoryButton = new javax.swing.JButton(); browserPanel = new javax.swing.JPanel(); closeButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setIconImage(null); setIconImages(null); pluginsCaption.setText("Installed Plugins"); fromFileButton.setText("Install from File"); fromFileButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { fromFileButtonActionPerformed(evt); } }); fromRepositoryButton.setText("Install from Repository"); fromRepositoryButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { fromRepositoryButtonActionPerformed(evt); } }); browserPanel.setBackground(new java.awt.Color(255, 255, 255)); browserPanel.setLayout(new java.awt.BorderLayout()); closeButton.setText("Cancel"); closeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { closeButtonActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(browserPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 549, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addComponent(pluginsCaption) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 302, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addComponent(closeButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(fromRepositoryButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) .addComponent(fromFileButton))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(pluginsCaption) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(browserPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(fromFileButton) .addComponent(closeButton) .addComponent(fromRepositoryButton)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void fromFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fromFileButtonActionPerformed File selectedFile = DialogUtils.chooseFileForOpen("Select Plugin JAR", null, null); if (selectedFile != null) { try { AppController.getInstance().installPlugin(selectedFile); } catch (Throwable x) { DialogUtils.displayException("Installation Error", String.format("<html>Unable to install plugin from <i>%s</i>: %s.</html>", selectedFile.getName(), x), x); } } }//GEN-LAST:event_fromFileButtonActionPerformed private void fromRepositoryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fromRepositoryButtonActionPerformed try { if (repositoryBrowser == null) { // TODO :getting the plugin URL isn't clean, fix it File file = ClientNetworkUtils.downloadFile(NetworkUtils.getKnownGoodURL(WebResources.PLUGIN_REPOSITORY_URLS[0]), DirectorySettings.getTmpDirectory(), null); repositoryBrowser = new PluginRepositoryDialog(this, "Install Plugins", "Install", file); } repositoryBrowser.setVisible(true); } catch (Exception x) { DialogUtils.displayException("Installation Error", String.format("<html>Problem downloading file <i>%s</i>.</html>", WebResources.PLUGIN_REPOSITORY_URLS[0]), x); } }//GEN-LAST:event_fromRepositoryButtonActionPerformed private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed setVisible(false); }//GEN-LAST:event_closeButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel browserPanel; private javax.swing.JButton closeButton; // End of variables declaration//GEN-END:variables }