Package de.innovationgate.eclipse.editors.design.wizards

Source Code of de.innovationgate.eclipse.editors.design.wizards.NewWGAPortlet

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

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbench;

import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.editors.ResourceIDs;
import de.innovationgate.eclipse.utils.WorkbenchUtils;
import de.innovationgate.eclipse.utils.ui.SingleStructuredSelection;
import de.innovationgate.eclipse.utils.ui.ValidatedMultiPageWizard;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;

public class NewWGAPortlet extends ValidatedMultiPageWizard{

  private IStructuredSelection _selection = null;
  private NewWGAPortletPage _page = null;
  private NewWGAPortletFolderSelectionPage _selectionPage = null;
  private String _defaultPortletName;
  private boolean _portletValidFolderSelected = false;

  public NewWGAPortlet() {
    super();
    setWindowTitle("New WGA Portlet");
  }
 
  @Override
  public boolean performFinish() {

    if (_page != null) {
      try {         
          String header = Plugin.getDefault().getHeaderFileMap().get(Plugin.HEADER_TML_MODUL).getHeaderForProject(_page.getTargetContainer().getProject());     
        IFile portlet = WGADesignStructureHelper.createPortlet(_page.getModes(), _page.getPortletName(), (IFolder) _page.getTargetContainer(),header);
        WorkbenchUtils.openEditor(Plugin.getDefault().getWorkbench(), portlet.getParent().getFile(new Path("mode-view.tml")), ResourceIDs.EDITOR_TML);
        WorkbenchUtils.setNavigationViewSelection(new SingleStructuredSelection(portlet.getParent().getFile(new Path("mode-view.tml"))));
      } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return true;
  }

 
  //TODO put into abstract class ?
  public void init(IWorkbench workbench, IStructuredSelection selection) {   
    _selection = selection;
    if(selection.getFirstElement() instanceof IContainer){
      IContainer container =  (IContainer)selection.getFirstElement();     
      if(WGADesignStructureHelper.isValidPortletLocation((container))){
        _portletValidFolderSelected  = true;
      }
    }else if(selection.getFirstElement() instanceof IFile){
      IFile file = (IFile) selection.getFirstElement();
      if(WGADesignStructureHelper.isValidPortletLocation(file.getParent())){
        _portletValidFolderSelected   = true;
      }     
    } 
   
   
  }

  @Override
  public void addPages() {   
    if(!_portletValidFolderSelected){
      _selectionPage = new NewWGAPortletFolderSelectionPage("Create new WGA Portlet", "Please select the design folder where you want to create the new portlet.", _selection);
      addPage(_selectionPage);
      _page = new NewWGAPortletPage("Create new WGA Portlet", "Please specify the portlet properties.");
      addPage(_page);
    }else{
      _page = new NewWGAPortletPage("Create new WGA Portlet", "Please specify the portlet properties.", _selection);
      addPage(_page);
    }
  }

  public String getDefaultPortletName() {
    return _defaultPortletName;
  }

  public void setDefaultPortletName(String defaultPortletName) {
    _defaultPortletName = defaultPortletName;
  }

}
TOP

Related Classes of de.innovationgate.eclipse.editors.design.wizards.NewWGAPortlet

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.