/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * Updater.java * * Created on Nov 18, 2010, 4:55:15 PM */ package br.uff.ourico.update.gui; import br.uff.ic.oceano.core.exception.ServiceException; import br.uff.ic.oceano.ourico.rcs.context.Constants; import br.uff.ic.oceano.ourico.update.OuricoUpdate; import java.io.File; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import org.tmatesoft.svn.core.SVNException; /** * * @author marapao */ public class Updater extends javax.swing.JFrame { /** Creates new form Updater */ public Updater() { initComponents(); } /** 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() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); tfLogin = new javax.swing.JTextField(); tfPassword = new javax.swing.JPasswordField(); jPanel2 = new javax.swing.JPanel(); jLabel3 = new javax.swing.JLabel(); tfWorkspaceParh = new javax.swing.JTextField(); btnSearch = new javax.swing.JButton(); btnUpdate = new javax.swing.JButton(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenu2 = new javax.swing.JMenu(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("SVN Data")); jLabel1.setText("Login"); jLabel2.setText("Password"); tfLogin.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { tfLoginActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addGap(38, 38, 38) .addComponent(tfLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(24, 24, 24) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(tfPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE) .addContainerGap()) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(tfLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2) .addComponent(tfPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Local data")); jLabel3.setText("Workspace Path"); btnSearch.setText("Search"); btnSearch.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSearchActionPerformed(evt); } }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(tfWorkspaceParh, javax.swing.GroupLayout.PREFERRED_SIZE, 355, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btnSearch, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE) .addContainerGap()) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(tfWorkspaceParh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnSearch)) .addContainerGap(25, Short.MAX_VALUE)) ); btnUpdate.setText("Update"); btnUpdate.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnUpdateActionPerformed(evt); } }); jMenu1.setText("File"); jMenuBar1.add(jMenu1); jMenu2.setText("Edit"); jMenuBar1.add(jMenu2); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGroup(layout.createSequentialGroup() .addGap(281, 281, 281) .addComponent(btnUpdate))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE) .addComponent(btnUpdate) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void tfLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfLoginActionPerformed // TODO add your handling code here: }//GEN-LAST:event_tfLoginActionPerformed private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed // TODO add your handling code here: File currentWorkspace = null; JFileChooser caminho = null; if(tfWorkspaceParh.getText() != null){ currentWorkspace = new File(tfWorkspaceParh.getText()); if(currentWorkspace.isDirectory()){ caminho = new JFileChooser(currentWorkspace); } else caminho = new JFileChooser(); } caminho.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (caminho.showOpenDialog(this) == javax.swing.JFileChooser.APPROVE_OPTION) { if (caminho.getSelectedFile() != null) { tfWorkspaceParh.setText(caminho.getSelectedFile().toString()); } else { tfWorkspaceParh.setText("Diretório não selecionado"); } } }//GEN-LAST:event_btnSearchActionPerformed private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateActionPerformed // TODO add your handling code here: OuricoUpdate ouricoUpdate = new OuricoUpdate(); String urlOceano = Constants.URL_OCEANO; try { ouricoUpdate.update(tfWorkspaceParh.getText(), tfLogin.getText(), tfPassword.getText(), urlOceano); } catch (ServiceException ex) { JOptionPane.showMessageDialog(rootPane, "Verificar se o servidor do oceano esta funcionando.", "Service exception", JOptionPane.ERROR_MESSAGE); Logger.getLogger(Updater.class.getName()).log(Level.SEVERE, null, ex); return; } catch (SVNException ex) { JOptionPane.showMessageDialog(rootPane, "Verificar login e senha.", "SVN exception", JOptionPane.ERROR_MESSAGE); Logger.getLogger(Updater.class.getName()).log(Level.SEVERE, null, ex); return; } JOptionPane.showMessageDialog(rootPane, "Update realizado com sucesso.", "Update concluido", JOptionPane.INFORMATION_MESSAGE); }//GEN-LAST:event_btnUpdateActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Updater().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnSearch; private javax.swing.JButton btnUpdate; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JTextField tfLogin; private javax.swing.JPasswordField tfPassword; private javax.swing.JTextField tfWorkspaceParh; // End of variables declaration//GEN-END:variables }