Changeset 292 for trunk/org.modelica.mdt.ui/src/org/modelica/mdt
- Timestamp:
- 02/05/06 16:04:42 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/org.modelica.mdt.ui/src/org/modelica/mdt/ui/wizards/NewPackageWizard.java
r288 r292 48 48 import org.eclipse.core.resources.IFolder; 49 49 import org.eclipse.core.resources.IWorkspaceRoot; 50 import org.eclipse.core.resources.IWorkspaceRunnable; 50 51 import org.eclipse.core.resources.ResourcesPlugin; 51 52 import org.eclipse.core.runtime.CoreException; … … 116 117 this.description = description; 117 118 } 119 120 /** 121 * the workhorse of this class, contains the actual code 122 * that creates the folder and files of the package 123 * 124 * @param monitor where the progress of creation of the package is 125 * reported 126 */ 127 private void createPackage(IProgressMonitor monitor) 128 throws CoreException 129 { 130 monitor.beginTask("Creating package " + packageName, 2); 131 /* 132 * generate contents of package.mo 133 */ 134 String contents = ""; 135 136 if (!parentPackage.equals("")) 137 { 138 /* generate within clause if we are not top level package */ 139 contents += "within " + parentPackage + ";\n\n"; 140 } 141 142 if (isEncapsulated) 143 { 144 contents += "encapsulated "; 145 } 146 contents += "package " + packageName; 147 148 if (!description.equals("")) 149 { 150 contents += " \"" + description + "\""; 151 } 152 contents += "\n\nend " + packageName + ";"; 153 154 monitor.worked(1); 155 156 /* 157 * create the new package's root folder 158 */ 159 160 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); 161 IContainer pkgParent = (IContainer) root.findMember(packagePath); 162 163 IFolder pkgFolder = 164 pkgParent.getFolder(new Path(packageName)); 165 166 pkgFolder.create(false, true, null); 167 monitor.worked(1); 168 169 /* 170 * create the new package's package.mo file 171 */ 172 IFile packageMo = 173 pkgFolder.getFile(new Path("package.mo")); 174 175 packageMo.create(new ByteArrayInputStream(contents.getBytes()), 176 true, null); 177 178 monitor.done(); 179 180 } 118 181 public void run(IProgressMonitor monitor) 119 182 throws InvocationTargetException, InterruptedException 120 183 { 121 monitor.beginTask("Creating package " + packageName, 3); 122 /* 123 * generate contents of package.mo 124 */ 125 String contents = ""; 126 127 if (!parentPackage.equals("")) 128 { 129 /* generate within clause if we are not top level package */ 130 contents += "within " + parentPackage + ";\n\n"; 131 } 132 133 if (isEncapsulated) 134 { 135 contents += "encapsulated "; 136 } 137 contents += "package " + packageName; 138 139 if (!description.equals("")) 140 { 141 contents += " \"" + description + "\""; 142 } 143 contents += "\n\nend " + packageName + ";"; 144 145 monitor.worked(1); 146 147 try 148 { 149 /* 150 * create the new package's root folder 151 */ 152 153 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); 154 IContainer pkgParent = (IContainer) root.findMember(packagePath); 155 156 IFolder pkgFolder = 157 pkgParent.getFolder(new Path(packageName)); 158 159 pkgFolder.create(false, true, null); 160 monitor.worked(1); 161 162 /* 163 * create the new package's package.mo file 164 */ 165 IFile packageMo = 166 pkgFolder.getFile(new Path("package.mo")); 167 168 packageMo.create(new ByteArrayInputStream(contents.getBytes()), 169 true, null); 170 monitor.worked(1); 171 184 /* 185 * run all package creation operations inside a IWorkspaceRunnble 186 * to provide better batching of change events 187 */ 188 IWorkspaceRunnable wr = new IWorkspaceRunnable() 189 { 190 public void run(IProgressMonitor monitor) throws CoreException 191 { 192 createPackage(monitor); 193 } 194 }; 195 196 try 197 { 198 ResourcesPlugin.getWorkspace().run(wr, monitor); 172 199 } 173 200 catch (CoreException e) 174 201 { 175 202 throw new InvocationTargetException(e); 176 }177 finally178 {179 monitor.done();180 203 } 181 204 }
Note: See TracChangeset
for help on using the changeset viewer.