/* * Copyright 2012 PRODYNA AG * * Licensed under the Eclipse Public License (EPL), Version 1.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.opensource.org/licenses/eclipse-1.0.php or * http://www.nabucco.org/License.html * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.nabucco.framework.generator.compiler.transformation.java.view.list; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.nabucco.framework.generator.compiler.constants.NabuccoJavaTemplateConstants; import org.nabucco.framework.generator.compiler.transformation.java.common.ast.JavaAstSupport; import org.nabucco.framework.generator.compiler.transformation.java.constants.ViewConstants; import org.nabucco.framework.generator.compiler.transformation.java.visitor.NabuccoToJavaVisitorContext; import org.nabucco.framework.generator.compiler.transformation.java.visitor.NabuccoToJavaVisitorSupport; import org.nabucco.framework.generator.compiler.visitor.NabuccoVisitorException; import org.nabucco.framework.generator.parser.model.client.NabuccoClientType; import org.nabucco.framework.generator.parser.syntaxtree.ListViewStatement; import org.nabucco.framework.mda.model.MdaModel; import org.nabucco.framework.mda.model.java.JavaCompilationUnit; import org.nabucco.framework.mda.model.java.JavaModel; import org.nabucco.framework.mda.model.java.JavaModelException; import org.nabucco.framework.mda.model.java.ast.element.JavaAstElementFactory; import org.nabucco.framework.mda.template.java.JavaTemplateException; /** * NabuccoToJavaRcpViewEditVisitor * * @author Stefanie Feld, Nicolas Moser, PRODYNA AG */ public class NabuccoToJavaRcpViewListWidgetFactoryVisitor extends NabuccoToJavaVisitorSupport { /** * Creates a new {@link NabuccoToJavaRcpViewListWidgetFactoryVisitor} instance. * * @param visitorContext * the visitor context */ public NabuccoToJavaRcpViewListWidgetFactoryVisitor(NabuccoToJavaVisitorContext visitorContext) { super(visitorContext); } @Override public void visit(ListViewStatement nabuccoListView, MdaModel<JavaModel> target) { JavaAstElementFactory javaFactory = JavaAstElementFactory.getInstance(); String name = nabuccoListView.nodeToken2.tokenImage + ViewConstants.WIDGET_FACTORY; String pkg = super.getVisitorContext().getPackage().replace(ViewConstants.UI, ViewConstants.UI_RCP) + ViewConstants.PKG_SEPARATOR + ViewConstants.VIEW_PACKAGE; String projectName = super.getComponentName(NabuccoClientType.RCP); try { JavaCompilationUnit unit = super.extractAst(NabuccoJavaTemplateConstants.LIST_VIEW_WIDGET_FACTORY_TEMPLATE); TypeDeclaration type = unit.getType(NabuccoJavaTemplateConstants.LIST_VIEW_WIDGET_FACTORY_TEMPLATE); javaFactory.getJavaAstType().setTypeName(type, name); javaFactory.getJavaAstUnit().setPackage(unit.getUnitDeclaration(), pkg); JavaAstSupport.convertAstNodes(unit, getVisitorContext().getContainerList(), getVisitorContext() .getImportList()); // Annotations JavaAstSupport.convertJavadocAnnotations(nabuccoListView.annotationDeclaration, type); unit.setProjectName(projectName); unit.setSourceFolder(super.getSourceFolder()); target.getModel().getUnitList().add(unit); } catch (JavaModelException jme) { throw new NabuccoVisitorException("Error during Java AST listview widgetfactory modification.", jme); } catch (JavaTemplateException te) { throw new NabuccoVisitorException("Error during Java template listview widgetfactory processing.", te); } } }