debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/newwizard/AbstractLaunchSettingsDialog.java
author dadubrow
Mon, 15 Feb 2010 13:49:01 -0600
changeset 956 d1e221a2875f
child 969 b0dd389735fb
permissions -rw-r--r--
new launch wizard implementation
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
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    33
import com.nokia.cdt.internal.debug.launch.LaunchPlugin;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    34
import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
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
 * 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    38
 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    39
public abstract class AbstractLaunchSettingsDialog extends TitleAreaDialog {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    40
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    41
	protected final static String UID = ".uid";
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    42
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    43
	protected final LaunchWizardData data;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    44
	protected int INDENT;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    45
	private String title;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    46
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    47
	protected abstract void validate();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    48
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    49
	/**
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    50
	 * @param parentShell
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    51
	 * @param data 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    52
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    53
	public AbstractLaunchSettingsDialog(Shell parentShell, LaunchWizardData data) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    54
		super(parentShell);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    55
		setShellStyle(getShellStyle() | SWT.RESIZE);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    56
		this.data = data;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    57
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    58
	/* (non-Javadoc)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    59
	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    60
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    61
	@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    62
	protected void configureShell(Shell newShell) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    63
		super.configureShell(newShell);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    64
		newShell.setText("New Launch Configuration Wizard");
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    65
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    66
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    67
	protected Composite initDialogArea(Composite parent, String title, String helpId) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    68
		Composite composite = (Composite) super.createDialogArea(parent);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    69
		GridLayoutFactory.fillDefaults().margins(6, 6).applyTo(composite);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    70
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    71
		INDENT = convertWidthInCharsToPixels(4);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    72
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    73
		setTitle(title);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    74
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    75
		this.title = title;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    76
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    77
		WorkbenchUtils.setHelpContextId(composite, helpId);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    78
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    79
		return composite;
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
	protected int severityToMsgType(int severity) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    83
		switch (severity) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    84
		case IStatus.OK:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    85
		case IStatus.CANCEL:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    86
		default:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    87
			break;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    88
		case IStatus.INFO:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    89
			return IMessageProvider.INFORMATION;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    90
		case IStatus.ERROR:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    91
			return IMessageProvider.ERROR;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    92
		case IStatus.WARNING:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    93
			return IMessageProvider.WARNING;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    94
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    95
		return IMessageProvider.NONE;
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
	protected IStatus error(String msg, Object... args) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    99
		return new Status(IStatus.ERROR, LaunchPlugin.PLUGIN_ID,
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   100
				MessageFormat.format(msg, args));
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
	protected IStatus warning(String msg, Object... args) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   104
		return new Status(IStatus.WARNING, LaunchPlugin.PLUGIN_ID,
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   105
				MessageFormat.format(msg, args));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   106
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   107
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   108
	private void setOkEnabled(boolean enabled) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   109
		Button okButton = getButton(IDialogConstants.OK_ID); 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   110
		if (okButton != null) 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   111
			okButton.setEnabled(enabled);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   112
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   113
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   114
	protected void updateStatus(IStatus status) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   115
		setTitle(title);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   116
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   117
		if (status.isOK()) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   118
			setMessage("", IMessageProvider.NONE);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   119
		} else {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   120
			setMessage(status.getMessage(), severityToMsgType(status.getSeverity()));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   121
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   122
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   123
		setOkEnabled(!status.matches(IStatus.ERROR));
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
}