Add new resource to navigator [message #199981] |
Thu, 20 October 2005 10:02 |
Eclipse User |
|
|
|
Originally posted by: prashanto.chatterjee.softwareag.com
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()).getEditorPa rt().getSite().getPage();
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
|
|
|
Re: Add new resource to navigator [message #200078 is a reply to message #199981] |
Thu, 20 October 2005 16:34 |
Eclipse User |
|
|
|
Originally posted by: none.unknown.com
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@softwareag.com> wrote in message
news:37e7165eda181c20c08a40b9007fcdb6$1@www.eclipse.org...
> 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()).getEditorPa rt().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
>
|
|
|
Re: Add new resource to navigator [message #200352 is a reply to message #200078] |
Fri, 21 October 2005 19:37 |
Eclipse User |
|
|
|
Originally posted by: pbeagan.yahoo_dontspamme_.com
Any resource creation/modification should be done using the
WorkspaceModificationOperation class to avoid getting out of sync with the
file system.
Pratik Shah wrote:
> 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@softwareag.com> wrote in message
> news:37e7165eda181c20c08a40b9007fcdb6$1@www.eclipse.org...
>> 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()).getEditorPa rt().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
>>
|
|
|
|
Powered by
FUDForum. Page generated in 0.04802 seconds