Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How could i customize a java editor with a pallete
How could i customize a java editor with a pallete [message #178307] Tue, 19 April 2005 16:46 Go to next message
Eclipse UserFriend
Originally posted by: sign119.yahoo.com

Hi,

According to the discription in GEF source code, we could implement a editor
with flyout palette. And now i'm working on a java editor with a pallete,
but I find something wrong with my code. In the method createPartControl(),
if I initial a SashForm, the java editor could be shown in one of the sash
window in the sashform, but if i initial a form, I can not see the java
editor in the form. could anyone kindly tell me how could I make the java
source code shown correctly, u know, i didn't need the sashform in this case
at all. thx u so much


public class SourceEditor extends CompilationUnitEditor {
private PaletteViewerProvider provider;
private FlyoutPaletteComposite paletteSplitter;
private CustomPalettePage palettePage;
private DefaultEditDomain editDomain = new DefaultEditDomain(this);
protected GraphicalViewer graphicalViewer;

/**
* Creates a PaletteViewerProvider that will be used to create palettes for
the view
* and the flyout.
*
* @return the palette provider
*/
protected PaletteViewerProvider createPaletteViewerProvider() {
return new PaletteViewerProvider(this.editDomain);
}

/**
* @return a newly-created {@link CustomPalettePage}
*/
protected CustomPalettePage createPalettePage() {
return new CustomPalettePage(getPaletteViewerProvider());
}

/**
* @see GraphicalEditor#createPartControl(Composite)
*/
public void createPartControl(Composite parent) {
paletteSplitter = new FlyoutPaletteComposite(parent, SWT.NONE,
getSite().getPage(), getPaletteViewerProvider(), getPalettePreferences());

// JVE/Text editor split on the right under editorComposite
// SashForm editorParent = new SashForm(paletteSplitter, SWT.VERTICAL);
ScrolledForm editorParent = new ScrolledForm(paletteSplitter,
SWT.VERTICAL);

createGraphicalViewer(editorParent);
// Let the super java text editor fill it in.
super.createPartControl(editorParent);
paletteSplitter.setGraphicalControl(editorParent);
if (palettePage != null) {
paletteSplitter.setExternalViewer(palettePage.getPaletteView er());
palettePage = null;
}
// int[] weight = editorParent.getWeights();
// weight[1] = 1000;
// weight[0] = 0;
// editorParent.setWeights(weight);
// Control[] children = editorParent.getChildren();
// children[1].setFocus();

}

protected Control createGraphicalViewer(Composite parent) {
graphicalViewer = new ScrollingGraphicalViewer();
Control gviewer = graphicalViewer.createControl(parent);
editDomain.addViewer(graphicalViewer);
paletteSplitter.hookDropTargetListener(graphicalViewer);
return gviewer;
}

/**
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Cla ss)
*/
public Object getAdapter(Class type) {
if (type == PalettePage.class) {
if (paletteSplitter == null) {
palettePage = createPalettePage();
return palettePage;
}
return createPalettePage();
}
return super.getAdapter(type);
}

/**
* @return the FlyoutPreferences object used to save the flyout palette's
preferences
*/
protected FlyoutPreferences getPalettePreferences(){
return new PaletteFlyoutPreferences();
}

/**
* Returns the PaletteRoot for the palette viewer.
* @return the palette root
*/
protected PaletteRoot getPaletteRoot(){
return new PaletteViewerCreator().createPaletteRoot();
}

/**
* Returns the palette viewer provider that is used to create palettes for
the view and
* the flyout. Creates one if it doesn't already exist.
*
* @return the PaletteViewerProvider that can be used to create
PaletteViewers for
* this editor
* @see #createPaletteViewerProvider()
*/
protected final PaletteViewerProvider getPaletteViewerProvider() {
if (provider == null)
provider = createPaletteViewerProvider();
return provider;
}

/**
* A custom PalettePage that helps GraphicalEditorWithFlyoutPalette keep
the two
* PaletteViewers (one displayed in the editor and the other displayed in
the PaletteView)
* in sync when switching from one to the other (i.e., it helps maintain
state across the
* two viewers).
*
* @author Pratik Shah
* @since 3.0
*/
protected class CustomPalettePage extends PaletteViewerPage {
/**
* Constructor
* @param provider the provider used to create a PaletteViewer
*/
public CustomPalettePage(PaletteViewerProvider provider) {
super(provider);
}
/**
* @see
org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widg ets.Composite)
*/
public void createControl(Composite parent) {
super.createControl(parent);
if (paletteSplitter != null)
paletteSplitter.setExternalViewer(viewer);
}
/**
* @see org.eclipse.ui.part.IPage#dispose()
*/
public void dispose() {
if (paletteSplitter != null)
paletteSplitter.setExternalViewer(null);
super.dispose();
}
/**
* @return the PaletteViewer created and displayed by this page
*/
public PaletteViewer getPaletteViewer() {
return viewer;
}
}

}
Re: How could i customize a java editor with a pallete [message #178371 is a reply to message #178307] Tue, 19 April 2005 22:01 Go to previous message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
You're creating a GEF-based Java editor? That's a bold move. I'd love to
see what you come up with. I hope you're using the latest version of the
draw2d.text package and have looked at org.eclipse.gef.examples.text
example.

What's a Form? Or ScrolledForm? If you're trying to split up the palette
and the editor, you don't need to do that. FlyoutPaletteComposite is the
"splitter". It'll take care of that.

"Magic" <sign119@yahoo.com> wrote in message
news:d43d43$kh1$1@news.eclipse.org...
> Hi,
>
> According to the discription in GEF source code, we could implement a
editor
> with flyout palette. And now i'm working on a java editor with a pallete,
> but I find something wrong with my code. In the method
createPartControl(),
> if I initial a SashForm, the java editor could be shown in one of the sash
> window in the sashform, but if i initial a form, I can not see the java
> editor in the form. could anyone kindly tell me how could I make the java
> source code shown correctly, u know, i didn't need the sashform in this
case
> at all. thx u so much
>
>
> public class SourceEditor extends CompilationUnitEditor {
> private PaletteViewerProvider provider;
> private FlyoutPaletteComposite paletteSplitter;
> private CustomPalettePage palettePage;
> private DefaultEditDomain editDomain = new DefaultEditDomain(this);
> protected GraphicalViewer graphicalViewer;
>
> /**
> * Creates a PaletteViewerProvider that will be used to create palettes
for
> the view
> * and the flyout.
> *
> * @return the palette provider
> */
> protected PaletteViewerProvider createPaletteViewerProvider() {
> return new PaletteViewerProvider(this.editDomain);
> }
>
> /**
> * @return a newly-created {@link CustomPalettePage}
> */
> protected CustomPalettePage createPalettePage() {
> return new CustomPalettePage(getPaletteViewerProvider());
> }
>
> /**
> * @see GraphicalEditor#createPartControl(Composite)
> */
> public void createPartControl(Composite parent) {
> paletteSplitter = new FlyoutPaletteComposite(parent, SWT.NONE,
> getSite().getPage(), getPaletteViewerProvider(), getPalettePreferences());
>
> // JVE/Text editor split on the right under editorComposite
> // SashForm editorParent = new SashForm(paletteSplitter, SWT.VERTICAL);
> ScrolledForm editorParent = new ScrolledForm(paletteSplitter,
> SWT.VERTICAL);
>
> createGraphicalViewer(editorParent);
> // Let the super java text editor fill it in.
> super.createPartControl(editorParent);
> paletteSplitter.setGraphicalControl(editorParent);
> if (palettePage != null) {
> paletteSplitter.setExternalViewer(palettePage.getPaletteView er());
> palettePage = null;
> }
> // int[] weight = editorParent.getWeights();
> // weight[1] = 1000;
> // weight[0] = 0;
> // editorParent.setWeights(weight);
> // Control[] children = editorParent.getChildren();
> // children[1].setFocus();
>
> }
>
> protected Control createGraphicalViewer(Composite parent) {
> graphicalViewer = new ScrollingGraphicalViewer();
> Control gviewer = graphicalViewer.createControl(parent);
> editDomain.addViewer(graphicalViewer);
> paletteSplitter.hookDropTargetListener(graphicalViewer);
> return gviewer;
> }
>
> /**
> * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Cla ss)
> */
> public Object getAdapter(Class type) {
> if (type == PalettePage.class) {
> if (paletteSplitter == null) {
> palettePage = createPalettePage();
> return palettePage;
> }
> return createPalettePage();
> }
> return super.getAdapter(type);
> }
>
> /**
> * @return the FlyoutPreferences object used to save the flyout palette's
> preferences
> */
> protected FlyoutPreferences getPalettePreferences(){
> return new PaletteFlyoutPreferences();
> }
>
> /**
> * Returns the PaletteRoot for the palette viewer.
> * @return the palette root
> */
> protected PaletteRoot getPaletteRoot(){
> return new PaletteViewerCreator().createPaletteRoot();
> }
>
> /**
> * Returns the palette viewer provider that is used to create palettes
for
> the view and
> * the flyout. Creates one if it doesn't already exist.
> *
> * @return the PaletteViewerProvider that can be used to create
> PaletteViewers for
> * this editor
> * @see #createPaletteViewerProvider()
> */
> protected final PaletteViewerProvider getPaletteViewerProvider() {
> if (provider == null)
> provider = createPaletteViewerProvider();
> return provider;
> }
>
> /**
> * A custom PalettePage that helps GraphicalEditorWithFlyoutPalette keep
> the two
> * PaletteViewers (one displayed in the editor and the other displayed in
> the PaletteView)
> * in sync when switching from one to the other (i.e., it helps maintain
> state across the
> * two viewers).
> *
> * @author Pratik Shah
> * @since 3.0
> */
> protected class CustomPalettePage extends PaletteViewerPage {
> /**
> * Constructor
> * @param provider the provider used to create a PaletteViewer
> */
> public CustomPalettePage(PaletteViewerProvider provider) {
> super(provider);
> }
> /**
> * @see
> org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widg ets.Composite)
> */
> public void createControl(Composite parent) {
> super.createControl(parent);
> if (paletteSplitter != null)
> paletteSplitter.setExternalViewer(viewer);
> }
> /**
> * @see org.eclipse.ui.part.IPage#dispose()
> */
> public void dispose() {
> if (paletteSplitter != null)
> paletteSplitter.setExternalViewer(null);
> super.dispose();
> }
> /**
> * @return the PaletteViewer created and displayed by this page
> */
> public PaletteViewer getPaletteViewer() {
> return viewer;
> }
> }
>
> }
>
>
Previous Topic:connections with right angle bends
Next Topic:How to create a new file inside an editor
Goto Forum:
  


Current Time: Fri Apr 26 20:54:30 GMT 2024

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

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

Back to the top