blob: 97b6026fde32c877c28a8b4d242a5626ff30ee92 [file] [log] [blame]
<%@ jet
package="org.eclipse.acceleo.internal.ide.ui.wizards.newproject"
class = "CreateModuleUIPopupMenuActionWriter"
imports = ""
%>
<%
CreateModuleUIData content = (CreateModuleUIData) argument;
%>
/*******************************************************************************
* Copyright (c) 2008, 2012 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package <%=content.getProjectName()%>.popupMenus;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import <%=content.getProjectName()%>.Activator;
import <%=content.getProjectName()%>.common.GenerateAll;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionDelegate;
/**
* <%=content.getModuleNameWithSpaces()%> code generation.
*/
public class AcceleoGenerate<%=content.getModuleNameWithoutSpaces()%>Action extends ActionDelegate implements IActionDelegate {
/**
* Selected model files.
*/
protected List<IFile> files;
/**{@inheritDoc}
*
* @see org.eclipse.ui.actions.ActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
* @generated
*/
@SuppressWarnings("unchecked")
public void selectionChanged(IAction action, ISelection selection) {
if (selection instanceof IStructuredSelection) {
files = ((IStructuredSelection) selection).toList();
}
}
/**{@inheritDoc}
*
* @see org.eclipse.ui.actions.ActionDelegate#run(org.eclipse.jface.action.IAction)
* @generated
*/
public void run(IAction action) {
if (files != null) {
IRunnableWithProgress operation = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
try {
Iterator<IFile> filesIt = files.iterator();
while (filesIt.hasNext()) {
IFile model = (IFile)filesIt.next();
URI modelURI = URI.createPlatformResourceURI(model.getFullPath().toString(), true);
try {
<%=content.getTargetFolderAccess().replaceAll("\n", "\n\t\t\t\t\t\t\t\t")%>
GenerateAll generator = new GenerateAll(modelURI, target, getArguments());
generator.doGenerate(monitor);
} catch (IOException e) {
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
Activator.getDefault().getLog().log(status);
} finally {
model.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
}
} catch (CoreException e) {
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
Activator.getDefault().getLog().log(status);
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().run(true, true, operation);
} catch (InvocationTargetException e) {
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
Activator.getDefault().getLog().log(status);
} catch (InterruptedException e) {
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
Activator.getDefault().getLog().log(status);
}
}
}
/**
* Computes the arguments of the generator.
*
* @return the arguments
* @generated
*/
protected List<? extends Object> getArguments() {
return new ArrayList<String>();
}
}