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