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