Search in sources :

Example 1 with IDiagramEditorFactory

use of com.archimatetool.editor.diagram.IDiagramEditorFactory 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 IDiagramEditorFactory

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

the class DiagramUtils method createViewer.

/**
 * Create a GraphicalViewerImpl to show the model. The Viewer has no Scroll Bars
 * @param model
 * @return A Graphical Viewer
 */
public static GraphicalViewerImpl createViewer(IDiagramModel model, Composite parent) {
    EditPartFactory editPartFactory = null;
    if (model instanceof IArchimateDiagramModel) {
        editPartFactory = new ArchimateDiagramEditPartFactory();
    } else if (model instanceof ISketchModel) {
        editPartFactory = new SketchEditPartFactory();
    } else {
        // Extensions
        IDiagramEditorFactory factory = DiagramEditorFactoryExtensionHandler.INSTANCE.getFactory(model);
        if (factory != null) {
            editPartFactory = factory.createEditPartFactory();
        }
    }
    if (editPartFactory == null) {
        // $NON-NLS-1$
        throw new RuntimeException("Unsupported model type");
    }
    GraphicalViewerImpl viewer = new GraphicalViewerImpl();
    viewer.createControl(parent);
    viewer.setEditPartFactory(editPartFactory);
    RootEditPart rootPart = new FreeformGraphicalRootEditPart();
    viewer.setRootEditPart(rootPart);
    viewer.setContents(model);
    viewer.flush();
    return viewer;
}
Also used : IDiagramEditorFactory(com.archimatetool.editor.diagram.IDiagramEditorFactory) ArchimateDiagramEditPartFactory(com.archimatetool.editor.diagram.editparts.ArchimateDiagramEditPartFactory) GraphicalViewerImpl(org.eclipse.gef.ui.parts.GraphicalViewerImpl) SketchEditPartFactory(com.archimatetool.editor.diagram.sketch.editparts.SketchEditPartFactory) SketchEditPartFactory(com.archimatetool.editor.diagram.sketch.editparts.SketchEditPartFactory) EditPartFactory(org.eclipse.gef.EditPartFactory) ArchimateDiagramEditPartFactory(com.archimatetool.editor.diagram.editparts.ArchimateDiagramEditPartFactory) FreeformGraphicalRootEditPart(org.eclipse.gef.editparts.FreeformGraphicalRootEditPart) ISketchModel(com.archimatetool.model.ISketchModel) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) RootEditPart(org.eclipse.gef.RootEditPart) FreeformGraphicalRootEditPart(org.eclipse.gef.editparts.FreeformGraphicalRootEditPart)

Aggregations

IDiagramEditorFactory (com.archimatetool.editor.diagram.IDiagramEditorFactory)2 IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)2 ISketchModel (com.archimatetool.model.ISketchModel)2 DiagramEditorInput (com.archimatetool.editor.diagram.DiagramEditorInput)1 IDiagramModelEditor (com.archimatetool.editor.diagram.IDiagramModelEditor)1 ArchimateDiagramEditPartFactory (com.archimatetool.editor.diagram.editparts.ArchimateDiagramEditPartFactory)1 SketchEditPartFactory (com.archimatetool.editor.diagram.sketch.editparts.SketchEditPartFactory)1 EditPartFactory (org.eclipse.gef.EditPartFactory)1 RootEditPart (org.eclipse.gef.RootEditPart)1 FreeformGraphicalRootEditPart (org.eclipse.gef.editparts.FreeformGraphicalRootEditPart)1 GraphicalViewerImpl (org.eclipse.gef.ui.parts.GraphicalViewerImpl)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1