pl.edu.agh.cast.editor
Class EditorUtil

java.lang.Object
  extended by pl.edu.agh.cast.editor.EditorUtil

public final class EditorUtil
extends java.lang.Object

Utility methods for editors.

Author:
Krzysiek&Piotrek ????, kpietak, awos, Pawel Kupinski (pawel.kupinski@gmail.com)

Constructor Summary
EditorUtil()
           
 
Method Summary
static java.util.List<DiagramEditorInput> closeProjectEditors(org.eclipse.core.resources.IProject project, boolean saveEditors)
          Close opened editors of given project.
static org.eclipse.core.resources.IFile findFile(java.lang.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(pl.edu.agh.cast.model.base.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(pl.edu.agh.cast.model.base.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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EditorUtil

public EditorUtil()
Method Detail

openNewEditor

public static org.eclipse.ui.IEditorPart openNewEditor(pl.edu.agh.cast.model.base.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(pl.edu.agh.cast.model.base.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

closeProjectEditors

public static java.util.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 chcecking editors file references.

Parameters:
project -
saveEditors - TODO
Returns:
The list of closed editor inputs.
Throws:
org.eclipse.core.runtime.CoreException

findFile

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

Parameters:
fileName -
container -
Returns:
Throws:
org.eclipse.core.runtime.CoreException
java.io.FileNotFoundException

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

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.


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-2008 AGH University of Science and Technology. All Rights Reserved.