The workspace is manipulated using resource handles. Resource handles are lightweight pointers to a particular project, folder, or file in the workspace. You can create a resource handle without creating a resource, and resources can exist regardless of whether any handles exist that point to them. To create a resource, you first have to create a resource handle and then tell it to create the resource. The following snippet uses resource handles to create a project, a folder, and a file.
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IProject project = root.getProject("MyProject");
IFolder folder = project.getFolder("Folder1");
IFile file = folder.getFile("hello.txt");
//at this point, no resources have been created
if (!project.exists()) project.create(null);
if (!project.isOpen()) project.open(null);
if (!folder.exists())
folder.create(IResource.NONE, true, null);
if (!file.exists()) {
byte[] bytes = "File contents".getBytes();
InputStream source = new ByteArrayInputStream(bytes);
file.create(source, IResource.NONE, null);
}
This example defensively checks that the resource doesn’t already exist before trying to create it. This kind of defensive programming is a good idea because an exception is thrown if you try to create a resource that already exists. This way, the example can be run more than once in the same workspace without causing an error. The nullparameters to the creation methods should be replaced by a progress monitor in a real application.
分享到:
相关推荐
5. **Automating Validation Without Changing Specifications**: Automated tests are created based on the examples, ensuring that the software behaves as expected. This automation allows for frequent ...
The solutions this platform allows can be created more quickly and are more cost effective than custom-developed solutions, and what is more, the platform provides a far greater degree of flexibility...
How are Message Maps Created? The BEGIN_MESSAGE_MAP() Macro Inside the Message Map Filling the Holes The END_MESSAGE_MAP() Macro Unfolding the Map There's No Sense of Obligation CObject Memory...
Title: Learn Mobile Game Development in One Day Using Gamesalad Author: Jamie Cross Length: 244 pages Edition: 1 Language: English Publisher: CreateSpace Independent ...Chapter 24: Review and Resources
- This section explains how new tasks (processes) are created and how existing tasks are terminated. It also covers the creation and management of kernel threads. 3. **Linux Scheduler (Section 2.3):...
Specific examples are created with vulnerable system images, which are available to the community to test scripts, techniques, and exploits. This book walks you through real-world penetration testing...
you how to install the distribution diskette and describe the directories created. I then explain some of the coding convent ions used. Before getting into the description of the examples, I describe ...
Suning Cloud Commerce is one of the largest privately owned ...We will share our story, experience and practice to enable such kind of big cloud and how to support them, best practise and lesson learn.
Destructors, on the other hand, are used for cleaning up resources when an object's lifetime ends. They are automatically called when an object goes out of scope or is explicitly deleted. Composition...
and indices are stored in resources created through the device. Chapter 6 covers vertex transformations, vertex blending and user-de¯ned clipping planes. With transformations, primitives can be ...
informed, while developers have virtually no resources. When a cracker learns how to remove a certain kind of protection, it is only a matter of time before detailed information on how to do so is ...
The boot.ini option /3GB was created for those cases where systems actually support greater than 2 GB of physical memory and an application can make use of it This capability allows memory intensive ...
- Displays can be created with predefined dimensions or by loading an existing image. - Destruction closes the display window and frees resources. - Copies are not applicable since displays typically ...
- **Selective Resource Inclusion**: Only include resources that are essential for the application’s functionality. ##### 3.2 Using an Obfuscator Obfuscators can reduce JAR file sizes by renaming ...
Program: DelforExp, Delphi Formatter Version: 2.4.1 for Delphi 2-7 ... are removed) If someone knows how to get and set the locations of these points I would be happy to hear from you.
Want to know when major new features are added? When a new stable version is released? Follow us on Twitter! 6/5/2016 Version 2.4 4/9/2016 Version 2.3.2 7/13/2015 Version 2.3.1 3/9/2015 Version 2.3 6...
Those are the prefabs that were used in scenes but are not in a Resources folder, nor referenced as a variable. === Size Readings === Why is the build size larger when shown in Windows Explorer?...
Packets are created, modified, and forwarded by agents according to the configured network protocols. Post Simulation After running a simulation, analysis is crucial to understanding the results. NS...