debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/newwizard/AbstractLaunchSettingsDialog.java
author dadubrow
Thu, 18 Feb 2010 09:07:17 -0600
changeset 983 8b4ee73c530c
parent 969 b0dd389735fb
child 1061 ceac11190019
permissions -rw-r--r--
New launch wizard UI tweaks based on demo feedback
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
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    22
import org.eclipse.core.runtime.IStatus;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    23
import org.eclipse.core.runtime.Status;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    24
import org.eclipse.jface.dialogs.IDialogConstants;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    25
import org.eclipse.jface.dialogs.IMessageProvider;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    26
import org.eclipse.jface.dialogs.TitleAreaDialog;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    27
import org.eclipse.jface.layout.GridLayoutFactory;
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.Button;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    30
import org.eclipse.swt.widgets.Composite;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    31
import org.eclipse.swt.widgets.Shell;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    32
983
8b4ee73c530c New launch wizard UI tweaks based on demo feedback
dadubrow
parents: 969
diff changeset
    33
import com.nokia.carbide.cpp.ui.CarbideUIPlugin;
8b4ee73c530c New launch wizard UI tweaks based on demo feedback
dadubrow
parents: 969
diff changeset
    34
import com.nokia.carbide.cpp.ui.ICarbideSharedImages;
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    35
import com.nokia.cdt.internal.debug.launch.LaunchPlugin;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    36
import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    37
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    38
/**
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    39
 * 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    40
 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    41
public abstract class AbstractLaunchSettingsDialog extends TitleAreaDialog {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    42
	
969
b0dd389735fb externalize strings
dadubrow
parents: 956
diff changeset
    43
	protected final static String UID = ".uid"; //$NON-NLS-1$
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    44
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    45
	protected final LaunchWizardData data;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    46
	protected int INDENT;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    47
	private String title;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    48
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    49
	protected abstract void validate();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    50
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    51
	/**
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    52
	 * @param parentShell
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    53
	 * @param data 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    54
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    55
	public AbstractLaunchSettingsDialog(Shell parentShell, LaunchWizardData data) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    56
		super(parentShell);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    57
		setShellStyle(getShellStyle() | SWT.RESIZE);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    58
		this.data = data;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    59
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    60
	/* (non-Javadoc)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    61
	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    62
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    63
	@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    64
	protected void configureShell(Shell newShell) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    65
		super.configureShell(newShell);
969
b0dd389735fb externalize strings
dadubrow
parents: 956
diff changeset
    66
		newShell.setText(Messages.getString("AbstractLaunchSettingsDialog.Title")); //$NON-NLS-1$
983
8b4ee73c530c New launch wizard UI tweaks based on demo feedback
dadubrow
parents: 969
diff changeset
    67
		setTitleImage(CarbideUIPlugin.getSharedImages().getImage(ICarbideSharedImages.IMG_NEW_LAUNCH_CONFIG_WIZARD_BANNER));
956
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
	protected Composite initDialogArea(Composite parent, String title, String helpId) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    71
		Composite composite = (Composite) super.createDialogArea(parent);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    72
		GridLayoutFactory.fillDefaults().margins(6, 6).applyTo(composite);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    73
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    74
		INDENT = convertWidthInCharsToPixels(4);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    75
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    76
		setTitle(title);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    77
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    78
		this.title = title;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    79
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    80
		WorkbenchUtils.setHelpContextId(composite, helpId);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    81
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    82
		return composite;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    83
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    84
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    85
	protected int severityToMsgType(int severity) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    86
		switch (severity) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    87
		case IStatus.OK:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    88
		case IStatus.CANCEL:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    89
		default:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    90
			break;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    91
		case IStatus.INFO:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    92
			return IMessageProvider.INFORMATION;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    93
		case IStatus.ERROR:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    94
			return IMessageProvider.ERROR;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    95
		case IStatus.WARNING:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    96
			return IMessageProvider.WARNING;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    97
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    98
		return IMessageProvider.NONE;
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
	protected IStatus error(String msg, Object... args) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   102
		return new Status(IStatus.ERROR, LaunchPlugin.PLUGIN_ID,
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   103
				MessageFormat.format(msg, args));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   104
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   105
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   106
	protected IStatus warning(String msg, Object... args) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   107
		return new Status(IStatus.WARNING, LaunchPlugin.PLUGIN_ID,
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   108
				MessageFormat.format(msg, args));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   109
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   110
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   111
	private void setOkEnabled(boolean enabled) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   112
		Button okButton = getButton(IDialogConstants.OK_ID); 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   113
		if (okButton != null) 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   114
			okButton.setEnabled(enabled);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   115
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   116
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   117
	protected void updateStatus(IStatus status) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   118
		setTitle(title);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   119
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   120
		if (status.isOK()) {
969
b0dd389735fb externalize strings
dadubrow
parents: 956
diff changeset
   121
			setMessage("", IMessageProvider.NONE); //$NON-NLS-1$
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   122
		} else {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   123
			setMessage(status.getMessage(), severityToMsgType(status.getSeverity()));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   124
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   125
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   126
		setOkEnabled(!status.matches(IStatus.ERROR));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   127
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   128
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   129
}