001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.preferences;
011:
012: import java.util.ArrayList;
013: import java.util.HashMap;
014: import java.util.Iterator;
015: import java.util.List;
016: import java.util.Map;
017:
018: import org.eclipse.swt.SWT;
019: import org.eclipse.swt.custom.StyledText;
020: import org.eclipse.swt.custom.VerifyKeyListener;
021: import org.eclipse.swt.events.FocusEvent;
022: import org.eclipse.swt.events.FocusListener;
023: import org.eclipse.swt.events.ModifyEvent;
024: import org.eclipse.swt.events.ModifyListener;
025: import org.eclipse.swt.events.SelectionEvent;
026: import org.eclipse.swt.events.SelectionListener;
027: import org.eclipse.swt.events.VerifyEvent;
028: import org.eclipse.swt.graphics.Font;
029: import org.eclipse.swt.layout.GridData;
030: import org.eclipse.swt.layout.GridLayout;
031: import org.eclipse.swt.widgets.Button;
032: import org.eclipse.swt.widgets.Combo;
033: import org.eclipse.swt.widgets.Composite;
034: import org.eclipse.swt.widgets.Control;
035: import org.eclipse.swt.widgets.Label;
036: import org.eclipse.swt.widgets.Menu;
037: import org.eclipse.swt.widgets.Shell;
038: import org.eclipse.swt.widgets.Text;
039: import org.eclipse.swt.widgets.Widget;
040:
041: import org.eclipse.jface.action.Action;
042: import org.eclipse.jface.action.GroupMarker;
043: import org.eclipse.jface.action.IAction;
044: import org.eclipse.jface.action.IMenuListener;
045: import org.eclipse.jface.action.IMenuManager;
046: import org.eclipse.jface.action.MenuManager;
047: import org.eclipse.jface.action.Separator;
048: import org.eclipse.jface.dialogs.IDialogConstants;
049: import org.eclipse.jface.dialogs.IDialogSettings;
050: import org.eclipse.jface.dialogs.StatusDialog;
051: import org.eclipse.jface.preference.IPreferenceStore;
052: import org.eclipse.jface.resource.JFaceResources;
053: import org.eclipse.jface.viewers.ISelectionChangedListener;
054: import org.eclipse.jface.viewers.SelectionChangedEvent;
055:
056: import org.eclipse.jface.text.BadLocationException;
057: import org.eclipse.jface.text.Document;
058: import org.eclipse.jface.text.IDocument;
059: import org.eclipse.jface.text.IRegion;
060: import org.eclipse.jface.text.ITextListener;
061: import org.eclipse.jface.text.ITextOperationTarget;
062: import org.eclipse.jface.text.ITextViewer;
063: import org.eclipse.jface.text.TextEvent;
064: import org.eclipse.jface.text.source.ISourceViewer;
065: import org.eclipse.jface.text.source.SourceViewer;
066: import org.eclipse.jface.text.templates.ContextTypeRegistry;
067: import org.eclipse.jface.text.templates.Template;
068: import org.eclipse.jface.text.templates.TemplateContextType;
069: import org.eclipse.jface.text.templates.TemplateException;
070:
071: import org.eclipse.ui.PlatformUI;
072: import org.eclipse.ui.texteditor.ITextEditorActionConstants;
073: import org.eclipse.ui.texteditor.IUpdate;
074:
075: import org.eclipse.jdt.internal.corext.template.java.JavaDocContextType;
076:
077: import org.eclipse.jdt.ui.IContextMenuConstants;
078: import org.eclipse.jdt.ui.PreferenceConstants;
079: import org.eclipse.jdt.ui.text.IJavaPartitions;
080: import org.eclipse.jdt.ui.text.JavaTextTools;
081:
082: import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
083: import org.eclipse.jdt.internal.ui.JavaPlugin;
084: import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
085: import org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer;
086: import org.eclipse.jdt.internal.ui.text.template.preferences.TemplateVariableProcessor;
087:
088: /**
089: * Dialog to edit a template.
090: */
091: class EditTemplateDialog extends StatusDialog {
092:
093: private static class TextViewerAction extends Action implements
094: IUpdate {
095:
096: private int fOperationCode = -1;
097: private ITextOperationTarget fOperationTarget;
098:
099: /**
100: * Creates a new action.
101: *
102: * @param viewer the viewer
103: * @param operationCode the opcode
104: */
105: public TextViewerAction(ITextViewer viewer, int operationCode) {
106: fOperationCode = operationCode;
107: fOperationTarget = viewer.getTextOperationTarget();
108: update();
109: }
110:
111: /**
112: * Updates the enabled state of the action.
113: * Fires a property change if the enabled state changes.
114: *
115: * @see Action#firePropertyChange(String, Object, Object)
116: */
117: public void update() {
118:
119: boolean wasEnabled = isEnabled();
120: boolean isEnabled = (fOperationTarget != null && fOperationTarget
121: .canDoOperation(fOperationCode));
122: setEnabled(isEnabled);
123:
124: if (wasEnabled != isEnabled) {
125: firePropertyChange(ENABLED, wasEnabled ? Boolean.TRUE
126: : Boolean.FALSE, isEnabled ? Boolean.TRUE
127: : Boolean.FALSE);
128: }
129: }
130:
131: /**
132: * @see Action#run()
133: */
134: public void run() {
135: if (fOperationCode != -1 && fOperationTarget != null) {
136: fOperationTarget.doOperation(fOperationCode);
137: }
138: }
139: }
140:
141: private Template fTemplate;
142:
143: private Text fNameText;
144: private Text fDescriptionText;
145: private Combo fContextCombo;
146: private SourceViewer fPatternEditor;
147: private Button fInsertVariableButton;
148: private Button fAutoInsertCheckbox;
149: private boolean fIsNameModifiable;
150:
151: private StatusInfo fValidationStatus;
152: private boolean fSuppressError = true; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=4354
153: private Map fGlobalActions = new HashMap(10);
154: private List fSelectionActions = new ArrayList(3);
155: private String[][] fContextTypes;
156:
157: private ContextTypeRegistry fContextTypeRegistry;
158:
159: private final TemplateVariableProcessor fTemplateProcessor = new TemplateVariableProcessor();
160:
161: /**
162: * Creates a new dialog.
163: *
164: * @param parent the shell parent of the dialog
165: * @param template the template to edit
166: * @param edit whether this is a new template or an existing being edited
167: * @param isNameModifiable whether the name of the template may be modified
168: * @param registry the context type registry to use
169: */
170: public EditTemplateDialog(Shell parent, Template template,
171: boolean edit, boolean isNameModifiable,
172: ContextTypeRegistry registry) {
173: super (parent);
174:
175: setShellStyle(getShellStyle() | SWT.MAX | SWT.RESIZE);
176:
177: String title = edit ? PreferencesMessages.EditTemplateDialog_title_edit
178: : PreferencesMessages.EditTemplateDialog_title_new;
179: setTitle(title);
180:
181: fTemplate = template;
182: fIsNameModifiable = isNameModifiable;
183:
184: String delim = new Document().getLegalLineDelimiters()[0];
185:
186: List contexts = new ArrayList();
187: for (Iterator it = registry.contextTypes(); it.hasNext();) {
188: TemplateContextType type = (TemplateContextType) it.next();
189: if (type.getId().equals("javadoc")) //$NON-NLS-1$
190: contexts.add(new String[] { type.getId(),
191: type.getName(), "/**" + delim }); //$NON-NLS-1$
192: else
193: contexts.add(0, new String[] { type.getId(),
194: type.getName(), "" }); //$NON-NLS-1$
195: }
196: fContextTypes = (String[][]) contexts
197: .toArray(new String[contexts.size()][]);
198:
199: fValidationStatus = new StatusInfo();
200:
201: fContextTypeRegistry = registry;
202:
203: TemplateContextType type = fContextTypeRegistry
204: .getContextType(template.getContextTypeId());
205: fTemplateProcessor.setContextType(type);
206: }
207:
208: /*
209: * @see org.eclipse.jdt.internal.ui.dialogs.StatusDialog#create()
210: */
211: public void create() {
212: super .create();
213: updateStatusAndButtons();
214: getButton(IDialogConstants.OK_ID)
215: .setEnabled(getStatus().isOK());
216: }
217:
218: /*
219: * @see Dialog#createDialogArea(Composite)
220: */
221: protected Control createDialogArea(Composite ancestor) {
222: Composite parent = new Composite(ancestor, SWT.NONE);
223: GridLayout layout = new GridLayout();
224: layout.numColumns = 2;
225: parent.setLayout(layout);
226: parent.setLayoutData(new GridData(GridData.FILL_BOTH));
227:
228: ModifyListener listener = new ModifyListener() {
229: public void modifyText(ModifyEvent e) {
230: doTextWidgetChanged(e.widget);
231: }
232: };
233:
234: if (fIsNameModifiable) {
235: createLabel(parent,
236: PreferencesMessages.EditTemplateDialog_name);
237:
238: Composite composite = new Composite(parent, SWT.NONE);
239: composite.setLayoutData(new GridData(
240: GridData.FILL_HORIZONTAL));
241: layout = new GridLayout();
242: layout.numColumns = 4;
243: layout.marginWidth = 0;
244: layout.marginHeight = 0;
245: composite.setLayout(layout);
246:
247: fNameText = createText(composite);
248: fNameText.addFocusListener(new FocusListener() {
249:
250: public void focusGained(FocusEvent e) {
251: }
252:
253: public void focusLost(FocusEvent e) {
254: if (fSuppressError) {
255: fSuppressError = false;
256: updateStatusAndButtons();
257: }
258: }
259: });
260:
261: createLabel(composite,
262: PreferencesMessages.EditTemplateDialog_context);
263: fContextCombo = new Combo(composite, SWT.READ_ONLY);
264:
265: for (int i = 0; i < fContextTypes.length; i++) {
266: fContextCombo.add(fContextTypes[i][1]);
267: }
268:
269: fContextCombo.addModifyListener(listener);
270:
271: fAutoInsertCheckbox = createCheckbox(composite,
272: PreferencesMessages.EditTemplateDialog_autoinsert);
273: fAutoInsertCheckbox.setSelection(fTemplate
274: .isAutoInsertable());
275: }
276:
277: createLabel(parent,
278: PreferencesMessages.EditTemplateDialog_description);
279:
280: int descFlags = fIsNameModifiable ? SWT.BORDER : SWT.BORDER
281: | SWT.READ_ONLY;
282: fDescriptionText = new Text(parent, descFlags);
283: fDescriptionText.setLayoutData(new GridData(
284: GridData.FILL_HORIZONTAL));
285:
286: fDescriptionText.addModifyListener(listener);
287:
288: Label patternLabel = createLabel(parent,
289: PreferencesMessages.EditTemplateDialog_pattern);
290: patternLabel.setLayoutData(new GridData(
291: GridData.VERTICAL_ALIGN_BEGINNING));
292: fPatternEditor = createEditor(parent);
293:
294: Label filler = new Label(parent, SWT.NONE);
295: filler.setLayoutData(new GridData());
296:
297: Composite composite = new Composite(parent, SWT.NONE);
298: layout = new GridLayout();
299: layout.marginWidth = 0;
300: layout.marginHeight = 0;
301: composite.setLayout(layout);
302: composite.setLayoutData(new GridData());
303:
304: fInsertVariableButton = new Button(composite, SWT.NONE);
305: fInsertVariableButton.setLayoutData(getButtonGridData());
306: fInsertVariableButton
307: .setText(PreferencesMessages.EditTemplateDialog_insert_variable);
308: fInsertVariableButton
309: .addSelectionListener(new SelectionListener() {
310: public void widgetSelected(SelectionEvent e) {
311: fPatternEditor.getTextWidget().setFocus();
312: fPatternEditor
313: .doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
314: }
315:
316: public void widgetDefaultSelected(SelectionEvent e) {
317: }
318: });
319:
320: fDescriptionText.setText(fTemplate.getDescription());
321: if (fIsNameModifiable) {
322: fNameText.setText(fTemplate.getName());
323: fNameText.addModifyListener(listener);
324: fContextCombo
325: .select(getIndex(fTemplate.getContextTypeId()));
326: } else {
327: fPatternEditor.getControl().setFocus();
328: }
329: initializeActions();
330:
331: applyDialogFont(parent);
332: return composite;
333: }
334:
335: protected void doTextWidgetChanged(Widget w) {
336: if (w == fNameText) {
337: fSuppressError = false;
338: updateStatusAndButtons();
339: } else if (w == fContextCombo) {
340: String contextId = getContextId();
341: fTemplateProcessor.setContextType(fContextTypeRegistry
342: .getContextType(contextId));
343: IDocument document = fPatternEditor.getDocument();
344: String prefix = getPrefix();
345: document.set(prefix + getPattern());
346: fPatternEditor.setVisibleRegion(prefix.length(), document
347: .getLength()
348: - prefix.length());
349: updateStatusAndButtons();
350: } else if (w == fDescriptionText) {
351: // nothing
352: }
353: }
354:
355: private String getContextId() {
356: if (fContextCombo != null && !fContextCombo.isDisposed()) {
357: String name = fContextCombo.getText();
358: for (int i = 0; i < fContextTypes.length; i++) {
359: if (name.equals(fContextTypes[i][1])) {
360: return fContextTypes[i][0];
361: }
362: }
363: }
364:
365: return fTemplate.getContextTypeId();
366: }
367:
368: protected void doSourceChanged(IDocument document) {
369: String text = document.get();
370: fValidationStatus.setOK();
371: TemplateContextType contextType = fContextTypeRegistry
372: .getContextType(getContextId());
373: if (contextType != null) {
374: try {
375: contextType.validate(text);
376: } catch (TemplateException e) {
377: fValidationStatus.setError(e.getLocalizedMessage());
378: }
379: }
380:
381: updateUndoAction();
382: updateStatusAndButtons();
383: }
384:
385: private static GridData getButtonGridData() {
386: GridData data = new GridData(GridData.FILL_HORIZONTAL);
387: return data;
388: }
389:
390: private static Label createLabel(Composite parent, String name) {
391: Label label = new Label(parent, SWT.NULL);
392: label.setText(name);
393: label.setLayoutData(new GridData());
394:
395: return label;
396: }
397:
398: private static Button createCheckbox(Composite parent, String name) {
399: Button button = new Button(parent, SWT.CHECK);
400: button.setText(name);
401: button.setLayoutData(new GridData());
402:
403: return button;
404: }
405:
406: private static Text createText(Composite parent) {
407: Text text = new Text(parent, SWT.BORDER);
408: text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
409:
410: return text;
411: }
412:
413: private SourceViewer createEditor(Composite parent) {
414: String prefix = getPrefix();
415: IDocument document = new Document(prefix
416: + fTemplate.getPattern());
417: JavaTextTools tools = JavaPlugin.getDefault()
418: .getJavaTextTools();
419: tools.setupJavaDocumentPartitioner(document,
420: IJavaPartitions.JAVA_PARTITIONING);
421: IPreferenceStore store = JavaPlugin.getDefault()
422: .getCombinedPreferenceStore();
423: SourceViewer viewer = new JavaSourceViewer(parent, null, null,
424: false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store);
425: CodeTemplateSourceViewerConfiguration configuration = new CodeTemplateSourceViewerConfiguration(
426: tools.getColorManager(), store, null,
427: fTemplateProcessor);
428: viewer.configure(configuration);
429: viewer.setEditable(true);
430: viewer.setDocument(document, prefix.length(), document
431: .getLength()
432: - prefix.length());
433:
434: Font font = JFaceResources
435: .getFont(PreferenceConstants.EDITOR_TEXT_FONT);
436: viewer.getTextWidget().setFont(font);
437: new JavaSourcePreviewerUpdater(viewer, configuration, store);
438:
439: int nLines = document.getNumberOfLines();
440: if (nLines < 5) {
441: nLines = 5;
442: } else if (nLines > 12) {
443: nLines = 12;
444: }
445:
446: Control control = viewer.getControl();
447: GridData data = new GridData(GridData.FILL_BOTH);
448: data.widthHint = convertWidthInCharsToPixels(80);
449: data.heightHint = convertHeightInCharsToPixels(nLines);
450: control.setLayoutData(data);
451:
452: viewer.addTextListener(new ITextListener() {
453: public void textChanged(TextEvent event) {
454: if (event.getDocumentEvent() != null)
455: doSourceChanged(event.getDocumentEvent()
456: .getDocument());
457: }
458: });
459:
460: viewer
461: .addSelectionChangedListener(new ISelectionChangedListener() {
462: public void selectionChanged(
463: SelectionChangedEvent event) {
464: updateSelectionDependentActions();
465: }
466: });
467:
468: viewer.prependVerifyKeyListener(new VerifyKeyListener() {
469: public void verifyKey(VerifyEvent event) {
470: handleVerifyKeyPressed(event);
471: }
472: });
473:
474: return viewer;
475: }
476:
477: private String getPrefix() {
478: String id = getContextId();
479: int idx = getIndex(id);
480: if (idx != -1)
481: return fContextTypes[idx][2];
482: else
483: return ""; //$NON-NLS-1$
484: }
485:
486: private void handleVerifyKeyPressed(VerifyEvent event) {
487: if (!event.doit)
488: return;
489:
490: if (event.stateMask != SWT.MOD1)
491: return;
492:
493: switch (event.character) {
494: case ' ':
495: fPatternEditor
496: .doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
497: event.doit = false;
498: break;
499:
500: // CTRL-Z
501: case 'z' - 'a' + 1:
502: fPatternEditor.doOperation(ITextOperationTarget.UNDO);
503: event.doit = false;
504: break;
505: }
506: }
507:
508: private void initializeActions() {
509: TextViewerAction action = new TextViewerAction(fPatternEditor,
510: ITextOperationTarget.UNDO);
511: action.setText(PreferencesMessages.EditTemplateDialog_undo);
512: fGlobalActions.put(ITextEditorActionConstants.UNDO, action);
513:
514: action = new TextViewerAction(fPatternEditor,
515: ITextOperationTarget.CUT);
516: action.setText(PreferencesMessages.EditTemplateDialog_cut);
517: fGlobalActions.put(ITextEditorActionConstants.CUT, action);
518:
519: action = new TextViewerAction(fPatternEditor,
520: ITextOperationTarget.COPY);
521: action.setText(PreferencesMessages.EditTemplateDialog_copy);
522: fGlobalActions.put(ITextEditorActionConstants.COPY, action);
523:
524: action = new TextViewerAction(fPatternEditor,
525: ITextOperationTarget.PASTE);
526: action.setText(PreferencesMessages.EditTemplateDialog_paste);
527: fGlobalActions.put(ITextEditorActionConstants.PASTE, action);
528:
529: action = new TextViewerAction(fPatternEditor,
530: ITextOperationTarget.SELECT_ALL);
531: action
532: .setText(PreferencesMessages.EditTemplateDialog_select_all);
533: fGlobalActions.put(ITextEditorActionConstants.SELECT_ALL,
534: action);
535:
536: action = new TextViewerAction(fPatternEditor,
537: ISourceViewer.CONTENTASSIST_PROPOSALS);
538: action
539: .setText(PreferencesMessages.EditTemplateDialog_content_assist);
540: fGlobalActions.put("ContentAssistProposal", action); //$NON-NLS-1$
541:
542: fSelectionActions.add(ITextEditorActionConstants.CUT);
543: fSelectionActions.add(ITextEditorActionConstants.COPY);
544: fSelectionActions.add(ITextEditorActionConstants.PASTE);
545:
546: // create context menu
547: MenuManager manager = new MenuManager(null, null);
548: manager.setRemoveAllWhenShown(true);
549: manager.addMenuListener(new IMenuListener() {
550: public void menuAboutToShow(IMenuManager mgr) {
551: fillContextMenu(mgr);
552: }
553: });
554:
555: StyledText text = fPatternEditor.getTextWidget();
556: Menu menu = manager.createContextMenu(text);
557: text.setMenu(menu);
558: }
559:
560: private void fillContextMenu(IMenuManager menu) {
561: menu
562: .add(new GroupMarker(
563: ITextEditorActionConstants.GROUP_UNDO));
564: menu.appendToGroup(ITextEditorActionConstants.GROUP_UNDO,
565: (IAction) fGlobalActions
566: .get(ITextEditorActionConstants.UNDO));
567:
568: menu.add(new Separator(ITextEditorActionConstants.GROUP_EDIT));
569: menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT,
570: (IAction) fGlobalActions
571: .get(ITextEditorActionConstants.CUT));
572: menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT,
573: (IAction) fGlobalActions
574: .get(ITextEditorActionConstants.COPY));
575: menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT,
576: (IAction) fGlobalActions
577: .get(ITextEditorActionConstants.PASTE));
578: menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT,
579: (IAction) fGlobalActions
580: .get(ITextEditorActionConstants.SELECT_ALL));
581:
582: menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
583: menu.appendToGroup(IContextMenuConstants.GROUP_GENERATE,
584: (IAction) fGlobalActions.get("ContentAssistProposal")); //$NON-NLS-1$
585: }
586:
587: protected void updateSelectionDependentActions() {
588: Iterator iterator = fSelectionActions.iterator();
589: while (iterator.hasNext())
590: updateAction((String) iterator.next());
591: }
592:
593: protected void updateUndoAction() {
594: IAction action = (IAction) fGlobalActions
595: .get(ITextEditorActionConstants.UNDO);
596: if (action instanceof IUpdate)
597: ((IUpdate) action).update();
598: }
599:
600: protected void updateAction(String actionId) {
601: IAction action = (IAction) fGlobalActions.get(actionId);
602: if (action instanceof IUpdate)
603: ((IUpdate) action).update();
604: }
605:
606: private int getIndex(String contextid) {
607:
608: if (contextid == null)
609: return -1;
610:
611: for (int i = 0; i < fContextTypes.length; i++) {
612: if (contextid.equals(fContextTypes[i][0])) {
613: return i;
614: }
615: }
616: return -1;
617: }
618:
619: protected void okPressed() {
620: String name = fNameText == null ? fTemplate.getName()
621: : fNameText.getText();
622: boolean isAutoInsertable = fAutoInsertCheckbox != null
623: && fAutoInsertCheckbox.getSelection();
624: fTemplate = new Template(name, fDescriptionText.getText(),
625: getContextId(), getPattern(), isAutoInsertable);
626: super .okPressed();
627: }
628:
629: private void updateStatusAndButtons() {
630: StatusInfo status = fValidationStatus;
631: boolean isEmpty = fNameText != null
632: && fNameText.getText().length() == 0;
633: if (!fSuppressError && isEmpty) {
634: status = new StatusInfo();
635: status
636: .setError(PreferencesMessages.EditTemplateDialog_error_noname);
637: } else if (fNameText != null
638: && !isValidTemplateName(fNameText.getText())) {
639: status = new StatusInfo();
640: status
641: .setError(PreferencesMessages.EditTemplateDialog_error_invalidName);
642: }
643: updateStatus(status);
644: }
645:
646: /**
647: * Checks whether the given string is a valid
648: * template name.
649: *
650: * @param name the string to test
651: * @return <code>true</code> if the name is valid
652: * @since 3.3.1
653: */
654: private boolean isValidTemplateName(String name) {
655: int nameLength = name.length();
656: if (nameLength == 0)
657: return true;
658:
659: char firstChar = name.charAt(0);
660: boolean isJavadocTemplate = JavaDocContextType.ID
661: .equals(getContextId());
662: if (!Character.isUnicodeIdentifierStart(firstChar)
663: && !(isJavadocTemplate && (firstChar == '<' || firstChar == '@')))
664: return false;
665:
666: if (nameLength == 1)
667: return true;
668:
669: for (int i = 1; i < nameLength - 1; i++) {
670: if (!Character.isUnicodeIdentifierPart(name.charAt(i)))
671: return false;
672: }
673:
674: char lastChar = name.charAt(nameLength - 1);
675: return Character.isUnicodeIdentifierPart(lastChar)
676: || isJavadocTemplate && lastChar == '>';
677: }
678:
679: /*
680: * @see org.eclipse.jface.window.Window#configureShell(Shell)
681: */
682: protected void configureShell(Shell newShell) {
683: super .configureShell(newShell);
684: PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell,
685: IJavaHelpContextIds.EDIT_TEMPLATE_DIALOG);
686: }
687:
688: /**
689: * Returns the created template.
690: *
691: * @return the created template
692: * @since 3.1
693: */
694: public Template getTemplate() {
695: return fTemplate;
696: }
697:
698: private String getPattern() {
699: IDocument doc = fPatternEditor.getDocument();
700: IRegion visible = fPatternEditor.getVisibleRegion();
701: try {
702: return doc.get(visible.getOffset(), doc.getLength()
703: - visible.getOffset());
704: } catch (BadLocationException e) {
705: return ""; //$NON-NLS-1$
706: }
707: }
708:
709: /*
710: * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings()
711: * @since 3.2
712: */
713: protected IDialogSettings getDialogBoundsSettings() {
714: String sectionName = getClass().getName() + "_dialogBounds"; //$NON-NLS-1$
715: IDialogSettings settings = JavaPlugin.getDefault()
716: .getDialogSettings();
717: IDialogSettings section = settings.getSection(sectionName);
718: if (section == null)
719: section = settings.addNewSection(sectionName);
720: return section;
721: }
722:
723: }
|