debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/newwizard/UnifiedLaunchOptionsPage.java
author dadubrow
Mon, 15 Feb 2010 14:48:52 -0600
changeset 960 1b51db390dc4
parent 956 d1e221a2875f
child 969 b0dd389735fb
permissions -rw-r--r--
ui tweaks to new launch wizard
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     1
/*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     3
* All rights reserved.
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     4
* This component and the accompanying materials are made available
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     6
* which accompanies this distribution, and is available
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     8
*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     9
* Initial Contributors:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    11
*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    12
* Contributors:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    13
*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    14
* Description: 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    15
*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    16
*/
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    17
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    18
package com.nokia.cdt.internal.debug.launch.newwizard;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    19
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    20
import java.text.MessageFormat;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    21
import java.util.ArrayList;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    22
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    23
import org.eclipse.core.runtime.IStatus;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    24
import org.eclipse.core.runtime.Status;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    25
import org.eclipse.jface.layout.GridDataFactory;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    26
import org.eclipse.jface.layout.GridLayoutFactory;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    27
import org.eclipse.jface.wizard.WizardPage;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    28
import org.eclipse.swt.SWT;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    29
import org.eclipse.swt.widgets.Composite;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    30
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    31
import com.nokia.cdt.internal.debug.launch.LaunchPlugin;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    32
import com.nokia.cdt.internal.debug.launch.newwizard.IWizardSection.ISectionChangeListener;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    33
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    34
/**
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    35
 * This page presents three sections:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    36
 * <p>
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    37
 * Connection to use:  container for the Remote Connection selection UI, plus a label
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    38
 * explaining how to handle the case of no connections defined.
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    39
 * <p>
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    40
 * Debug process: section explaining how the launch will happen, with a combo
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    41
 * allowing selecting different process to launch, and a button allowing more
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    42
 * in-depth configuration.
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    43
 * <p>
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    44
 * Build before debug: section with the build-before-debug preference for this
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    45
 * launch configuration.
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    46
 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    47
public class UnifiedLaunchOptionsPage extends WizardPage implements ISectionChangeListener {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    48
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    49
	private final LaunchWizardData data;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    50
	private ArrayList<IWizardSection> sections;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    51
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    52
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    53
	/**
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    54
	 * @param mmps
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    55
	 * @param exes
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    56
	 * @param defaultExecutable
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    57
	 * @param project
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    58
	 * @param configurationName
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    59
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    60
	public UnifiedLaunchOptionsPage(LaunchWizardData data) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    61
		super("Configure Launch Settings");
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    62
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    63
		setDescription("Configure the connection and process to launch.");
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    64
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    65
		this.data = data;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    66
		this.sections = new ArrayList<IWizardSection>();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    67
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    68
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    69
		IWizardSection section;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    70
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    71
		section = new ConnectToDeviceSection(data, this);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    72
		sections.add(section);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    73
		
960
1b51db390dc4 ui tweaks to new launch wizard
dadubrow
parents: 956
diff changeset
    74
		section = new DebugRunProcessSection(data, this);
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    75
		sections.add(section);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    76
		
960
1b51db390dc4 ui tweaks to new launch wizard
dadubrow
parents: 956
diff changeset
    77
		section = new OtherSettingsSection(data, this);
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    78
		sections.add(section);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    79
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    80
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    81
	/* (non-Javadoc)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    82
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    83
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    84
	public void createControl(Composite parent) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    85
		Composite composite = new Composite(parent, SWT.NONE);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    86
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    87
		GridLayoutFactory.fillDefaults().applyTo(composite);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    88
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    89
		setPageComplete(false);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    90
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    91
		for (IWizardSection section : sections) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    92
			section.createControl(composite);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    93
			section.setChangeListener(this);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    94
			GridDataFactory.fillDefaults().grab(true, true).applyTo(section.getControl());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    95
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    96
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    97
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    98
		setControl(composite);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    99
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   100
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   101
	/**
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   102
	 * @return
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   103
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   104
	public void validatePage() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   105
		setMessage(null, INFORMATION);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   106
		setErrorMessage(null);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   107
		setPageComplete(true);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   108
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   109
		IStatus pageStatus = null;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   110
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   111
		// validate the subsections
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   112
		StringBuilder builder = new StringBuilder();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   113
		int severity = IStatus.OK;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   114
		for (IWizardSection section : sections) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   115
			IStatus status = section.getStatus();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   116
			if (status.isOK())
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   117
				continue;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   118
			if (builder.length() > 0)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   119
				builder.append("\n");
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   120
			
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   121
			builder.append(MessageFormat.format("{0}: {1}",
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   122
					section.getSectionName(), 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   123
					status.getMessage()));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   124
			severity = Math.max(severity, status.getSeverity());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   125
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   126
		if (severity != 0 || builder.length() > 0) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   127
			// error from one or more sections
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   128
			pageStatus = new Status(severity, LaunchPlugin.PLUGIN_ID, builder.toString());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   129
		} else {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   130
			// sections are good; validate the page as a whole
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   131
			pageStatus = data.validate();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   132
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   133
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   134
		setTitle("Configure launch configuration");
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   135
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   136
		if (pageStatus != null && !pageStatus.isOK()) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   137
			setMessage(pageStatus.getMessage(), severityToMsgType(pageStatus.getSeverity()));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   138
			setPageComplete(false);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   139
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   140
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   141
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   142
	private int severityToMsgType(int severity) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   143
		switch (severity) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   144
		case IStatus.OK:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   145
		case IStatus.INFO:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   146
			return INFORMATION;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   147
		case IStatus.WARNING:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   148
			return WARNING;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   149
		case IStatus.ERROR:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   150
		default:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   151
			return ERROR;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   152
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   153
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   154
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   155
	/*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   156
	private String getSeverityTag(int severity) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   157
		if (severity == IStatus.OK || severity == IStatus.INFO || severity == IStatus.CANCEL)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   158
			return "";
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   159
		if (severity == IStatus.WARNING)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   160
			return "warning";
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   161
		return "error";
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   162
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   163
	*/
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   164
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   165
	public void initializeSettings() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   166
		for (IWizardSection section : sections) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   167
			section.initializeSettings();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   168
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   169
		validatePage();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   170
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   171
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   172
	/* (non-Javadoc)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   173
	 * @see com.nokia.cdt.internal.debug.launch.wizard2.IWizardSection.ISectionChangeListener#changed()
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   174
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   175
	public void changed() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   176
		validatePage();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   177
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   178
}