Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 48966 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/jdt/internal/ui/preferences/formatter/ProfileConfigurationBlock.java (-20 / +71 lines)
Lines 13-18 Link Here
13
import java.io.File;
13
import java.io.File;
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Collection;
15
import java.util.Collection;
16
import java.util.Iterator;
16
import java.util.List;
17
import java.util.List;
17
import java.util.Observable;
18
import java.util.Observable;
18
import java.util.Observer;
19
import java.util.Observer;
Lines 32-37 Link Here
32
import org.eclipse.swt.widgets.Shell;
33
import org.eclipse.swt.widgets.Shell;
33
34
34
import org.eclipse.core.runtime.CoreException;
35
import org.eclipse.core.runtime.CoreException;
36
import org.eclipse.core.runtime.Platform;
37
import org.eclipse.core.runtime.content.IContentType;
35
import org.eclipse.core.runtime.preferences.DefaultScope;
38
import org.eclipse.core.runtime.preferences.DefaultScope;
36
import org.eclipse.core.runtime.preferences.IScopeContext;
39
import org.eclipse.core.runtime.preferences.IScopeContext;
37
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
40
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
Lines 58-63 Link Here
58
import org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.Profile;
61
import org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.Profile;
59
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
62
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
60
import org.eclipse.jdt.internal.ui.util.SWTUtil;
63
import org.eclipse.jdt.internal.ui.util.SWTUtil;
64
import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
61
65
62
66
63
public abstract class ProfileConfigurationBlock {
67
public abstract class ProfileConfigurationBlock {
Lines 146-151 Link Here
146
			fEditButton.addSelectionListener(this);
150
			fEditButton.addSelectionListener(this);
147
			fDeleteButton.addSelectionListener(this);
151
			fDeleteButton.addSelectionListener(this);
148
			fLoadButton.addSelectionListener(this);
152
			fLoadButton.addSelectionListener(this);
153
			fExportAllButton.addSelectionListener(this);
149
			update(fProfileManager, null);
154
			update(fProfileManager, null);
150
		}
155
		}
151
156
Lines 165-170 Link Here
165
				newButtonPressed();
170
				newButtonPressed();
166
			else if (button == fLoadButton)
171
			else if (button == fLoadButton)
167
				loadButtonPressed();
172
				loadButtonPressed();
173
			else if(button == fExportAllButton)
174
				exportAllButtonPressed();
175
		}
176
177
		/**
178
		 * Exports all the profiles to a file.
179
		 * @since 3.6
180
		 */
181
		private void exportAllButtonPressed() {
182
			final FileDialog dialog= new FileDialog(fComposite.getShell(), SWT.SAVE);
183
			dialog.setText(FormatterMessages.CodingStyleConfigurationBlock_export_profiles_dialog_title);
184
			dialog.setFileName("formatterprofiles"); //$NON-NLS-1$
185
			dialog.setFilterExtensions(new String [] {"*.xml"}); //$NON-NLS-1$
186
			final String lastPath= JavaPlugin.getDefault().getDialogSettings().get(fLastSaveLoadPathKey + ".loadpath"); //$NON-NLS-1$
187
			if (lastPath != null) {
188
				dialog.setFilterPath(lastPath);
189
			}
190
			final String path= dialog.open();
191
			if (path == null)
192
				return;
193
194
			JavaPlugin.getDefault().getDialogSettings().put(fLastSaveLoadPathKey + ".savepath", dialog.getFilterPath()); //$NON-NLS-1$
195
196
			final File file= new File(path);
197
			if (file.exists() && !MessageDialog.openQuestion(fComposite.getShell(), FormatterMessages.CodingStyleConfigurationBlock_export_profiles_overwrite_title, Messages.format(FormatterMessages.CodingStyleConfigurationBlock_export_profiles_overwrite_message, BasicElementLabels.getPathLabel(file)))) {
198
				return;
199
			}
200
			String encoding= ProfileStore.ENCODING;
201
			final IContentType type= Platform.getContentTypeManager().getContentType("org.eclipse.core.runtime.xml"); //$NON-NLS-1$
202
			if (type != null)
203
				encoding= type.getDefaultCharset();
204
			final Collection profiles= new ArrayList();
205
			profiles.addAll(fProfileManager.getSortedProfiles());
206
			try {
207
				fProfileStore.writeProfilesToFile(profiles, file, encoding);
208
			} catch (CoreException e) {
209
				final String title= FormatterMessages.CodingStyleConfigurationBlock_export_profiles_error_title;
210
				final String message= FormatterMessages.CodingStyleConfigurationBlock_export_profiles_error_message;
211
				ExceptionHandler.handle(e, fComposite.getShell(), title, message);
212
			}
213
168
		}
214
		}
169
215
170
		public void widgetDefaultSelected(SelectionEvent e) {
216
		public void widgetDefaultSelected(SelectionEvent e) {
Lines 218-246 Link Here
218
			}
264
			}
219
			if (profiles == null || profiles.isEmpty())
265
			if (profiles == null || profiles.isEmpty())
220
				return;
266
				return;
267
			Iterator iter=profiles.iterator();
268
			while (iter.hasNext()) {
269
				final CustomProfile profile= (CustomProfile)iter.next();
270
271
				if (!fProfileVersioner.getProfileKind().equals(profile.getKind())) {
272
					final String title= FormatterMessages.CodingStyleConfigurationBlock_load_profile_error_title;
273
					final String message= Messages.format(FormatterMessages.ProfileConfigurationBlock_load_profile_wrong_profile_message, new String[] { fProfileVersioner.getProfileKind(),
274
							profile.getKind() });
275
					MessageDialog.openError(fComposite.getShell(), title, message);
276
					return;
277
				}
221
278
222
			final CustomProfile profile= (CustomProfile)profiles.iterator().next();
279
				if (profile.getVersion() > fProfileVersioner.getCurrentVersion()) {
223
280
					final String title= FormatterMessages.CodingStyleConfigurationBlock_load_profile_error_too_new_title;
224
			if (!fProfileVersioner.getProfileKind().equals(profile.getKind())) {
281
					final String message= FormatterMessages.CodingStyleConfigurationBlock_load_profile_error_too_new_message;
225
				final String title= FormatterMessages.CodingStyleConfigurationBlock_load_profile_error_title;
282
					MessageDialog.openWarning(fComposite.getShell(), title, message);
226
				final String message= Messages.format(FormatterMessages.ProfileConfigurationBlock_load_profile_wrong_profile_message, new String[] {fProfileVersioner.getProfileKind(), profile.getKind()});
283
				}
227
				MessageDialog.openError(fComposite.getShell(), title, message);
228
				return;
229
			}
230
231
			if (profile.getVersion() > fProfileVersioner.getCurrentVersion()) {
232
				final String title= FormatterMessages.CodingStyleConfigurationBlock_load_profile_error_too_new_title;
233
				final String message= FormatterMessages.CodingStyleConfigurationBlock_load_profile_error_too_new_message;
234
				MessageDialog.openWarning(fComposite.getShell(), title, message);
235
			}
236
284
237
			if (fProfileManager.containsName(profile.getName())) {
285
				if (fProfileManager.containsName(profile.getName())) {
238
				final AlreadyExistsDialog aeDialog= new AlreadyExistsDialog(fComposite.getShell(), profile, fProfileManager);
286
					final AlreadyExistsDialog aeDialog= new AlreadyExistsDialog(fComposite.getShell(), profile, fProfileManager);
239
				if (aeDialog.open() != Window.OK)
287
					if (aeDialog.open() != Window.OK)
240
					return;
288
						return;
289
				}
290
				fProfileVersioner.update(profile);
291
				fProfileManager.addProfile(profile);
241
			}
292
			}
242
			fProfileVersioner.update(profile);
243
			fProfileManager.addProfile(profile);
244
		}
293
		}
245
	}
294
	}
246
295
Lines 253-258 Link Here
253
	private Button fDeleteButton;
302
	private Button fDeleteButton;
254
	private Button fNewButton;
303
	private Button fNewButton;
255
	private Button fLoadButton;
304
	private Button fLoadButton;
305
	private Button fExportAllButton;
256
306
257
	private PixelConverter fPixConv;
307
	private PixelConverter fPixConv;
258
	/**
308
	/**
Lines 365-370 Link Here
365
415
366
		fNewButton= createButton(fComposite, FormatterMessages.CodingStyleConfigurationBlock_new_button_desc, GridData.HORIZONTAL_ALIGN_BEGINNING);
416
		fNewButton= createButton(fComposite, FormatterMessages.CodingStyleConfigurationBlock_new_button_desc, GridData.HORIZONTAL_ALIGN_BEGINNING);
367
		fLoadButton= createButton(fComposite, FormatterMessages.CodingStyleConfigurationBlock_load_button_desc, GridData.HORIZONTAL_ALIGN_END);
417
		fLoadButton= createButton(fComposite, FormatterMessages.CodingStyleConfigurationBlock_load_button_desc, GridData.HORIZONTAL_ALIGN_END);
418
		fExportAllButton= createButton(fComposite, FormatterMessages.CodingStyleConfigurationBlock_export_all_button_desc, GridData.HORIZONTAL_ALIGN_BEGINNING);
368
		createLabel(fComposite, "", 3); //$NON-NLS-1$
419
		createLabel(fComposite, "", 3); //$NON-NLS-1$
369
420
370
		configurePreview(fComposite, numColumns, fProfileManager);
421
		configurePreview(fComposite, numColumns, fProfileManager);
(-)ui/org/eclipse/jdt/internal/ui/preferences/formatter/FormatterMessages.java (-1 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 456-461 Link Here
456
	public static String CodingStyleConfigurationBlock_load_profile_error_too_new_message;
456
	public static String CodingStyleConfigurationBlock_load_profile_error_too_new_message;
457
	public static String CodingStyleConfigurationBlock_save_profile_overwrite_title;
457
	public static String CodingStyleConfigurationBlock_save_profile_overwrite_title;
458
	public static String CodingStyleConfigurationBlock_save_profile_overwrite_message;
458
	public static String CodingStyleConfigurationBlock_save_profile_overwrite_message;
459
	public static String CodingStyleConfigurationBlock_export_all_button_desc;
460
	public static String CodingStyleConfigurationBlock_export_profiles_dialog_title;
461
	public static String CodingStyleConfigurationBlock_export_profiles_error_title;	
462
	public static String CodingStyleConfigurationBlock_export_profiles_error_message;
463
	public static String CodingStyleConfigurationBlock_export_profiles_overwrite_title;
464
	public static String CodingStyleConfigurationBlock_export_profiles_overwrite_message;
459
	public static String CodingStyleConfigurationBlock_edit_button_desc;
465
	public static String CodingStyleConfigurationBlock_edit_button_desc;
460
	public static String CodingStyleConfigurationBlock_remove_button_desc;
466
	public static String CodingStyleConfigurationBlock_remove_button_desc;
461
	public static String CodingStyleConfigurationBlock_new_button_desc;
467
	public static String CodingStyleConfigurationBlock_new_button_desc;
(-)ui/org/eclipse/jdt/internal/ui/preferences/formatter/FormatterMessages.properties (-1 / +7 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2008 IBM Corporation and others.
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 518-523 Link Here
518
that upgrading profiles from older to newer builds is fully supported.
518
that upgrading profiles from older to newer builds is fully supported.
519
CodingStyleConfigurationBlock_save_profile_overwrite_title=Export Profile
519
CodingStyleConfigurationBlock_save_profile_overwrite_title=Export Profile
520
CodingStyleConfigurationBlock_save_profile_overwrite_message=The file ''{0}'' already exists.\nDo you want to replace it?
520
CodingStyleConfigurationBlock_save_profile_overwrite_message=The file ''{0}'' already exists.\nDo you want to replace it?
521
CodingStyleConfigurationBlock_export_all_button_desc=E&xport All...
522
CodingStyleConfigurationBlock_export_profiles_dialog_title= Export Profiles
523
CodingStyleConfigurationBlock_export_profiles_error_title=Export Profiles
524
CodingStyleConfigurationBlock_export_profiles_error_message=Could not export the profiles.
525
CodingStyleConfigurationBlock_export_profiles_overwrite_title= Export Profiles
526
CodingStyleConfigurationBlock_export_profiles_overwrite_message=The file ''{0}'' already exists.\nDo you want to replace it?
521
CodingStyleConfigurationBlock_edit_button_desc=&Edit...
527
CodingStyleConfigurationBlock_edit_button_desc=&Edit...
522
CodingStyleConfigurationBlock_remove_button_desc=&Remove
528
CodingStyleConfigurationBlock_remove_button_desc=&Remove
523
CodingStyleConfigurationBlock_new_button_desc=Ne&w...
529
CodingStyleConfigurationBlock_new_button_desc=Ne&w...

Return to bug 48966