00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "codegenerationwizard.h"
00022
00023
00024 #include <qdir.h>
00025 #include <qlistview.h>
00026 #include <qfileinfo.h>
00027 #include <qapplication.h>
00028 #include <kdebug.h>
00029 #include <klocale.h>
00030 #include <kmessagebox.h>
00031
00032
00033 #include "codegenerationoptionspage.h"
00034 #include "../classifier.h"
00035 #include "../codegenerator.h"
00036 #include "../uml.h"
00037 #include "../umldoc.h"
00038
00039
00040 CodeGenerationWizard::CodeGenerationWizard(UMLClassifierList *classList)
00041 : CodeGenerationWizardBase((QWidget*)UMLApp::app()) {
00042 m_doc = UMLApp::app()->getDocument();
00043 m_app = UMLApp::app();
00044 m_availableList -> setAllColumnsShowFocus(true);
00045 m_availableList -> setResizeMode(QListView::AllColumns);
00046 m_selectedList -> setAllColumnsShowFocus(true);
00047 m_selectedList -> setResizeMode(QListView::AllColumns);
00048 m_statusList -> setAllColumnsShowFocus(true);
00049 m_statusList -> setResizeMode(QListView::AllColumns);
00050
00051 m_CodeGenerationOptionsPage = new CodeGenerationOptionsPage(this);
00052 connect( m_CodeGenerationOptionsPage, SIGNAL(languageChanged()), this, SLOT(changeLanguage()) );
00053
00054 insertPage(m_CodeGenerationOptionsPage, i18n("Code Generation Options"), 1);
00055
00056 UMLClassifierList cList;
00057
00058 if (classList == NULL) {
00059 cList = m_doc->getClassesAndInterfaces();
00060 classList = &cList;
00061 }
00062 for (UMLClassifier *c = classList->first(); c ; c = classList->next()) {
00063 new QListViewItem( m_selectedList, c->getFullyQualifiedName());
00064 }
00065
00066 setNextEnabled(page(0),m_selectedList->childCount() > 0);
00067
00068 setFinishEnabled(page(2),true);
00069 finishButton()->disconnect();
00070 finishButton()->setText(i18n("&Generate"));
00071 connect(finishButton(),SIGNAL(clicked()),this,SLOT(generateCode()));
00072 if ( QApplication::reverseLayout() )
00073 {
00074 QPixmap tmpPixmap( *m_addButton->pixmap() );
00075 m_addButton->setPixmap(*m_removeButton->pixmap());
00076 m_removeButton->setPixmap(tmpPixmap);
00077 }
00078 }
00079
00080 CodeGenerationWizard::~CodeGenerationWizard() {}
00081
00082
00083 void CodeGenerationWizard::selectClass() {
00084 moveSelectedItems(m_availableList, m_selectedList);
00085
00086 if (m_selectedList->childCount() > 0) {
00087 setNextEnabled(currentPage(), true);
00088 }
00089 }
00090
00091 void CodeGenerationWizard::deselectClass() {
00092 moveSelectedItems(m_selectedList, m_availableList);
00093
00094 if (m_selectedList->childCount() == 0) {
00095 setNextEnabled(currentPage(), false);
00096 }
00097 }
00098
00099 void CodeGenerationWizard::generateCode() {
00100 backButton()->setEnabled(false);
00101
00102 CodeGenerator* codeGenerator = m_app->getGenerator();
00103
00104 if (codeGenerator) {
00105
00106 cancelButton()->setEnabled(false);
00107
00108 connect( codeGenerator, SIGNAL(codeGenerated(UMLClassifier*, bool)),
00109 this, SLOT(classGenerated(UMLClassifier*, bool)) );
00110
00111 UMLClassifierList cList;
00112 cList.setAutoDelete(false);
00113
00114 for(QListViewItem *item = m_statusList->firstChild(); item;
00115 item = item-> nextSibling()) {
00116 UMLClassifier *concept = m_doc->findUMLClassifier(item->text(0));
00117 cList.append(concept);
00118 }
00119 codeGenerator->writeCodeToFile(cList);
00120 finishButton()->setText(i18n("Finish"));
00121 finishButton()->disconnect();
00122 connect(finishButton(),SIGNAL(clicked()),this,SLOT(accept()));
00123
00124 }
00125 }
00126
00127 void CodeGenerationWizard::classGenerated(UMLClassifier* concept, bool generated) {
00128 QListViewItem* item = m_statusList->findItem( concept->getFullyQualifiedName(), 0 );
00129 if( !item ) {
00130 kError()<<"GenerationStatusPage::Error finding class in list view"<<endl;
00131 } else if (generated) {
00132 item->setText( 1, i18n("Code Generated") );
00133 } else {
00134 item->setText( 1, i18n("Not Generated") );
00135 }
00136 }
00137
00138 void CodeGenerationWizard::populateStatusList() {
00139 m_statusList->clear();
00140 for(QListViewItem* item = m_selectedList->firstChild(); item; item = item->nextSibling()) {
00141 new QListViewItem(m_statusList,item->text(0),i18n("Not Yet Generated"));
00142 }
00143 }
00144
00145 void CodeGenerationWizard::showPage(QWidget *page) {
00146 if (indexOf(page) == 2)
00147 {
00148
00149 ((CodeGenerationOptionsPage*)QWizard::page(1))->apply();
00150
00151
00152
00153
00154
00155 CodeGenerationPolicy *policy = UMLApp::app()->getCommonPolicy();
00156
00157
00158 QFileInfo info(policy->getOutputDirectory().absPath());
00159 if(!info.exists())
00160 {
00161 if (KMessageBox::questionYesNo(this,
00162 i18n("The folder %1 does not exist. Do you want to create it now?").arg(info.filePath()),
00163 i18n("Output Folder Does Not Exist"), i18n("Create Folder"), i18n("Do Not Create")) == KMessageBox::Yes)
00164 {
00165 QDir dir;
00166 if(!dir.mkdir(info.filePath()))
00167 {
00168 KMessageBox::sorry(this,i18n("The folder could not be created.\nPlease make sure you have write access to its parent folder or select another, valid, folder."),
00169 i18n("Error Creating Folder"));
00170 return;
00171 }
00172
00173 }
00174 else
00175 {
00176 KMessageBox::information(this,i18n("Please select a valid folder."),
00177 i18n("Output Folder Does Not Exist"));
00178 return;
00179 }
00180 } else {
00181
00182 if(!info.isWritable())
00183 {
00184 KMessageBox::sorry(this,i18n("The output folder exists, but it is not writable.\nPlease set the appropriate permissions or choose another folder."),
00185 i18n("Error Writing to Output Folder"));
00186 return;
00187 }
00188
00189 if(!info.isDir())
00190 {
00191 KMessageBox::sorry(this,i18n("%1 does not seem to be a folder. Please choose a valid folder.").arg(info.filePath()),
00192 i18n("Please Choose Valid Folder"));
00193 return;
00194 }
00195 }
00196 }
00197 populateStatusList();
00198 QWizard::showPage(page);
00199 }
00200
00201 CodeGenerator* CodeGenerationWizard::generator() {
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 return (CodeGenerator*) NULL;
00227 }
00228
00229 void CodeGenerationWizard::moveSelectedItems(QListView* fromList, QListView* toList) {
00230 QListViewItemIterator it(fromList, QListViewItemIterator::Selected);
00231 while (it.current()) {
00232 QListViewItem* selectedItem = it.current();
00233
00234 QString name = selectedItem->text(0);
00235 if (!toList->findItem(name, 0)) {
00236 new QListViewItem(toList, name);
00237 }
00238
00239 ++it;
00240
00241
00242
00243 fromList->removeItem(selectedItem);
00244 }
00245 }
00246
00247
00248
00249 void CodeGenerationWizard::changeLanguage()
00250 {
00251 m_app->setActiveLanguage( m_CodeGenerationOptionsPage->getCodeGenerationLanguage() );
00252
00253
00254
00255 m_CodeGenerationOptionsPage->apply();
00256 }
00257
00258 #include "codegenerationwizard.moc"