com.adobe.flexbuilder.designmodel
Class DesignModelPlugin

java.lang.Object
  extended by org.eclipse.core.runtime.Plugin
      extended by com.adobe.flexbuilder.designmodel.DesignModelPlugin
All Implemented Interfaces:
org.osgi.framework.BundleActivator

public class DesignModelPlugin
extends org.eclipse.core.runtime.Plugin

A plugin that maintains browsable, editable object models that continuously synchronize with a corresponding source code document.


Nested Class Summary
static interface DesignModelPlugin.EditEnabler
          Passed to getModelForDocument
 
Field Summary
 
Fields inherited from class org.eclipse.core.runtime.Plugin
PLUGIN_PREFERENCE_SCOPE, PREFERENCES_DEFAULT_OVERRIDE_BASE_NAME, PREFERENCES_DEFAULT_OVERRIDE_FILE_NAME
 
Constructor Summary
DesignModelPlugin()
          Constructor
 
Method Summary
 void addModel(com.adobe.flexbuilder.designmodel.DesignModel model)
          Add a model
 boolean checkResourcesDisposed()
           
 ICSSModel createCSSModel()
          Creates an empty CSS model.
 IMXMLModel createMXMLModel()
          Creates an empty MXML model.
static void defineFakeDefaultProperty(java.lang.String component, java.lang.String property)
           
 void editorGoingAway(org.eclipse.jface.text.IDocument document, org.eclipse.jface.viewers.ISelectionProvider selectionProvider, org.eclipse.jface.text.IUndoManager undoManager)
          Call this when an IDocument is going to be shut down, for example because an editor is being closed.
 IDesignModel getDebugModelForFile(java.lang.String filename, com.adobe.flexbuilder.designmodel.MarkerSplitter splitter, boolean editable)
           
static DesignModelPlugin getDefault()
          Fetch the one-and-only singleton instance of the Design Model plugin.
 IDesignModel getEditableModelForFile(org.eclipse.core.resources.IFile file)
          get the editable model for the file
 IDesignModel getEditorOrDiskModelForFile(org.eclipse.core.resources.IFile file, boolean create)
          If the given file is open in an editor, returns the model used by that editor.
 IDesignModel getModelForDocument(org.eclipse.jface.text.IDocument document, org.eclipse.jface.viewers.ISelectionProvider selectionProvider, org.eclipse.jface.text.IUndoManager undoManager, org.eclipse.core.resources.IFile file, DesignModelPlugin.EditEnabler editEnabler)
          Finds or creates a Design model that corresponds to the text of an IDocument.
 IDesignModel getModelForFile(org.eclipse.core.resources.IFile file)
          Finds or creates a Design model corresponding to the file.
 IDesignModel getUniqueModelForFile(org.eclipse.core.resources.IFile file)
          see getModelForFile.
 boolean hasModelForDocument(org.eclipse.jface.text.IDocument document)
          Finds out if there already exists a design model that corresponds to the text of an IDocument.
static boolean isCreateVirtualItems()
           
static boolean isDumpStateDebugInfo()
           
static boolean isEditorModel(IDesignModel model)
          Returns whether a model is in use by an editor
static boolean isUseHardCoded()
           
 void removeModel(com.adobe.flexbuilder.designmodel.DesignModel model)
          Remove a model
 void saveDiskModel(IDesignModel model)
          If the given model is a model for a file on disk, saves the model out to the file.
 void selectionEvent(IDesignModel model, org.eclipse.jface.viewers.SelectionChangedEvent event)
           
static void setCreateVirtualItems(boolean createVirtualItems)
           
static void setDumpStateDebugInfo(boolean dump)
           
 void setEditListener(com.adobe.flexbuilder.designmodel.IEditListener endEdit)
           
static void setUseHardCoded(boolean useHardCoded)
           
 void start(org.osgi.framework.BundleContext context)
          This method is called upon plug-in activation
 void updateDocument(org.eclipse.core.resources.IFile oldFile, org.eclipse.jface.text.IDocument newDocument, org.eclipse.jface.viewers.ISelectionProvider selectionProvider, org.eclipse.jface.text.IUndoManager undoManager, org.eclipse.core.resources.IFile newFile, boolean editable)
          Call this when the IDocument/IFile associated with a model need to change, for example after doing a Save As or Rename.
static java.lang.String xmlEscape(java.lang.String str)
          Finds any special characters in a string and replaces them with the corresponding XML Entity.
 
Methods inherited from class org.eclipse.core.runtime.Plugin
find, find, getBundle, getDescriptor, getLog, getPluginPreferences, getStateLocation, internalInitializeDefaultPluginPreferences, isDebugging, openStream, openStream, savePluginPreferences, setDebugging, shutdown, startup, stop, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DesignModelPlugin

public DesignModelPlugin()
Constructor

Method Detail

start

public void start(org.osgi.framework.BundleContext context)
           throws java.lang.Exception
This method is called upon plug-in activation

Specified by:
start in interface org.osgi.framework.BundleActivator
Overrides:
start in class org.eclipse.core.runtime.Plugin
Throws:
java.lang.Exception

hasModelForDocument

public boolean hasModelForDocument(org.eclipse.jface.text.IDocument document)
Finds out if there already exists a design model that corresponds to the text of an IDocument.

Parameters:
document - an IDocument, such as the document owned by a text editor
Returns:
true if we've already created an IDesignModel for the IDocument

getModelForDocument

public IDesignModel getModelForDocument(org.eclipse.jface.text.IDocument document,
                                        org.eclipse.jface.viewers.ISelectionProvider selectionProvider,
                                        org.eclipse.jface.text.IUndoManager undoManager,
                                        org.eclipse.core.resources.IFile file,
                                        DesignModelPlugin.EditEnabler editEnabler)
                                 throws java.lang.Exception
Finds or creates a Design model that corresponds to the text of an IDocument. Once it is created, the Design model will remain synchronized with the IDocument. If a Design model corresponding to the IDocument already exists, you get that one, otherwise a new model is created and associated with the IDocument. If the IDocument's associated file is closed, the IDesignModel remains valid, but becomes non-editable. If you re-open the file, it becomes editable again, and so on.

Typical usage is:

IDocument doc = ....;
IDesignModel model = DesignModelPlugin.getDefault().getModelForDocument(doc);

Parameters:
document - an IDocument, such as the document owned by a text editor
selectionProvider - the selection provider
undoManager - the undo manager
file - the file
editEnabler - the edit enabler
Returns:
the corresponding Design model
Throws:
java.lang.Exception

getModelForFile

public IDesignModel getModelForFile(org.eclipse.core.resources.IFile file)
                             throws java.lang.Exception
Finds or creates a Design model corresponding to the file. If the file is currently open in an editor, we find/create an Design model that corresponds to that editor's IDocument. If the file is not currently open, we create a non-editable IDesignModel. If the file is subsequently opened in an editor, the IDesignModel will become editable. If the file is then closed, the IDesignModel will become non-editable again, and so on.

When the file is open/editable, the IDesignModel will notify listeners of all edits. When the file is closed/noneditable, the IDesignModel will notify listeners if the file is modified.

Parameters:
file - a file
Returns:
an IDesignModel
Throws:
file - system exceptions if we fail to open the file, or ModelEditException if the file's extension is not MXML or CSS.
java.lang.Exception

getUniqueModelForFile

public IDesignModel getUniqueModelForFile(org.eclipse.core.resources.IFile file)
                                   throws java.lang.Exception
see getModelForFile.

Parameters:
file - a file
Returns:
n IDesignModel
Throws:
java.lang.Exception

getEditorOrDiskModelForFile

public IDesignModel getEditorOrDiskModelForFile(org.eclipse.core.resources.IFile file,
                                                boolean create)
                                         throws java.lang.Exception
If the given file is open in an editor, returns the model used by that editor. Otherwise, returns a fresh editable model for the file on disk; use saveDiskModel() to save it.

Parameters:
file - the file
create - whether to create the file
Returns:
the model
Throws:
java.lang.Exception

isEditorModel

public static boolean isEditorModel(IDesignModel model)
Returns whether a model is in use by an editor

Parameters:
model - the model in question
Returns:
true if the model is being used by an editor

saveDiskModel

public void saveDiskModel(IDesignModel model)
                   throws org.eclipse.core.runtime.CoreException,
                          ModelEditException
If the given model is a model for a file on disk, saves the model out to the file. Otherwise, does nothing (e.g. if the model is open in an editor).

Parameters:
model - the model
Throws:
ModelEditException
org.eclipse.core.runtime.CoreException

getEditableModelForFile

public IDesignModel getEditableModelForFile(org.eclipse.core.resources.IFile file)
                                     throws java.lang.Exception
get the editable model for the file

Parameters:
file - the fiel
Returns:
the model
Throws:
java.lang.Exception

getDebugModelForFile

public IDesignModel getDebugModelForFile(java.lang.String filename,
                                         com.adobe.flexbuilder.designmodel.MarkerSplitter splitter,
                                         boolean editable)
                                  throws java.lang.Exception
Throws:
java.lang.Exception

createMXMLModel

public IMXMLModel createMXMLModel()
Creates an empty MXML model.

Returns:
a new, empty MXML model

createCSSModel

public ICSSModel createCSSModel()
Creates an empty CSS model.

Returns:
a new, empty CSS model

updateDocument

public void updateDocument(org.eclipse.core.resources.IFile oldFile,
                           org.eclipse.jface.text.IDocument newDocument,
                           org.eclipse.jface.viewers.ISelectionProvider selectionProvider,
                           org.eclipse.jface.text.IUndoManager undoManager,
                           org.eclipse.core.resources.IFile newFile,
                           boolean editable)
Call this when the IDocument/IFile associated with a model need to change, for example after doing a Save As or Rename. For use by the MXMLEditor.


editorGoingAway

public void editorGoingAway(org.eclipse.jface.text.IDocument document,
                            org.eclipse.jface.viewers.ISelectionProvider selectionProvider,
                            org.eclipse.jface.text.IUndoManager undoManager)
Call this when an IDocument is going to be shut down, for example because an editor is being closed. For use by the FlexBuilder code editor.


getDefault

public static DesignModelPlugin getDefault()
Fetch the one-and-only singleton instance of the Design Model plugin.

Returns:
the singleton instance.

addModel

public void addModel(com.adobe.flexbuilder.designmodel.DesignModel model)
Add a model

Parameters:
model - model to add

removeModel

public void removeModel(com.adobe.flexbuilder.designmodel.DesignModel model)
Remove a model

Parameters:
model - model to remove

checkResourcesDisposed

public boolean checkResourcesDisposed()

xmlEscape

public static java.lang.String xmlEscape(java.lang.String str)
Finds any special characters in a string and replaces them with the corresponding XML Entity. I'm sure there's a more complete version of this somewhere...

Parameters:
str -
Returns:
a copy of 'str', with special characters replaced by XML entities

selectionEvent

public void selectionEvent(IDesignModel model,
                           org.eclipse.jface.viewers.SelectionChangedEvent event)

isCreateVirtualItems

public static boolean isCreateVirtualItems()

setCreateVirtualItems

public static void setCreateVirtualItems(boolean createVirtualItems)

isUseHardCoded

public static boolean isUseHardCoded()

setUseHardCoded

public static void setUseHardCoded(boolean useHardCoded)

setEditListener

public void setEditListener(com.adobe.flexbuilder.designmodel.IEditListener endEdit)

isDumpStateDebugInfo

public static boolean isDumpStateDebugInfo()

setDumpStateDebugInfo

public static void setDumpStateDebugInfo(boolean dump)

defineFakeDefaultProperty

public static void defineFakeDefaultProperty(java.lang.String component,
                                             java.lang.String property)