blob: 4f1627f59d79e413c40e58a98c3ed215635edcbd [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2011-2016 EclipseSource Muenchen GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Johannes Faltermeier - initial API and implementation
******************************************************************************/
package org.eclipse.emf.ecp.internal.ide.editor.view.templatebridge.actions;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecp.view.spi.model.VElement;
import org.eclipse.emf.ecp.view.spi.treemasterdetail.ui.swt.MasterDetailAction;
import org.eclipse.emf.ecp.view.template.tooling.wizards.EMFFormsTemplateWizard;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.handlers.HandlerUtil;
/**
* Handler for opening the template editor.
*
* @author Johannes Faltermeier
*
*/
public class OpenTemplateEditorAction extends MasterDetailAction {
@Override
public boolean shouldShow(EObject eObject) {
return VElement.class.isInstance(eObject);
}
@Override
public void execute(EObject object) {
final WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(),
new EMFFormsTemplateWizard(VElement.class.cast(object)));
dialog.open();
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Object selection = ((IStructuredSelection) HandlerUtil.getActiveMenuSelection(event)).getFirstElement();
if (selection == null || !(selection instanceof EObject)) {
return null;
}
execute((EObject) selection);
return null;
}
}