Package tool.search

Source Code of tool.search.SelectType

package tool.search;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.core.resources.IProject;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;

import tool.model.ToolComponent;
import tool.model.ToolPlan;
import tool.model.ToolServiceObject;
import tool.model.ToolType;
import tool.navigator.common.LabelProvider;

public class SelectType {
 
 
  public static ToolComponent select(ToolComponent component, ToolComponent initialSelection){
    IProject project  = component.getFile().getProject();
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(
        Display.getDefault().getActiveShell(),
          new LabelProvider(),
          new SupplierContentProvider(project));
   
      ToolPlan rootPlan = null;
      if (component instanceof ToolServiceObject){
        rootPlan = ((ToolServiceObject)component).getPlan();
      } else if (component instanceof ToolType){
        rootPlan = ((ToolType)component).getPlan();
      }
      Set<String> planNames = new HashSet<String>(rootPlan.getSupplierPlans());
      planNames.add(rootPlan.getToolName());
      dialog.setTitle("Type Selection");
      dialog.setMessage("Select the type from the tree:");
      dialog.setInput(planNames);
      dialog.setAllowMultiple(false);
      dialog.setEmptyListMessage("No types available");
      dialog.setSorter(new ViewerSorter());
      if (initialSelection != null)
        dialog.setInitialSelection(initialSelection);
      if (dialog.open() == ElementTreeSelectionDialog.OK){
        Object selectedObject = dialog.getFirstResult();
        if (selectedObject instanceof ToolType)
          return (ToolType)selectedObject;
        else
          return null;
      }else {
        return null;
      }
  }

}
TOP

Related Classes of tool.search.SelectType

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.