com.ibm.jdg2e.msseditor.ui
Class MiniSSResourceEditor

java.lang.Object
  extended byorg.eclipse.ui.part.WorkbenchPart
      extended byorg.eclipse.ui.part.EditorPart
          extended bycom.ibm.jdg2e.msseditor.ui.AbstractMiniSSEditor
              extended bycom.ibm.jdg2e.msseditor.ui.MiniSSResourceEditor
All Implemented Interfaces:
java.util.EventListener, org.eclipse.core.runtime.IAdaptable, org.eclipse.ui.IEditorPart, org.eclipse.core.runtime.IExecutableExtension, IMiniSSListener, org.eclipse.core.resources.IResourceChangeListener, org.eclipse.ui.ISaveablePart, org.eclipse.ui.part.IShowInSource, org.eclipse.ui.part.IShowInTargetList, org.eclipse.ui.IWorkbenchPart, org.eclipse.ui.IWorkbenchPart2

public class MiniSSResourceEditor
extends AbstractMiniSSEditor
implements org.eclipse.core.resources.IResourceChangeListener, org.eclipse.ui.part.IShowInSource, org.eclipse.ui.part.IShowInTargetList

Defines a sample "mini-spreadsheet" editor that demonstrates how to create an editor whose input is based on resources from the workspace.

The mini-spreadsheet editor defines its own toolbar button, main menu bar pull-down labeled "Calculations," and context menu. It will also allow others to extend it with their own actions; for example, the com.ibm.jdg2e.msseditor.extras plug-in contributes toolbar buttons, menu choices, and editor pop-up menu choices (denoted in the UI with an asterisk).


Field Summary
 
Fields inherited from class com.ibm.jdg2e.msseditor.ui.AbstractMiniSSEditor
miniSpreadsheet
 
Fields inherited from interface org.eclipse.ui.IEditorPart
PROP_DIRTY, PROP_INPUT
 
Fields inherited from interface org.eclipse.ui.IWorkbenchPart
PROP_TITLE
 
Constructor Summary
MiniSSResourceEditor()
           
 
Method Summary
 org.eclipse.ui.IEditorInput createNewInput(java.lang.String message)
          Create a new valid IEditorInput for this concrete implementation, an editor input of IFile.
 void dispose()
           
 org.eclipse.ui.part.ShowInContext getShowInContext()
           
 java.lang.String[] getShowInTargetIds()
           
 void init(org.eclipse.ui.IEditorSite site, org.eclipse.ui.IEditorInput editorInput)
           
 void resourceChanged(org.eclipse.core.resources.IResourceChangeEvent event)
          This editor is a resource change listener in order to detect "special" situations.
 boolean saveContents()
          Persist the mini-spreadsheet as a workspace resource, allowing for the Restore from Local History options.
 void setContents(org.eclipse.ui.IEditorInput editorInput)
          Set the mini-spreadsheet's contents using the given IEditorInput, knowing that it has already been validated.
 org.eclipse.ui.IEditorInput validateEditorInput(org.eclipse.ui.IEditorInput editorInput)
          Return the given editor input if it valid without attempting to adapt it.
 
Methods inherited from class com.ibm.jdg2e.msseditor.ui.AbstractMiniSSEditor
appendRow, createPartControl, doSave, doSaveAs, getDefaultAlignment, getMiniSpreadsheet, isDirty, isSaveAsAllowed, rowsChanged, selectAll, selectionChanged, setAlignment, setFocus, setIsDirty, valueChanged
 
Methods inherited from class org.eclipse.ui.part.EditorPart
getEditorInput, getEditorSite, getTitleToolTip, isSaveOnCloseNeeded, setContentDescription, setInitializationData, setInput, setPartName
 
Methods inherited from class org.eclipse.ui.part.WorkbenchPart
addPropertyListener, firePropertyChange, getAdapter, getConfigurationElement, getContentDescription, getDefaultImage, getPartName, getSite, getTitle, getTitleImage, removePropertyListener, setSite, setTitle, setTitleImage, setTitleToolTip, showBusy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.ui.IWorkbenchPart
addPropertyListener, getSite, getTitle, getTitleImage, removePropertyListener
 
Methods inherited from interface org.eclipse.core.runtime.IAdaptable
getAdapter
 

Constructor Detail

MiniSSResourceEditor

public MiniSSResourceEditor()
Method Detail

createNewInput

public org.eclipse.ui.IEditorInput createNewInput(java.lang.String message)
                                           throws org.eclipse.core.runtime.CoreException
Create a new valid IEditorInput for this concrete implementation, an editor input of IFile.

Specified by:
createNewInput in class AbstractMiniSSEditor
Throws:
org.eclipse.core.runtime.CoreException

dispose

public void dispose()
Specified by:
dispose in interface org.eclipse.ui.IWorkbenchPart
See Also:
IWorkbenchPart.dispose()

getShowInContext

public org.eclipse.ui.part.ShowInContext getShowInContext()
Specified by:
getShowInContext in interface org.eclipse.ui.part.IShowInSource

getShowInTargetIds

public java.lang.String[] getShowInTargetIds()
Specified by:
getShowInTargetIds in interface org.eclipse.ui.part.IShowInTargetList

init

public void init(org.eclipse.ui.IEditorSite site,
                 org.eclipse.ui.IEditorInput editorInput)
          throws org.eclipse.ui.PartInitException
Specified by:
init in interface org.eclipse.ui.IEditorPart
Overrides:
init in class AbstractMiniSSEditor
Throws:
org.eclipse.ui.PartInitException
See Also:
IEditorPart.init(IEditorSite, IEditorInput)

resourceChanged

public void resourceChanged(org.eclipse.core.resources.IResourceChangeEvent event)
This editor is a resource change listener in order to detect "special" situations. Specifically: This editor supports both file-based and stream-based inputs. Note that the editor input can become file-based if the user chooses "Save As...".

Specified by:
resourceChanged in interface org.eclipse.core.resources.IResourceChangeListener
See Also:
IResourceChangeListener.resourceChanged(IResourceChangeEvent)

saveContents

public boolean saveContents()
                     throws org.eclipse.core.runtime.CoreException
Persist the mini-spreadsheet as a workspace resource, allowing for the Restore from Local History options.

Specified by:
saveContents in class AbstractMiniSSEditor
Throws:
org.eclipse.core.runtime.CoreException

setContents

public void setContents(org.eclipse.ui.IEditorInput editorInput)
                 throws org.eclipse.core.runtime.CoreException
Set the mini-spreadsheet's contents using the given IEditorInput, knowing that it has already been validated.

Specified by:
setContents in class AbstractMiniSSEditor
Throws:
org.eclipse.core.runtime.CoreException
See Also:
validateEditorInput(IEditorInput)

validateEditorInput

public org.eclipse.ui.IEditorInput validateEditorInput(org.eclipse.ui.IEditorInput editorInput)
Return the given editor input if it valid without attempting to adapt it.

Editor Note: A fuller implementation might accept any input that is adaptable to the ILocationProvider protocol. As coded, this implementation will only allow workspace resources, not arbitrary files, such as those that are accessible from the File > Open External File... menu choice. Moving the MiniSSEditorInput from the com.ibm.jdg2e.msseditor.miniwp project to the com.ibm.jdg2e.msseditor.common project would accomplish much of this goal, if desired. We decided against this approach because it would blur the distinction between workspace-centric and file system-centric implementations. Or to put it another way, allowing arbitrary file system access in a workspace-oriented editor may serve the interests of the user, but would complicate the points our book wishes to convey.

Also see related bug 58179 ("Problems with opening external files").

Specified by:
validateEditorInput in class AbstractMiniSSEditor
See Also:
org.eclipse.ui.editors.text.ILocationProvider, AbstractMiniSSEditor.validateEditorInput(IEditorInput)