Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Multipage XML Editor
Multipage XML Editor [message #286332] Tue, 07 June 2005 14:14 Go to next message
Eclipse UserFriend
Originally posted by: Langerjo.de.ibm.com

Hi @ all!

Anyone knows a nice tutorial how to create a multi page editor, which
edits an xml File like the plugin.xml?

And which eclipse plugin defines the functionality for editing the
plugin.xml?

Thanks in advance

Johannes
Re: Multipage XML Editor [message #286353 is a reply to message #286332] Tue, 07 June 2005 16:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse.rizzoweb.com

Johannes Langer wrote:
> Hi @ all!
>
> Anyone knows a nice tutorial how to create a multi page editor, which
> edits an xml File like the plugin.xml?
>
> And which eclipse plugin defines the functionality for editing the
> plugin.xml?

I'm not sure if you're looking for this info as a learning tool or
because you want a good generic XML editor to use. If it is the latter,
you'll find that there are already several good XML editors available
for Eclipse. One is XMLBuddy, MyEclipse includes another one. Also,
search at www.eclipse-plugins.info for more.

HTH,
Eric
Re: Multipage XML Editor [message #286383 is a reply to message #286353] Wed, 08 June 2005 09:00 Go to previous message
Eclipse UserFriend
Originally posted by: jerome.bourgeon.bull.net

Eric Rizzo wrote:
> Johannes Langer wrote:
>
>> Hi @ all!
>>
>> Anyone knows a nice tutorial how to create a multi page editor, which
>> edits an xml File like the plugin.xml?
>>
>> And which eclipse plugin defines the functionality for editing the
>> plugin.xml?
>
>
> I'm not sure if you're looking for this info as a learning tool or
> because you want a good generic XML editor to use. If it is the latter,
> you'll find that there are already several good XML editors available
> for Eclipse. One is XMLBuddy, MyEclipse includes another one. Also,
> search at www.eclipse-plugins.info for more.
>
> HTH,
> Eric

Hi,

NB: it's an example (not for doing a XML multi page editor, but a multi
page editor) i don't know if it's a good use but it works( excuse me I'm
a little busy today if you have some question, and if there are mistakes
you can correct me (I'm a newbee).

to create a multi page editor you need :
- in the plugin.xml :
<extension point="org.eclipse.ui.editors">
<editor
class="org.example.XMLEditor"
default="true"
icon="penguin.gif"
id="org.example.XMLEditor"
matchingStrategy="org.example.XMLEditorMatchingStrategy"
name="XMLEditor">
</editor>
</extension>

You can add of course the extension of the files, the icon...

- The class XMLEditor
public class XMLEditor extends FormEditor {

public static final String ID_EDITOR = "org.example.XMLEditor";
//$NON-NLS-1$

protected FormToolkit createToolkit(Display display) {
// Create a toolkit that shares colors between editors.
return new
FormToolkit(ConfigurationPlugin.getDefault().getFormColors(d isplay));
}
protected void addPages() {
try{ // note book like in the editor
addPage(new FreeFormPage(this));
addPage(new FreeFormPage2(this));
addPage(new FormPage3(this));
addPage(new FormPage4(this));
addPage(new FormPage5(this));
}catch(PartInitException e){

}

}

public void doSave(IProgressMonitor monitor) {
// TODO Auto-generated method stub

}

public void doSaveAs() {
// TODO Auto-generated method stub

}

public boolean isSaveAsAllowed() {
// TODO Auto-generated method stub
return false;
}

public void init(IEditorSite site, IEditorInput input) throws
PartInitException {
this.setPartName(input.getName());
this.setTitleImage(ConfigurationPlugin.getImageDescriptor("an
image").createImage());
this.setTitleToolTip(input.getName());
super.init(site, input);
}

}

- a class XMLEditorInput whiwh define your instance of an editor

public class XMLEditorInput implements IEditorInput {
private String name = null;

public XMLEditorInput() {
super();
// TODO Auto-generated constructor stub
}

public XMLEditorInput(String name) {
super();
this.name=name;
// TODO Auto-generated constructor stub
}

public boolean exists() {
// TODO Auto-generated method stub
return true;
}

public ImageDescriptor getImageDescriptor() {
// TODO Auto-generated method stub
return null;
}

public String getName() {
// TODO Auto-generated method stub
return name;
}

public IPersistableElement getPersistable() {
// TODO Auto-generated method stub
return null;
}

public String getToolTipText() {
// TODO Auto-generated method stub
return name;
}

public Object getAdapter(Class adapter) {
// TODO Auto-generated method stub
return null;
}

public boolean equals(Object obj) {
if (obj == null) return false;
if (! (obj instanceof XMLEditorInput)) return false;
XMLEditorInput other = (XMLEditorInput)obj;
if (!(other.name.equals(this.name)))return false;

return true;
}

public int hashCode() {
// TODO Auto-generated method stub
return name.hashCode();
}

}

- the matching strategy class

public class XMLEditorMatchingStrategy implements IEditorMatchingStrategy {

public XMLEditorMatchingStrategy() {
super();
// TODO Auto-generated constructor stub
}

public boolean matches(IEditorReference editorRef, IEditorInput input) {
try { // check you have not the same editoralready open, useful for
opening a new one
return editorRef.getEditorInput().equals(input);
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}

}
- the pages you add
public class FreeFormPage extends FormPage {...
Here you can do your "editor" for an XML



I you use a tree view you have done by yourself
in the double click action for example do this :
doubleClickAction = new Action() {
public void run() {
ISelection sel = viewer.getSelection();
if (sel instanceof IStructuredSelection) {
IStructuredSelection selection = (StructuredSelection) sel;
Object obj = selection.getFirstElement();
IWorkbenchPage page = ConfigurationPlugin.getDefault()
.getWorkbench().getActiveWorkbenchWindow()
.getActivePage();// it's the plugin.java of my apps
File temp = (File) obj;
try {
IEditorInput input = new XMLEditorInput(temp.getName());

page.openEditor(input,
"The id of your editor");
} catch (PartInitException e) {
System.out.println(e);
}

}

}
};


THE END :D
Previous Topic:Active Wokrbench Window not set at startup
Next Topic:How to extend the code completion behaviour
Goto Forum:
  


Current Time: Sun Oct 06 14:22:43 GMT 2024

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

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

Back to the top