Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Visual Editor (VE) » openning visual editor programmatically
openning visual editor programmatically [message #117131] Wed, 08 February 2006 12:33 Go to next message
Eclipse UserFriend
Originally posted by: rashmi.h.ramachandra.sap.com

Hi All,
I am trying to open Visual Editor. I am using the following code.

JavaVisualEditorPart javaVisualEditor =
(JavaVisualEditorPart)activePage.openEditor(new
FileEditorInput(file)," org.eclipse.ve.internal.java.codegen.editorpart.JavaVisualEd itor ",true);

This code I have used in a plugin that can be invoked from the package
explorer's context menu on a particular file . When I invoke the menu item
on the file ,it says 'file not found' in the java editor window and has a
blank page in the visual editor window. The FileEditorInput is loading
properly. I have checked it.
can anybody please help,
-Rashmi . H. R
Re: openning visual editor programmatically [message #117156 is a reply to message #117131] Wed, 08 February 2006 15:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Make sure that the IFile exists and is in a java source directory in a
java project. Another thing you can try is to try opening the standard
java editor using the id "org.eclipse.jdt.ui.CompilationUnitEditor" and
see if that works. If it doesn't work then the problem is in the file,
if it does then it the problem is with the VE.

Rashmi H.R wrote:
> Hi All,
> I am trying to open Visual Editor. I am using the following code.
>
> JavaVisualEditorPart javaVisualEditor =
> (JavaVisualEditorPart)activePage.openEditor(new
> FileEditorInput(file)," org.eclipse.ve.internal.java.codegen.editorpart.JavaVisualEd itor ",true);
>
>
> This code I have used in a plugin that can be invoked from the package
> explorer's context menu on a particular file . When I invoke the menu
> item on the file ,it says 'file not found' in the java editor window and
> has a blank page in the visual editor window. The FileEditorInput is
> loading properly. I have checked it.
> can anybody please help,
> -Rashmi . H. R
>
>

--
Thanks,
Rich Kulp
Re: openning visual editor programmatically [message #117219 is a reply to message #117156] Thu, 09 February 2006 06:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rashmi.h.ramachandra.sap.com

hi Rich,

Thanks for the reply.
I am not able to open the compilationUnitEditor also, I am using the
following code.

activePage.openEditor(new
FileEditorInput(file),"org.eclipse.jdt.ui.CompilationUnitEditor ",true) ;

The IFile exists because I able to print it's absolute path and relative
path through the FileEditorInput object. They are pointing to correct path.

I am retriving the IFile from the CompilationUnit as follows.

IFile f = ijp.getProject().getFile(type.getPath());

,where 'type' is my CompilationUnit object. I am able to do operation on
the CompilationUnit such as adding a method, field etc and that is
reflected in the java file. Hence I assume that my CompilationUnit object
is a valid one.

I am using Eclipse 3.1 and V.E 1.1.

Is there any problem with the way I am accessing the IFile?
Can you Please help.

Thanks and Best Regards
-Rashmi H.R
Re: openning visual editor programmatically [message #117230 is a reply to message #117156] Thu, 09 February 2006 06:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rashmi.h.ramachandra.sap.com

Hi Rich,
One more thing I had left out . I am able to open the Java Editor on the
CompilationUnit object using the following code.

IEditorPart javaEditor = JavaUI.openInEditor(type);

but unable to open the visual editor.

Thanks and Regards
-Rashmi H.r
Re: openning visual editor programmatically [message #117268 is a reply to message #117230] Thu, 09 February 2006 19:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

I don't know. I'm stumped.

Rashmi H.R wrote:
> Hi Rich,
> One more thing I had left out . I am able to open the Java Editor on
> the CompilationUnit object using the following code.
>
> IEditorPart javaEditor = JavaUI.openInEditor(type);
>
> but unable to open the visual editor.
>
> Thanks and Regards
> -Rashmi H.r
>
>

--
Thanks,
Rich Kulp
Re: openning visual editor programmatically [message #117294 is a reply to message #117268] Fri, 10 February 2006 04:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rashmi.h.ramachandra.sap.com

hi Rich,

Sorry there was a code mistake.

IFile f = type.getJavaProject.getProject().getFile(type.getPath));

,'type' is a object of type ICompilationUnit.

-Rashmi H.Ramachandra.
Re: openning visual editor programmatically [message #117306 is a reply to message #117294] Fri, 10 February 2006 04:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rashmi.h.ramachandra.sap.com

Hi Rich ,

The Following is the class that I am using. If this not the correct way to
acces and use IFile to open any editor. Can you please help me regarding
how to access the IFile on the File selection in Package Explorer.

Thanks in advance ,
Rashmi H Ramachandra




import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.FileEditorInput;



/**
* Our sample action implements workbench action delegate.
* The action proxy will be created by the workbench and
* shown in the UI. When the user tries to use the action,
* this delegate will be created and execution will be
* delegated to it.
* @see IWorkbenchWindowActionDelegate
*/
public class SampleAction implements IObjectActionDelegate {
private IWorkbenchWindow window;
/**
* The constructor.
*/
public SampleAction() {
}

/**
* The action has been activated. The argument of the
* method represents the 'real' action sitting
* in the workbench UI.
* @see IWorkbenchWindowActionDelegate#run
*/
public void run(IAction action) {

if(!(selection instanceof IStructuredSelection))
return;

IStructuredSelection structured = (IStructuredSelection)selection;
ICompilationUnit type =
(ICompilationUnit)structured.getFirstElement();
IFile file=
type.getJavaProject().getProject().getFile(type.getElementNa me());

IWorkbenchWindow window =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage activePage = window.getActivePage();

// For opening java editor::::
// IEditorPart javaEditor = JavaUI.openInEditor(type);

try {

activePage.openEditor(new
FileEditorInput(file)," org.eclipse.ve.internal.java.codegen.editorpart.JavaVisualEd itor ",true)
;
// JavaVisualEditorPart javaVisualEditor =
(JavaVisualEditorPart)activePage.openEditor(fei," org.eclipse.ve.internal.java.codegen.editorpart.JavaVisualEd itor ",true)
;

} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


/**
* Selection in the workbench has been changed. We
* can change the state of the 'real' action here
* if we want, but this can only happen after
* the delegate has been created.
* @see IWorkbenchWindowActionDelegate#selectionChanged
*/
ISelection selection;

public void selectionChanged(IAction action, ISelection selection)
{
this.selection=selection;
}

/* (non-Javadoc)
* @see
org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclip se.jface.action.IAction,
org.eclipse.ui.IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
// TODO Auto-generated method stub
}
}
Re: openning visual editor programmatically [message #117331 is a reply to message #117306] Fri, 10 February 2006 15:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Try this instead:

ICompilationUnit type = (ICompilationUnit)structured.getFirstElement();
IFile file = (IFile) type.getResource();


type.getElementName() does not return the fullname of the file. It does
not include the package name or the packagefragment root, so if your
class is not in the default package in the root of the project it won't
be a valid file. getFile(String) will ALWAYS return an IFile, but the
file it points to might not exist.

--
Thanks,
Rich Kulp
Re: openning visual editor programmatically [message #118196 is a reply to message #117331] Fri, 17 February 2006 05:46 Go to previous message
Eclipse UserFriend
Originally posted by: rashmi.h.ramachandra.sap.com

Hi Rich,

Thank you very much . It worked.

Regards,
Rashmi H.R
Re: openning visual editor programmatically [message #611984 is a reply to message #117131] Wed, 08 February 2006 15:00 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Make sure that the IFile exists and is in a java source directory in a
java project. Another thing you can try is to try opening the standard
java editor using the id "org.eclipse.jdt.ui.CompilationUnitEditor" and
see if that works. If it doesn't work then the problem is in the file,
if it does then it the problem is with the VE.

Rashmi H.R wrote:
> Hi All,
> I am trying to open Visual Editor. I am using the following code.
>
> JavaVisualEditorPart javaVisualEditor =
> (JavaVisualEditorPart)activePage.openEditor(new
> FileEditorInput(file)," org.eclipse.ve.internal.java.codegen.editorpart.JavaVisualEd itor ",true);
>
>
> This code I have used in a plugin that can be invoked from the package
> explorer's context menu on a particular file . When I invoke the menu
> item on the file ,it says 'file not found' in the java editor window and
> has a blank page in the visual editor window. The FileEditorInput is
> loading properly. I have checked it.
> can anybody please help,
> -Rashmi . H. R
>
>

--
Thanks,
Rich Kulp
Re: openning visual editor programmatically [message #611989 is a reply to message #117156] Thu, 09 February 2006 06:46 Go to previous message
Eclipse UserFriend
Originally posted by: rashmi.h.ramachandra.sap.com

hi Rich,

Thanks for the reply.
I am not able to open the compilationUnitEditor also, I am using the
following code.

activePage.openEditor(new
FileEditorInput(file),"org.eclipse.jdt.ui.CompilationUnitEditor ",true) ;

The IFile exists because I able to print it's absolute path and relative
path through the FileEditorInput object. They are pointing to correct path.

I am retriving the IFile from the CompilationUnit as follows.

IFile f = ijp.getProject().getFile(type.getPath());

,where 'type' is my CompilationUnit object. I am able to do operation on
the CompilationUnit such as adding a method, field etc and that is
reflected in the java file. Hence I assume that my CompilationUnit object
is a valid one.

I am using Eclipse 3.1 and V.E 1.1.

Is there any problem with the way I am accessing the IFile?
Can you Please help.

Thanks and Best Regards
-Rashmi H.R
Re: openning visual editor programmatically [message #611990 is a reply to message #117156] Thu, 09 February 2006 06:54 Go to previous message
Eclipse UserFriend
Originally posted by: rashmi.h.ramachandra.sap.com

Hi Rich,
One more thing I had left out . I am able to open the Java Editor on the
CompilationUnit object using the following code.

IEditorPart javaEditor = JavaUI.openInEditor(type);

but unable to open the visual editor.

Thanks and Regards
-Rashmi H.r
Re: openning visual editor programmatically [message #611993 is a reply to message #117230] Thu, 09 February 2006 19:40 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

I don't know. I'm stumped.

Rashmi H.R wrote:
> Hi Rich,
> One more thing I had left out . I am able to open the Java Editor on
> the CompilationUnit object using the following code.
>
> IEditorPart javaEditor = JavaUI.openInEditor(type);
>
> but unable to open the visual editor.
>
> Thanks and Regards
> -Rashmi H.r
>
>

--
Thanks,
Rich Kulp
Re: openning visual editor programmatically [message #611995 is a reply to message #117268] Fri, 10 February 2006 04:37 Go to previous message
Eclipse UserFriend
Originally posted by: rashmi.h.ramachandra.sap.com

hi Rich,

Sorry there was a code mistake.

IFile f = type.getJavaProject.getProject().getFile(type.getPath));

,'type' is a object of type ICompilationUnit.

-Rashmi H.Ramachandra.
Re: openning visual editor programmatically [message #611996 is a reply to message #117294] Fri, 10 February 2006 04:57 Go to previous message
Eclipse UserFriend
Originally posted by: rashmi.h.ramachandra.sap.com

Hi Rich ,

The Following is the class that I am using. If this not the correct way to
acces and use IFile to open any editor. Can you please help me regarding
how to access the IFile on the File selection in Package Explorer.

Thanks in advance ,
Rashmi H Ramachandra




import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.FileEditorInput;



/**
* Our sample action implements workbench action delegate.
* The action proxy will be created by the workbench and
* shown in the UI. When the user tries to use the action,
* this delegate will be created and execution will be
* delegated to it.
* @see IWorkbenchWindowActionDelegate
*/
public class SampleAction implements IObjectActionDelegate {
private IWorkbenchWindow window;
/**
* The constructor.
*/
public SampleAction() {
}

/**
* The action has been activated. The argument of the
* method represents the 'real' action sitting
* in the workbench UI.
* @see IWorkbenchWindowActionDelegate#run
*/
public void run(IAction action) {

if(!(selection instanceof IStructuredSelection))
return;

IStructuredSelection structured = (IStructuredSelection)selection;
ICompilationUnit type =
(ICompilationUnit)structured.getFirstElement();
IFile file=
type.getJavaProject().getProject().getFile(type.getElementNa me());

IWorkbenchWindow window =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage activePage = window.getActivePage();

// For opening java editor::::
// IEditorPart javaEditor = JavaUI.openInEditor(type);

try {

activePage.openEditor(new
FileEditorInput(file)," org.eclipse.ve.internal.java.codegen.editorpart.JavaVisualEd itor ",true)
;
// JavaVisualEditorPart javaVisualEditor =
(JavaVisualEditorPart)activePage.openEditor(fei," org.eclipse.ve.internal.java.codegen.editorpart.JavaVisualEd itor ",true)
;

} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


/**
* Selection in the workbench has been changed. We
* can change the state of the 'real' action here
* if we want, but this can only happen after
* the delegate has been created.
* @see IWorkbenchWindowActionDelegate#selectionChanged
*/
ISelection selection;

public void selectionChanged(IAction action, ISelection selection)
{
this.selection=selection;
}

/* (non-Javadoc)
* @see
org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclip se.jface.action.IAction,
org.eclipse.ui.IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
// TODO Auto-generated method stub
}
}
Re: openning visual editor programmatically [message #611998 is a reply to message #117306] Fri, 10 February 2006 15:03 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Try this instead:

ICompilationUnit type = (ICompilationUnit)structured.getFirstElement();
IFile file = (IFile) type.getResource();


type.getElementName() does not return the fullname of the file. It does
not include the package name or the packagefragment root, so if your
class is not in the default package in the root of the project it won't
be a valid file. getFile(String) will ALWAYS return an IFile, but the
file it points to might not exist.

--
Thanks,
Rich Kulp
Re: openning visual editor programmatically [message #612135 is a reply to message #117331] Fri, 17 February 2006 05:46 Go to previous message
Eclipse UserFriend
Originally posted by: rashmi.h.ramachandra.sap.com

Hi Rich,

Thank you very much . It worked.

Regards,
Rashmi H.R
Previous Topic:replacing or extending overrides
Next Topic:Inside the Visual Editor
Goto Forum:
  


Current Time: Fri Apr 26 16:39:52 GMT 2024

Powered by FUDForum. Page generated in 0.03393 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top