Save This Page
Home » openjdk-7 » net » sf » bloof » browser » [javadoc | source]
    1   /*
    2       Bloof - visualize the evolution of your software project  
    3       Copyright ( C ) 2003  Lukasz Pekacki <lukasz@pekacki.de>
    4       http://bloof.sf.net/
    5     
    6       This program is free software; you can redistribute it and/or modify it
    7       under the terms of the GNU General Public License.
    8       
    9       This program is distributed in the hope that it will be useful,
   10       but WITHOUT ANY WARRANTY; without even the implied warranty of
   11       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12       GNU General Public License for more details.
   13       
   14       You should have received a copy of the GNU General Public License along with
   15       this program; if not, write to the Free Software Foundation, Inc., 
   16       59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   17   
   18       $RCSfile: DialogImportProject.java,v $ 
   19       Created on $Date: 2003/06/28 13:41:25 $ 
   20   */
   21   package net.sf.bloof.browser;
   22   
   23   import java.awt.BorderLayout;
   24   import java.awt.Dimension;
   25   import java.awt.FlowLayout;
   26   import java.awt.Frame;
   27   import java.awt.event.ActionEvent;
   28   import java.awt.event.ActionListener;
   29   import java.io.File;
   30   import java.util.Iterator;
   31   
   32   import javax.swing.Box;
   33   import javax.swing.BoxLayout;
   34   import javax.swing.JButton;
   35   import javax.swing.JCheckBox;
   36   import javax.swing.JComboBox;
   37   import javax.swing.JComponent;
   38   import javax.swing.JDialog;
   39   import javax.swing.JFileChooser;
   40   import javax.swing.JOptionPane;
   41   import javax.swing.JPanel;
   42   import javax.swing.JPasswordField;
   43   import javax.swing.JTabbedPane;
   44   import javax.swing.JTextField;
   45   
   46   
   47   import net.sf.bloof.Bloof;
   48   import net.sf.bloof.browser.Main;
   49   import net.sf.bloof.db.DbAccess;
   50   import net.sf.bloof.scm.ScmAccess;
   51   import net.sf.bloof.scm.cvsplugin.CvsAccess;
   52   import net.sf.bloof.scm.cvsplugin.CvsConnectionMethod;
   53   import net.sf.bloof.scm.cvsplugin.CvsPlugin;
   54   import net.sf.bloof.scm.cvsplugin.InvalidRepositoryLocationException;
   55   import net.sf.bloof.scm.cvsplugin.LoginDetails;
   56   import net.sf.bloof.scm.cvsplugin.RepositoryLocation;
   57   import net.sf.bloof.browser.intl.Messages;
   58   import net.sf.bloof.browser.intl.Text;
   59   
   60   /**
   61    * Dialog for specifying SCM access information and starting
   62    * the SCM access data use case
   63    * @author Lukasz Pekacki <pekacki@users.sourceforge.net>
   64    * TODO: separate already configured repositories from new ones
   65    */
   66   
   67   public class DialogImportProject extends JDialog {
   68   
   69       /**
   70        * @see java.awt.Dialog#Dialog( Frame, String, boolean )
   71        */
   72       public DialogImportProject(Frame aFrame, String aTitle, boolean aModal) {
   73           super(aFrame, aTitle, aModal);
   74           try {
   75               initDialog();
   76               pack();
   77           } catch (Exception ex) {
   78               ex.printStackTrace();
   79           }
   80       }
   81   
   82       private void addDatabaseActionPerformed(ActionEvent aE) {
   83           Main.getGuiControl().processUselessEvent(aE);
   84           DialogDatabaseAdd addDatabase = new DialogDatabaseAdd(this, "Add Database access", true);
   85           Main.getGuiControl().centerOnScreen(addDatabase);
   86           addDatabase.setVisible(true);
   87           DbAccess newDbAccess = addDatabase.getdbAccess();
   88           addDatabase.dispose();
   89           Bloof.addDbAccessMethos(newDbAccess);
   90           getDbAccessMethods();
   91           this.paintComponents(this.getGraphics());
   92       }
   93   
   94       private void cancelButtonActionPerformed(ActionEvent aE) {
   95           Main.getGuiControl().processUselessEvent(aE);
   96           this.dispose();
   97       }
   98   
   99       /**
  100        * Method getdbAccess.
  101        * @return DbAccess
  102        */
  103       public DbAccess getdbAccess() {
  104           return mDbAccess;
  105       }
  106       /**
  107       * Method reloadDBAccess.
  108       */
  109       private void getDbAccessMethods() {
  110           mDatabaseCombo.removeAllItems();
  111           for (int i = 0; i < Bloof.getDbAccessMethods().length; i++) {
  112               mDatabaseCombo.addItem(Bloof.getDbAccessMethods()[i]);
  113           }
  114   
  115       }
  116   
  117       private JComponent getFiller(int aWidth, int aHeight) {
  118           Dimension d = new Dimension(aWidth, aHeight);
  119           return new Box.Filler(d, d, d);
  120       }
  121   
  122       /**
  123        * Method getScmAccess.
  124        * @return ScmAccess
  125        */
  126       public ScmAccess getScmAccess() {
  127           return mScmAccess;
  128       }
  129   
  130       /**
  131        * Creates the JPanel for the Buttons
  132        * @return JPanel for the Buttons
  133        */
  134       private JPanel initButtonsPanel() {
  135           JPanel buttonsPanel = new JPanel();
  136           /* init buttons */
  137           mCancelButton.setText(Messages.getString(Text.CANCEL_BUTTON));
  138           mCancelButton.addActionListener(new java.awt.event.ActionListener() {
  139               public void actionPerformed(ActionEvent aE) {
  140                   cancelButtonActionPerformed(aE);
  141               }
  142           });
  143           mOkButton.setText(Messages.getString(Text.OK_BUTTON));
  144           mOkButton.addActionListener(new java.awt.event.ActionListener() {
  145               public void actionPerformed(ActionEvent aE) {
  146                   okButtonActionPerformed(aE);
  147               }
  148           });
  149           /* construct buttons pane */
  150           buttonsPanel.add(mOkButton);
  151           buttonsPanel.add(mCancelButton);
  152           return buttonsPanel;
  153       }
  154   
  155       private JPanel initCvsAccessPanel() {
  156           /*
  157            * Tab Pane for CVS Access
  158            * 
  159            * */
  160           mCvsTabPane = new JPanel(new BorderLayout());
  161           JPanel contentPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
  162           contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
  163           for (Iterator iter = Bloof.getCvsLocations(); iter.hasNext();) {
  164               CvsAccess element = (CvsAccess) iter.next();
  165               mCvsLocations.addItem(element);
  166           }
  167           mCvsLocations.addActionListener(new ActionListener() {
  168               public void actionPerformed(ActionEvent aE) {
  169                   updateCvsAccessFields((CvsAccess) mCvsLocations.getSelectedItem());
  170               }
  171           });
  172           JPanel options = new JPanel();
  173           options.add(mSshServer);
  174           
  175   
  176           /* construct cvs tabb pane */
  177           if (mCvsLocations.getItemCount() > 0) {
  178               updateCvsAccessFields((CvsAccess) mCvsLocations.getSelectedItem());
  179               contentPanel.add(Main.getGuiControl().createLabel(Messages.getString(Text.PICK_KNOWN_REPOSITORY)));
  180               contentPanel.add(mCvsLocations);
  181           }
  182           contentPanel.add(Main.getGuiControl().createLabel(Messages.getString(Text.PROJECT_NAME)));
  183           contentPanel.add(mCvsAccessName);
  184           contentPanel.add(Main.getGuiControl().createLabel(Messages.getString(Text.PASSWORD)));
  185           contentPanel.add(mPassword);
  186           contentPanel.add(
  187               Main.getGuiControl().createLabel(Messages.getString(Text.REPOSITORY_PATH)));
  188           contentPanel.add(mCvsAccessRepositoryPath);
  189           contentPanel.add(Main.getGuiControl().createLabel(Messages.getString(Text.MODULE_NAME)));
  190           contentPanel.add(mCvsAccessModuleName);
  191           contentPanel.add(
  192               Main.getGuiControl().createLabel(Messages.getString(Text.OPTIONS)));
  193           contentPanel.add(options);
  194           mCvsTabPane.add(getFiller(FILLER_WIDTH, FILLER_HEIGHT), BorderLayout.WEST);
  195           mCvsTabPane.add(getFiller(FILLER_WIDTH, FILLER_HEIGHT), BorderLayout.EAST);
  196           mCvsTabPane.add(contentPanel, BorderLayout.CENTER);
  197           return mCvsTabPane;
  198   
  199       }
  200   
  201       /**
  202        * @return
  203        */
  204       private JPanel initCvsLogFilePanel() {
  205           /* init cvs local file pane */
  206           mCvsLogFilePane.setLayout(new BorderLayout());
  207           JPanel contentPanel = new JPanel();
  208           contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
  209           JButton chooseFile = new JButton(Messages.getString(Text.CHOOSE_FILE));
  210           chooseFile.addActionListener(new ActionListener() {
  211               /**
  212                * @see java.awt.event.ActionListener#actionPerformed( ActionEvent )
  213                */
  214               public void actionPerformed(ActionEvent aE) {
  215                   Main.getGuiControl().processUselessEvent(aE);
  216                   JFileChooser chooser = new JFileChooser();
  217                   int returnVal = chooser.showOpenDialog(mCvsLogFilePane);
  218                   if (returnVal == JFileChooser.APPROVE_OPTION) {
  219                       mCvsLocalFileName.setText(chooser.getSelectedFile().getAbsolutePath());
  220                   }
  221   
  222               }
  223           });
  224           /* construct cvs local file log pange*/
  225           contentPanel.add(getFiller(FILLER_HEIGHT, FILLER_WIDTH));
  226           contentPanel.add(Main.getGuiControl().createLabel(Messages.getString(Text.NAME)));
  227           contentPanel.add(mCvsLocalFileAccessName);
  228           contentPanel.add(
  229               Main.getGuiControl().createLabel(Messages.getString(Text.LOGFILE_LOCATION)));
  230           contentPanel.add(mCvsLocalFileName);
  231           contentPanel.add(chooseFile);
  232           contentPanel.add(getFiller(FILLER_HEIGHT, FILLER_WIDTH));
  233           mCvsLogFilePane.add(
  234               Main.getGuiControl().createLabel(Messages.getString(Text.LOAD_FROM_LOGFILE)),
  235               BorderLayout.NORTH);
  236           mCvsLogFilePane.add(getFiller(FILLER_HEIGHT, FILLER_WIDTH), BorderLayout.EAST);
  237           mCvsLogFilePane.add(getFiller(FILLER_HEIGHT, FILLER_WIDTH), BorderLayout.WEST);
  238           mCvsLogFilePane.add(contentPanel, BorderLayout.CENTER);
  239   
  240           return mCvsLogFilePane;
  241       }
  242   
  243       /**
  244        * @return
  245        */
  246       private JPanel initDatabasePanel() {
  247           /* init database panel */
  248           JPanel panel = new JPanel();
  249           panel.setLayout(new FlowLayout());
  250           JButton specifyDatabaseButton = new JButton(Messages.getString(Text.ADD_NEW));
  251           specifyDatabaseButton.addActionListener(new java.awt.event.ActionListener() {
  252               public void actionPerformed(ActionEvent aE) {
  253                   addDatabaseActionPerformed(aE);
  254               }
  255           });
  256   
  257           for (int i = 0; i < Bloof.getDbAccessMethods().length; i++) {
  258               mDatabaseCombo.addItem(Bloof.getDbAccessMethods()[i]);
  259           }
  260           /* construct database panel */
  261           panel.add(Main.getGuiControl().createLabel("Choose a database"));
  262           panel.add(mDatabaseCombo);
  263           panel.add(specifyDatabaseButton);
  264           return panel;
  265       }
  266   
  267       private void initDialog() throws Exception {
  268           /*
  269            * Create components
  270            * 
  271            * */
  272           mCvsTabPane = initCvsAccessPanel();
  273           mCvsLogFilePane = initCvsLogFilePanel();
  274           mSamplePane = initSamplePanel();
  275           JPanel databasePanel = initDatabasePanel();
  276           JPanel buttonsPanel = initButtonsPanel();
  277           /*
  278            * Connect components
  279            * 
  280            * */
  281   
  282           /* root components */
  283           mRootPanel.setLayout(new BorderLayout());
  284           JPanel southPanel = new JPanel();
  285           southPanel.setLayout(new BoxLayout(southPanel, BoxLayout.Y_AXIS));
  286           /* tabb */
  287           mTabbMaster.add(mCvsTabPane, "CVS");
  288           mTabbMaster.add(mSamplePane, "Examples");
  289           mTabbMaster.add(mCvsLogFilePane, "CVS log file");
  290           /* buttons and database */
  291           southPanel.add(databasePanel);
  292           southPanel.add(buttonsPanel);
  293           /* construct root pane */
  294           getContentPane().add(mRootPanel);
  295           mRootPanel.add(mTabbMaster, BorderLayout.CENTER);
  296           mRootPanel.add(southPanel, BorderLayout.SOUTH);
  297       }
  298   
  299       /**
  300        * @return
  301        */
  302       private JPanel initSamplePanel() {
  303           /* init cvs sample pane*/
  304           mSamplePane.setLayout(new BoxLayout(mSamplePane, BoxLayout.Y_AXIS));
  305           JPanel cvsSampleBoxPane = new JPanel();
  306           for (int s = 0; s < CvsPlugin.getSamples().length; s++) {
  307               mCvsSampleChooser.addItem(CvsPlugin.getSamples()[s]);
  308           }
  309           cvsSampleBoxPane.add(mCvsSampleChooser);
  310           /* construct cvs sample tabb pane */
  311           mSamplePane.add(
  312               Main.getGuiControl().createLabel(Messages.getString(Text.CHOOSE_ONE_SAMPLE)));
  313           mSamplePane.add(cvsSampleBoxPane);
  314           return mSamplePane;
  315       }
  316   
  317       private void updateCvsAccessFields(CvsAccess aCvsAccess) {
  318           mCvsAccessRepositoryPath.setText(aCvsAccess.getCvsRoot());
  319           mCvsAccessName.setText(aCvsAccess.getName());
  320           mCvsAccessModuleName.setText(aCvsAccess.getModuleName());
  321           if (aCvsAccess.getConnectionMethod() == CvsConnectionMethod.SSH) {
  322               mSshServer.setSelected(true);
  323           } else {
  324               mSshServer.setSelected(false);
  325           }
  326       }
  327       private void okButtonActionPerformed(ActionEvent aE) {
  328           Main.getGuiControl().processUselessEvent(aE);
  329           mScmAccess = null;
  330           if (mTabbMaster.getSelectedComponent() == mCvsTabPane) {
  331               try {
  332                   RepositoryLocation rl = new RepositoryLocation(mCvsAccessRepositoryPath.getText());
  333                   if (mSshServer.isSelected()) {
  334                       rl.setConnectionMethod(CvsConnectionMethod.SSH); 
  335                   }
  336                   mScmAccess =
  337                       new CvsAccess(
  338                           rl,
  339                           new LoginDetails(rl.getUserName(), new String(mPassword.getPassword())),
  340                           mCvsAccessModuleName.getText(),
  341                           mCvsAccessName.getText());
  342               } catch (InvalidRepositoryLocationException e) {
  343                   e.printStackTrace();
  344                   return;
  345               }
  346           } else if (mTabbMaster.getSelectedComponent() == mSamplePane) {
  347               mScmAccess = (CvsAccess) mCvsSampleChooser.getSelectedItem();
  348           } else if (mTabbMaster.getSelectedComponent() == mCvsLogFilePane) {
  349               File f = new File(mCvsLocalFileName.getText());
  350               if (!f.exists()) {
  351                   JOptionPane.showMessageDialog(
  352                       null,
  353                       "File does not exist." + f.getAbsolutePath(),
  354                       "Error occured",
  355                       JOptionPane.ERROR_MESSAGE);
  356   
  357                   return;
  358               }
  359               try {
  360                   mScmAccess =
  361                       new CvsAccess(
  362                           new RepositoryLocation(
  363                               CvsConnectionMethod.LOGFILE,
  364                               "nouser",
  365                               "nohost",
  366                               "nomodule"),
  367                           mCvsLocalFileName.getText(),
  368                           mCvsLocalFileAccessName.getText());
  369               } catch (InvalidRepositoryLocationException e) {
  370                   e.printStackTrace();
  371                   return;
  372               }
  373   
  374           } else {
  375               mScmAccess = null;
  376           }
  377           mDbAccess = (DbAccess) mDatabaseCombo.getSelectedItem();
  378           this.dispose();
  379       }
  380       private static final int FILLER_WIDTH = 40, FILLER_HEIGHT = 40;
  381       private JButton mCancelButton = new JButton(), mOkButton = new JButton();
  382       private JTextField mCvsAccessName = new JTextField(),
  383           mCvsAccessRepositoryPath = new JTextField(),
  384           mCvsLocalFileName = new JTextField(),
  385           mCvsLocalFileAccessName = new JTextField(),
  386           mCvsAccessModuleName = new JTextField();
  387       private JComboBox mCvsLocations = new JComboBox(),
  388           mCvsSampleChooser = new JComboBox(),
  389           mDatabaseCombo = new JComboBox();
  390       private JPanel mCvsLogFilePane = new JPanel(),
  391           mCvsTabPane,
  392           mRootPanel = new JPanel(),
  393           mSamplePane = new JPanel();
  394       private DbAccess mDbAccess;
  395       private JPasswordField mPassword = new JPasswordField("");
  396       private ScmAccess mScmAccess;
  397       private JTabbedPane mTabbMaster = new JTabbedPane();
  398       private JCheckBox mSshServer = new JCheckBox(Messages.getString(Text.SSH_SERVER));
  399   }

Save This Page
Home » openjdk-7 » net » sf » bloof » browser » [javadoc | source]