wiki:Grits_InjectedObjects

Services Provided by Grits

IGritsDataModelService

  • void addEntry(Entry parentEntry, Entry childEntry)
  • void addProjectEntry(Entry projectEntry)
  • void closeProject(Entry entry)
  • void deleteEntry(Entry entry)
  • Entry findParentByType(Entry entry, String type)
  • Entry getRootEntry()
  • void removeAllChildren(Entry parent)
  • void removeEntry(Entry parent, Entry toRemove)
  • void renameEntry(Entry entry, String newName)
  • void setRoot(Entry workspaceEntry)
  • void updateProjectModificationTime(Entry entry)

IGritsUIService

  • MPart openEntryInPart(Entry entry)
  • void closePartForEntry(Entry entry)
  • MPart findPartForEntry(Entry entry)
  • MPartDescriptor findPartDescriptorForEntry(Entry entry)
  • MPerspective findPerspectiveForPartDescriptor(String partDescriptorId)
  • void selectPerspective(String perspectiveId)

Examples

Example code for setting a projectEntry as "closed"

	@Execute
	public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) Entry entry,
			IGritsDataModelService gritsDataModelService,
			IGritsUIService gritsUIService)
	{
		//
		....
		//
		gritsUIService.closePartForEntry(entry);
		gritsDataModelService.closeProject(entry);
	
	}

Example code for creating a new entry

	@Execute
	public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) Entry selectedEntry,
			@Named(IServiceConstants.ACTIVE_PART) MPart projectExplorerPart,
			IGritsDataModelService gritsDataModelService, IGritsUIService gritsUIService)
	{
		//
		....
		//
		// create contents for new entry and the new entry object
		...
		//
		gritsDataModelService.addEntry(selectedEntry, newEntry);
		try
		{
			ProjectFileHandler.saveProject(gritsDataModelService
				.findParentByType(selectedEntry, ProjectProperty.TYPE));
			gritsUIService.openEntryInPart(newEntry);
		} catch (IOException e)
		{
			logger.error(e.getMessage(),e);
			gritsDataModelService.deleteEntry(newEntry);
			// do error handling
		}
	}

Example code for opening an entry

	@Execute
	public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) Entry selectedEntry,
			@Named(IServiceConstants.ACTIVE_PART) MPart projectExplorerPart,
			IGritsUIService gritsUIService)
	{
		//
		....
		//
		gritsUIService.openEntryInPart(selectedEntry);
	}

Injected Objects and Runtime Constants from Grits

All the runtime constants are listed in org.grits.toolbox.core.dataShare.IGritsConstants interface. The root workspace Entry object can be retrieved by using the name IGritsConstants.WORKSPACE_ENTRY. Here is a list of names and their types.

Object type Object Name
String CONFIG_LOC_INSTALL
String CONFIG_LOCATION
String WORKSPACE_LOCATION
Entry WORKSPACE_ENTRY

Examples

Example for retrieving workspace entry

     public void doSomething(@Named(IGritsConstants.WORKSPACE_ENTRY) Entry workspaceEntry)
     {
          // do something
          ....
     }

Example for retrieving workspace location

     public void doSomething(@Named(IGritsConstants.WORKSPACE_LOCATION)
                                   String workspaceLocation)
     {
          // do something
          ....
     }

Last modified 4 years ago Last modified on 05/04/2016 05:48:27 PM