debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/newwizard/UnifiedLaunchOptionsPage.java
author dadubrow
Tue, 23 Feb 2010 14:39:53 -0600
changeset 1013 83255eb26cdb
parent 993 df87e2d581e4
child 1067 856622c7b203
permissions -rw-r--r--
bug 10786 - fix and add help context ids
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;
993
df87e2d581e4 Fix UI glitch
dadubrow
parents: 969
diff changeset
    30
import org.eclipse.swt.widgets.Control;
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    31
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    32
import com.nokia.cdt.internal.debug.launch.LaunchPlugin;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    33
import com.nokia.cdt.internal.debug.launch.newwizard.IWizardSection.ISectionChangeListener;
1013
83255eb26cdb bug 10786 - fix and add help context ids
dadubrow
parents: 993
diff changeset
    34
import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    35
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    36
/**
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    37
 * This page presents three sections:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    38
 * <p>
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    39
 * Connection to use:  container for the Remote Connection selection UI, plus a label
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    40
 * explaining how to handle the case of no connections defined.
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    41
 * <p>
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    42
 * Debug process: section explaining how the launch will happen, with a combo
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    43
 * allowing selecting different process to launch, and a button allowing more
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    44
 * in-depth configuration.
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    45
 * <p>
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    46
 * Build before debug: section with the build-before-debug preference for this
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    47
 * launch configuration.
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    48
 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    49
public class UnifiedLaunchOptionsPage extends WizardPage implements ISectionChangeListener {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    50
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    51
	private final LaunchWizardData data;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    52
	private ArrayList<IWizardSection> sections;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    53
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    54
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    55
	/**
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    56
	 * @param mmps
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    57
	 * @param exes
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    58
	 * @param defaultExecutable
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    59
	 * @param project
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    60
	 * @param configurationName
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    61
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    62
	public UnifiedLaunchOptionsPage(LaunchWizardData data) {
969
b0dd389735fb externalize strings
dadubrow
parents: 960
diff changeset
    63
		super(Messages.getString("UnifiedLaunchOptionsPage.Title")); //$NON-NLS-1$
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    64
		
969
b0dd389735fb externalize strings
dadubrow
parents: 960
diff changeset
    65
		setDescription(Messages.getString("UnifiedLaunchOptionsPage.Desc")); //$NON-NLS-1$
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    66
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    67
		this.data = data;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    68
		this.sections = new ArrayList<IWizardSection>();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    69
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    70
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    71
		IWizardSection section;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    72
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    73
		section = new ConnectToDeviceSection(data, this);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    74
		sections.add(section);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    75
		
960
1b51db390dc4 ui tweaks to new launch wizard
dadubrow
parents: 956
diff changeset
    76
		section = new DebugRunProcessSection(data, this);
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    77
		sections.add(section);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    78
		
960
1b51db390dc4 ui tweaks to new launch wizard
dadubrow
parents: 956
diff changeset
    79
		section = new OtherSettingsSection(data, this);
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    80
		sections.add(section);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    81
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    82
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    83
	/* (non-Javadoc)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    84
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    85
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    86
	public void createControl(Composite parent) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    87
		Composite composite = new Composite(parent, SWT.NONE);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    88
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    89
		GridLayoutFactory.fillDefaults().applyTo(composite);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    90
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    91
		setPageComplete(false);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    92
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    93
		for (IWizardSection section : sections) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    94
			section.createControl(composite);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    95
			section.setChangeListener(this);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    96
			GridDataFactory.fillDefaults().grab(true, true).applyTo(section.getControl());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    97
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    98
		
1013
83255eb26cdb bug 10786 - fix and add help context ids
dadubrow
parents: 993
diff changeset
    99
		WorkbenchUtils.setHelpContextId(composite, LaunchWizardHelpIds.WIZARD_DIALOG_LAUNCH_OPTIONS_PAGE);
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   100
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   101
		setControl(composite);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   102
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   103
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   104
	/**
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   105
	 * @return
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   106
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   107
	public void validatePage() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   108
		setMessage(null, INFORMATION);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   109
		setErrorMessage(null);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   110
		setPageComplete(true);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   111
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   112
		IStatus pageStatus = null;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   113
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   114
		// validate the subsections
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   115
		StringBuilder builder = new StringBuilder();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   116
		int severity = IStatus.OK;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   117
		for (IWizardSection section : sections) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   118
			IStatus status = section.getStatus();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   119
			if (status.isOK())
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   120
				continue;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   121
			if (builder.length() > 0)
969
b0dd389735fb externalize strings
dadubrow
parents: 960
diff changeset
   122
				builder.append("\n"); //$NON-NLS-1$
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   123
			
969
b0dd389735fb externalize strings
dadubrow
parents: 960
diff changeset
   124
			builder.append(MessageFormat.format("{0}: {1}", //$NON-NLS-1$
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   125
					section.getSectionName(), 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   126
					status.getMessage()));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   127
			severity = Math.max(severity, status.getSeverity());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   128
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   129
		if (severity != 0 || builder.length() > 0) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   130
			// error from one or more sections
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   131
			pageStatus = new Status(severity, LaunchPlugin.PLUGIN_ID, builder.toString());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   132
		} else {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   133
			// sections are good; validate the page as a whole
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   134
			pageStatus = data.validate();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   135
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   136
		
969
b0dd389735fb externalize strings
dadubrow
parents: 960
diff changeset
   137
		setTitle(Messages.getString("UnifiedLaunchOptionsPage.TitleText")); //$NON-NLS-1$
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   138
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   139
		if (pageStatus != null && !pageStatus.isOK()) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   140
			setMessage(pageStatus.getMessage(), severityToMsgType(pageStatus.getSeverity()));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   141
			setPageComplete(false);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   142
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   143
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   144
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   145
	private int severityToMsgType(int severity) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   146
		switch (severity) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   147
		case IStatus.OK:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   148
		case IStatus.INFO:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   149
			return INFORMATION;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   150
		case IStatus.WARNING:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   151
			return WARNING;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   152
		case IStatus.ERROR:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   153
		default:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   154
			return ERROR;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   155
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   156
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   157
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   158
	/*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   159
	private String getSeverityTag(int severity) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   160
		if (severity == IStatus.OK || severity == IStatus.INFO || severity == IStatus.CANCEL)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   161
			return "";
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   162
		if (severity == IStatus.WARNING)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   163
			return "warning";
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   164
		return "error";
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   165
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   166
	*/
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   167
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   168
	public void initializeSettings() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   169
		for (IWizardSection section : sections) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   170
			section.initializeSettings();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   171
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   172
		validatePage();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   173
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   174
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   175
	/* (non-Javadoc)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   176
	 * @see com.nokia.cdt.internal.debug.launch.wizard2.IWizardSection.ISectionChangeListener#changed()
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   177
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   178
	public void changed() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   179
		validatePage();
993
df87e2d581e4 Fix UI glitch
dadubrow
parents: 969
diff changeset
   180
		Control control = getControl();
df87e2d581e4 Fix UI glitch
dadubrow
parents: 969
diff changeset
   181
		if (control != null && !control.isDisposed())
df87e2d581e4 Fix UI glitch
dadubrow
parents: 969
diff changeset
   182
			getWizard().getContainer().getShell().pack();
df87e2d581e4 Fix UI glitch
dadubrow
parents: 969
diff changeset
   183
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   184
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   185
}