|
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); |