|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2006 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2007 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 73-78
Link Here
|
| 73 |
import org.eclipse.ui.texteditor.ITextEditorActionConstants; |
73 |
import org.eclipse.ui.texteditor.ITextEditorActionConstants; |
| 74 |
import org.eclipse.ui.texteditor.IUpdate; |
74 |
import org.eclipse.ui.texteditor.IUpdate; |
| 75 |
|
75 |
|
|
|
76 |
import org.eclipse.jdt.internal.corext.template.java.JavaDocContextType; |
| 77 |
|
| 76 |
import org.eclipse.jdt.ui.IContextMenuConstants; |
78 |
import org.eclipse.jdt.ui.IContextMenuConstants; |
| 77 |
import org.eclipse.jdt.ui.PreferenceConstants; |
79 |
import org.eclipse.jdt.ui.PreferenceConstants; |
| 78 |
import org.eclipse.jdt.ui.text.IJavaPartitions; |
80 |
import org.eclipse.jdt.ui.text.IJavaPartitions; |
|
Lines 201-208
Link Here
|
| 201 |
public void create() { |
203 |
public void create() { |
| 202 |
super.create(); |
204 |
super.create(); |
| 203 |
updateStatusAndButtons(); |
205 |
updateStatusAndButtons(); |
| 204 |
boolean isEmpty= fNameText != null && fNameText.getText().length() == 0; |
206 |
getButton(IDialogConstants.OK_ID).setEnabled(getStatus().isOK()); |
| 205 |
getButton(IDialogConstants.OK_ID).setEnabled(!isEmpty); |
|
|
| 206 |
} |
207 |
} |
| 207 |
|
208 |
|
| 208 |
/* |
209 |
/* |
|
Lines 310-316
Link Here
|
| 310 |
protected void doTextWidgetChanged(Widget w) { |
311 |
protected void doTextWidgetChanged(Widget w) { |
| 311 |
if (w == fNameText) { |
312 |
if (w == fNameText) { |
| 312 |
fSuppressError= false; |
313 |
fSuppressError= false; |
| 313 |
updateStatusAndButtons(); |
314 |
updateStatusAndButtons(); |
| 314 |
} else if (w == fContextCombo) { |
315 |
} else if (w == fContextCombo) { |
| 315 |
String contextId= getContextId(); |
316 |
String contextId= getContextId(); |
| 316 |
fTemplateProcessor.setContextType(fContextTypeRegistry.getContextType(contextId)); |
317 |
fTemplateProcessor.setContextType(fContextTypeRegistry.getContextType(contextId)); |
|
Lines 318-323
Link Here
|
| 318 |
String prefix= getPrefix(); |
319 |
String prefix= getPrefix(); |
| 319 |
document.set(prefix + getPattern()); |
320 |
document.set(prefix + getPattern()); |
| 320 |
fPatternEditor.setVisibleRegion(prefix.length(), document.getLength() - prefix.length()); |
321 |
fPatternEditor.setVisibleRegion(prefix.length(), document.getLength() - prefix.length()); |
|
|
322 |
updateStatusAndButtons(); |
| 321 |
} else if (w == fDescriptionText) { |
323 |
} else if (w == fDescriptionText) { |
| 322 |
// nothing |
324 |
// nothing |
| 323 |
} |
325 |
} |
|
Lines 562-574
Link Here
|
| 562 |
if (!fSuppressError && isEmpty) { |
564 |
if (!fSuppressError && isEmpty) { |
| 563 |
status= new StatusInfo(); |
565 |
status= new StatusInfo(); |
| 564 |
status.setError(PreferencesMessages.EditTemplateDialog_error_noname); |
566 |
status.setError(PreferencesMessages.EditTemplateDialog_error_noname); |
| 565 |
} else if (fNameText != null && fNameText.getText().indexOf(' ') > -1) { |
567 |
} else if (fNameText != null && !isValidTemplateName(fNameText.getText())) { |
| 566 |
status= new StatusInfo(); |
568 |
status= new StatusInfo(); |
| 567 |
status.setError(PreferencesMessages.EditTemplateDialog_error_spaces); |
569 |
status.setError(PreferencesMessages.EditTemplateDialog_error_spaces); |
| 568 |
} |
570 |
} |
| 569 |
updateStatus(status); |
571 |
updateStatus(status); |
| 570 |
} |
572 |
} |
| 571 |
|
573 |
|
|
|
574 |
/** |
| 575 |
* Checks whether the given string is a valid |
| 576 |
* template name. |
| 577 |
* |
| 578 |
* @param name the string to test |
| 579 |
* @return <code>true</code> if the name is valid |
| 580 |
* @since 3.3.1 |
| 581 |
*/ |
| 582 |
private boolean isValidTemplateName(String name) { |
| 583 |
int nameLength= name.length(); |
| 584 |
if (nameLength == 0) |
| 585 |
return true; |
| 586 |
|
| 587 |
char firstChar= name.charAt(0); |
| 588 |
boolean isJavadocTemplate= JavaDocContextType.NAME.equals(getContextId()); |
| 589 |
if (!Character.isUnicodeIdentifierStart(firstChar) && !(isJavadocTemplate && (firstChar == '<' || firstChar == '@'))) |
| 590 |
return false; |
| 591 |
|
| 592 |
if (nameLength == 1) |
| 593 |
return true; |
| 594 |
|
| 595 |
for (int i= 1; i < nameLength - 1; i++) { |
| 596 |
if (!Character.isUnicodeIdentifierPart(name.charAt(i))) |
| 597 |
return false; |
| 598 |
} |
| 599 |
|
| 600 |
char lastChar= name.charAt(nameLength - 1); |
| 601 |
return Character.isUnicodeIdentifierPart(lastChar) || isJavadocTemplate && lastChar == '>'; |
| 602 |
} |
| 603 |
|
| 572 |
/* |
604 |
/* |
| 573 |
* @see org.eclipse.jface.window.Window#configureShell(Shell) |
605 |
* @see org.eclipse.jface.window.Window#configureShell(Shell) |
| 574 |
*/ |
606 |
*/ |