Lines 12-17
Link Here
|
12 |
*******************************************************************************/ |
12 |
*******************************************************************************/ |
13 |
package org.eclipse.ui.internal.ide.dialogs; |
13 |
package org.eclipse.ui.internal.ide.dialogs; |
14 |
|
14 |
|
|
|
15 |
import java.util.Arrays; |
16 |
|
15 |
import org.eclipse.core.resources.IProject; |
17 |
import org.eclipse.core.resources.IProject; |
16 |
import org.eclipse.core.resources.IncrementalProjectBuilder; |
18 |
import org.eclipse.core.resources.IncrementalProjectBuilder; |
17 |
import org.eclipse.core.resources.ResourcesPlugin; |
19 |
import org.eclipse.core.resources.ResourcesPlugin; |
Lines 56-201
Link Here
|
56 |
* @since 3.0 |
58 |
* @since 3.0 |
57 |
*/ |
59 |
*/ |
58 |
public class CleanDialog extends MessageDialog { |
60 |
public class CleanDialog extends MessageDialog { |
59 |
|
61 |
|
60 |
private static final String DIALOG_SETTINGS_SECTION = "CleanDialogSettings"; //$NON-NLS-1$ |
62 |
private static final String DIALOG_SETTINGS_SECTION = "CleanDialogSettings"; //$NON-NLS-1$ |
61 |
private static final String DIALOG_ORIGIN_X = "DIALOG_X_ORIGIN"; //$NON-NLS-1$ |
63 |
private static final String DIALOG_ORIGIN_X = "DIALOG_X_ORIGIN"; //$NON-NLS-1$ |
62 |
private static final String DIALOG_ORIGIN_Y = "DIALOG_Y_ORIGIN"; //$NON-NLS-1$ |
64 |
private static final String DIALOG_ORIGIN_Y = "DIALOG_Y_ORIGIN"; //$NON-NLS-1$ |
63 |
private static final String DIALOG_WIDTH = "DIALOG_WIDTH"; //$NON-NLS-1$ |
65 |
private static final String DIALOG_WIDTH = "DIALOG_WIDTH"; //$NON-NLS-1$ |
64 |
private static final String DIALOG_HEIGHT = "DIALOG_HEIGHT"; //$NON-NLS-1$ |
66 |
private static final String DIALOG_HEIGHT = "DIALOG_HEIGHT"; //$NON-NLS-1$ |
65 |
private static final String TOGGLE_SELECTED = "TOGGLE_SELECTED"; //$NON-NLS-1$ |
67 |
private static final String TOGGLE_SELECTED = "TOGGLE_SELECTED"; //$NON-NLS-1$ |
66 |
private static final String BUILD_NOW = "BUILD_NOW"; //$NON-NLS-1$ |
68 |
private static final String BUILD_NOW = "BUILD_NOW"; //$NON-NLS-1$ |
67 |
|
69 |
|
68 |
private Button allButton, selectedButton, buildNowButton; |
70 |
private Button allButton, selectedButton, buildNowButton; |
69 |
|
71 |
|
70 |
private CheckboxTableViewer projectNames; |
72 |
private CheckboxTableViewer projectNames; |
71 |
|
73 |
|
72 |
private Object[] selection; |
74 |
private Object[] selection; |
73 |
|
75 |
|
74 |
private IWorkbenchWindow window; |
76 |
private IWorkbenchWindow window; |
75 |
|
77 |
|
76 |
/** |
78 |
/** |
77 |
* Gets the text of the clean dialog, depending on whether the |
79 |
* Gets the text of the clean dialog, depending on whether the workspace is |
78 |
* workspace is currently in autobuild mode. |
80 |
* currently in autobuild mode. |
79 |
* @return String the question the user will be asked. |
81 |
* |
80 |
*/ |
82 |
* @return String the question the user will be asked. |
81 |
private static String getQuestion() { |
83 |
*/ |
82 |
boolean autoBuilding = ResourcesPlugin.getWorkspace().isAutoBuilding(); |
84 |
private static String getQuestion() { |
83 |
if (autoBuilding) { |
85 |
boolean autoBuilding = ResourcesPlugin.getWorkspace().isAutoBuilding(); |
|
|
86 |
if (autoBuilding) { |
84 |
return IDEWorkbenchMessages.CleanDialog_buildCleanAuto; |
87 |
return IDEWorkbenchMessages.CleanDialog_buildCleanAuto; |
85 |
} |
88 |
} |
86 |
return IDEWorkbenchMessages.CleanDialog_buildCleanManual; |
89 |
return IDEWorkbenchMessages.CleanDialog_buildCleanManual; |
87 |
} |
90 |
} |
88 |
|
91 |
|
89 |
/** |
92 |
/** |
90 |
* Creates a new clean dialog. |
93 |
* Creates a new clean dialog. |
91 |
* |
94 |
* |
92 |
* @param window the window to create it in |
95 |
* @param window |
93 |
* @param selection the currently selected projects (may be empty) |
96 |
* the window to create it in |
94 |
*/ |
97 |
* @param selection |
95 |
public CleanDialog(IWorkbenchWindow window, IProject[] selection) { |
98 |
* the currently selected projects (may be empty) |
96 |
super( |
99 |
*/ |
97 |
window.getShell(), |
100 |
public CleanDialog(IWorkbenchWindow window, IProject[] selection) { |
98 |
IDEWorkbenchMessages.CleanDialog_title, null, getQuestion(), NONE, new String[] { |
101 |
super(window.getShell(), IDEWorkbenchMessages.CleanDialog_title, null, |
99 |
IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0); |
102 |
getQuestion(), NONE, new String[] { IDialogConstants.OK_LABEL, |
100 |
this.window = window; |
103 |
IDialogConstants.CANCEL_LABEL }, 0); |
101 |
this.selection = selection; |
104 |
this.window = window; |
102 |
if (this.selection == null) { |
105 |
this.selection = selection; |
|
|
106 |
if (this.selection == null) { |
103 |
this.selection = new Object[0]; |
107 |
this.selection = new Object[0]; |
104 |
} |
108 |
} |
105 |
} |
109 |
} |
106 |
|
110 |
|
107 |
/* |
111 |
/* |
108 |
* (non-Javadoc) |
112 |
* (non-Javadoc) |
109 |
* |
113 |
* |
110 |
* @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) |
114 |
* @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) |
111 |
*/ |
115 |
*/ |
112 |
protected void buttonPressed(int buttonId) { |
116 |
protected void buttonPressed(int buttonId) { |
113 |
final boolean cleanAll = allButton.getSelection(); |
117 |
final boolean cleanAll = allButton.getSelection(); |
114 |
final boolean buildAll = buildNowButton != null |
118 |
final boolean buildAll = buildNowButton != null |
115 |
&& buildNowButton.getSelection(); |
119 |
&& buildNowButton.getSelection(); |
116 |
super.buttonPressed(buttonId); |
120 |
super.buttonPressed(buttonId); |
117 |
if (buttonId != IDialogConstants.OK_ID) { |
121 |
if (buttonId != IDialogConstants.OK_ID) { |
118 |
return; |
122 |
return; |
119 |
} |
123 |
} |
120 |
//save all dirty editors |
124 |
// save all dirty editors |
121 |
BuildUtilities.saveEditors(null); |
125 |
// save dirty editors in projects to be cleaned |
122 |
//batching changes ensures that autobuild runs after cleaning |
126 |
if (cleanAll) { |
123 |
WorkspaceJob cleanJob = new WorkspaceJob(IDEWorkbenchMessages.CleanDialog_taskName) { |
127 |
if (!BuildUtilities.saveEditors(null)) { |
124 |
public boolean belongsTo(Object family) { |
128 |
return; |
125 |
return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family); |
129 |
} |
126 |
} |
130 |
} else { |
127 |
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { |
131 |
if (!BuildUtilities.saveEditors(Arrays.asList(selection))) { |
128 |
doClean(cleanAll, monitor); |
132 |
return; |
129 |
//see if a build was requested |
133 |
} |
130 |
if (buildAll) { |
134 |
} |
131 |
//start an immediate workspace build |
135 |
|
132 |
GlobalBuildAction build = new GlobalBuildAction(window, |
136 |
// batching changes ensures that autobuild runs after cleaning |
133 |
IncrementalProjectBuilder.INCREMENTAL_BUILD); |
137 |
// batching changes ensures that autobuild runs after cleaning |
134 |
build.doBuild(); |
138 |
WorkspaceJob cleanJob = new WorkspaceJob( |
135 |
} |
139 |
IDEWorkbenchMessages.CleanDialog_taskName) { |
136 |
return Status.OK_STATUS; |
140 |
public boolean belongsTo(Object family) { |
137 |
} |
141 |
return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family); |
138 |
}; |
142 |
} |
139 |
cleanJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory() |
143 |
|
140 |
.buildRule()); |
144 |
public IStatus runInWorkspace(IProgressMonitor monitor) |
141 |
cleanJob.setUser(true); |
145 |
throws CoreException { |
142 |
cleanJob.schedule(); |
146 |
doClean(cleanAll, monitor); |
143 |
} |
147 |
// see if a build was requested |
144 |
|
148 |
if (buildAll) { |
145 |
/* (non-Javadoc) |
149 |
// start an immediate workspace build |
146 |
* @see org.eclipse.jface.dialogs.MessageDialog#createCustomArea(org.eclipse.swt.widgets.Composite) |
150 |
GlobalBuildAction build = new GlobalBuildAction(window, |
147 |
*/ |
151 |
IncrementalProjectBuilder.INCREMENTAL_BUILD); |
148 |
protected Control createCustomArea(Composite parent) { |
152 |
build.doBuild(); |
149 |
Composite area = new Composite(parent, SWT.NONE); |
153 |
} |
150 |
GridLayout layout = new GridLayout(); |
154 |
return Status.OK_STATUS; |
151 |
layout.marginWidth = layout.marginHeight = 0; |
155 |
} |
152 |
layout.numColumns = 2; |
156 |
}; |
153 |
layout.makeColumnsEqualWidth = true; |
157 |
cleanJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory() |
154 |
area.setLayout(layout); |
158 |
.buildRule()); |
155 |
area.setLayoutData(new GridData(GridData.FILL_BOTH)); |
159 |
cleanJob.setUser(true); |
156 |
SelectionListener updateEnablement = new SelectionAdapter() { |
160 |
cleanJob.schedule(); |
157 |
public void widgetSelected(SelectionEvent e) { |
161 |
} |
158 |
updateEnablement(); |
162 |
|
159 |
} |
163 |
/* |
160 |
}; |
164 |
* (non-Javadoc) |
161 |
|
165 |
* |
162 |
IDialogSettings settings = getDialogSettings(DIALOG_SETTINGS_SECTION); |
166 |
* @see org.eclipse.jface.dialogs.MessageDialog#createCustomArea(org.eclipse.swt.widgets.Composite) |
163 |
boolean selectSelectedButton= settings.getBoolean(TOGGLE_SELECTED); |
167 |
*/ |
164 |
//first row |
168 |
protected Control createCustomArea(Composite parent) { |
165 |
allButton = new Button(area, SWT.RADIO); |
169 |
Composite area = new Composite(parent, SWT.NONE); |
166 |
allButton.setText(IDEWorkbenchMessages.CleanDialog_cleanAllButton); |
170 |
GridLayout layout = new GridLayout(); |
167 |
allButton.setSelection(!selectSelectedButton); |
171 |
layout.marginWidth = layout.marginHeight = 0; |
168 |
allButton.addSelectionListener(updateEnablement); |
172 |
layout.numColumns = 2; |
169 |
selectedButton = new Button(area, SWT.RADIO); |
173 |
layout.makeColumnsEqualWidth = true; |
170 |
selectedButton.setText(IDEWorkbenchMessages.CleanDialog_cleanSelectedButton); |
174 |
area.setLayout(layout); |
171 |
selectedButton.setSelection(selectSelectedButton); |
175 |
area.setLayoutData(new GridData(GridData.FILL_BOTH)); |
172 |
selectedButton.addSelectionListener(updateEnablement); |
176 |
SelectionListener updateEnablement = new SelectionAdapter() { |
173 |
|
177 |
public void widgetSelected(SelectionEvent e) { |
174 |
//second row |
178 |
updateEnablement(); |
175 |
createProjectSelectionTable(area); |
179 |
} |
176 |
|
180 |
}; |
177 |
//third row |
181 |
|
178 |
//only prompt for immediate build if autobuild is off |
182 |
IDialogSettings settings = getDialogSettings(DIALOG_SETTINGS_SECTION); |
179 |
if (!ResourcesPlugin.getWorkspace().isAutoBuilding()) { |
183 |
boolean selectSelectedButton = settings.getBoolean(TOGGLE_SELECTED); |
180 |
buildNowButton = new Button(parent, SWT.CHECK); |
184 |
// first row |
181 |
buildNowButton.setText(IDEWorkbenchMessages.CleanDialog_buildNowButton); |
185 |
allButton = new Button(area, SWT.RADIO); |
182 |
String buildNow = settings.get(BUILD_NOW); |
186 |
allButton.setText(IDEWorkbenchMessages.CleanDialog_cleanAllButton); |
183 |
buildNowButton.setSelection(buildNow == null || Boolean.valueOf(buildNow).booleanValue()); |
187 |
allButton.setSelection(!selectSelectedButton); |
184 |
buildNowButton.setLayoutData(new GridData( |
188 |
allButton.addSelectionListener(updateEnablement); |
185 |
GridData.HORIZONTAL_ALIGN_BEGINNING)); |
189 |
selectedButton = new Button(area, SWT.RADIO); |
186 |
} |
190 |
selectedButton |
187 |
projectNames.getTable().setEnabled(selectSelectedButton); |
191 |
.setText(IDEWorkbenchMessages.CleanDialog_cleanSelectedButton); |
188 |
return area; |
192 |
selectedButton.setSelection(selectSelectedButton); |
189 |
} |
193 |
selectedButton.addSelectionListener(updateEnablement); |
190 |
|
194 |
|
191 |
private void createProjectSelectionTable(Composite radioGroup) { |
195 |
// second row |
192 |
projectNames = CheckboxTableViewer.newCheckList(radioGroup, SWT.BORDER); |
196 |
createProjectSelectionTable(area); |
193 |
projectNames.setContentProvider(new WorkbenchContentProvider()); |
197 |
|
194 |
projectNames.setLabelProvider(new WorkbenchLabelProvider()); |
198 |
// third row |
195 |
projectNames.setComparator(new ResourceComparator(ResourceComparator.NAME)); |
199 |
// only prompt for immediate build if autobuild is off |
196 |
projectNames.addFilter(new ViewerFilter() { |
200 |
if (!ResourcesPlugin.getWorkspace().isAutoBuilding()) { |
197 |
private final IProject[] projectHolder = new IProject[1]; |
201 |
buildNowButton = new Button(parent, SWT.CHECK); |
198 |
public boolean select(Viewer viewer, Object parentElement, Object element) { |
202 |
buildNowButton |
|
|
203 |
.setText(IDEWorkbenchMessages.CleanDialog_buildNowButton); |
204 |
String buildNow = settings.get(BUILD_NOW); |
205 |
buildNowButton.setSelection(buildNow == null |
206 |
|| Boolean.valueOf(buildNow).booleanValue()); |
207 |
buildNowButton.setLayoutData(new GridData( |
208 |
GridData.HORIZONTAL_ALIGN_BEGINNING)); |
209 |
} |
210 |
projectNames.getTable().setEnabled(selectSelectedButton); |
211 |
return area; |
212 |
} |
213 |
|
214 |
private void createProjectSelectionTable(Composite radioGroup) { |
215 |
projectNames = CheckboxTableViewer.newCheckList(radioGroup, SWT.BORDER); |
216 |
projectNames.setContentProvider(new WorkbenchContentProvider()); |
217 |
projectNames.setLabelProvider(new WorkbenchLabelProvider()); |
218 |
projectNames.setComparator(new ResourceComparator( |
219 |
ResourceComparator.NAME)); |
220 |
projectNames.addFilter(new ViewerFilter() { |
221 |
private final IProject[] projectHolder = new IProject[1]; |
222 |
|
223 |
public boolean select(Viewer viewer, Object parentElement, |
224 |
Object element) { |
199 |
if (!(element instanceof IProject)) { |
225 |
if (!(element instanceof IProject)) { |
200 |
return false; |
226 |
return false; |
201 |
} |
227 |
} |
Lines 204-222
Link Here
|
204 |
return false; |
230 |
return false; |
205 |
} |
231 |
} |
206 |
projectHolder[0] = project; |
232 |
projectHolder[0] = project; |
207 |
return BuildUtilities.isEnabled(projectHolder, IncrementalProjectBuilder.CLEAN_BUILD); |
233 |
return BuildUtilities.isEnabled(projectHolder, |
|
|
234 |
IncrementalProjectBuilder.CLEAN_BUILD); |
208 |
} |
235 |
} |
209 |
}); |
236 |
}); |
210 |
projectNames.setInput(ResourcesPlugin.getWorkspace().getRoot()); |
237 |
projectNames.setInput(ResourcesPlugin.getWorkspace().getRoot()); |
211 |
GridData data = new GridData(GridData.FILL_BOTH); |
238 |
GridData data = new GridData(GridData.FILL_BOTH); |
212 |
data.horizontalSpan = 2; |
239 |
data.horizontalSpan = 2; |
213 |
data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; |
240 |
data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; |
214 |
data.heightHint = IDialogConstants.ENTRY_FIELD_WIDTH; |
241 |
data.heightHint = IDialogConstants.ENTRY_FIELD_WIDTH; |
215 |
projectNames.getTable().setLayoutData(data); |
242 |
projectNames.getTable().setLayoutData(data); |
216 |
projectNames.setCheckedElements(selection); |
243 |
projectNames.setCheckedElements(selection); |
217 |
//table is disabled to start because all button is selected |
244 |
// table is disabled to start because all button is selected |
218 |
projectNames.getTable().setEnabled(selectedButton.getSelection()); |
245 |
projectNames.getTable().setEnabled(selectedButton.getSelection()); |
219 |
projectNames.addCheckStateListener(new ICheckStateListener() { |
246 |
projectNames.addCheckStateListener(new ICheckStateListener() { |
220 |
public void checkStateChanged(CheckStateChangedEvent event) { |
247 |
public void checkStateChanged(CheckStateChangedEvent event) { |
221 |
selection = projectNames.getCheckedElements(); |
248 |
selection = projectNames.getCheckedElements(); |
222 |
updateEnablement(); |
249 |
updateEnablement(); |
Lines 226-365
Link Here
|
226 |
|
253 |
|
227 |
/** |
254 |
/** |
228 |
* Performs the actual clean operation. |
255 |
* Performs the actual clean operation. |
229 |
* @param cleanAll if <code>true</true> clean all projects |
256 |
* |
|
|
257 |
* @param cleanAll |
258 |
* if <code>true</true> clean all projects |
230 |
* @param monitor The monitor that the build will report to |
259 |
* @param monitor The monitor that the build will report to |
231 |
* @throws CoreException thrown if there is a problem from the |
260 |
* @throws CoreException thrown if there is a problem from the |
232 |
* core builder. |
261 |
* core builder. |
233 |
*/ |
262 |
*/ |
234 |
protected void doClean(boolean cleanAll, IProgressMonitor monitor) |
263 |
protected void doClean(boolean cleanAll, IProgressMonitor monitor) |
235 |
throws CoreException { |
264 |
throws CoreException { |
236 |
if (cleanAll) { |
265 |
if (cleanAll) { |
237 |
ResourcesPlugin.getWorkspace().build( |
266 |
ResourcesPlugin.getWorkspace().build( |
238 |
IncrementalProjectBuilder.CLEAN_BUILD, monitor); |
267 |
IncrementalProjectBuilder.CLEAN_BUILD, monitor); |
239 |
} else { |
268 |
} else { |
240 |
try { |
269 |
try { |
241 |
monitor.beginTask(IDEWorkbenchMessages.CleanDialog_taskName, selection.length); |
270 |
monitor.beginTask(IDEWorkbenchMessages.CleanDialog_taskName, |
242 |
for (int i = 0; i < selection.length; i++) { |
271 |
selection.length); |
|
|
272 |
for (int i = 0; i < selection.length; i++) { |
243 |
((IProject) selection[i]).build( |
273 |
((IProject) selection[i]).build( |
244 |
IncrementalProjectBuilder.CLEAN_BUILD, |
274 |
IncrementalProjectBuilder.CLEAN_BUILD, |
245 |
new SubProgressMonitor(monitor, 1)); |
275 |
new SubProgressMonitor(monitor, 1)); |
246 |
} |
276 |
} |
247 |
} finally { |
277 |
} finally { |
248 |
monitor.done(); |
278 |
monitor.done(); |
249 |
} |
279 |
} |
250 |
} |
280 |
} |
251 |
} |
281 |
} |
252 |
|
282 |
|
253 |
/** |
283 |
/** |
254 |
* Updates the enablement of the dialog's ok button based |
284 |
* Updates the enablement of the dialog's ok button based on the current |
255 |
* on the current choices in the dialog. |
285 |
* choices in the dialog. |
256 |
*/ |
286 |
*/ |
257 |
protected void updateEnablement() { |
287 |
protected void updateEnablement() { |
258 |
projectNames.getTable().setEnabled(selectedButton.getSelection()); |
288 |
projectNames.getTable().setEnabled(selectedButton.getSelection()); |
259 |
boolean enabled = allButton.getSelection() || selection.length > 0; |
289 |
boolean enabled = allButton.getSelection() || selection.length > 0; |
260 |
getButton(OK).setEnabled(enabled); |
290 |
getButton(OK).setEnabled(enabled); |
261 |
} |
291 |
} |
262 |
|
292 |
|
263 |
/* (non-Javadoc) |
293 |
/* |
264 |
* @see org.eclipse.jface.window.Window#close() |
294 |
* (non-Javadoc) |
265 |
*/ |
295 |
* |
266 |
public boolean close() { |
296 |
* @see org.eclipse.jface.window.Window#close() |
267 |
persistDialogSettings(getShell(), DIALOG_SETTINGS_SECTION); |
297 |
*/ |
268 |
return super.close(); |
298 |
public boolean close() { |
269 |
} |
299 |
persistDialogSettings(getShell(), DIALOG_SETTINGS_SECTION); |
270 |
|
300 |
return super.close(); |
271 |
/* (non-Javadoc) |
301 |
} |
272 |
* @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point) |
302 |
|
273 |
*/ |
303 |
/* |
274 |
protected Point getInitialLocation(Point initialSize) { |
304 |
* (non-Javadoc) |
275 |
Point p = getInitialLocation(DIALOG_SETTINGS_SECTION); |
305 |
* |
276 |
return p != null ? p : super.getInitialLocation(initialSize); |
306 |
* @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point) |
277 |
} |
307 |
*/ |
278 |
|
308 |
protected Point getInitialLocation(Point initialSize) { |
279 |
/* (non-Javadoc) |
309 |
Point p = getInitialLocation(DIALOG_SETTINGS_SECTION); |
280 |
* @see org.eclipse.jface.window.Window#getInitialSize() |
310 |
return p != null ? p : super.getInitialLocation(initialSize); |
281 |
*/ |
311 |
} |
282 |
protected Point getInitialSize() { |
312 |
|
283 |
Point p = super.getInitialSize(); |
313 |
/* |
284 |
return getInitialSize(DIALOG_SETTINGS_SECTION, p); |
314 |
* (non-Javadoc) |
285 |
} |
315 |
* |
286 |
|
316 |
* @see org.eclipse.jface.window.Window#getInitialSize() |
287 |
/** |
317 |
*/ |
288 |
* Returns the initial location which is persisted in the Ant UI Plugin dialog settings |
318 |
protected Point getInitialSize() { |
289 |
* under the provided dialog setttings section name. |
319 |
Point p = super.getInitialSize(); |
290 |
* If location is not persisted in the settings, the <code>null</code> is returned. |
320 |
return getInitialSize(DIALOG_SETTINGS_SECTION, p); |
291 |
* |
321 |
} |
292 |
* @param dialogSettingsSectionName The name of the dialog settings section |
322 |
|
293 |
* @return The initial location or <code>null</code> |
323 |
/** |
294 |
*/ |
324 |
* Returns the initial location which is persisted in the Ant UI Plugin |
295 |
public Point getInitialLocation(String dialogSettingsSectionName) { |
325 |
* dialog settings under the provided dialog setttings section name. If |
296 |
IDialogSettings settings = getDialogSettings(dialogSettingsSectionName); |
326 |
* location is not persisted in the settings, the <code>null</code> is |
297 |
try { |
327 |
* returned. |
298 |
int x= settings.getInt(DIALOG_ORIGIN_X); |
328 |
* |
299 |
int y= settings.getInt(DIALOG_ORIGIN_Y); |
329 |
* @param dialogSettingsSectionName |
300 |
return new Point(x,y); |
330 |
* The name of the dialog settings section |
301 |
} catch (NumberFormatException e) { |
331 |
* @return The initial location or <code>null</code> |
302 |
} |
332 |
*/ |
303 |
return null; |
333 |
public Point getInitialLocation(String dialogSettingsSectionName) { |
304 |
} |
334 |
IDialogSettings settings = getDialogSettings(dialogSettingsSectionName); |
305 |
|
335 |
try { |
306 |
private IDialogSettings getDialogSettings(String dialogSettingsSectionName) { |
336 |
int x = settings.getInt(DIALOG_ORIGIN_X); |
307 |
IDialogSettings settings = IDEWorkbenchPlugin.getDefault().getDialogSettings(); |
337 |
int y = settings.getInt(DIALOG_ORIGIN_Y); |
308 |
IDialogSettings section = settings.getSection(dialogSettingsSectionName); |
338 |
return new Point(x, y); |
309 |
if (section == null) { |
339 |
} catch (NumberFormatException e) { |
310 |
section = settings.addNewSection(dialogSettingsSectionName); |
340 |
} |
311 |
} |
341 |
return null; |
312 |
return section; |
342 |
} |
313 |
} |
343 |
|
314 |
|
344 |
private IDialogSettings getDialogSettings(String dialogSettingsSectionName) { |
315 |
/** |
345 |
IDialogSettings settings = IDEWorkbenchPlugin.getDefault() |
316 |
* Persists the location and dimensions of the shell and other user settings in the |
346 |
.getDialogSettings(); |
317 |
* plugin's dialog settings under the provided dialog settings section name |
347 |
IDialogSettings section = settings |
318 |
* |
348 |
.getSection(dialogSettingsSectionName); |
319 |
* @param shell The shell whose geometry is to be stored |
349 |
if (section == null) { |
320 |
* @param dialogSettingsSectionName The name of the dialog settings section |
350 |
section = settings.addNewSection(dialogSettingsSectionName); |
321 |
*/ |
351 |
} |
322 |
private void persistDialogSettings(Shell shell, String dialogSettingsSectionName) { |
352 |
return section; |
323 |
Point shellLocation = shell.getLocation(); |
353 |
} |
324 |
Point shellSize = shell.getSize(); |
354 |
|
325 |
IDialogSettings settings = getDialogSettings(dialogSettingsSectionName); |
355 |
/** |
326 |
settings.put(DIALOG_ORIGIN_X, shellLocation.x); |
356 |
* Persists the location and dimensions of the shell and other user settings |
327 |
settings.put(DIALOG_ORIGIN_Y, shellLocation.y); |
357 |
* in the plugin's dialog settings under the provided dialog settings |
328 |
settings.put(DIALOG_WIDTH, shellSize.x); |
358 |
* section name |
329 |
settings.put(DIALOG_HEIGHT, shellSize.y); |
359 |
* |
330 |
|
360 |
* @param shell |
331 |
if (buildNowButton != null) { |
361 |
* The shell whose geometry is to be stored |
332 |
settings.put(BUILD_NOW, buildNowButton.getSelection()); |
362 |
* @param dialogSettingsSectionName |
333 |
} |
363 |
* The name of the dialog settings section |
334 |
settings.put(TOGGLE_SELECTED, selectedButton.getSelection()); |
364 |
*/ |
335 |
} |
365 |
private void persistDialogSettings(Shell shell, |
336 |
|
366 |
String dialogSettingsSectionName) { |
337 |
/** |
367 |
Point shellLocation = shell.getLocation(); |
338 |
* Returns the initial size which is the larger of the <code>initialSize</code> or |
368 |
Point shellSize = shell.getSize(); |
339 |
* the size persisted in the Ant UI Plugin dialog settings under the provided dialog setttings section name. |
369 |
IDialogSettings settings = getDialogSettings(dialogSettingsSectionName); |
340 |
* If no size is persisted in the settings, the <code>initialSize</code> is returned. |
370 |
settings.put(DIALOG_ORIGIN_X, shellLocation.x); |
341 |
* |
371 |
settings.put(DIALOG_ORIGIN_Y, shellLocation.y); |
342 |
* @param initialSize The initialSize to compare against |
372 |
settings.put(DIALOG_WIDTH, shellSize.x); |
343 |
* @param dialogSettingsSectionName The name of the dialog settings section |
373 |
settings.put(DIALOG_HEIGHT, shellSize.y); |
344 |
* @return the initial size |
374 |
|
345 |
*/ |
375 |
if (buildNowButton != null) { |
346 |
private Point getInitialSize(String dialogSettingsSectionName, Point initialSize) { |
376 |
settings.put(BUILD_NOW, buildNowButton.getSelection()); |
347 |
IDialogSettings settings = getDialogSettings(dialogSettingsSectionName); |
377 |
} |
348 |
try { |
378 |
settings.put(TOGGLE_SELECTED, selectedButton.getSelection()); |
349 |
int x, y; |
379 |
} |
350 |
x = settings.getInt(DIALOG_WIDTH); |
380 |
|
351 |
y = settings.getInt(DIALOG_HEIGHT); |
381 |
/** |
352 |
return new Point(Math.max(x, initialSize.x), Math.max(y, initialSize.y)); |
382 |
* Returns the initial size which is the larger of the |
353 |
} catch (NumberFormatException e) { |
383 |
* <code>initialSize</code> or the size persisted in the Ant UI Plugin |
354 |
} |
384 |
* dialog settings under the provided dialog setttings section name. If no |
355 |
return initialSize; |
385 |
* size is persisted in the settings, the <code>initialSize</code> is |
356 |
} |
386 |
* returned. |
357 |
|
387 |
* |
358 |
/* |
388 |
* @param initialSize |
359 |
* (non-Javadoc) |
389 |
* The initialSize to compare against |
360 |
* @see org.eclipse.jface.dialogs.Dialog#isResizable() |
390 |
* @param dialogSettingsSectionName |
361 |
*/ |
391 |
* The name of the dialog settings section |
362 |
protected boolean isResizable() { |
392 |
* @return the initial size |
363 |
return true; |
393 |
*/ |
364 |
} |
394 |
private Point getInitialSize(String dialogSettingsSectionName, |
|
|
395 |
Point initialSize) { |
396 |
IDialogSettings settings = getDialogSettings(dialogSettingsSectionName); |
397 |
try { |
398 |
int x, y; |
399 |
x = settings.getInt(DIALOG_WIDTH); |
400 |
y = settings.getInt(DIALOG_HEIGHT); |
401 |
return new Point(Math.max(x, initialSize.x), Math.max(y, |
402 |
initialSize.y)); |
403 |
} catch (NumberFormatException e) { |
404 |
} |
405 |
return initialSize; |
406 |
} |
407 |
|
408 |
/* |
409 |
* (non-Javadoc) |
410 |
* |
411 |
* @see org.eclipse.jface.dialogs.Dialog#isResizable() |
412 |
*/ |
413 |
protected boolean isResizable() { |
414 |
return true; |
415 |
} |
365 |
} |
416 |
} |