Search in sources :

Example 1 with DiagramEditorInput

use of com.archimatetool.editor.diagram.DiagramEditorInput in project archi by archimatetool.

the class EditorManager method openDiagramEditor.

/**
 * Open the Diagram Editor for a given DiagramModel Model
 * @param name
 */
public static IDiagramModelEditor openDiagramEditor(IDiagramModel model) {
    if (model == null || model.eContainer() == null || !PlatformUI.isWorkbenchRunning()) {
        return null;
    }
    String id = null;
    IEditorInput editorInput = null;
    if (model instanceof IArchimateDiagramModel) {
        id = IArchimateDiagramEditor.ID;
        editorInput = new DiagramEditorInput(model);
    } else if (model instanceof ISketchModel) {
        id = ISketchEditor.ID;
        editorInput = new DiagramEditorInput(model);
    } else {
        IDiagramEditorFactory factory = DiagramEditorFactoryExtensionHandler.INSTANCE.getFactory(model);
        if (factory != null) {
            id = factory.getEditorID();
            editorInput = factory.createEditorInput(model);
        }
    }
    if (id == null || editorInput == null) {
        // $NON-NLS-1$
        throw new RuntimeException("Unsupported model type");
    }
    IEditorPart part = openEditor(editorInput, id);
    // Check it actually is IDiagramModelEditor, it could be an org.eclipse.ui.internal.ErrorEditorPart if an error occurs
    return part instanceof IDiagramModelEditor ? (IDiagramModelEditor) part : null;
}
Also used : IDiagramEditorFactory(com.archimatetool.editor.diagram.IDiagramEditorFactory) DiagramEditorInput(com.archimatetool.editor.diagram.DiagramEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) IDiagramModelEditor(com.archimatetool.editor.diagram.IDiagramModelEditor) IEditorInput(org.eclipse.ui.IEditorInput) ISketchModel(com.archimatetool.model.ISketchModel) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel)

Example 2 with DiagramEditorInput

use of com.archimatetool.editor.diagram.DiagramEditorInput in project archi by archimatetool.

the class EditorManager method closeDiagramEditors.

/**
 * Close open Diagram Editor Parts for a model
 * @param model
 */
public static void closeDiagramEditors(IArchimateModel model) {
    if (model == null || !PlatformUI.isWorkbenchRunning()) {
        return;
    }
    List<IEditorReference> list = new ArrayList<IEditorReference>();
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    for (IEditorReference ref : page.getEditorReferences()) {
        try {
            IEditorInput input = ref.getEditorInput();
            if (input instanceof DiagramEditorInput && ((DiagramEditorInput) input).getDiagramModel().getArchimateModel() == model) {
                list.add(ref);
            }
        } catch (PartInitException ex) {
            ex.printStackTrace();
        }
    }
    if (!list.isEmpty()) {
        IEditorReference[] refs = list.toArray(new IEditorReference[list.size()]);
        page.closeEditors(refs, false);
    }
}
Also used : DiagramEditorInput(com.archimatetool.editor.diagram.DiagramEditorInput) IEditorReference(org.eclipse.ui.IEditorReference) ArrayList(java.util.ArrayList) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

DiagramEditorInput (com.archimatetool.editor.diagram.DiagramEditorInput)2 IEditorInput (org.eclipse.ui.IEditorInput)2 IDiagramEditorFactory (com.archimatetool.editor.diagram.IDiagramEditorFactory)1 IDiagramModelEditor (com.archimatetool.editor.diagram.IDiagramModelEditor)1 IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)1 ISketchModel (com.archimatetool.model.ISketchModel)1 ArrayList (java.util.ArrayList)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IEditorReference (org.eclipse.ui.IEditorReference)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 PartInitException (org.eclipse.ui.PartInitException)1