debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/newwizard/AbstractLaunchWizardSection.java
author dadubrow
Mon, 18 Oct 2010 16:58:49 -0500
changeset 2160 3a82092877ea
parent 993 df87e2d581e4
child 2163 f0a9f2d04d4a
permissions -rw-r--r--
initial commit for PS 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.layout.GridDataFactory;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    25
import org.eclipse.jface.layout.GridLayoutFactory;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    26
import org.eclipse.jface.resource.JFaceResources;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    27
import org.eclipse.jface.window.Window;
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.events.ControlAdapter;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    30
import org.eclipse.swt.events.ControlEvent;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    31
import org.eclipse.swt.events.DisposeEvent;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    32
import org.eclipse.swt.events.DisposeListener;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    33
import org.eclipse.swt.events.SelectionAdapter;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    34
import org.eclipse.swt.events.SelectionEvent;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    35
import org.eclipse.swt.graphics.GC;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    36
import org.eclipse.swt.graphics.Point;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    37
import org.eclipse.swt.widgets.Button;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    38
import org.eclipse.swt.widgets.Composite;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    39
import org.eclipse.swt.widgets.Control;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    40
import org.eclipse.swt.widgets.Label;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    41
import org.eclipse.swt.widgets.Shell;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    42
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    43
import com.nokia.cdt.internal.debug.launch.LaunchPlugin;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    44
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    45
/**
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    46
 * 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    47
 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    48
public abstract class AbstractLaunchWizardSection implements IWizardSection {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    49
969
b0dd389735fb externalize strings
dadubrow
parents: 960
diff changeset
    50
	private static final String CHANGE_LABEL = Messages.getString("AbstractLaunchWizardSection.ChangeLabel"); //$NON-NLS-1$
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    51
	protected final LaunchWizardData data;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    52
	private String sectionName;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    53
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    54
	protected IStatus status;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    55
	protected Label descriptionLabel;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    56
	protected Button changeButton;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    57
	protected Composite control;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    58
	private ISectionChangeListener changeListener;
2160
3a82092877ea initial commit for PS wizard
dadubrow
parents: 993
diff changeset
    59
	protected final AbstractUnifiedLaunchOptionsPage launchOptionsPage;
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    60
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    61
2160
3a82092877ea initial commit for PS wizard
dadubrow
parents: 993
diff changeset
    62
	public AbstractLaunchWizardSection(LaunchWizardData data, String sectionName, AbstractUnifiedLaunchOptionsPage launchOptionsPage) {
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    63
		this.data = data;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    64
		this.sectionName = sectionName;
960
1b51db390dc4 ui tweaks to new launch wizard
dadubrow
parents: 956
diff changeset
    65
		this.launchOptionsPage = launchOptionsPage;
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    66
		status = Status.OK_STATUS;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    67
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    68
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    69
	abstract protected void dispose();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    70
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    71
	public IStatus getStatus() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    72
		return status;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    73
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    74
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    75
	/** Initialize the data for this section (before UI shown). */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    76
	public abstract void initializeSettings();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    77
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    78
	/** Validate the settings and update status. */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    79
	abstract protected void validate();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    80
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    81
	/** Update the UI when data changes. Called after validate(). */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    82
	protected abstract void updateUI();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    83
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    84
	/** Create the UI for this section. */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    85
	public abstract void createControl(Composite parent);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    86
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    87
	/** Create the dialog for the Change... button. */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    88
	protected abstract AbstractLaunchSettingsDialog createChangeSettingsDialog(Shell shell, LaunchWizardData dialogData);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    89
	/** Refresh the section after the Change... dialog has been closed. */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    90
	protected abstract void refresh();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    91
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    92
	public Control getControl() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    93
		return control; 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    94
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    95
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    96
	public String getSectionName() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    97
		return sectionName;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    98
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    99
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   100
	/* (non-Javadoc)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   101
	 * @see com.nokia.cdt.internal.debug.launch.wizard2.IWizardSection#setChangeListener(com.nokia.cdt.internal.debug.launch.wizard2.IWizardSection.ISectionChangeListener)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   102
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   103
	public void setChangeListener(ISectionChangeListener listener) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   104
		this.changeListener = listener;
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 void createSection(Composite parent, int acceleratorIndex) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   108
		Composite composite = new Composite(parent, SWT.NONE);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   109
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   110
		GC gc = new GC(parent);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   111
		int INDENT = gc.getAdvanceWidth('m') * 4;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   112
		gc.dispose();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   113
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   114
		GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 0).applyTo(composite);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   115
		
983
8b4ee73c530c New launch wizard UI tweaks based on demo feedback
dadubrow
parents: 969
diff changeset
   116
		// spacing
8b4ee73c530c New launch wizard UI tweaks based on demo feedback
dadubrow
parents: 969
diff changeset
   117
		Label spacer = new Label(composite, SWT.NONE);
8b4ee73c530c New launch wizard UI tweaks based on demo feedback
dadubrow
parents: 969
diff changeset
   118
		GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(spacer);
8b4ee73c530c New launch wizard UI tweaks based on demo feedback
dadubrow
parents: 969
diff changeset
   119
		
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   120
		Label titleLabel = new Label(composite, SWT.NONE);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   121
		titleLabel.setText(sectionName);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   122
		titleLabel.setFont(JFaceResources.getBannerFont());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   123
		GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(titleLabel);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   124
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   125
		descriptionLabel = new Label(composite, SWT.WRAP);
983
8b4ee73c530c New launch wizard UI tweaks based on demo feedback
dadubrow
parents: 969
diff changeset
   126
		GridDataFactory.fillDefaults().grab(true, true).indent(INDENT, 0).hint(350, SWT.DEFAULT).applyTo(descriptionLabel);
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   127
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   128
		String label = MessageFormat.format("{0}&{1}", //$NON-NLS-1$
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   129
				CHANGE_LABEL.substring(0, acceleratorIndex), CHANGE_LABEL.substring(acceleratorIndex));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   130
		changeButton = new Button(composite, SWT.PUSH);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   131
		changeButton.setText(label);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   132
		Point minSize = changeButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
983
8b4ee73c530c New launch wizard UI tweaks based on demo feedback
dadubrow
parents: 969
diff changeset
   133
		GridDataFactory.defaultsFor(changeButton).grab(false, false).hint(minSize.x + INDENT, SWT.DEFAULT).indent(6, 0).applyTo(changeButton);
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   134
		changeButton.addSelectionListener(new SelectionAdapter() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   135
			@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   136
			public void widgetSelected(SelectionEvent e) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   137
				doChange();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   138
				if (changeListener != null)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   139
					changeListener.changed();
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
		composite.addControlListener(new ControlAdapter() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   144
			@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   145
			public void controlResized(ControlEvent e) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   146
				descriptionLabel.pack();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   147
			}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   148
		});
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   149
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   150
		this.control = composite;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   151
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   152
		control.addDisposeListener(new DisposeListener() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   153
			
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   154
			public void widgetDisposed(DisposeEvent e) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   155
				dispose();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   156
			}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   157
		});
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   158
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   159
		validate();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   160
		updateUI();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   161
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   162
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   163
	/* (non-Javadoc)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   164
	 * @see com.nokia.cdt.internal.debug.launch.wizard2.AbstractLaunchWizardSection#doChange()
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   165
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   166
	protected void doChange() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   167
		LaunchWizardData dialogData = data.copy();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   168
		AbstractLaunchSettingsDialog dialog = createChangeSettingsDialog(getControl().getShell(), dialogData);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   169
		if (dialog.open() == Window.OK) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   170
			data.apply(dialogData);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   171
			refresh();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   172
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   173
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   174
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   175
	protected static IStatus error(String msg, Object... args) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   176
		return new Status(IStatus.ERROR, LaunchPlugin.PLUGIN_ID,
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   177
				MessageFormat.format(msg, args));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   178
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   179
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   180
	protected IStatus warning(String msg, Object... args) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   181
		return new Status(IStatus.WARNING, LaunchPlugin.PLUGIN_ID,
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   182
				MessageFormat.format(msg, args));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   183
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   184
}