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