debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/newwizard/AbstractLaunchSettingsDialog.java
changeset 956 d1e221a2875f
child 969 b0dd389735fb
equal deleted inserted replaced
948:ee68c935ffb7 956:d1e221a2875f
       
     1 /*
       
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the License "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: 
       
    15  *
       
    16  */
       
    17 
       
    18 package com.nokia.cdt.internal.debug.launch.newwizard;
       
    19 
       
    20 import java.text.MessageFormat;
       
    21 
       
    22 import org.eclipse.core.runtime.IStatus;
       
    23 import org.eclipse.core.runtime.Status;
       
    24 import org.eclipse.jface.dialogs.IDialogConstants;
       
    25 import org.eclipse.jface.dialogs.IMessageProvider;
       
    26 import org.eclipse.jface.dialogs.TitleAreaDialog;
       
    27 import org.eclipse.jface.layout.GridLayoutFactory;
       
    28 import org.eclipse.swt.SWT;
       
    29 import org.eclipse.swt.widgets.Button;
       
    30 import org.eclipse.swt.widgets.Composite;
       
    31 import org.eclipse.swt.widgets.Shell;
       
    32 
       
    33 import com.nokia.cdt.internal.debug.launch.LaunchPlugin;
       
    34 import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
       
    35 
       
    36 /**
       
    37  * 
       
    38  */
       
    39 public abstract class AbstractLaunchSettingsDialog extends TitleAreaDialog {
       
    40 	
       
    41 	protected final static String UID = ".uid";
       
    42 	
       
    43 	protected final LaunchWizardData data;
       
    44 	protected int INDENT;
       
    45 	private String title;
       
    46 
       
    47 	protected abstract void validate();
       
    48 
       
    49 	/**
       
    50 	 * @param parentShell
       
    51 	 * @param data 
       
    52 	 */
       
    53 	public AbstractLaunchSettingsDialog(Shell parentShell, LaunchWizardData data) {
       
    54 		super(parentShell);
       
    55 		setShellStyle(getShellStyle() | SWT.RESIZE);
       
    56 		this.data = data;
       
    57 	}
       
    58 	/* (non-Javadoc)
       
    59 	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
       
    60 	 */
       
    61 	@Override
       
    62 	protected void configureShell(Shell newShell) {
       
    63 		super.configureShell(newShell);
       
    64 		newShell.setText("New Launch Configuration Wizard");
       
    65 	}
       
    66 
       
    67 	protected Composite initDialogArea(Composite parent, String title, String helpId) {
       
    68 		Composite composite = (Composite) super.createDialogArea(parent);
       
    69 		GridLayoutFactory.fillDefaults().margins(6, 6).applyTo(composite);
       
    70 
       
    71 		INDENT = convertWidthInCharsToPixels(4);
       
    72 		
       
    73 		setTitle(title);
       
    74 		
       
    75 		this.title = title;
       
    76 
       
    77 		WorkbenchUtils.setHelpContextId(composite, helpId);
       
    78 		
       
    79 		return composite;
       
    80 	}
       
    81 	
       
    82 	protected int severityToMsgType(int severity) {
       
    83 		switch (severity) {
       
    84 		case IStatus.OK:
       
    85 		case IStatus.CANCEL:
       
    86 		default:
       
    87 			break;
       
    88 		case IStatus.INFO:
       
    89 			return IMessageProvider.INFORMATION;
       
    90 		case IStatus.ERROR:
       
    91 			return IMessageProvider.ERROR;
       
    92 		case IStatus.WARNING:
       
    93 			return IMessageProvider.WARNING;
       
    94 		}
       
    95 		return IMessageProvider.NONE;
       
    96 	}
       
    97 
       
    98 	protected IStatus error(String msg, Object... args) {
       
    99 		return new Status(IStatus.ERROR, LaunchPlugin.PLUGIN_ID,
       
   100 				MessageFormat.format(msg, args));
       
   101 	}
       
   102 
       
   103 	protected IStatus warning(String msg, Object... args) {
       
   104 		return new Status(IStatus.WARNING, LaunchPlugin.PLUGIN_ID,
       
   105 				MessageFormat.format(msg, args));
       
   106 	}
       
   107 	
       
   108 	private void setOkEnabled(boolean enabled) {
       
   109 		Button okButton = getButton(IDialogConstants.OK_ID); 
       
   110 		if (okButton != null) 
       
   111 			okButton.setEnabled(enabled);
       
   112 	}
       
   113 
       
   114 	protected void updateStatus(IStatus status) {
       
   115 		setTitle(title);
       
   116 
       
   117 		if (status.isOK()) {
       
   118 			setMessage("", IMessageProvider.NONE);
       
   119 		} else {
       
   120 			setMessage(status.getMessage(), severityToMsgType(status.getSeverity()));
       
   121 		}
       
   122 		
       
   123 		setOkEnabled(!status.matches(IStatus.ERROR));
       
   124 	}
       
   125 	
       
   126 }