01: /**
02: *
03: */package newprocess.diagram.cust.annotations.wizards;
04:
05: import newprocess.diagram.cust.annotations.utils.AnnotationTypes;
06:
07: import org.eclipse.core.runtime.IPath;
08: import org.eclipse.emf.common.util.URI;
09: import org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages;
10: import org.eclipse.jface.viewers.IStructuredSelection;
11: import org.eclipse.osgi.util.NLS;
12: import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
13:
14: /**
15: * @author sh
16: *
17: */
18: public class NewFileCreationPage extends WizardNewFileCreationPage {
19: private String annotationType = null;
20:
21: public NewFileCreationPage(String pageName,
22: IStructuredSelection selection, String type) {
23: super (pageName, selection);
24: annotationType = type;
25: }
26:
27: @Override
28: protected boolean validatePage() {
29: if (super .validatePage()) {
30: // do additional validation on the anticipated filename
31: String filename = getFileName();
32: if (filename == null)
33: return false;
34:
35: IPath path = getContainerFullPath().append(filename);
36: URI fileURI = URI.createURI(path.toString());
37:
38: // check if the file ends with the correct type
39: if (!checkFiletype(fileURI)) {
40: // set an error message
41: setErrorMessage(NLS
42: .bind(
43: EditorMessages.EditorWizardPage_InvalidFilename,
44: filename));
45: return false;
46: }
47: return true;
48: }
49: return false;
50: }
51:
52: /*
53: * Method to check if the commited file
54: * is in the correct format
55: */
56: private boolean checkFiletype(URI fileuri) {
57: // FIXME "Preference Page Workaround"
58: String extension = fileuri.fileExtension();
59: if (annotationType.equals(AnnotationTypes.MSEXCEL)) {
60: if (extension.equals(AnnotationTypes.MSEXCEL_FILEEXTENSION))
61: return true;
62: } else if (annotationType.equals(AnnotationTypes.MSWORD)) {
63: if (extension.equals(AnnotationTypes.MSWORD_FILEEXTENSION))
64: return true;
65: }
66: return false;
67: }
68: }
|