Package de.innovationgate.eclipse.wgadesigner

Source Code of de.innovationgate.eclipse.wgadesigner.WGADesignFactory

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* 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:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.wgadesigner;

import java.io.File;
import java.io.IOException;
import java.util.zip.ZipException;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;

import de.innovationgate.eclipse.utils.FileUtils;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;
import de.innovationgate.eclipse.wgadesigner.models.DesignTemplate;
import de.innovationgate.eclipse.wgadesigner.natures.WGADesign;
import de.innovationgate.eclipse.wgadesigner.utils.JDTUtils;
import de.innovationgate.wga.common.DesignDirectory;
import de.innovationgate.wga.common.beans.DesignDefinition;

public class WGADesignFactory
 
 
  public static void createDesign(IFolder folder, String designKey, DesignTemplate designTemplate){     
    try {
      FileUtils.unzip(designTemplate.getContent(), folder.getLocation().toFile());
     
      // remove properties from project
      folder.refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor());
      IFile props = folder.getFile(DesignTemplate.PROPERTIES_FILENAME);
      if (props.exists()) {
        props.delete(true, new NullProgressMonitor());
      }     
     
      DesignDefinition syncinfo = new DesignDefinition();   
      syncinfo.setDesignKey(designKey);
      syncinfo.setFileEncoding(DesignDefinition.FILEENCODING_CSCONFIG_DEFINED);     
      try {
        syncinfo.write(new File(folder.getLocation().toFile(), DesignDirectory.DESIGN_DEFINITION_FILE));
      } catch (IOException e) {
        WGADesignerPlugin.getDefault().logError("cound not create design definition", e);
      }
      folder.refreshLocal(IResource.DEPTH_INFINITE, null);
      new WGADesignStructureHelper(folder).enforceDesignEncoding();
      folder.refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (ZipException e) {
      WGADesignerPlugin.getDefault().logError("File "+folder.getLocation().toFile().getAbsolutePath()+" is not a Zipfile" ,e);
     
    } catch (IOException e) {
      WGADesignerPlugin.getDefault().logError("File "+folder.getLocation().toFile().getAbsolutePath()+" not found",e);
    } catch (CoreException e) {
      WGADesignerPlugin.getDefault().logError("Refreshing folder "+folder.getLocation().toFile().getAbsolutePath() +" failed",e);
    }   
  }
 
  public static WGADesign createDesign(IProject project, DesignTemplate template) throws CoreException {
    if (!project.exists()) {
      project.create(null);
    }
    project.open(null);
    JDTUtils.addNature(project, WGADesignerPlugin.NATURE_WGA_DESIGN);     
    WGADesign design = (WGADesign)project.getNature(WGADesignerPlugin.NATURE_WGA_DESIGN);
    if (template != null) {
      WGADesignFactory.createDesign(design.getDesignFolder(), design.getProject().getName(), template)
    }
    return design;
  }
}
TOP

Related Classes of de.innovationgate.eclipse.wgadesigner.WGADesignFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.