/******************************************************************************* | |
* Copyright (c) 2016 KPIT Technologies. | |
* | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v2.0 | |
* which accompanies this distribution, and is available at | |
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html | |
* | |
* SPDX-License-Identifier: EPL-2.0 | |
* | |
* Contributors: | |
* Jan Mauersberger- initial API and implementation | |
* Sascha Baumgart- initial API and implementation | |
*******************************************************************************/ | |
package org.eclipse.opencert.infra.ui.loadresource; | |
import org.eclipse.core.commands.ExecutionEvent; | |
import org.eclipse.core.commands.ExecutionException; | |
import org.eclipse.emf.edit.ui.action.LoadResourceAction; | |
import org.eclipse.emf.transaction.TransactionalEditingDomain; | |
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor; | |
import org.eclipse.gmf.tooling.runtime.actions.DefaultLoadResourceAction; | |
import org.eclipse.swt.widgets.Shell; | |
import org.eclipse.ui.IEditorPart; | |
import org.eclipse.ui.handlers.HandlerUtil; | |
public class DawnAwareLoadResourceHandler extends DefaultLoadResourceAction { | |
public Object execute(ExecutionEvent event) throws ExecutionException { | |
IEditorPart editorPart = HandlerUtil.getActiveEditor(event); | |
IEditorPart diagramEditor = HandlerUtil.getActiveEditorChecked(event); | |
Shell shell = diagramEditor.getEditorSite().getShell(); | |
assert diagramEditor instanceof DiagramEditor; | |
TransactionalEditingDomain editingDomain = ((DiagramEditor) diagramEditor) | |
.getEditingDomain(); | |
if (EditorTypeUtil.isFileEditor(editorPart)) { | |
LoadResourceAction.LoadResourceDialog loadResourceDialog = new LoadResourceAction.LoadResourceDialog( | |
shell, editingDomain); | |
loadResourceDialog.open(); | |
} else { | |
LoadResourceDialog loadResourceDialog = new LoadResourceDialog( | |
shell, editingDomain); | |
loadResourceDialog.open(); | |
} | |
return null; | |
} | |
} |