sk.uniba.euromath.editor.xmlEditor
Class XMLEditor

java.lang.Object
  extended by sk.uniba.euromath.editor.xmlEditor.XMLEditor
All Implemented Interfaces:
EventListener, FocusListener, org.eclipse.swt.internal.SWTEventListener, IEditor, IDOMSelectionChangedListener, IDOMSelectionProvider
Direct Known Subclasses:
TextEditor

public class XMLEditor
extends Object
implements IEditor, IDOMSelectionProvider, FocusListener

TODO: Kollar change comment Common editor for any namespaces and any renderer used by default if no other is find for namespace examinig all registered editors for that namespace. Is implemented using GEF, providing selections, context menu, editing capability by that menu. Uses only one type EditPart - XMLEditPart. EditDomain provide one tool - XMLSelectionTool. GraphicalViewer is XMLScrollingGraphicalViewer if this is root editor in IEditor "hierarchy" otherwise GraphicalViewerImpl. Uses XMLActionContributor to create context menu and to contribute to global bars and context menu.

Author:
Tomáš Studva 31.7.2005 Martin Kollar

Constructor Summary
XMLEditor()
          Constructor.
 
Method Summary
 void addFocusListener(IFocusListener listener)
          Adds listener for focus events.
 void addSelectionChangedListener(IDOMSelectionChangedListener listener)
          Adds a listener for selection changes in this selection provider.
protected  void configureGraphicalViewer()
          Configures viewer for work.
protected  IActionContributor createActionContributor()
          Creates action contributor.
protected  void createAndInitKeyHandler()
          Creates and inits KeyHandler which handles key events, when no tool is active.
protected  org.eclipse.gef.EditDomain createEditDomain()
          Creates and configures EditDomain.
protected  XMLEditPartFactory createEditPartFactory()
          Creates XMLEditPartFactory.
 void createGraphicalViewer(Composite parent)
          Creates GraphicalViewer on parent Composite for transformed doc source.
protected  org.eclipse.gef.RootEditPart createRootEditPart()
          Creates root editpart
protected  org.eclipse.gef.EditPart createTopEditPart(IEMFigure rootFigure)
          Creates top most editpart which is editor dependend - manipulates with model, is used as editpart for editor dependent view - root figure.
 void dispose()
          Prepares for end of work.
protected  void fireSelectionChangeEvent(sk.baka.ikslibs.interval.DOMIntervalSet selection)
          Fires selection change event.
 void focusGained(FocusEvent e)
           
 void focusLost(FocusEvent e)
           
 IActionContributor getActionContributor()
          Returns xml action contributor, can be called only after init.
 Composite getClientComposite()
          Returns Composite where children IEditors will be created.
protected  org.eclipse.gef.commands.CommandStack getCommandStack()
          Returns the command stack.
 sk.baka.ikslibs.interval.DOMIntervalSet getDOMSelection()
          Returns copy of the current selection of provider.
protected  org.eclipse.gef.EditDomain getEditDomain()
          Returns EditDomain.
protected  EditorSite getEditorSite()
          Getter.
 XMLEditPartFactory getEditPartFactory()
          Getter
 List<IFocusListener> getFocusListeners()
           
protected  org.eclipse.gef.GraphicalViewer getGraphicalViewer()
          Returns graphical viewer hooked on this Editor's composite.
 Composite getHostingComposite()
          Returns composite, which host this IEditor.
protected  IEditorSite getIEditorSite()
          Returns EditorSite's PartSite.
 IRenderer getRenderer()
          Returns renderer associated with this IEditor.
 ArrayList<IDOMSelectionChangedListener> getSelectionListeners()
           
 IdVisualInfo getVisualInfo()
          Returns IdVisualInfo object.
 Set<String> getVisualizedIds()
          Returns ids of nodes which are graphically rendered(represented) by this editor.
 XMLAccess getXMLAccess()
          Getter.
protected  void hookGraphicalViewer()
          Hooks the GraphicalViewer to the rest of the EditorSite.
 void init(Source transformedDoc, IRenderer renderer, Composite parent, XMLAccess xmlAccess, EditorSite editorSite)
           Initializes the editor.
protected  void initializeGraphicalViewer(IEMFigure rootFigure)
          Set the contents of the GraphicalViewer, when is ready.
 boolean isRootEditor()
           
 void performPaintUpdate()
          Paints all figures needed to repaint.
 void reinit(Source transformedDoc, sk.baka.ikslibs.modify.IChangeCollector changes)
           Reinitialize the editor when a partial change of the transformed document occurs.
 void removeFocusListener(IFocusListener listener)
          Removes listener for focus events.
 void removeSelectionChangedListener(IDOMSelectionChangedListener listener)
          Removes the given selection change listener from this selection provider.
 void selectionChanged(DOMSelectionChangedEvent event)
          If event is IXMLSelection than this selection is routed to SelectionListeners in other way do nothing
 void setActionContributor(IActionContributor actionContributor)
           
 void setEditPartFactory(XMLEditPartFactory editPartFactory)
          Setter.
 void setFocus()
          Sets this Editor active.
protected  void setGraphicalViewer(org.eclipse.gef.GraphicalViewer viewer)
          Setter for GraphicalViewer.
protected  void setKeyHandler(org.eclipse.gef.KeyHandler keyHandler)
           
 void setSelection(sk.baka.ikslibs.interval.DOMIntervalSet selection)
          Routs information about this new IXMLSelection to SelectionListeners
 void sortIds(List<String> ids)
          Sorts ids in manner as they are graphicaly displayed.
protected  void startSelectionListening()
          Registers this editor as selection listeners to graphical viewer.
protected  void stopSelectionListening()
          Unregisters this editor as selection listeners from this editor's listeners.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLEditor

public XMLEditor()
Constructor.

Method Detail

getEditorSite

protected EditorSite getEditorSite()
Getter.

Returns:
EditorSite instance

isRootEditor

public boolean isRootEditor()
Returns:
true if this is a rootEditor

configureGraphicalViewer

protected void configureGraphicalViewer()
Configures viewer for work. After this configuration viewer is prepared to display contents.

Parameters:
source -

createEditPartFactory

protected XMLEditPartFactory createEditPartFactory()
Creates XMLEditPartFactory.

Returns:
created XMLEditPartFactory

createAndInitKeyHandler

protected void createAndInitKeyHandler()
Creates and inits KeyHandler which handles key events, when no tool is active.


hookGraphicalViewer

protected void hookGraphicalViewer()
Hooks the GraphicalViewer to the rest of the EditorSite.


getGraphicalViewer

protected org.eclipse.gef.GraphicalViewer getGraphicalViewer()
Returns graphical viewer hooked on this Editor's composite.

Returns:
graphical viewer.

setGraphicalViewer

protected void setGraphicalViewer(org.eclipse.gef.GraphicalViewer viewer)
Setter for GraphicalViewer.

Parameters:
viewer -

createGraphicalViewer

public void createGraphicalViewer(Composite parent)
Creates GraphicalViewer on parent Composite for transformed doc source.

Parameters:
parent -
source -

initializeGraphicalViewer

protected void initializeGraphicalViewer(IEMFigure rootFigure)
Set the contents of the GraphicalViewer, when is ready.

Parameters:
rootFigure - root of tree of figures, to edit/display.

createTopEditPart

protected org.eclipse.gef.EditPart createTopEditPart(IEMFigure rootFigure)
Creates top most editpart which is editor dependend - manipulates with model, is used as editpart for editor dependent view - root figure.

Parameters:
rootFigure - root of figure tree to edit/display
Returns:
created top editpart

init

public void init(Source transformedDoc,
                 IRenderer renderer,
                 Composite parent,
                 XMLAccess xmlAccess,
                 EditorSite editorSite)
          throws EditorException
Description copied from interface: IEditor

Initializes the editor. The editor should retrieve all figures from the renderer and display them on given composite. It must NOT resize nor move the composite or its children - this is handled by the EditorSite itself.

The editor works with two 'kinds' of document:

Specified by:
init in interface IEditor
Parameters:
transformedDoc - the transformed document, rendered by the renderer. May be instance of DOMSource or ObjectSource only. Editor is encouraged to throw any exception including ClassCastException if it encounters illegal objects, to detect invalid objects quickly and cleanly.
renderer - instance of the renderer, rendering the transformed document. The renderer instance is used only in this instance of editor.
parent - Composite where to install IFigures.
xmlAccess - the source document accessor.
editorSite - host for this class.
Throws:
EditorException - if the editor cannot be initialized. In such case the common text editor/generic editor/read-only editor shall be used.

reinit

public void reinit(Source transformedDoc,
                   sk.baka.ikslibs.modify.IChangeCollector changes)
Description copied from interface: IEditor

Reinitialize the editor when a partial change of the transformed document occurs. The reinitialization of renderer is already finished - editor should query for new figures for each changed element.

Specified by:
reinit in interface IEditor
Parameters:
transformedDoc - source with all changes already applied.
changes - defines changed elements. Has appropriate type for transformedDoc parameter, i.e. DOMChangeCollector for DOMSource etc.

getVisualInfo

public IdVisualInfo getVisualInfo()
Returns IdVisualInfo object. Holds which ids have been visualized and by which XMLEditPart

Returns:
IdVisualInfo

createActionContributor

protected IActionContributor createActionContributor()
Creates action contributor.

Returns:
created IActionContributor

getXMLAccess

public XMLAccess getXMLAccess()
Getter.

Returns:
XMLAccess

getIEditorSite

protected IEditorSite getIEditorSite()
Returns EditorSite's PartSite.

Returns:
IEditorSite of EditoSite.

getRenderer

public IRenderer getRenderer()
Returns renderer associated with this IEditor.

Specified by:
getRenderer in interface IEditor
Returns:
renderer associated with this editor

getClientComposite

public Composite getClientComposite()
Returns Composite where children IEditors will be created.

Specified by:
getClientComposite in interface IEditor
Returns:
composite for children editors placement

getHostingComposite

public Composite getHostingComposite()
Returns composite, which host this IEditor.

Specified by:
getHostingComposite in interface IEditor
Returns:
composite where this editor is placed

setFocus

public void setFocus()
Sets this Editor active.

Specified by:
setFocus in interface IEditor

performPaintUpdate

public void performPaintUpdate()
Description copied from interface: IEditor
Paints all figures needed to repaint.

Specified by:
performPaintUpdate in interface IEditor

getCommandStack

protected org.eclipse.gef.commands.CommandStack getCommandStack()
Returns the command stack.

Returns:
the command stack

getEditDomain

protected org.eclipse.gef.EditDomain getEditDomain()
Returns EditDomain.

Returns:
editomain

createEditDomain

protected org.eclipse.gef.EditDomain createEditDomain()
Creates and configures EditDomain. Sets DefaultTool a ActiveTool

Returns:
new EditDomain

createRootEditPart

protected org.eclipse.gef.RootEditPart createRootEditPart()
Creates root editpart

Returns:
created root editpart

getEditPartFactory

public XMLEditPartFactory getEditPartFactory()
Getter

Returns:
used EditPartFactory

setEditPartFactory

public void setEditPartFactory(XMLEditPartFactory editPartFactory)
Setter.

Parameters:
editPartFactory - to set

dispose

public void dispose()
Description copied from interface: IEditor
Prepares for end of work. Must remove this as listeners, ... .

Specified by:
dispose in interface IEditor

getDOMSelection

public sk.baka.ikslibs.interval.DOMIntervalSet getDOMSelection()
Description copied from interface: IDOMSelectionProvider
Returns copy of the current selection of provider.

Specified by:
getDOMSelection in interface IDOMSelectionProvider
Returns:
Selection in that is stored, what is selected in whole document

addSelectionChangedListener

public void addSelectionChangedListener(IDOMSelectionChangedListener listener)
Description copied from interface: IDOMSelectionProvider
Adds a listener for selection changes in this selection provider. Has no effect if an identical listener is already registered.

Specified by:
addSelectionChangedListener in interface IDOMSelectionProvider
Parameters:
listener - IDOMSelectionChangedListener to be add to listeners

removeSelectionChangedListener

public void removeSelectionChangedListener(IDOMSelectionChangedListener listener)
Description copied from interface: IDOMSelectionProvider
Removes the given selection change listener from this selection provider. Has no affect if an identical listener is not registered.

Specified by:
removeSelectionChangedListener in interface IDOMSelectionProvider
Parameters:
listener - IDOMSelectionChangedListener to be removed from listeners

stopSelectionListening

protected void stopSelectionListening()
Unregisters this editor as selection listeners from this editor's listeners. Editors listeners are GraphicalViever and EditorSite.


startSelectionListening

protected void startSelectionListening()
Registers this editor as selection listeners to graphical viewer.


fireSelectionChangeEvent

protected void fireSelectionChangeEvent(sk.baka.ikslibs.interval.DOMIntervalSet selection)
Fires selection change event.

Parameters:
selection - DOMIntervalSet instance which will be fired

setSelection

public void setSelection(sk.baka.ikslibs.interval.DOMIntervalSet selection)
Routs information about this new IXMLSelection to SelectionListeners

Specified by:
setSelection in interface IDOMSelectionProvider
Parameters:
selection - IXMLSelection to set

selectionChanged

public void selectionChanged(DOMSelectionChangedEvent event)
If event is IXMLSelection than this selection is routed to SelectionListeners in other way do nothing

Specified by:
selectionChanged in interface IDOMSelectionChangedListener
Parameters:
event -

getSelectionListeners

public ArrayList<IDOMSelectionChangedListener> getSelectionListeners()
Returns:
Returns the selectionListeners.

getActionContributor

public IActionContributor getActionContributor()
Returns xml action contributor, can be called only after init.

Specified by:
getActionContributor in interface IEditor
Returns:
action contributor to bars and menus

setActionContributor

public void setActionContributor(IActionContributor actionContributor)
Parameters:
actionContributor - The ActionContributor to set.

addFocusListener

public void addFocusListener(IFocusListener listener)
Description copied from interface: IEditor
Adds listener for focus events.

Specified by:
addFocusListener in interface IEditor

removeFocusListener

public void removeFocusListener(IFocusListener listener)
Description copied from interface: IEditor
Removes listener for focus events.

Specified by:
removeFocusListener in interface IEditor

focusGained

public void focusGained(FocusEvent e)
Specified by:
focusGained in interface FocusListener

focusLost

public void focusLost(FocusEvent e)
Specified by:
focusLost in interface FocusListener

getFocusListeners

public List<IFocusListener> getFocusListeners()
Returns:
Returns the focusListeners.

getVisualizedIds

public Set<String> getVisualizedIds()
Description copied from interface: IEditor
Returns ids of nodes which are graphically rendered(represented) by this editor. Id's are without :N suffix.

Specified by:
getVisualizedIds in interface IEditor
Returns:
new instance, list of ids which are visualized

setKeyHandler

protected void setKeyHandler(org.eclipse.gef.KeyHandler keyHandler)
Parameters:
keyHandler - The keyHandler to set.

sortIds

public void sortIds(List<String> ids)
Description copied from interface: IEditor
Sorts ids in manner as they are graphicaly displayed. X and also Y coordinates of graphics for id is considered. Use full ids, include with their :N component.

Specified by:
sortIds in interface IEditor
Parameters:
ids - list of ids to sort


Copyright © 2003-2006 null. All Rights Reserved.