`
eric_kong
  • 浏览: 14717 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论
  • cash23: 另外,问下,每次我生成模块或建立数据库后,之前库里的其他表数据 ...
    CMS
  • cash23: 没有信息吗,前台页面怎么看
    CMS

How are resources created?

 
阅读更多

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.

分享到:
评论

相关推荐

    Specification by Example - How Successful Teams Deliver the Right Software

    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 ...

    SharePoint 2013 User's Guide 4th Edition

    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...

    Professional.MFC.with.VC6

    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...

    Learn.Mobile.Game.Development.in.One.Day.Using.Gamesalad

    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

    Linux Kernel 2.4 Internals

    - 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):...

    Learning Penetration Testing with Python(PACKT,2015)

    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...

    uCOSII [繁體版]

    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 ...

    苏宁Heat实践分享: Explore and enable elastic cluster for Internet applications

    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.

    C 程序设计教学课件:Chapter 3 class and object.ppt

    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...

    D3D render pipeline

    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 ...

    Crack&逆向技术.7z

    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 ...

    微软内部资料-SQL性能优化2

    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 ...

    CImg Reference

    - 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 ...

    Efficient MIDP Programming

    - **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 ...

    DelForExD2007

    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.

    .NET反编译工具ILSpy2.3.0 获得DLL EXE 项目的源代码 好用 免费 最新 最全

    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...

    Build Report Tool 3.0.19.rar

    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?...

    NS by examples.doc

    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...

Global site tag (gtag.js) - Google Analytics