core/com.nokia.carbide.bugreport/src/com/nokia/carbide/internal/bugreport/ui/wizards/NewBugReportWizard.java
author timkelly
Fri, 27 Mar 2009 10:47:09 -0500
changeset 17 71c0485f97c2
parent 2 d760517a8095
permissions -rw-r--r--
new image for CDK
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
cawthron
parents:
diff changeset
     1
/*
cawthron
parents:
diff changeset
     2
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
cawthron
parents:
diff changeset
     3
* All rights reserved.
cawthron
parents:
diff changeset
     4
* This component and the accompanying materials are made available
cawthron
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
cawthron
parents:
diff changeset
     6
* which accompanies this distribution, and is available
cawthron
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
cawthron
parents:
diff changeset
     8
*
cawthron
parents:
diff changeset
     9
* Initial Contributors:
cawthron
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
cawthron
parents:
diff changeset
    11
*
cawthron
parents:
diff changeset
    12
* Contributors:
cawthron
parents:
diff changeset
    13
*
cawthron
parents:
diff changeset
    14
* Description: 
cawthron
parents:
diff changeset
    15
*
cawthron
parents:
diff changeset
    16
*/
cawthron
parents:
diff changeset
    17
 
cawthron
parents:
diff changeset
    18
package com.nokia.carbide.internal.bugreport.ui.wizards;
cawthron
parents:
diff changeset
    19
cawthron
parents:
diff changeset
    20
import org.eclipse.jface.wizard.*;
cawthron
parents:
diff changeset
    21
import org.eclipse.jface.operation.IRunnableWithProgress;
cawthron
parents:
diff changeset
    22
import org.eclipse.core.runtime.*;
cawthron
parents:
diff changeset
    23
import com.nokia.carbide.internal.bugreport.export.IProduct;
cawthron
parents:
diff changeset
    24
import com.nokia.carbide.internal.bugreport.model.BugReportConsole;
cawthron
parents:
diff changeset
    25
import com.nokia.carbide.internal.bugreport.model.Communication;
cawthron
parents:
diff changeset
    26
import com.nokia.carbide.internal.bugreport.model.ConsoleLine;
cawthron
parents:
diff changeset
    27
import com.nokia.carbide.internal.bugreport.model.FieldsHandler;
cawthron
parents:
diff changeset
    28
import com.nokia.carbide.internal.bugreport.model.ProductHandler;
cawthron
parents:
diff changeset
    29
import com.nokia.carbide.internal.bugreport.resources.*;
cawthron
parents:
diff changeset
    30
cawthron
parents:
diff changeset
    31
import java.util.*;
cawthron
parents:
diff changeset
    32
import org.eclipse.jface.dialogs.MessageDialog;
cawthron
parents:
diff changeset
    33
import org.eclipse.jface.resource.ImageDescriptor;
cawthron
parents:
diff changeset
    34
cawthron
parents:
diff changeset
    35
/**
cawthron
parents:
diff changeset
    36
 * Bug_Report wizard
cawthron
parents:
diff changeset
    37
 *
cawthron
parents:
diff changeset
    38
 */
cawthron
parents:
diff changeset
    39
public class NewBugReportWizard extends Wizard implements IWizard {
cawthron
parents:
diff changeset
    40
cawthron
parents:
diff changeset
    41
	static private final ImageDescriptor bannerImgDescriptor = 
cawthron
parents:
diff changeset
    42
		ImageResourceManager.getImageDescriptor(ImageKeys.WIZARD_BANNER);
cawthron
parents:
diff changeset
    43
	
cawthron
parents:
diff changeset
    44
	ProductSelectionPage productPage;
cawthron
parents:
diff changeset
    45
	BugDescriptionPage bugPage;
cawthron
parents:
diff changeset
    46
	SummaryPage summaryPage;
cawthron
parents:
diff changeset
    47
	FieldsHandler fieldsHandler = null;
cawthron
parents:
diff changeset
    48
	ProductHandler productHandler = null;
cawthron
parents:
diff changeset
    49
	BugReportConsole console = null;
cawthron
parents:
diff changeset
    50
	
cawthron
parents:
diff changeset
    51
	
cawthron
parents:
diff changeset
    52
	public NewBugReportWizard() throws RuntimeException {
cawthron
parents:
diff changeset
    53
		setDefaultPageImageDescriptor(bannerImgDescriptor);
cawthron
parents:
diff changeset
    54
		productHandler = new ProductHandler();
cawthron
parents:
diff changeset
    55
		fieldsHandler = new FieldsHandler();
cawthron
parents:
diff changeset
    56
		console = new BugReportConsole();
cawthron
parents:
diff changeset
    57
	}
cawthron
parents:
diff changeset
    58
	
cawthron
parents:
diff changeset
    59
	@Override
cawthron
parents:
diff changeset
    60
	public boolean performFinish() {
cawthron
parents:
diff changeset
    61
		try {
cawthron
parents:
diff changeset
    62
			getContainer().run(true, true, new IRunnableWithProgress() {
cawthron
parents:
diff changeset
    63
		      public void run(IProgressMonitor monitor) {
cawthron
parents:
diff changeset
    64
		         monitor.beginTask(Messages.getString("NewBugReportWizard.SendingReport"), IProgressMonitor.UNKNOWN); //$NON-NLS-1$
cawthron
parents:
diff changeset
    65
		         String bugNumber = Communication.sendBugReport(fieldsHandler.getFieldsForSending(), productHandler.getProduct());
cawthron
parents:
diff changeset
    66
		         ConsoleLine line = new ConsoleLine(productHandler.getProduct(), bugNumber);
cawthron
parents:
diff changeset
    67
		         console.addLineToConsole(line);
cawthron
parents:
diff changeset
    68
		         
cawthron
parents:
diff changeset
    69
		         monitor.done();
cawthron
parents:
diff changeset
    70
		      }
cawthron
parents:
diff changeset
    71
		   });
cawthron
parents:
diff changeset
    72
		} catch (Exception e) {
cawthron
parents:
diff changeset
    73
			e.printStackTrace();
cawthron
parents:
diff changeset
    74
			MessageDialog.openError(this.getShell(), Messages.getString("NewBugReportWizard.BugReporting"), e.getCause().getLocalizedMessage()); //$NON-NLS-1$
cawthron
parents:
diff changeset
    75
			return false;
cawthron
parents:
diff changeset
    76
		}
cawthron
parents:
diff changeset
    77
cawthron
parents:
diff changeset
    78
		return true;
cawthron
parents:
diff changeset
    79
	}
cawthron
parents:
diff changeset
    80
	
cawthron
parents:
diff changeset
    81
	@Override
cawthron
parents:
diff changeset
    82
	public void addPages() {
cawthron
parents:
diff changeset
    83
		
cawthron
parents:
diff changeset
    84
		// product is not initialized if there were multiple product plugins.
cawthron
parents:
diff changeset
    85
		// in this case add a product selection page.
cawthron
parents:
diff changeset
    86
		if (productHandler.getProduct() == null) {
cawthron
parents:
diff changeset
    87
			productPage = new ProductSelectionPage(productHandler.getProducts());
cawthron
parents:
diff changeset
    88
			addPage(productPage);
cawthron
parents:
diff changeset
    89
		}
cawthron
parents:
diff changeset
    90
		
cawthron
parents:
diff changeset
    91
		bugPage = new BugDescriptionPage();
cawthron
parents:
diff changeset
    92
		addPage(bugPage);
cawthron
parents:
diff changeset
    93
		bugPage.setProduct(productHandler.getProduct());
cawthron
parents:
diff changeset
    94
		
cawthron
parents:
diff changeset
    95
		summaryPage = new SummaryPage();
cawthron
parents:
diff changeset
    96
		addPage(summaryPage);
cawthron
parents:
diff changeset
    97
		
cawthron
parents:
diff changeset
    98
		setWindowTitle(Messages.getString("NewBugReportWizard.BugReporting")); //$NON-NLS-1$
cawthron
parents:
diff changeset
    99
	}
cawthron
parents:
diff changeset
   100
cawthron
parents:
diff changeset
   101
	@Override
cawthron
parents:
diff changeset
   102
	public IWizardPage getNextPage(IWizardPage page) {
cawthron
parents:
diff changeset
   103
		
cawthron
parents:
diff changeset
   104
		// if there was a product selection page (because of multiple product plugins)
cawthron
parents:
diff changeset
   105
		// get the selected product and give it to bugPage. Return bugPage for showing.
cawthron
parents:
diff changeset
   106
		if (page == productPage) {
cawthron
parents:
diff changeset
   107
			IProduct product = productPage.getProduct();
cawthron
parents:
diff changeset
   108
			if (product == null) {
cawthron
parents:
diff changeset
   109
				throw new RuntimeException(Messages.getString("NewBugReportWizard.CouldNotInitializeProduct")); //$NON-NLS-1$
cawthron
parents:
diff changeset
   110
			}
cawthron
parents:
diff changeset
   111
			productHandler.setProduct(product);
cawthron
parents:
diff changeset
   112
			bugPage.setProduct(product);
cawthron
parents:
diff changeset
   113
			return bugPage;
cawthron
parents:
diff changeset
   114
		// Changing from bug_page to summary page.
cawthron
parents:
diff changeset
   115
		} else if (page == bugPage) {
cawthron
parents:
diff changeset
   116
			if (bugPage.canChangePage()) {
cawthron
parents:
diff changeset
   117
				Hashtable<String, String> fields = bugPage.getFields();
cawthron
parents:
diff changeset
   118
				fieldsHandler.prepareFinalFields(fields, productHandler.getProduct());
cawthron
parents:
diff changeset
   119
				summaryPage.setSummaryText(fieldsHandler.getSummary());
cawthron
parents:
diff changeset
   120
				return summaryPage;
cawthron
parents:
diff changeset
   121
			}
cawthron
parents:
diff changeset
   122
		}
cawthron
parents:
diff changeset
   123
		return null;
cawthron
parents:
diff changeset
   124
	}		
cawthron
parents:
diff changeset
   125
	
cawthron
parents:
diff changeset
   126
	@Override
cawthron
parents:
diff changeset
   127
	public boolean canFinish() {
cawthron
parents:
diff changeset
   128
		if (getContainer().getCurrentPage() == summaryPage)
cawthron
parents:
diff changeset
   129
			return true;
cawthron
parents:
diff changeset
   130
		
cawthron
parents:
diff changeset
   131
		return false;
cawthron
parents:
diff changeset
   132
	}
cawthron
parents:
diff changeset
   133
	
cawthron
parents:
diff changeset
   134
	@Override
cawthron
parents:
diff changeset
   135
	public boolean needsProgressMonitor() {
cawthron
parents:
diff changeset
   136
		return true;
cawthron
parents:
diff changeset
   137
	}
cawthron
parents:
diff changeset
   138
	
cawthron
parents:
diff changeset
   139
}