Package de.innovationgate.eclipse.wgadesigner.actions

Source Code of de.innovationgate.eclipse.wgadesigner.actions.MigrateToWGARuntimeProject

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

import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IActionDelegate;

import de.innovationgate.eclipse.utils.WorkbenchUtils;
import de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin;
import de.innovationgate.eclipse.wgadesigner.editors.helpers.WGADeployment;
import de.innovationgate.eclipse.wgadesigner.editors.helpers.WGADeploymentManager;
import de.innovationgate.eclipse.wgadesigner.natures.WGARuntime;
import de.innovationgate.eclipse.wgadesigner.tomcat.TomcatUtils;
import de.innovationgate.eclipse.wgadesigner.utils.JDTUtils;

public class MigrateToWGARuntimeProject implements IActionDelegate {

  private IProject _project;

  public void run(IAction action) {
    try {
      if (_project != null && !_project.hasNature(WGADesignerPlugin.NATURE_WGA_RUNTIME)) {
        boolean result = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Migrate project '" + _project.getName() + "'?", "Are you sure you want to migrate the project '" + _project.getName() + "' to an WGA runtime project? Migration will add the runtime nature and create necessary default resources.");
        if (result) {
          JDTUtils.addNature(_project, WGADesignerPlugin.NATURE_WGA_RUNTIME);     
         
          WGARuntime runtime = (WGARuntime) _project.getNature(WGADesignerPlugin.NATURE_WGA_RUNTIME);
         
          // set wga distribution
          WGADeploymentManager manager = WGADesignerPlugin.getDefault().getWGADeploymentManager();
          WGADeployment deployment = null;
          if (manager.hasDeployment(WGADeploymentManager.DEFAULT_DEPLOYMENT_NAME)) {
            deployment = manager.getDefaultDeployment();
          } else if (manager.getDeployments().size() > 0) {
            deployment = manager.getDeployments().get(0);
          }
          if (deployment != null) {
            runtime.getConfiguration().setWgaDistribution(deployment.getName());
          }
         
          runtime.flushConfig();
         
          // configure tomcat
          Map<String,String> variables = new HashMap<String,String>();
          TomcatUtils.getInstance().initConfDir(runtime.getCatalinaConf().getLocation().toFile(), variables);       
 
          _project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
        }
      }
    } catch (Exception e) {
      WorkbenchUtils.showErrorDialog(WGADesignerPlugin.getDefault(), Display.getCurrent().getActiveShell(), "Migration to WGA Runtime failed.", "Unable to migrate project '" + _project + "' to runtime.", e);
    }
  }

  public void selectionChanged(IAction action, ISelection selection) {
    action.setEnabled(false);
    if (WGARuntime.fromSelection(selection) == null) {
      if (selection instanceof IStructuredSelection) {
        IStructuredSelection structSelection = (IStructuredSelection) selection;
        Object selectedElement = structSelection.getFirstElement();
        if (selectedElement instanceof IProject) {
          _project = (IProject) selectedElement;
          action.setEnabled(true);
        } else if (selectedElement instanceof IJavaProject) {
          _project = ((IJavaProject) selectedElement).getProject();
          action.setEnabled(true);
        }
      }
    }
  }

}
TOP

Related Classes of de.innovationgate.eclipse.wgadesigner.actions.MigrateToWGARuntimeProject

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.