[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools.gef] Re: Add new resource to navigator

You don't create the resource "in the navigator view."  The navigator view
shows whatever resources are in the workspace, and you just create a
resource in the workspace.

Here's an example from one of our tests that might prove helpful to you:

 // Create the logic file if it doesn't exist
 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
 IProject project = root.getProject(prjName);
 if (!project.exists())
  project.create(null);
 if (!project.isOpen())
  project.open(null);
 file = project.getFile(fileName);
 if (!file.exists()) {
  LogicDiagram diagram = createLogicDiagram();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  ObjectOutputStream oos = new ObjectOutputStream(out);
  oos.writeObject(diagram);
  oos.close();
  file.create(new ByteArrayInputStream(out.toByteArray()), false, null);
  out.close();
 }

If you're still having problems, I suggest you post on the platform
newsgroup with more details (about what happens when you execute your code
and such), since this is not GEF's domain.

"Prashanto" <prashanto.chatterjee@xxxxxxxxxxxxxx> wrote in message
news:37e7165eda181c20c08a40b9007fcdb6$1@xxxxxxxxxxxxxxxxxx
> Hi All,
> The kind of feature that I am looking for is this - I am inside an
> EditPart's performRequest() method. From here I would like to create a new
> Resource in the navigator view. Somwhow I cannot find any handle to create
> a new resource. My current code looks like this:
>
> --------------------------------------------------------------------------
----
> public void performRequest(Request req) {
> if(req.getType().equals(REQ_OPEN)){
>     setSelected(SELECTED_NONE);
> try{
>         IWorkbenchPage page =
>
((DefaultEditDomain)getViewer().getEditDomain()).getEditorPart().getSite().g
etPage();
>         IFile newFile =
> EditorUtils.createNewFile(((Shape)this.getModel()).hashCode()+".eci");
>         IViewPart navView =
> (ResourceNavigator)page.findView(IPageLayout.ID_RES_NAV);
>         deactivate();
>         AppEditor editorPart =
> (AppEditor)IDE.openEditor(page,newFile,"appedit",true);
>         editorPart.addPageSequence((PageSequence)getModel());
>
> }catch(Exception we){
> we.printStackTrace();
> }
> }
> }
> --------------------------------------------------------------------------
----
>
> I have got the handle to the navigator but cannot find a way to add a new
> resource to the navigator. Please help.
>
> Appreciate any help in this regard,
> Prashanto Chatterjee
>