debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/newwizard/AbstractLaunchWizardSection.java
author dadubrow
Mon, 15 Feb 2010 13:49:01 -0600
changeset 956 d1e221a2875f
child 960 1b51db390dc4
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.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
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    50
	private static final String CHANGE_LABEL = "Change...";
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;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    59
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    60
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    61
	public AbstractLaunchWizardSection(LaunchWizardData data, String sectionName) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    62
		this.data = data;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    63
		this.sectionName = sectionName;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    64
		status = Status.OK_STATUS;
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
	abstract protected void dispose();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    68
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    69
	public IStatus getStatus() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    70
		return status;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    71
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    72
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    73
	/** Initialize the data for this section (before UI shown). */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    74
	public abstract void initializeSettings();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    75
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    76
	/** Validate the settings and update status. */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    77
	abstract protected void validate();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    78
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    79
	/** Update the UI when data changes. Called after validate(). */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    80
	protected abstract void updateUI();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    81
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    82
	/** Create the UI for this section. */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    83
	public abstract void createControl(Composite parent);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    84
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    85
	/** Create the dialog for the Change... button. */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    86
	protected abstract AbstractLaunchSettingsDialog createChangeSettingsDialog(Shell shell, LaunchWizardData dialogData);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    87
	/** Refresh the section after the Change... dialog has been closed. */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    88
	protected abstract void refresh();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    89
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    90
	public Control getControl() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    91
		return control; 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    92
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    93
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    94
	public String getSectionName() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    95
		return sectionName;
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
	/* (non-Javadoc)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    99
	 * @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
   100
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   101
	public void setChangeListener(ISectionChangeListener listener) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   102
		this.changeListener = listener;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   103
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   104
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   105
	protected void createSection(Composite parent, int acceleratorIndex) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   106
		Composite composite = new Composite(parent, SWT.NONE);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   107
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   108
		GC gc = new GC(parent);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   109
		int INDENT = gc.getAdvanceWidth('m') * 4;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   110
		gc.dispose();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   111
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   112
		GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 0).applyTo(composite);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   113
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   114
		Label titleLabel = new Label(composite, SWT.NONE);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   115
		titleLabel.setText(sectionName);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   116
		titleLabel.setFont(JFaceResources.getBannerFont());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   117
		GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(titleLabel);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   118
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   119
		// spacing
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   120
		Label spacer = new Label(composite, SWT.NONE);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   121
		GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(spacer);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   122
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   123
		descriptionLabel = new Label(composite, SWT.WRAP);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   124
		GridDataFactory.fillDefaults().grab(true, true).indent(INDENT, 0).applyTo(descriptionLabel);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   125
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   126
		String label = MessageFormat.format("{0}&{1}", //$NON-NLS-1$
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   127
				CHANGE_LABEL.substring(0, acceleratorIndex), CHANGE_LABEL.substring(acceleratorIndex));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   128
		changeButton = new Button(composite, SWT.PUSH);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   129
		changeButton.setText(label);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   130
		Point minSize = changeButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   131
		GridDataFactory.defaultsFor(changeButton).grab(false, false).hint(minSize.x + INDENT, SWT.DEFAULT).applyTo(changeButton);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   132
		changeButton.addSelectionListener(new SelectionAdapter() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   133
			@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   134
			public void widgetSelected(SelectionEvent e) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   135
				doChange();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   136
				if (changeListener != null)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   137
					changeListener.changed();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   138
			}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   139
		});
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   140
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   141
		composite.addControlListener(new ControlAdapter() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   142
			@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   143
			public void controlResized(ControlEvent e) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   144
				descriptionLabel.pack();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   145
			}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   146
		});
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   147
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   148
		this.control = composite;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   149
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   150
		control.addDisposeListener(new DisposeListener() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   151
			
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   152
			public void widgetDisposed(DisposeEvent e) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   153
				dispose();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   154
			}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   155
		});
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   156
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   157
		validate();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   158
		updateUI();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   159
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   160
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   161
	/* (non-Javadoc)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   162
	 * @see com.nokia.cdt.internal.debug.launch.wizard2.AbstractLaunchWizardSection#doChange()
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   163
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   164
	protected void doChange() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   165
		LaunchWizardData dialogData = data.copy();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   166
		AbstractLaunchSettingsDialog dialog = createChangeSettingsDialog(getControl().getShell(), dialogData);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   167
		if (dialog.open() == Window.OK) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   168
			data.apply(dialogData);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   169
			refresh();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   170
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   171
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   172
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   173
	protected static IStatus error(String msg, Object... args) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   174
		return new Status(IStatus.ERROR, LaunchPlugin.PLUGIN_ID,
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   175
				MessageFormat.format(msg, args));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   176
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   177
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   178
	protected IStatus warning(String msg, Object... args) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   179
		return new Status(IStatus.WARNING, LaunchPlugin.PLUGIN_ID,
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   180
				MessageFormat.format(msg, args));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   181
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   182
}