001: package newprocess.diagram.part;
002:
003: import java.io.IOException;
004: import java.lang.reflect.InvocationTargetException;
005: import java.util.Collections;
006: import newprocess.NewprocessFactory;
007: import newprocess.Process;
008: import newprocess.diagram.view.factories.ProcessViewFactory;
009: import org.eclipse.core.commands.ExecutionException;
010: import org.eclipse.core.resources.IFile;
011: import org.eclipse.core.resources.ResourcesPlugin;
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.core.runtime.IAdaptable;
014: import org.eclipse.core.runtime.IProgressMonitor;
015: import org.eclipse.core.runtime.IStatus;
016: import org.eclipse.core.runtime.NullProgressMonitor;
017: import org.eclipse.core.runtime.Status;
018: import org.eclipse.emf.ecore.resource.Resource;
019: import org.eclipse.emf.ecore.resource.ResourceSet;
020: import org.eclipse.emf.transaction.TransactionalEditingDomain;
021: import org.eclipse.emf.workspace.AbstractEMFOperation;
022: import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory;
023: import org.eclipse.gmf.runtime.notation.Diagram;
024: import org.eclipse.gmf.runtime.notation.NotationFactory;
025: import org.eclipse.jface.dialogs.ErrorDialog;
026: import org.eclipse.ui.PartInitException;
027: import org.eclipse.ui.PlatformUI;
028: import org.eclipse.ui.actions.WorkspaceModifyOperation;
029: import org.eclipse.ui.ide.IDE;
030: import org.eclipse.core.runtime.IPath;
031: import org.eclipse.core.runtime.Path;
032: import org.eclipse.emf.common.util.URI;
033: import org.eclipse.jface.viewers.IStructuredSelection;
034: import org.eclipse.osgi.util.NLS;
035: import org.eclipse.swt.widgets.Composite;
036: import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
037:
038: /**
039: * @generated
040: */
041: public class New_processCreationWizardPage extends
042: WizardNewFileCreationPage {
043:
044: /**
045: * @generated
046: */
047: private final String fileExtension;
048:
049: /**
050: * @generated
051: */
052: public New_processCreationWizardPage(String pageName,
053: IStructuredSelection selection, String fileExtension) {
054: super (pageName, selection);
055: this .fileExtension = fileExtension;
056: }
057:
058: /**
059: * Override to create files with this extension.
060: *
061: * @generated
062: */
063: protected String getExtension() {
064: return fileExtension;
065: }
066:
067: /**
068: * @generated
069: */
070: public URI getURI() {
071: return URI.createPlatformResourceURI(getFilePath().toString());
072: }
073:
074: /**
075: * @generated
076: */
077: protected IPath getFilePath() {
078: IPath path = getContainerFullPath();
079: if (path == null) {
080: path = new Path(""); //$NON-NLS-1$
081: }
082: String fileName = getFileName();
083: if (fileName != null) {
084: path = path.append(fileName);
085: }
086: return path;
087: }
088:
089: /**
090: * @generated
091: */
092: private String getUniqueFileName(IPath containerFullPath,
093: String fileName) {
094: if (containerFullPath == null) {
095: containerFullPath = new Path(""); //$NON-NLS-1$
096: }
097: if (fileName == null || fileName.trim().length() == 0) {
098: fileName = "default"; //$NON-NLS-1$
099: }
100: IPath filePath = containerFullPath.append(fileName);
101: String extension = getExtension();
102: if (extension != null
103: && !extension.equals(filePath.getFileExtension())) {
104: filePath = filePath.addFileExtension(extension);
105: }
106:
107: extension = filePath.getFileExtension();
108: fileName = filePath.removeFileExtension().lastSegment();
109: int i = 1;
110: while (New_processDiagramEditorUtil.exists(filePath)) {
111: i++;
112: filePath = containerFullPath.append(fileName + i);
113: if (extension != null) {
114: filePath = filePath.addFileExtension(extension);
115: }
116: }
117: return filePath.lastSegment();
118: }
119:
120: /**
121: * @generated
122: */
123: public void createControl(Composite parent) {
124: super .createControl(parent);
125: setFileName(getUniqueFileName(getContainerFullPath(),
126: getFileName()));
127: setPageComplete(validatePage());
128: }
129:
130: /**
131: * @generated
132: */
133: protected boolean validatePage() {
134: if (!super .validatePage()) {
135: return false;
136: }
137: String extension = getExtension();
138: if (extension != null
139: && !getFilePath().toString().endsWith("." + extension)) {
140: setErrorMessage(NLS.bind(
141: "File name should have ''{0}'' extension.",
142: extension));
143: return false;
144: }
145: return true;
146: }
147: }
|