com.ibm.designer.domino.xsp.api.palette
Class XPagesPaletteDropActionDelegate

java.lang.Object
  extended by org.eclipse.core.commands.common.EventManager
      extended by org.eclipse.jface.action.AbstractAction
          extended by org.eclipse.jface.action.Action
              extended by com.ibm.designer.domino.xsp.api.palette.XPagesPaletteDropActionDelegate
All Implemented Interfaces:
org.eclipse.jface.action.IAction

public class XPagesPaletteDropActionDelegate
extends org.eclipse.jface.action.Action

A generic drop action delegate used by the XPages editor when dropping controls from the Controls Palette onto an XPage. This drop action takes care of ensuring that a namespace definition exists on the page for the tag that is being dropped. This drop action also populates the tag being dropped onto the page with all of the default attributes that are defined as required by that tag. This drop action also ensure that a unique id is defined for the tag (or var if the tag is a data source). Finally this drop action takes care of formatting the newly inserted tag correctly.


Field Summary
 
Fields inherited from interface org.eclipse.jface.action.IAction
AS_CHECK_BOX, AS_DROP_DOWN_MENU, AS_PUSH_BUTTON, AS_RADIO_BUTTON, AS_UNSPECIFIED, CHECKED, DESCRIPTION, ENABLED, HANDLED, IMAGE, RESULT, TEXT, TOOL_TIP_TEXT
 
Constructor Summary
XPagesPaletteDropActionDelegate()
          Creates a new instance of this class.
 
Method Summary
protected  org.w3c.dom.Element createElement(org.w3c.dom.Document doc, java.lang.String prefix)
          Creates a new DOM element.
protected  void fillDefaultProperties(org.w3c.dom.Element element)
          Populates the element with default values for properties that are defined as 'required' in the FacesRegistry.
protected  FacesDefinition findGlobalDefAndAddDependency()
          Determines if the tag (returned from getUri() and getTagName()) belongs to a library that has not yet been added as a dependency of the current application.
 java.lang.Object getAdapter(java.lang.Class adapter)
           
 org.eclipse.gef.commands.CommandStack getCommandStack()
          Returns the GEF CommandStack for the current editor.
 org.eclipse.swt.widgets.Control getControl()
          Returns the palette control.
 DesignerProject getDesignerProject()
          Returns the DesignerProject that represents the current application.
 org.w3c.dom.Document getDocument()
          Returns the document associated with the current XPage
 org.eclipse.ui.IEditorPart getEditorPart()
          Returns the editor part for the currently active editor.
 org.eclipse.swt.dnd.DropTargetEvent getEvent()
          Returns the event information about the current drop action.
protected  FacesDefinition getFacesDefinition()
          Returns the faces definition for the control being dropped onto the page.
 FacesRegistry getFacesRegistry()
           
 org.w3c.dom.Node getFocusedNode()
          Returns the node that has focus when the drop action occurred.
 org.eclipse.swt.graphics.Point getPosition()
          Returns a point that represents the editor location where the drop is to occur
protected  java.lang.String getPrefix()
          Returns the prefix for the tag that is to be inserted.
 org.w3c.dom.ranges.Range getRange()
          Returns the range of nodes currently selected.
 org.w3c.dom.Node getSelectedNodeFromSource()
          If the editor is in source mode (e.g.
 java.lang.String getTagName()
          Returns the tag name (XML local name) of the tag being dropped from the palette.
 java.lang.String getUri()
          Returns the URI that corresponds to the tag/control being dropped.
 void run()
          This method is responsible for executing the command that inserts the item being dropped from the palette onto the page.
 void setAdapter(java.lang.Object adapter)
          Used internally by the drop action delegate code.
 void setCommandStack(org.eclipse.gef.commands.CommandStack commandStack)
          Sets the GEF CommandStack that is to be used for the current operation
 void setControl(org.eclipse.swt.widgets.Control control)
          Sets the control that may be used later in the drop operation to surface further UI, such as a dialog box.
 void setDesignerProject(DesignerProject designerProject)
          Sets the DesignerProject for the current action.
 void setDocument(org.w3c.dom.Document document)
          Sets the DOM document for the current operation.
 void setEditorPart(org.eclipse.ui.IEditorPart editor)
          Sets the editor associated with this action.
 void setTagName(java.lang.String tagName)
          Set the tag name that is to be inserted in the page.
 void setUri(java.lang.String uri)
          Set the URI corresponding to the tag that is to be inserted in the page.
 
Methods inherited from class org.eclipse.jface.action.Action
convertAccelerator, convertAccelerator, findKeyCode, findKeyString, findModifier, findModifierString, getAccelerator, getActionDefinitionId, getDescription, getDisabledImageDescriptor, getHelpListener, getHoverImageDescriptor, getId, getImageDescriptor, getMenuCreator, getStyle, getText, getToolTipText, isChecked, isEnabled, isHandled, notifyResult, removeAcceleratorText, removeMnemonics, runWithEvent, setAccelerator, setActionDefinitionId, setChecked, setDescription, setDisabledImageDescriptor, setEnabled, setHelpListener, setHoverImageDescriptor, setId, setImageDescriptor, setMenuCreator, setText, setToolTipText
 
Methods inherited from class org.eclipse.jface.action.AbstractAction
addPropertyChangeListener, firePropertyChange, firePropertyChange, removePropertyChangeListener
 
Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.jface.action.IAction
addPropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

XPagesPaletteDropActionDelegate

public XPagesPaletteDropActionDelegate()
Creates a new instance of this class.

Method Detail

createElement

protected org.w3c.dom.Element createElement(org.w3c.dom.Document doc,
                                            java.lang.String prefix)
Creates a new DOM element. The element returned will be inserted into the XPage.

It is advised that clients override this method if a custom event needs to occur during the drop action. This is the preferred location to pop up a dialog for user input.

Parameters:
doc - the XPage document
prefix - the tag prefix based on the namespace URI
Returns:
returns a fully qualified element (e.g. <xp:inputText/>)

fillDefaultProperties

protected void fillDefaultProperties(org.w3c.dom.Element element)
Populates the element with default values for properties that are defined as 'required' in the FacesRegistry. Clients may override this method to add additional properties based on on context.

Parameters:
element - the element that is about to be inserted into the XPage

findGlobalDefAndAddDependency

protected FacesDefinition findGlobalDefAndAddDependency()
                                                 throws java.lang.IllegalArgumentException
Determines if the tag (returned from getUri() and getTagName()) belongs to a library that has not yet been added as a dependency of the current application. If the tag is a member of a library that is not a dependency of this application, then the user will be prompted to add the library as a dependency of the current application. If the user declines this operation (cancels) then an IllegalArgumentException is generated.

Returns:
returns the FacesDefinition for the tag that is about to be inserted. If null is returned then it means the tag cannot be found in the FacesRegistry, most likely meaning the name of the tag or namespace URI has been entered incorrectly.
Throws:
java.lang.IllegalArgumentException - throws IllegalArgumentException if the user cancels when prompted to add the new external library as a dependency of the current application.

getAdapter

public java.lang.Object getAdapter(java.lang.Class adapter)

getCommandStack

public org.eclipse.gef.commands.CommandStack getCommandStack()
Returns the GEF CommandStack for the current editor.

Returns:

getControl

public org.eclipse.swt.widgets.Control getControl()
Returns the palette control. This control may be used to create additional UI that is needed during the drop action (e.g. Composite c = new Composite(control.getShell, SWT.NONE);).

Returns:
an SWT control object, may be null

getDesignerProject

public DesignerProject getDesignerProject()
Returns the DesignerProject that represents the current application.

Returns:
returns the current DesignerProject
See Also:
DesignerProject

getDocument

public org.w3c.dom.Document getDocument()
Returns the document associated with the current XPage

Returns:
W3C DOM Document

getEditorPart

public org.eclipse.ui.IEditorPart getEditorPart()
Returns the editor part for the currently active editor.

Returns:
editor part associated with this action, null if action has not been initialized incorrectly.

getEvent

public org.eclipse.swt.dnd.DropTargetEvent getEvent()
Returns the event information about the current drop action. The event can be examined for information such as the drop location.

Returns:
an event that describes the current drop action

getFacesDefinition

protected FacesDefinition getFacesDefinition()
Returns the faces definition for the control being dropped onto the page. It also checks if the current (application level) FacesRegistry contains a dependency on the library which contains the control being dropper. If it doesn't then the dependency gets added.

Returns:
the FacesDefinition of the control being dropped. Null if the control is not found in the FacesRegistry.

getFacesRegistry

public FacesRegistry getFacesRegistry()

getFocusedNode

public org.w3c.dom.Node getFocusedNode()
Returns the node that has focus when the drop action occurred. e.g. if the user dropped the current control (being created by this drop action) onto a table cell (xp:td), then the xp:td node would be returned as the focused node.

Returns:
W3C DOM Node

getPosition

public org.eclipse.swt.graphics.Point getPosition()
Returns a point that represents the editor location where the drop is to occur

Returns:

getPrefix

protected java.lang.String getPrefix()
Returns the prefix for the tag that is to be inserted. The default implementation of this method examines the current XPage to test if the namespace has been defined already on the XPage. If it has, the existing prefix is returned. If the prefix has not been defined, the the registry is examined for an appropriate prefix, and if the component belongs to an external library the user is prompted to add a dependency on that library if needed.

Returns:
the prefix corresponding to the URI returned by getUri()

getRange

public org.w3c.dom.ranges.Range getRange()
Returns the range of nodes currently selected.

Returns:

getSelectedNodeFromSource

public org.w3c.dom.Node getSelectedNodeFromSource()
If the editor is in source mode (e.g. the source tab is selected) then the target node may not be obvious to the tooling. This method will return the selected node if the editor is in source mode.

Returns:
the selected node in source mode

getTagName

public java.lang.String getTagName()
Returns the tag name (XML local name) of the tag being dropped from the palette.

Returns:
an XML local tag name

getUri

public java.lang.String getUri()
Returns the URI that corresponds to the tag/control being dropped.

Returns:
a qualified namespace URI

run

public void run()
This method is responsible for executing the command that inserts the item being dropped from the palette onto the page. Clients should be wary about overriding this action. Helper methods are provided that allow clients to intercept certain events that occur during the drop.
createElement(Document, String) is called by the run method, clients may override this method to create their own element. Similarly clients may override fillDefaultProperties(Element) in order to add default properties to the tag being inserted.

The workflow of the default run method is as follows:
  1. Get the document representing the current XPage
  2. Get the prefix for the namespace URI provided.
  3. Add the namespace definition to the XPage if it does not already exist
  4. Prompt the user to add an external library dependency if the namespace is from an external library
  5. Create a new Element (using createElement(Document, String) which is to be inserted at the drop target
  6. Set the default properties on the tag being inserted (using fillDefaultProperties(Element))
  7. Ensure the tag has a unique ID/Var attribute
  8. Insert the newly created element into the XPage
Clients overriding this method need to ensure that all of the above workflow operations are completed.

Specified by:
run in interface org.eclipse.jface.action.IAction
Overrides:
run in class org.eclipse.jface.action.Action

setAdapter

public final void setAdapter(java.lang.Object adapter)
Used internally by the drop action delegate code. Not intended to be used by clients.

Parameters:
adapter -

setCommandStack

public void setCommandStack(org.eclipse.gef.commands.CommandStack commandStack)
Sets the GEF CommandStack that is to be used for the current operation

Parameters:
commandStack -

setControl

public void setControl(org.eclipse.swt.widgets.Control control)
Sets the control that may be used later in the drop operation to surface further UI, such as a dialog box.

Parameters:
control -

setDesignerProject

public void setDesignerProject(DesignerProject designerProject)
Sets the DesignerProject for the current action.

Parameters:
designerProject - a DesignerProject representing the current Application
See Also:
DesignerProject

setDocument

public void setDocument(org.w3c.dom.Document document)
Sets the DOM document for the current operation. Clients are advised not to override or call this method, unless the current delege is being reused outside of the context of the Controls palette.

Parameters:
document -

setEditorPart

public void setEditorPart(org.eclipse.ui.IEditorPart editor)
Sets the editor associated with this action.

Parameters:
editor, - may not be null
Throws:
java.lang.NullPointerException - throws a NullPointerException if the IEditorPart parameter is NULL

setTagName

public void setTagName(java.lang.String tagName)
Set the tag name that is to be inserted in the page.

Parameters:
tagName -

setUri

public void setUri(java.lang.String uri)
Set the URI corresponding to the tag that is to be inserted in the page.

Parameters:
uri -