Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » XML Editor use in WTP 1.5.2 -
XML Editor use in WTP 1.5.2 - [message #186967] Thu, 25 January 2007 13:59 Go to next message
Eclipse User
Originally posted by: durchgedreht.gmx.de

I just migrated my development from 1.5.1 to 1.5.2
Now I cannot create the editor as eclipse tells me "Unsupported Content =
=

Type in editor". I have to register it by hand to XML. I did not have to=
=

do this in 1.5.1 !?

1) How should I register my own extension to eclipse programmatically?

Here is my Code. I followed the tutorial at
http://www.eclipse.org/webtools/wst/components/sse/tutorials /multipage-e=
ditor-tutorial.html
expect I'm using .jdx instead of .xml as extzension.

2) How can I instantiate the design page?

Please help!

Thanks,
Dennis

------------------------------------------------------------ --------
Code for the Editor page creation:
------------------------------------------------------------ --------
protected IEditorSite createSite(IEditorPart page) {
IEditorSite site =3D null;
if (page =3D=3D editor) {
site =3D new MultiPageEditorSite(this, page) {
@SuppressWarnings("restriction")
public String getId() {
// Sets this ID so nested editor is configured for XML source
return ContentTypeIdForXML.ContentTypeID_XML + ".source"; =

//$NON-NLS-1$;
}
};
}
else {
site =3D super.createSite(page);
}
return site;
}


------------------------------------------------------------ --------
Complete code:
(Note that I changed the page order - comments may be irritating :-)
------------------------------------------------------------ --------

package org.jdeluxe.editors;


import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.io.StringWriter;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FontDialog;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.part.MultiPageEditorSite;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
import =

org.eclipse.wst.xml.core.internal.provisional.contenttype.Co ntentTypeIdF=
orXML;

public class JdeluxeMultiPageEditor extends MultiPageEditorPart implemen=
ts =

IResourceChangeListener{

/** The text editor used in XML source editor */
private StructuredTextEditor editor;

/** The font chosen in page 1. */
private Font font;

/** The text widget used in page 2. */
private StyledText text;
/**
* Creates a multi-page editor example.
*/

public JdeluxeMultiPageEditor() {
super();
System.out.println("Start test");
getXmlDb();
System.out.println("end test");
ResourcesPlugin.getWorkspace().addResourceChangeListener(thi s);
}
=

/**
* Creates page 0 of the multi-page editor,
* which shows the sorted text.
*/
void createPage0() {
Composite composite =3D new Composite(getContainer(), SWT.NONE);
FillLayout layout =3D new FillLayout();
composite.setLayout(layout);
text =3D new StyledText(composite, SWT.H_SCROLL | SWT.V_SCROLL);
text.setEditable(false);
=

int index =3D addPage(composite);
setPageText(index, "Preview");
}
=

/**
* Creates the xml source editor
*/
void createXMLEditorPage() {
try {
editor =3D new StructuredTextEditor();
int index =3D addPage(editor, getEditorInput());
setPageText(index, editor.getTitle());
} catch (PartInitException e) {
ErrorDialog.openError(
getSite().getShell(),
"Error creating nested text editor",
null,
e.getStatus());
}
}
=

/**
* Creates page 1 of the multi-page editor,
* which allows you to change the font used in page 2.
*/
void createPage2() {

Composite composite =3D new Composite(getContainer(), SWT.NONE);
GridLayout layout =3D new GridLayout();
composite.setLayout(layout);
layout.numColumns =3D 2;

Button fontButton =3D new Button(composite, SWT.NONE);
GridData gd =3D new GridData(GridData.BEGINNING);
gd.horizontalSpan =3D 2;
fontButton.setLayoutData(gd);
fontButton.setText("Change Font...");
=

fontButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
setFont();
}
});

int index =3D addPage(composite);
setPageText(index, "Properties");
}
=

/**
* Creates the pages of the multi-page editor.
*/
protected void createPages() {
createPage0();
createXMLEditorPage();
createPage2();
}
=

/**
* The <code>MultiPageEditorPart</code> implementation of this
* <code>IWorkbenchPart</code> method disposes all nested editors.
* Subclasses may extend.
*/
public void dispose() {
ResourcesPlugin.getWorkspace().removeResourceChangeListener( this);
super.dispose();
}
/**
* Saves the multi-page editor's document.
*/
public void doSave(IProgressMonitor monitor) {
getEditor(1).doSave(monitor);
}
/**
* Saves the multi-page editor's document as another file.
* Also updates the text for page 0's tab, and updates this multi-page =
=

editor's input
* to correspond to the nested editor's.
*/
public void doSaveAs() {
IEditorPart editor =3D getEditor(1);
editor.doSaveAs();
setPageText(1, editor.getTitle());
setInput(editor.getEditorInput());
}
/* (non-Javadoc)
* Method declared on IEditorPart
*/
public void gotoMarker(IMarker marker) {
setActivePage(1);
IDE.gotoMarker(getEditor(1), marker);
}
/**
* The <code>MultiPageEditorExample</code> implementation of this metho=
d
* checks that the input is an instance of <code>IFileEditorInput</code=
>.
*/
public void init(IEditorSite site, IEditorInput editorInput)
throws PartInitException {
if (!(editorInput instanceof IFileEditorInput))
throw new PartInitException("Invalid Input: Must be IFileEditorInput"=
);
super.init(site, editorInput);
}
/* (non-Javadoc)
* Method declared on IEditorPart.
*/
public boolean isSaveAsAllowed() {
return true;
}
/**
* Calculates the contents of page 2 when the it is activated.
*/
protected void pageChange(int newPageIndex) {
super.pageChange(newPageIndex);
if (newPageIndex =3D=3D 2) {
sortWords();
}
}
/**
* Closes all project files on project close.
*/
public void resourceChanged(final IResourceChangeEvent event){
if(event.getType() =3D=3D IResourceChangeEvent.PRE_CLOSE){
Display.getDefault().asyncExec(new Runnable(){
public void run(){
IWorkbenchPage[] pages =3D getSite().getWorkbenchWindow().getPages(=
);
for (int i =3D 0; i<pages.length; i++){
if(((FileEditorInput)editor.getEditorInput()).getFile().getP roject=
().equals(event.getResource())){
IEditorPart editorPart =3D =

pages[i].findEditor(editor.getEditorInput());
pages[i].closeEditor(editorPart,true);
}
}
}
});
}
}
/**
* Sets the font related data to be applied to the text in page 2.
*/
void setFont() {
FontDialog fontDialog =3D new FontDialog(getSite().getShell());
fontDialog.setFontList(text.getFont().getFontData());
FontData fontData =3D fontDialog.open();
if (fontData !=3D null) {
if (font !=3D null)
font.dispose();
font =3D new Font(text.getDisplay(), fontData);
text.setFont(font);
}
}
/**
* Sorts the words in page 0, and shows them in page 2.
*/
void sortWords() {

String editorText =3D
editor.getDocumentProvider().getDocument(editor.getEditorInp ut()).get=
();

StringTokenizer tokenizer =3D
new StringTokenizer(editorText, " =

\t\n\r\f!@#\u0024%^&*()-_=3D+`~[]{};:'\",.<>/?|\\");
ArrayList editorWords =3D new ArrayList();
while (tokenizer.hasMoreTokens()) {
editorWords.add(tokenizer.nextToken());
}

Collections.sort(editorWords, Collator.getInstance());
StringWriter displayText =3D new StringWriter();
for (int i =3D 0; i < editorWords.size(); i++) {
displayText.write(((String) editorWords.get(i)));
displayText.write(System.getProperty("line.separator"));
}
text.setText(displayText.toString());
}
=

=

/**
* @see =

org.eclipse.ui.part.MultiPageEditorPart#createSite(org.eclip se.ui.IEdito=
rPart)
*/
protected IEditorSite createSite(IEditorPart page) {
IEditorSite site =3D null;
if (page =3D=3D editor) {
site =3D new MultiPageEditorSite(this, page) {
@SuppressWarnings("restriction")
public String getId() {
// Sets this ID so nested editor is configured for XML source
return ContentTypeIdForXML.ContentTypeID_XML + ".source"; =

//$NON-NLS-1$;
}
};
}
else {
site =3D super.createSite(page);
}
return site;
}
=

private void getXmlDb(){
=

}
}
Re: XML Editor use in WTP 1.5.2 - [message #187085 is a reply to message #186967] Fri, 26 January 2007 13:23 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2272
Registered: July 2009
Senior Member
Dennis Meyer wrote:
> I just migrated my development from 1.5.1 to 1.5.2
> Now I cannot create the editor as eclipse tells me "Unsupported Content
> Type in editor". I have to register it by hand to XML. I did not have to
> do this in 1.5.1 !?
>
> 1) How should I register my own extension to eclipse programmatically?
>
> Here is my Code. I followed the tutorial at
> http://www.eclipse.org/webtools/wst/components/sse/tutorials /multipage-editor-tutorial.html
>
> expect I'm using .jdx instead of .xml as extzension.

In both versions, you would have had to tell the platform to treat
*.jdx like XML (you're certain you didn't do something similar under
1.5.1?). The org.eclipse.core.runtime.contentTypes extension point
is how you would do so, either by using a file-association element
to associate .jdx with the XML content type or by using the
content-type element to make a new subtype of the XML content type.

http://help.eclipse.org/help32/topic/org.eclipse.platform.do c.isv/reference/extension-points/org_eclipse_core_contenttyp e_contentTypes.html


> 2) How can I instantiate the design page?

The design page is internal and not meant to be instantiated outside
of the XML Editor itself.

--
Nitin Dahyabhai
Structured Source Editor


---
Nitin Dahyabhai
Eclipse WTP, IBM
Re: XML Editor use in WTP 1.5.2 - [message #187114 is a reply to message #187085] Fri, 26 January 2007 15:25 Go to previous message
Eclipse User
Originally posted by: durchgedreht.gmx.de

Thanks for your answer.

1) This was a good idea! I did configure it, but it seems I did somethin=
g =

wrong. When I delete the contenttype setting in the runtime Eclipse that=
I =

added myself, it will throw an error "contenttype not supported". So I'm=
=

doing something wrong!

<extension
id=3D"org.eclipse.core.contenttype.contentTypes"
name=3D"Jdeluxe"
point=3D"org.eclipse.core.contenttype.contentTypes">
<file-association
content-type=3D"org.eclipse.core.runtime.xml"
file-extensions=3D"jdx"
/>
</extension>

2) Does this mean, I will see it every time I use the XML Editor or does=
=

this mean I cannot see the design page inside my Multipage Editor at all=
?

Thanks for your help!
Dennis


Am 26.01.2007, 14:23 Uhr, schrieb Nitin Dahyabhai <nitind@us.ibm.com>:

> Dennis Meyer wrote:
>> I just migrated my development from 1.5.1 to 1.5.2
>> Now I cannot create the editor as eclipse tells me "Unsupported Conte=
nt =

>> Type in editor". I have to register it by hand to XML. I did not have=
=

>> to do this in 1.5.1 !?
>> 1) How should I register my own extension to eclipse programmaticall=
y?
>> Here is my Code. I followed the tutorial at
>> http://www.eclipse.org/webtools/wst/components/sse/tutorials /multipag=
e-editor-tutorial.html =

>> expect I'm using .jdx instead of .xml as extzension.
>
> In both versions, you would have had to tell the platform to treat *.j=
dx =

> like XML (you're certain you didn't do something similar under 1.5.1?)=
.. =

> The org.eclipse.core.runtime.contentTypes extension point is how you =

> would do so, either by using a file-association element to associate =

> .jdx with the XML content type or by using the content-type element to=
=

> make a new subtype of the XML content type.
>
> http://help.eclipse.org/help32/topic/org.eclipse.platform.do c.isv/refe=
rence/extension-points/org_eclipse_core_contenttype_contentT ypes.html
>
>
>> 2) How can I instantiate the design page?
>
> The design page is internal and not meant to be instantiated outside o=
f =

> the XML Editor itself.
>
> --
> Nitin Dahyabhai
> Structured Source Editor



-- =

Erstellt mit Operas revolution=C3=A4rem E-Mail-Modul: http://www.opera.c=
om/mail/
Previous Topic:dynamic web project + struts
Next Topic:Preventing external loading of xsd
Goto Forum:
  


Current Time: Thu Sep 18 23:50:31 GMT 2014

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

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