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

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

/*******************************************************************************
* 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 java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.IStructuredSelection;

import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.utils.FolderSelectionViewFilter;
import de.innovationgate.eclipse.utils.ui.FolderSelectionPage;
import de.innovationgate.eclipse.utils.ui.SingleStructuredSelection;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;

public class DesignFolderSelectionPage extends FolderSelectionPage {

  public DesignFolderSelectionPage(String title, String description, IStructuredSelection preSelection) {
    super(title, description, preSelection);
  }

  @Override
  protected FolderSelectionViewFilter getFilter() {
    return new FolderSelectionViewFilter() {     
      @Override
      public boolean isValidLocation(IContainer container) {
        return WGADesignStructureHelper.isDesignFolder(container);
      }
    };
  }

  @Override
  public List<IStatus> validate() {
    List<IStatus> messages = new ArrayList<IStatus>();
    IResource selected = getSelectedResource();
    if (selected == null || !(selected instanceof IContainer) || !getFilter().isValidLocation((IContainer)selected)) {
      messages.add(new Status(Status.ERROR, Plugin.PLUGIN_ID, "Please select a valid design folder."));
    }
    return messages;
  }

  @Override
  protected IStructuredSelection getPreSelection(IResource workspaceSelection) {
    if (workspaceSelection == null) {
      return null;
    } else {
      IContainer bestContainer = null;
      if (workspaceSelection instanceof IContainer) {
        bestContainer = (IContainer) workspaceSelection;
      } else if (workspaceSelection instanceof IFile) {
        bestContainer = ((IFile) workspaceSelection).getParent();
      }
     
      if (bestContainer != null) {
        IFile syncInfo = WGADesignStructureHelper.determineSyncInfo(bestContainer);
        if (syncInfo != null) {
          WGADesignStructureHelper helper = new WGADesignStructureHelper(syncInfo);
          return new SingleStructuredSelection(helper.getDesignRoot());
        }
      }
    }
    return new SingleStructuredSelection(workspaceSelection.getProject());   
  }

 
 
 

}
TOP

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

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.