Package de.innovationgate.eclipse.wgadesigner.wizards

Source Code of de.innovationgate.eclipse.wgadesigner.wizards.NewWGADesign

/*******************************************************************************
* 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.wizards;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;

import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.utils.WorkbenchUtils;
import de.innovationgate.eclipse.utils.ui.SingleStructuredSelection;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;
import de.innovationgate.eclipse.wgadesigner.WGADesignFactory;
import de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin;
import de.innovationgate.eclipse.wgadesigner.editors.helpers.WGADeployment;
import de.innovationgate.eclipse.wgadesigner.models.DesignTemplate;
import de.innovationgate.eclipse.wgadesigner.natures.WGARuntime;
import de.innovationgate.wga.common.beans.csconfig.v1.CSConfig;
import de.innovationgate.wga.model.VersionCompliance;
import de.innovationgate.wga.model.WGADesignConfigurationModel;

public class NewWGADesign extends Wizard implements INewWizard {

  private NewWGADesignPage _page;
  private ISelection _selection;

  public NewWGADesign() {
    super();
    setWindowTitle("New WGA Application");
  }

  public void addPages() {
    _page = new NewWGADesignPage(_selection);
    addPage(_page);
  }


  public boolean performFinish() {
    WGARuntime runtime = _page.getRuntime();   
    if(runtime != null){
      try {
        IFolder folder = runtime.getDesignRoot().getFolder(new Path(_page.getDesignName()));
        if (!folder.exists()) {
          folder.create(false, true, new NullProgressMonitor());
          DesignTemplate template = _page.getTemplate();
          WGADesignFactory.createDesign(folder, folder.getName(), template);
         
          if (!_page.isCreateContentStore()) {
            _page.getRuntime().register(folder, false, null, null, null, template.getProperties());
          } else {
            _page.getRuntime().register(folder, true, _page.getDatabaseKey(), _page.getDatabaseTitle(), _page.getDomain(), template.getProperties());
          }
         
          WGADesignStructureHelper helper = new WGADesignStructureHelper(folder);
            
          try {
            // select new created design in packages explorer, resource navigator & project explorer 
              if(template.getName().equals("empty")){
                  String wgaDistributionName = runtime.getConfiguration().getWgaDistribution();             
                            WGADeployment wgaDeployment = WGADesignerPlugin.getDefault().getWGADeploymentManager().getDeployment(wgaDistributionName);
                            WGADesignConfigurationModel configModel = helper.createModel();   
                            VersionCompliance vc = WGADesignStructureHelper.wgaVersionToVersionCompliance(wgaDeployment.getWGAVersion());
                            if(vc!=null){
                                configModel.setVersionCompliance(vc);
                                configModel.saveChanges();
                            }
             }
             
             
            WorkbenchUtils.setNavigationViewSelection(new SingleStructuredSelection(helper.getSyncInfo()));
            WorkbenchUtils.setNavigationViewSelection(new SingleStructuredSelection(folder));
          } catch (Exception e) {           
          }
         
          return true;
        } else {
          WorkbenchUtils.showErrorDialog(getShell(), "Design creation failed", "A design with name '" + _page.getDesignName() + "' already exists in the runtime '" + runtime.getName() + "'.");
          return false;
        }
      } catch (CoreException e) {
        WorkbenchUtils.showErrorDialog(WGADesignerPlugin.getDefault(), getShell(), "Design creation failed", "Unable to create new design in runtime '" + runtime.getName() + "'.", e);
        return false;
      }
    } else {
      WorkbenchUtils.showErrorDialog(getShell(), "Design creation failed", "No runtime selected for new design.");
      return false;
    }
  }

  public void init(IWorkbench workbench, IStructuredSelection selection) {
    this._selection = selection;   
  }
}
TOP

Related Classes of de.innovationgate.eclipse.wgadesigner.wizards.NewWGADesign

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.