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;
}
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);
}
}
Aggregations