Main Page | Packages | Class Hierarchy | Class List | File List | Class Members

ArgoPrintJDialog.java

Go to the documentation of this file.
00001 //$Id: ArgoPrintJDialog_8java-source.html 336 2010-01-12 20:03:17Z linus $
00002 //Copyright (c) 2003, Mikael Albertsson, Mattias Danielsson, Per Engström, 
00003 //Fredrik Gröndahl, Martin Gyllensten, Anna Kent, Anders Olsson, 
00004 //Mattias Sidebäck.
00005 //All rights reserved.
00006 //
00007 //Redistribution and use in source and binary forms, with or without 
00008 //modification, are permitted provided that the following conditions are met:
00009 //
00010 //* Redistributions of source code must retain the above copyright notice, 
00011 //  this list of conditions and the following disclaimer.
00012 // 
00013 //* Redistributions in binary form must reproduce the above copyright 
00014 //  notice, this list of conditions and the following disclaimer in the 
00015 //  documentation and/or other materials provided with the distribution.
00016 //
00017 //* Neither the name of the University of Linköping nor the names of its 
00018 //  contributors may be used to endorse or promote products derived from 
00019 //  this software without specific prior written permission. 
00020 //
00021 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00022 //AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00023 //IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00024 //ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
00025 //LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00026 //CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00027 //SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00028 //INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00029 //CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00030 //ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
00031 //THE POSSIBILITY OF SUCH DAMAGE.
00032 
00033 package org.argoprint.ui;
00034 
00035 /*
00036  * ArgoPrintJDialog.java
00037  *
00038  * Created on den 17 november 2003, 14:38
00039  */
00040 
00041 import org.argoprint.uml_interface.*;
00042 import org.argoprint.engine.*;
00043 
00044 import org.argouml.kernel.Project;
00045 import org.argouml.kernel.ProjectManager;
00046 import org.argouml.ui.ProjectBrowser;
00047 
00048 import org.argouml.model.ModelFacade;
00049 
00050 import java.awt.*;
00051 import java.awt.event.*;
00052 
00053 import java.lang.*;
00054 
00055 import java.util.*;
00056 
00057 import org.apache.log4j.Logger;
00058 
00059 import javax.swing.*;
00060 import javax.swing.filechooser.*;
00061 import java.awt.*;
00062 
00063 /**
00064  *
00065  * @author  Martin Gyllensten, Per Engstrom
00066  */
00067 public class ArgoPrintJDialog extends javax.swing.JDialog {
00068 
00069     private Logger log;
00070     
00071     /**
00072      * Sets the logger (log) to logger
00073      *
00074      * @param logger a Logger
00075      */
00076     public void setLog(Logger logger){ log = logger; }
00077     
00078     /**
00079      * Creates new form JDialog
00080      *
00081      * @param parent The parent of the ArgoPrint gui (should be ArgoUML's gui).
00082      * @param modal not user (hardcoded to true).
00083      */
00084     public ArgoPrintJDialog(java.awt.Frame parent, boolean modal) {
00085         super(parent, true);
00086         initComponents();
00087     }
00088     
00089     /** This method is called from within the constructor to
00090      * initialize the form.
00091      * 
00092      */
00093     private void initComponents() {
00094     jUIPanel = new javax.swing.JPanel();
00095     jButtonPanel = new javax.swing.JPanel();
00096         jTemplateLabel = new javax.swing.JLabel();
00097         jTemplateTextField = new javax.swing.JTextField();
00098         jTemplateBrowseButton = new javax.swing.JButton();
00099         jOutputFileLabel = new javax.swing.JLabel();
00100         jOutputFileTextField = new javax.swing.JTextField();
00101         jOutputFileBrowseButton = new javax.swing.JButton();
00102         jOutputDirLabel = new javax.swing.JLabel();
00103         jOutputDirTextField = new javax.swing.JTextField();
00104         jOutputDirBrowseButton = new javax.swing.JButton();
00105 //      jLabel4 = new javax.swing.JLabel();
00106         jGenerateButton = new javax.swing.JButton();
00107         jCancelButton = new javax.swing.JButton();
00108 
00109     /** Dialog config */
00110         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
00111         setTitle("ArgoPrint");
00112         addWindowListener(new java.awt.event.WindowAdapter() {
00113             public void windowClosing(java.awt.event.WindowEvent evt) {
00114                 closeDialog(evt);
00115             }
00116         });
00117 
00118     BorderLayout bl = new BorderLayout();
00119     getContentPane().setLayout( bl );
00120 
00121 
00122     getContentPane().add( jUIPanel );
00123     getContentPane().add( jButtonPanel, bl.SOUTH );
00124 
00125 
00126     /** Init UI Panel */
00127     GridLayout gl = new GridLayout( 3, 3 );
00128     jUIPanel.setLayout( gl );
00129 
00130         jTemplateLabel.setText("Template file:");
00131     
00132         jUIPanel.add(jTemplateLabel);
00133 
00134         jTemplateTextField.setText("myTemplate.xml");
00135     
00136         jUIPanel.add(jTemplateTextField);
00137 
00138         jTemplateBrowseButton.setText("Browse");
00139         jTemplateBrowseButton.addActionListener(new java.awt.event.ActionListener() {
00140             public void actionPerformed(java.awt.event.ActionEvent evt) {
00141                 jTemplateBrowseButtonActionPerformed(evt);
00142             }
00143         });
00144 
00145     jUIPanel.add(jTemplateBrowseButton);
00146         jOutputFileLabel.setText("Output file:");
00147         jUIPanel.add(jOutputFileLabel);
00148         jOutputFileTextField.setText("myOutput.xml");
00149     
00150         jUIPanel.add(jOutputFileTextField);
00151 
00152         jOutputFileBrowseButton.setText("Browse");
00153         jOutputFileBrowseButton.addActionListener(new java.awt.event.ActionListener() {
00154             public void actionPerformed(java.awt.event.ActionEvent evt) {
00155                 jOutputFileBrowseButtonActionPerformed(evt);
00156             }
00157         });
00158 
00159     jUIPanel.add(jOutputFileBrowseButton);
00160 
00161 
00162 
00163         jOutputDirLabel.setText("Data storage directory:");
00164     
00165         jUIPanel.add(jOutputDirLabel);
00166 
00167         jOutputDirTextField.setText("myDataDirectory");
00168 
00169         jUIPanel.add(jOutputDirTextField);
00170 
00171         jOutputDirBrowseButton.setText("Browse");
00172         jOutputDirBrowseButton.addActionListener(new java.awt.event.ActionListener() {
00173             public void actionPerformed(java.awt.event.ActionEvent evt) {
00174                 jOutputDirBrowseButtonActionPerformed(evt);
00175             }
00176         });
00177     
00178         jUIPanel.add(jOutputDirBrowseButton);
00179 
00180         jGenerateButton.setText("Generate");
00181         jGenerateButton.addActionListener(new java.awt.event.ActionListener() {
00182             public void actionPerformed(java.awt.event.ActionEvent evt) {
00183                 jGenerateButtonActionPerformed(evt);
00184             }
00185         });
00186 
00187     jButtonPanel.add(jGenerateButton);
00188 
00189 
00190         jCancelButton.setText("Cancel");
00191         jCancelButton.addActionListener(new java.awt.event.ActionListener() {
00192             public void actionPerformed(java.awt.event.ActionEvent evt) {
00193                 jCancelButtonActionPerformed(evt);
00194             }
00195         });
00196 
00197         jButtonPanel.add(jCancelButton);
00198 
00199 
00200         pack();
00201     }
00202 
00203     /**
00204      * Closes the dialog
00205      *
00206      * @param evt action event!!!
00207      */
00208     private void jCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
00209     setVisible( false );
00210         dispose();
00211     }
00212 
00213     /**
00214      * Open file browser
00215      *
00216      * @param evt action event!!!
00217      */
00218     private void jOutputDirBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {
00219 
00220         JFileChooser chooser = new JFileChooser();
00221         
00222         chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
00223         int returnVal = chooser.showOpenDialog( this );
00224         if(returnVal == JFileChooser.APPROVE_OPTION) {
00225                 jOutputDirTextField.setText( chooser.getSelectedFile().getPath() );
00226         }
00227     }
00228 
00229     /**
00230      * Open file browser
00231      *
00232      * @param evt action event!!!
00233      */
00234     private void jOutputFileBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {
00235         
00236         JFileChooser chooser = new JFileChooser();
00237         
00238         int returnVal = chooser.showOpenDialog( this );
00239         if(returnVal == JFileChooser.APPROVE_OPTION) {
00240                 jOutputFileTextField.setText( chooser.getSelectedFile().getPath() );
00241         }
00242     }
00243 
00244     /**
00245      * Open file browser
00246      *
00247      * @param evt action event!!!
00248      */
00249     private void jTemplateBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {
00250 
00251         JFileChooser chooser = new JFileChooser();
00252         
00253         int returnVal = chooser.showOpenDialog( this );
00254         if(returnVal == JFileChooser.APPROVE_OPTION) {
00255                 jTemplateTextField.setText(chooser.getSelectedFile().getPath() );
00256         }
00257 
00258     }
00259 
00260     /**
00261      * Executes a generation
00262      *
00263      * @param evt action event!!!
00264      */
00265     private void jGenerateButtonActionPerformed(java.awt.event.ActionEvent evt) {
00266     /******************************************************
00267          * This is where Engine is invoked!!!!!
00268          *
00269          * (Not in the comment ofcourse!)
00270          ******************************************************/
00271         
00272     UMLInterface umlIf = new UMLInterface();
00273     Environment env = new Environment();
00274 
00275     //setting argopprint for current project
00276     ProjectBrowser pb = ProjectBrowser.getInstance();
00277     Project p =  ProjectManager.getManager().getCurrentProject();
00278     
00279     umlIf.setLog(log);
00280     umlIf.setProject(p);
00281     umlIf.setProjectBrowser(pb);
00282     umlIf.setOutputDir( jOutputDirTextField.getText() );
00283     
00284     //testing "simulated" template
00285     Object args[] = new Object[1];
00286     args[0] = p.getModel();
00287     
00288     try{
00289         log.info("Test simulated template");
00290         Object response = 
00291         umlIf.caller(new String("getOwnedElements(model)"));      
00292 
00293         if(response instanceof Collection){     
00294         ArgoPrintIterator iter =
00295             new ArgoPrintIterator(((Collection) response).iterator());
00296         
00297         env.addIterator(new String("element"), iter);
00298         
00299         while(iter.hasNext()){
00300             
00301             Object element = iter.next();
00302             args[0] = element; 
00303 
00304 //              Object response2 = 
00305 //              umlIf.caller(new String("isAClass()"), element);   
00306                     
00307 //              if((response2 instanceof Boolean) && 
00308 //                 (((Boolean)response2).booleanValue())){
00309             
00310 //              log.info("Class name: " + 
00311 //                   ModelFacade.getFacade().getName(element));
00312             
00313 //              Object response3 = 
00314 //                  umlIf.caller(new String("getOperations()"), 
00315 //                       element);
00316             
00317 //              if(response3 instanceof Collection){
00318 //                  iter = 
00319 //                  new ArgoPrintIterator(((Collection) 
00320 //                                 response3).iterator());
00321                 
00322 //                  env.addIterator(new String("operation"), iter);
00323 //                  while(iter.hasNext()){
00324 //                  Object operation = iter.next();
00325 //                  log.info("operation name: "+ 
00326 //                       ModelFacade.getFacade().getName(operation));
00327 //                  }
00328                 
00329 //                  env.removeIterator(new String("operation"));
00330 //                  iter = env.getIterator(new String("element"));
00331 //              }
00332 //              } else{
00333             log.info("Element name: " + 
00334                  ModelFacade.getFacade().getName(element));
00335 //          }
00336         }
00337         env.removeIterator(new String("element"));
00338         }
00339         
00340         
00341     } catch(Exception e){
00342         log.info("Gui crash");
00343     }
00344     
00345     Settings settings = new Settings(jTemplateTextField.getText(),
00346                      jOutputFileTextField.getText(),
00347                      jOutputDirTextField.getText());
00348     
00349     Main main = new Main();
00350     try{
00351         main.initializeSystem(settings, log);
00352         main.go();
00353     }
00354     catch(Exception e){
00355         JOptionPane.showMessageDialog( this, e.getMessage());   
00356         e.printStackTrace();
00357         return;
00358     }
00359     
00360     JOptionPane.showMessageDialog( this, "Output generation complete!");
00361     }
00362 
00363     /**
00364      * Closes the dialog
00365      *
00366      * @param evt window event!!!
00367      */
00368     private void closeDialog(java.awt.event.WindowEvent evt) {
00369         setVisible(false);
00370         dispose();
00371     }
00372 
00373     /** main panel */
00374     private javax.swing.JPanel jUIPanel;
00375     /** the button panel */
00376     private javax.swing.JPanel jButtonPanel;
00377     /** browse directory button */
00378     private javax.swing.JButton jOutputDirBrowseButton;
00379     /** output file button */
00380     private javax.swing.JButton jOutputFileBrowseButton;
00381     /** template file button */
00382     private javax.swing.JButton jTemplateBrowseButton;
00383     /** generation executor */
00384     private javax.swing.JButton jGenerateButton;
00385     /** cancel button */
00386     private javax.swing.JButton jCancelButton;
00387     /** directory text field */
00388     private javax.swing.JTextField jOutputDirTextField;
00389     /** output text field */
00390     private javax.swing.JTextField jOutputFileTextField;
00391     /** template text field */
00392     private javax.swing.JTextField jTemplateTextField;
00393     /** THE PYGMY SHREW!!! */
00394 //  private javax.swing.JLabel jLabel4;
00395     /** output dir label */
00396     private javax.swing.JLabel jOutputDirLabel;
00397     /** output file label */
00398     private javax.swing.JLabel jOutputFileLabel;
00399     /** template label */
00400     private javax.swing.JLabel jTemplateLabel;
00401 }

Generated on Tue Dec 2 22:50:56 2003 for ArgoPrint by doxygen 1.3.4