Package de.innovationgate.eclipse.wgadesigner.wizards

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

/*******************************************************************************
* 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 java.util.Iterator;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.forms.editor.FormEditor;

import de.innovationgate.eclipse.utils.Activator;
import de.innovationgate.eclipse.utils.BeanListPreferencesStore;
import de.innovationgate.eclipse.utils.WorkbenchUtils;
import de.innovationgate.eclipse.utils.ui.SingleStructuredSelection;
import de.innovationgate.eclipse.utils.ui.model.WGADesignConfigurationModelWrapper;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;
import de.innovationgate.eclipse.wgadesigner.ExternalResourceIDs;
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.WGADesign;
import de.innovationgate.eclipse.wgadesigner.natures.WGARuntime;
import de.innovationgate.wga.model.VersionCompliance;
import de.innovationgate.wga.model.WGADesignConfigurationModel;

public class NewWGAPlugin extends Wizard implements INewWizard {

  private NewWGAPluginPage _page;
  private ISelection _selection;


  public NewWGAPlugin() {
    super();
    setWindowTitle("New WGA Plugin");
    setNeedsProgressMonitor(true);
  }

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

  public boolean performFinish() {
    //WGADesignStructureHelper.createDirklink(targetFolder, (IContainer) _treeViewer.getTree().getSelection()[0].getData(), _linkNameText.getText());
   
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(_page.getPluginName());
    if (project != null && project.exists()) {
      String message = "A project with name '" + project.getName() + "' already exists in the workspace.";
      WorkbenchUtils.showErrorDialog(getShell(), "Plugin creation failed", message);
      return false;
    } else {
      try {
        // create new project
        WGADesign designProject = WGADesignFactory.createDesign(project, getPluginTemplate());
       
        // register with runtime
        WGARuntime runtime = _page.getRuntime();
        if (runtime != null) {         
          WGADesignStructureHelper.createDirklink(runtime.getPluginRoot(), designProject.getDesignFolder(), _page.getPluginName());
         
         
          try {
            // elapse dirlink folder in navigation views
            WorkbenchUtils.setNavigationViewSelection(new SingleStructuredSelection(runtime.getPluginRoot().getFolder(_page.getPluginName())));
          } catch (Exception e) {           
          }
        }
                     
        // modify plugin config and open plugin design editor
        IFile syncInfo = new WGADesignStructureHelper(designProject.getDesignFolder()).getSyncInfo();
        WGADesignConfigurationModel model = new WGADesignConfigurationModelWrapper(syncInfo);
       

                model.setVersionCompliance(Activator.DEFAULT_VERSION_COMPLIANCE);
              
        model.createPluginConfig();
        model.setPluginUniqueName(_page.getPluginUniqueName());
        model.saveChanges();
       
        try {
          // select syncinfo in navigation views
          WorkbenchUtils.setNavigationViewSelection(new SingleStructuredSelection(syncInfo));
        } catch (Exception e) {         
        }
       
        // open plugin config
        IEditorPart editor = WorkbenchUtils.openEditor(WGADesignerPlugin.getDefault().getWorkbench(), syncInfo, ExternalResourceIDs.EDITOR_WGA_DESIGN);
        if (editor instanceof FormEditor) {
          ((FormEditor) editor).setActivePage(ExternalResourceIDs.EDITORPAGE_WGA_DESIGN_PLUGINCONFIGURATION);
        }

        return true;
      } catch (Exception e) {
        WorkbenchUtils.showErrorDialog(WGADesignerPlugin.getDefault(), getShell(), "Plugin creation failed", "Unable to create new plugin.", e);
        return false;
      }
    }
  }
 
 
  private DesignTemplate getPluginTemplate() {
    // init design with "empty" template
    BeanListPreferencesStore<DesignTemplate> templateStore = WGADesignerPlugin.getDefault().getDesginTemplateStore();
    templateStore.load();
    DesignTemplate template = null;
    Iterator<DesignTemplate> templates = templateStore.getBeans().iterator();
    while (templates.hasNext()) {
      DesignTemplate temp = templates.next();
      if (temp.getName().equals("empty")) {
        return temp;
      }
    }
    return null;
  }

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

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

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.