pl.edu.agh.cast.backward.editor
Class EditorUtilBackward

java.lang.Object
  extended by pl.edu.agh.cast.backward.editor.EditorUtilBackward

public final class EditorUtilBackward
extends Object

Utility methods for editors.

Author:
AGH CAST Team

Constructor Summary
EditorUtilBackward()
           
 
Method Summary
static List<DiagramEditorInput> closeProjectEditors(org.eclipse.core.resources.IProject project, boolean saveEditors)
          Close opened editors of given project.
static org.eclipse.core.resources.IFile findFile(String fileName, org.eclipse.core.resources.IContainer container)
          Find reference to a file in given container.
static IDiagram getActiveDiagram()
          Returns the active diagram - the diagram from active editor, if it has one.
static org.eclipse.gef.commands.CommandStack getActiveEditorCommandStack()
          Returns CommandStack for active editor.
static org.eclipse.ui.IEditorDescriptor[] getAllEditors()
           
static org.eclipse.ui.IEditorDescriptor getDefaultEditor()
           
static org.eclipse.ui.IEditorPart openEditorForSavedDiagram(IDiagram diagram, org.eclipse.ui.IEditorDescriptor desc, org.eclipse.core.resources.IFile file)
          Opens editor from a saved diagram.
static org.eclipse.ui.IEditorPart openEmptyEditor(org.eclipse.core.resources.IProject project, org.eclipse.ui.IEditorDescriptor editorDescriptor)
          Opens a new empty editor of given type.
static org.eclipse.ui.IEditorPart openNewEditor(IDataSet dataSet, org.eclipse.core.resources.IProject project, org.eclipse.ui.IEditorDescriptor editorType)
          Opens a new editor for single data set.
static org.eclipse.ui.IEditorPart openNewEditor(IModel model, org.eclipse.core.resources.IProject project, org.eclipse.ui.IEditorDescriptor editorType)
          Opens a new editor for the whole model.
static void runWithProgressMonitor(org.eclipse.jface.operation.IRunnableWithProgress runnable, IExceptionHandler exceptionHandler)
          Runs given runnable.
static void runWithProgressMonitorInUIThread(org.eclipse.jface.operation.IRunnableWithProgress runnable, IExceptionHandler exceptionHandler)
          Runs given runnable in UI thread (see Display.asyncExec(Runnable)).
static boolean saveModifiedEditors(org.eclipse.core.resources.IProject project)
          Saves all modified files which belongs to specified project asking user file by file if he/she wants to save them.
static void switchToDiagramPerspective()
          Method is switching to default workbench perspective.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EditorUtilBackward

public EditorUtilBackward()
Method Detail

switchToDiagramPerspective

public static void switchToDiagramPerspective()
Method is switching to default workbench perspective.


openNewEditor

public static org.eclipse.ui.IEditorPart openNewEditor(IDataSet dataSet,
                                                       org.eclipse.core.resources.IProject project,
                                                       org.eclipse.ui.IEditorDescriptor editorType)
                                                throws org.eclipse.ui.PartInitException
Opens a new editor for single data set. Uses ProjectStore.getNewDiagramInfo to get information about new diagram name and creates an editor based on this information. Sets diagram's display name and lays out nodes using the default layout if opened editor is a SchemaEditor.

Parameters:
dataSet - input data set
project - containing project
editorType - ID of the editor to create
Returns:
created editor part
Throws:
org.eclipse.ui.PartInitException

openNewEditor

public static org.eclipse.ui.IEditorPart openNewEditor(IModel model,
                                                       org.eclipse.core.resources.IProject project,
                                                       org.eclipse.ui.IEditorDescriptor editorType)
                                                throws org.eclipse.ui.PartInitException
Opens a new editor for the whole model. In most cases you want only to open editor for single data set! Uses ProjectStore.getNewDiagramInfo to get information about new diagram name and creates an editor based on this information. Sets diagram's display name and lays out nodes using the default layout if opened editor is a SchemaEditor.

Parameters:
model - input model
project - containing project
editorType - ID of the editor to create
Returns:
created editor part
Throws:
org.eclipse.ui.PartInitException

openEmptyEditor

public static org.eclipse.ui.IEditorPart openEmptyEditor(org.eclipse.core.resources.IProject project,
                                                         org.eclipse.ui.IEditorDescriptor editorDescriptor)
                                                  throws org.eclipse.ui.PartInitException
Opens a new empty editor of given type. Uses ProjectStore.getNewDiagramInfo to get information about new diagram name and creates an editor based on this information. Sets diagram's display name.

Parameters:
project - containing project
editorDescriptor - descriptor of the editor to open
Returns:
created editor part
Throws:
org.eclipse.ui.PartInitException

openEditorForSavedDiagram

public static org.eclipse.ui.IEditorPart openEditorForSavedDiagram(IDiagram diagram,
                                                                   org.eclipse.ui.IEditorDescriptor desc,
                                                                   org.eclipse.core.resources.IFile file)
                                                            throws org.eclipse.ui.PartInitException
Opens editor from a saved diagram. Creates a new DiagramEditorInput and opens an editor based on this input.

Parameters:
diagram - input diagram to open
desc - editor descriptor
file - input file
Returns:
created editor part
Throws:
org.eclipse.ui.PartInitException - on workbench initialization exception

closeProjectEditors

public static List<DiagramEditorInput> closeProjectEditors(org.eclipse.core.resources.IProject project,
                                                           boolean saveEditors)
                                                    throws org.eclipse.core.runtime.CoreException
Close opened editors of given project. It is done by checking editors file references.

Parameters:
project - the project to close editors for
saveEditors - whether editors should be saved
Returns:
the list of closed editor inputs
Throws:
org.eclipse.core.runtime.CoreException - on exception

findFile

public static org.eclipse.core.resources.IFile findFile(String fileName,
                                                        org.eclipse.core.resources.IContainer container)
                                                 throws org.eclipse.core.runtime.CoreException,
                                                        FileNotFoundException
Find reference to a file in given container.

Parameters:
fileName - file name
container - container to look in
Returns:
instance of searched IFile
Throws:
org.eclipse.core.runtime.CoreException
FileNotFoundException - when file could not be located

saveModifiedEditors

public static boolean saveModifiedEditors(org.eclipse.core.resources.IProject project)
Saves all modified files which belongs to specified project asking user file by file if he/she wants to save them.

Parameters:
project - project to save modifications for
Returns:
false if user click cancel button, true otherwise

getActiveEditorCommandStack

public static org.eclipse.gef.commands.CommandStack getActiveEditorCommandStack()
Returns CommandStack for active editor. If cannot reach active workbench/page/editor then returns null.

Returns:
CommandStack for active editor or null

getDefaultEditor

public static org.eclipse.ui.IEditorDescriptor getDefaultEditor()

getAllEditors

public static org.eclipse.ui.IEditorDescriptor[] getAllEditors()

getActiveDiagram

public static IDiagram getActiveDiagram()
Returns the active diagram - the diagram from active editor, if it has one.

Returns:
the active diagram

runWithProgressMonitor

public static void runWithProgressMonitor(org.eclipse.jface.operation.IRunnableWithProgress runnable,
                                          IExceptionHandler exceptionHandler)
Runs given runnable. If possible displays it's progress.

Parameters:
runnable - runnable to run
exceptionHandler - instance of IExceptionHandler for handling InvocationTargetException and InterruptedException as may be thrown by IRunnableWithProgress.run(org.eclipse.core.runtime.IProgressMonitor)

runWithProgressMonitorInUIThread

public static void runWithProgressMonitorInUIThread(org.eclipse.jface.operation.IRunnableWithProgress runnable,
                                                    IExceptionHandler exceptionHandler)
Runs given runnable in UI thread (see Display.asyncExec(Runnable)). If possible displays it's progress. This is useful when the runnable performs some GUI actions, like drawing nodes.

Parameters:
runnable - runnable to run
exceptionHandler - instance of IExceptionHandler for handling InvocationTargetException and InterruptedException as may be thrown by IRunnableWithProgress.run(org.eclipse.core.runtime.IProgressMonitor)


Copyright © 2007-2009 IISG AGH-UST Krakow, Poland. All Rights Reserved.