Update MANIFEST.MF, replaced deprecated Provide-Package with Export-Package.
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpdt / internal / ui / preferences / CodeTemplateBlock.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.preferences;
12
13 import java.io.BufferedInputStream;
14 import java.io.BufferedOutputStream;
15 import java.io.File;
16 import java.io.FileInputStream;
17 import java.io.FileNotFoundException;
18 import java.io.FileOutputStream;
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.io.OutputStream;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.List;
25
26 import net.sourceforge.phpdt.internal.corext.template.php.CodeTemplateContextType;
27 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
28 import net.sourceforge.phpdt.internal.ui.text.template.preferences.TemplateVariableProcessor;
29 import net.sourceforge.phpdt.internal.ui.util.PixelConverter;
30 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.DialogField;
31 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
32 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.ITreeListAdapter;
33 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.LayoutUtil;
34 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
35 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.TreeListDialogField;
36 import net.sourceforge.phpdt.ui.PreferenceConstants;
37 import net.sourceforge.phpdt.ui.text.JavaTextTools;
38 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
39 import net.sourceforge.phpeclipse.phpeditor.JavaSourceViewer;
40 import net.sourceforge.phpeclipse.ui.WebUI;
41
42 import org.eclipse.jface.dialogs.MessageDialog;
43 import org.eclipse.jface.preference.IPreferenceStore;
44 import org.eclipse.jface.resource.JFaceResources;
45 import org.eclipse.jface.text.Document;
46 import org.eclipse.jface.text.IDocument;
47 import org.eclipse.jface.text.source.SourceViewer;
48 import org.eclipse.jface.text.templates.Template;
49 import org.eclipse.jface.text.templates.TemplateContextType;
50 import org.eclipse.jface.text.templates.persistence.TemplatePersistenceData;
51 import org.eclipse.jface.text.templates.persistence.TemplateReaderWriter;
52 import org.eclipse.jface.text.templates.persistence.TemplateStore;
53 import org.eclipse.jface.viewers.LabelProvider;
54 import org.eclipse.jface.viewers.StructuredSelection;
55 import org.eclipse.jface.window.Window;
56 import org.eclipse.swt.SWT;
57 import org.eclipse.swt.events.KeyEvent;
58 import org.eclipse.swt.graphics.Font;
59 import org.eclipse.swt.graphics.Image;
60 import org.eclipse.swt.layout.GridData;
61 import org.eclipse.swt.layout.GridLayout;
62 import org.eclipse.swt.widgets.Composite;
63 import org.eclipse.swt.widgets.Control;
64 import org.eclipse.swt.widgets.FileDialog;
65 import org.eclipse.swt.widgets.Label;
66 import org.eclipse.swt.widgets.Shell;
67
68 /**
69  */
70 public class CodeTemplateBlock {
71
72         private class CodeTemplateAdapter implements ITreeListAdapter,
73                         IDialogFieldListener {
74
75                 private final Object[] NO_CHILDREN = new Object[0];
76
77                 public void customButtonPressed(TreeListDialogField field, int index) {
78                         doButtonPressed(index, field.getSelectedElements());
79                 }
80
81                 public void selectionChanged(TreeListDialogField field) {
82                         List selected = field.getSelectedElements();
83                         field.enableButton(IDX_EDIT, canEdit(selected));
84                         field.enableButton(IDX_EXPORT, !selected.isEmpty());
85
86                         updateSourceViewerInput(selected);
87                 }
88
89                 public void doubleClicked(TreeListDialogField field) {
90                         List selected = field.getSelectedElements();
91                         if (canEdit(selected)) {
92                                 doButtonPressed(IDX_EDIT, selected);
93                         }
94                 }
95
96                 public Object[] getChildren(TreeListDialogField field, Object element) {
97                         if (element == COMMENT_NODE || element == CODE_NODE) {
98                                 return getTemplateOfCategory(element == COMMENT_NODE);
99                         }
100                         return NO_CHILDREN;
101                 }
102
103                 public Object getParent(TreeListDialogField field, Object element) {
104                         if (element instanceof TemplatePersistenceData) {
105                                 TemplatePersistenceData data = (TemplatePersistenceData) element;
106                                 if (data.getTemplate().getName().endsWith(
107                                                 CodeTemplateContextType.COMMENT_SUFFIX)) {
108                                         return COMMENT_NODE;
109                                 }
110                                 return CODE_NODE;
111                         }
112                         return null;
113                 }
114
115                 public boolean hasChildren(TreeListDialogField field, Object element) {
116                         return (element == COMMENT_NODE || element == CODE_NODE);
117                 }
118
119                 public void dialogFieldChanged(DialogField field) {
120                 }
121
122                 public void keyPressed(TreeListDialogField field, KeyEvent event) {
123                 }
124
125         }
126
127         private static class CodeTemplateLabelProvider extends LabelProvider {
128
129                 /*
130                  * (non-Javadoc)
131                  * 
132                  * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
133                  */
134                 public Image getImage(Object element) {
135                         return null;
136
137                 }
138
139                 /*
140                  * (non-Javadoc)
141                  * 
142                  * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
143                  */
144                 public String getText(Object element) {
145                         if (element == COMMENT_NODE || element == CODE_NODE) {
146                                 return (String) element;
147                         }
148                         TemplatePersistenceData data = (TemplatePersistenceData) element;
149                         Template template = data.getTemplate();
150                         String name = template.getName();
151                         if (CodeTemplateContextType.CATCHBLOCK.equals(name)) {
152                                 return PreferencesMessages
153                                                 .getString("CodeTemplateBlock.catchblock.label"); //$NON-NLS-1$
154                         } else if (CodeTemplateContextType.METHODSTUB.equals(name)) {
155                                 return PreferencesMessages
156                                                 .getString("CodeTemplateBlock.methodstub.label"); //$NON-NLS-1$
157                         } else if (CodeTemplateContextType.CONSTRUCTORSTUB.equals(name)) {
158                                 return PreferencesMessages
159                                                 .getString("CodeTemplateBlock.constructorstub.label"); //$NON-NLS-1$
160                         } else if (CodeTemplateContextType.GETTERSTUB.equals(name)) {
161                                 return PreferencesMessages
162                                                 .getString("CodeTemplateBlock.getterstub.label"); //$NON-NLS-1$
163                         } else if (CodeTemplateContextType.SETTERSTUB.equals(name)) {
164                                 return PreferencesMessages
165                                                 .getString("CodeTemplateBlock.setterstub.label"); //$NON-NLS-1$
166                         } else if (CodeTemplateContextType.NEWTYPE.equals(name)) {
167                                 return PreferencesMessages
168                                                 .getString("CodeTemplateBlock.newtype.label"); //$NON-NLS-1$
169                         } else if (CodeTemplateContextType.TYPECOMMENT.equals(name)) {
170                                 return PreferencesMessages
171                                                 .getString("CodeTemplateBlock.typecomment.label"); //$NON-NLS-1$
172                         } else if (CodeTemplateContextType.FIELDCOMMENT.equals(name)) {
173                                 return PreferencesMessages
174                                                 .getString("CodeTemplateBlock.fieldcomment.label"); //$NON-NLS-1$
175                         } else if (CodeTemplateContextType.METHODCOMMENT.equals(name)) {
176                                 return PreferencesMessages
177                                                 .getString("CodeTemplateBlock.methodcomment.label"); //$NON-NLS-1$
178                         } else if (CodeTemplateContextType.OVERRIDECOMMENT.equals(name)) {
179                                 return PreferencesMessages
180                                                 .getString("CodeTemplateBlock.overridecomment.label"); //$NON-NLS-1$
181                         } else if (CodeTemplateContextType.CONSTRUCTORCOMMENT.equals(name)) {
182                                 return PreferencesMessages
183                                                 .getString("CodeTemplateBlock.constructorcomment.label"); //$NON-NLS-1$
184                         } else if (CodeTemplateContextType.GETTERCOMMENT.equals(name)) {
185                                 return PreferencesMessages
186                                                 .getString("CodeTemplateBlock.gettercomment.label"); //$NON-NLS-1$
187                         } else if (CodeTemplateContextType.SETTERCOMMENT.equals(name)) {
188                                 return PreferencesMessages
189                                                 .getString("CodeTemplateBlock.settercomment.label"); //$NON-NLS-1$
190                         }
191                         return template.getDescription();
192                 }
193
194         }
195
196         private final static int IDX_EDIT = 0;
197
198         private final static int IDX_IMPORT = 2;
199
200         private final static int IDX_EXPORT = 3;
201
202         private final static int IDX_EXPORTALL = 4;
203
204         protected final static Object COMMENT_NODE = PreferencesMessages
205                         .getString("CodeTemplateBlock.templates.comment.node"); //$NON-NLS-1$
206
207         protected final static Object CODE_NODE = PreferencesMessages
208                         .getString("CodeTemplateBlock.templates.code.node"); //$NON-NLS-1$
209
210         private static final String PREF_JAVADOC_STUBS = PreferenceConstants.CODEGEN_ADD_COMMENTS;
211
212         private TreeListDialogField fCodeTemplateTree;
213
214         private SelectionButtonDialogField fCreateJavaDocComments;
215
216         protected TemplateStore fTemplates;
217
218         private PixelConverter fPixelConverter;
219
220         private SourceViewer fPatternViewer;
221
222         private Control fSWTWidget;
223
224         private TemplateVariableProcessor fTemplateProcessor;
225
226         public CodeTemplateBlock() {
227
228                 fTemplates = WebUI.getDefault().getCodeTemplateStore();
229                 fTemplateProcessor = new TemplateVariableProcessor();
230
231                 CodeTemplateAdapter adapter = new CodeTemplateAdapter();
232
233                 String[] buttonLabels = new String[] {
234                                 /* IDX_EDIT */PreferencesMessages
235                                                 .getString("CodeTemplateBlock.templates.edit.button"), //$NON-NLS-1$
236                                 /* */null,
237                                 /* IDX_IMPORT */PreferencesMessages
238                                                 .getString("CodeTemplateBlock.templates.import.button"), //$NON-NLS-1$
239                                 /* IDX_EXPORT */PreferencesMessages
240                                                 .getString("CodeTemplateBlock.templates.export.button"), //$NON-NLS-1$
241                                 /* IDX_EXPORTALL */PreferencesMessages
242                                                 .getString("CodeTemplateBlock.templates.exportall.button") //$NON-NLS-1$
243
244                 };
245                 fCodeTemplateTree = new TreeListDialogField(adapter, buttonLabels,
246                                 new CodeTemplateLabelProvider());
247                 fCodeTemplateTree.setDialogFieldListener(adapter);
248                 fCodeTemplateTree.setLabelText(PreferencesMessages
249                                 .getString("CodeTemplateBlock.templates.label")); //$NON-NLS-1$
250
251                 fCodeTemplateTree.enableButton(IDX_EXPORT, false);
252                 fCodeTemplateTree.enableButton(IDX_EDIT, false);
253
254                 fCodeTemplateTree.addElement(COMMENT_NODE);
255                 fCodeTemplateTree.addElement(CODE_NODE);
256
257                 fCreateJavaDocComments = new SelectionButtonDialogField(SWT.CHECK
258                                 | SWT.WRAP);
259                 fCreateJavaDocComments.setLabelText(PreferencesMessages
260                                 .getString("CodeTemplateBlock.createcomment.label")); //$NON-NLS-1$
261                 fCreateJavaDocComments.setSelection(PreferenceConstants
262                                 .getPreferenceStore().getBoolean(PREF_JAVADOC_STUBS));
263
264                 fCodeTemplateTree.selectFirstElement();
265         }
266
267         protected Control createContents(Composite parent) {
268                 fPixelConverter = new PixelConverter(parent);
269                 fSWTWidget = parent;
270
271                 Composite composite = new Composite(parent, SWT.NONE);
272                 GridLayout layout = new GridLayout();
273                 layout.marginHeight = 0;
274                 layout.marginWidth = 0;
275                 layout.numColumns = 2;
276                 composite.setLayout(layout);
277
278                 fCodeTemplateTree.doFillIntoGrid(composite, 3);
279                 LayoutUtil
280                                 .setHorizontalSpan(fCodeTemplateTree.getLabelControl(null), 2);
281                 LayoutUtil
282                                 .setHorizontalGrabbing(fCodeTemplateTree.getTreeControl(null));
283
284                 fPatternViewer = createViewer(composite, 2);
285
286                 fCreateJavaDocComments.doFillIntoGrid(composite, 2);
287
288                 DialogField label = new DialogField();
289                 label.setLabelText(PreferencesMessages
290                                 .getString("CodeTemplateBlock.createcomment.description")); //$NON-NLS-1$
291                 label.doFillIntoGrid(composite, 2);
292
293                 return composite;
294
295         }
296
297         private Shell getShell() {
298                 if (fSWTWidget != null) {
299                         return fSWTWidget.getShell();
300                 }
301                 return WebUI.getActiveWorkbenchShell();
302         }
303
304         private SourceViewer createViewer(Composite parent, int nColumns) {
305                 Label label = new Label(parent, SWT.NONE);
306                 label.setText(PreferencesMessages
307                                 .getString("CodeTemplateBlock.preview")); //$NON-NLS-1$
308                 GridData data = new GridData();
309                 data.horizontalSpan = nColumns;
310                 label.setLayoutData(data);
311
312                 IDocument document = new Document();
313                 JavaTextTools tools = WebUI.getDefault().getJavaTextTools();
314                 tools.setupJavaDocumentPartitioner(document,
315                                 IPHPPartitions.PHP_PARTITIONING);
316                 IPreferenceStore store = WebUI.getDefault()
317                                 .getCombinedPreferenceStore();
318                 SourceViewer viewer = new JavaSourceViewer(parent, null, null, false,
319                                 SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store);
320                 TemplateEditorSourceViewerConfiguration configuration = new TemplateEditorSourceViewerConfiguration(
321                                 tools.getColorManager(), store, null, fTemplateProcessor);
322                 viewer.configure(configuration);
323                 viewer.setEditable(false);
324                 viewer.setDocument(document);
325
326                 Font font = JFaceResources
327                                 .getFont(PreferenceConstants.EDITOR_TEXT_FONT);
328                 viewer.getTextWidget().setFont(font);
329                 new JavaSourcePreviewerUpdater(viewer, configuration, store);
330
331                 Control control = viewer.getControl();
332                 data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
333                                 | GridData.FILL_VERTICAL);
334                 data.horizontalSpan = nColumns;
335                 data.heightHint = fPixelConverter.convertHeightInCharsToPixels(5);
336                 control.setLayoutData(data);
337
338                 return viewer;
339         }
340
341         protected TemplatePersistenceData[] getTemplateOfCategory(boolean isComment) {
342                 ArrayList res = new ArrayList();
343                 TemplatePersistenceData[] templates = fTemplates.getTemplateData(false);
344                 for (int i = 0; i < templates.length; i++) {
345                         TemplatePersistenceData curr = templates[i];
346                         if (isComment == curr.getTemplate().getName().endsWith(
347                                         CodeTemplateContextType.COMMENT_SUFFIX)) {
348                                 res.add(curr);
349                         }
350                 }
351                 return (TemplatePersistenceData[]) res
352                                 .toArray(new TemplatePersistenceData[res.size()]);
353         }
354
355         protected static boolean canEdit(List selected) {
356                 return selected.size() == 1
357                                 && (selected.get(0) instanceof TemplatePersistenceData);
358         }
359
360         protected void updateSourceViewerInput(List selection) {
361                 if (fPatternViewer == null
362                                 || fPatternViewer.getTextWidget().isDisposed()) {
363                         return;
364                 }
365                 if (selection.size() == 1
366                                 && selection.get(0) instanceof TemplatePersistenceData) {
367                         TemplatePersistenceData data = (TemplatePersistenceData) selection
368                                         .get(0);
369                         Template template = data.getTemplate();
370                         TemplateContextType type = WebUI.getDefault()
371                                         .getCodeTemplateContextRegistry().getContextType(
372                                                         template.getContextTypeId());
373                         fTemplateProcessor.setContextType(type);
374                         fPatternViewer.getDocument().set(template.getPattern());
375                 } else {
376                         fPatternViewer.getDocument().set(""); //$NON-NLS-1$
377                 }
378         }
379
380         protected void doButtonPressed(int buttonIndex, List selected) {
381                 if (buttonIndex == IDX_EDIT) {
382                         edit((TemplatePersistenceData) selected.get(0));
383                 } else if (buttonIndex == IDX_EXPORT) {
384                         export(selected);
385                 } else if (buttonIndex == IDX_EXPORTALL) {
386                         exportAll();
387                 } else if (buttonIndex == IDX_IMPORT) {
388                         import_();
389                 }
390         }
391
392         private void edit(TemplatePersistenceData data) {
393                 Template newTemplate = new Template(data.getTemplate());
394                 EditTemplateDialog dialog = new EditTemplateDialog(getShell(),
395                                 newTemplate, true, false, WebUI.getDefault()
396                                                 .getCodeTemplateContextRegistry());
397                 if (dialog.open() == Window.OK) {
398                         // changed
399                         data.setTemplate(newTemplate);
400                         fCodeTemplateTree.refresh(data);
401                         fCodeTemplateTree.selectElements(new StructuredSelection(data));
402                 }
403         }
404
405         private void import_() {
406                 FileDialog dialog = new FileDialog(getShell());
407                 dialog.setText(PreferencesMessages
408                                 .getString("CodeTemplateBlock.import.title")); //$NON-NLS-1$
409                 dialog.setFilterExtensions(new String[] { PreferencesMessages
410                                 .getString("CodeTemplateBlock.import.extension") }); //$NON-NLS-1$
411                 String path = dialog.open();
412
413                 if (path == null)
414                         return;
415
416                 try {
417                         TemplateReaderWriter reader = new TemplateReaderWriter();
418                         File file = new File(path);
419                         if (file.exists()) {
420                                 InputStream input = new BufferedInputStream(
421                                                 new FileInputStream(file));
422                                 TemplatePersistenceData[] datas = reader.read(input, null);
423                                 for (int i = 0; i < datas.length; i++) {
424                                         updateTemplate(datas[i]);
425                                 }
426                         }
427
428                         fCodeTemplateTree.refresh();
429                         updateSourceViewerInput(fCodeTemplateTree.getSelectedElements());
430
431                 } catch (FileNotFoundException e) {
432                         openReadErrorDialog(e);
433                 } catch (IOException e) {
434                         openReadErrorDialog(e);
435                 }
436
437         }
438
439         private void updateTemplate(TemplatePersistenceData data) {
440                 TemplatePersistenceData[] datas = fTemplates.getTemplateData(true);
441                 for (int i = 0; i < datas.length; i++) {
442                         String id = datas[i].getId();
443                         if (id != null && id.equals(data.getId())) {
444                                 datas[i].setTemplate(data.getTemplate());
445                                 break;
446                         }
447                 }
448         }
449
450         private void exportAll() {
451                 export(fTemplates.getTemplateData(false));
452         }
453
454         private void export(List selected) {
455                 List datas = new ArrayList();
456                 for (int i = 0; i < selected.size(); i++) {
457                         Object curr = selected.get(i);
458                         if (curr instanceof TemplatePersistenceData) {
459                                 datas.add(curr);
460                         } else {
461                                 TemplatePersistenceData[] cat = getTemplateOfCategory(curr == COMMENT_NODE);
462                                 datas.addAll(Arrays.asList(cat));
463                         }
464                 }
465                 export((TemplatePersistenceData[]) datas
466                                 .toArray(new TemplatePersistenceData[datas.size()]));
467         }
468
469         private void export(TemplatePersistenceData[] templates) {
470                 FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
471                 dialog
472                                 .setText(PreferencesMessages
473                                                 .getFormattedString(
474                                                                 "CodeTemplateBlock.export.title", String.valueOf(templates.length))); //$NON-NLS-1$
475                 dialog.setFilterExtensions(new String[] { PreferencesMessages
476                                 .getString("CodeTemplateBlock.export.extension") }); //$NON-NLS-1$
477                 dialog.setFileName(PreferencesMessages
478                                 .getString("CodeTemplateBlock.export.filename")); //$NON-NLS-1$
479                 String path = dialog.open();
480
481                 if (path == null)
482                         return;
483
484                 File file = new File(path);
485
486                 if (file.isHidden()) {
487                         String title = PreferencesMessages
488                                         .getString("CodeTemplateBlock.export.error.title"); //$NON-NLS-1$ 
489                         String message = PreferencesMessages
490                                         .getFormattedString(
491                                                         "CodeTemplateBlock.export.error.hidden", file.getAbsolutePath()); //$NON-NLS-1$
492                         MessageDialog.openError(getShell(), title, message);
493                         return;
494                 }
495
496                 if (file.exists() && !file.canWrite()) {
497                         String title = PreferencesMessages
498                                         .getString("CodeTemplateBlock.export.error.title"); //$NON-NLS-1$
499                         String message = PreferencesMessages
500                                         .getFormattedString(
501                                                         "CodeTemplateBlock.export.error.canNotWrite", file.getAbsolutePath()); //$NON-NLS-1$
502                         MessageDialog.openError(getShell(), title, message);
503                         return;
504                 }
505
506                 if (!file.exists() || confirmOverwrite(file)) {
507                         try {
508                                 OutputStream output = new BufferedOutputStream(
509                                                 new FileOutputStream(file));
510                                 TemplateReaderWriter writer = new TemplateReaderWriter();
511                                 writer.save(templates, output);
512                         } catch (IOException e) {
513                                 openWriteErrorDialog(e);
514                         }
515                 }
516
517         }
518
519         private boolean confirmOverwrite(File file) {
520                 return MessageDialog
521                                 .openQuestion(
522                                                 getShell(),
523                                                 PreferencesMessages
524                                                                 .getString("CodeTemplateBlock.export.exists.title"), //$NON-NLS-1$
525                                                 PreferencesMessages
526                                                                 .getFormattedString(
527                                                                                 "CodeTemplateBlock.export.exists.message", file.getAbsolutePath())); //$NON-NLS-1$
528         }
529
530         public void performDefaults() {
531                 IPreferenceStore prefs = WebUI.getDefault()
532                                 .getPreferenceStore();
533                 fCreateJavaDocComments.setSelection(prefs
534                                 .getDefaultBoolean(PREF_JAVADOC_STUBS));
535
536                 fTemplates.restoreDefaults();
537
538                 // refresh
539                 fCodeTemplateTree.refresh();
540                 updateSourceViewerInput(fCodeTemplateTree.getSelectedElements());
541         }
542
543         public boolean performOk(boolean enabled) {
544                 IPreferenceStore prefs = PreferenceConstants.getPreferenceStore();
545                 prefs.setValue(PREF_JAVADOC_STUBS, fCreateJavaDocComments.isSelected());
546                 WebUI.getDefault().savePluginPreferences();
547
548                 try {
549                         fTemplates.save();
550                 } catch (IOException e) {
551                         WebUI.log(e);
552                         openWriteErrorDialog(e);
553                 }
554                 return true;
555         }
556
557         public void performCancel() {
558                 try {
559                         fTemplates.load();
560                 } catch (IOException e) {
561                         openReadErrorDialog(e);
562                 }
563         }
564
565         private void openReadErrorDialog(Exception e) {
566                 String title = PreferencesMessages
567                                 .getString("CodeTemplateBlock.error.read.title"); //$NON-NLS-1$
568
569                 String message = e.getLocalizedMessage();
570                 if (message != null)
571                         message = PreferencesMessages.getFormattedString(
572                                         "CodeTemplateBlock.error.parse.message", message); //$NON-NLS-1$
573                 else
574                         message = PreferencesMessages
575                                         .getString("CodeTemplateBlock.error.read.message"); //$NON-NLS-1$
576                 MessageDialog.openError(getShell(), title, message);
577         }
578
579         private void openWriteErrorDialog(Exception e) {
580                 String title = PreferencesMessages
581                                 .getString("CodeTemplateBlock.error.write.title"); //$NON-NLS-1$
582                 String message = PreferencesMessages
583                                 .getString("CodeTemplateBlock.error.write.message"); //$NON-NLS-1$
584                 MessageDialog.openError(getShell(), title, message);
585         }
586
587 }