Folder/Package/classパス選択


import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
import org.eclipse.jdt.internal.ui.JavaUIMessages;
import org.eclipse.jdt.internal.ui.actions.OpenTypeAction;
import org.eclipse.jdt.internal.ui.dialogs.OpenTypeSelectionDialog2;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.help.WorkbenchHelp;

public class OpenJavaAction extends OpenTypeAction {
	private OpenTypeSelectionDialog2 dialog;

	private Shell parent;
	
	private boolean bool = true;
	public OpenJavaAction() {
		super();
		setText(JavaUIMessages.OpenTypeAction_label); //$NON-NLS-1$
		setDescription(JavaUIMessages.OpenTypeAction_description); //$NON-NLS-1$
		setToolTipText(JavaUIMessages.OpenTypeAction_tooltip); //$NON-NLS-1$
		setImageDescriptor(JavaPluginImages.DESC_TOOL_OPENTYPE);
		WorkbenchHelp.setHelp(this, IJavaHelpContextIds.OPEN_TYPE_ACTION);
		parent = JavaPlugin.getActiveWorkbenchShell();
		try {
			dialog = new OpenTypeSelectionDialog2(parent,true, PlatformUI
					.getWorkbench().getProgressService(),
					 SearchEngine
							.createWorkspaceScope(),IJavaSearchConstants.TYPE);
		} catch (OperationCanceledException e) {
			return;
		}
	}

	public OpenTypeSelectionDialog2 getDialog() {
		return dialog;
	}
	
	public Object[] getType(){
		return dialog.getResult();
	}
	
	public void setBool(boolean bool){
		this.bool = bool;
	}

	public void run() {

//		dialog.setMatchEmptyString(true);
		dialog.setTitle(JavaUIMessages.OpenTypeAction_dialogTitle); //$NON-NLS-1$
		dialog.setMessage(JavaUIMessages.OpenTypeAction_dialogMessage); //$NON-NLS-1$ //$NON-NLS-1$		
		int result = dialog.open();
		if (result != IDialogConstants.OK_ID)
			return;

		Object[] types = dialog.getResult();
		if (types != null && types.length > 0) {
			IType type = (IType) types[0];
			if(bool){
				try {
					IEditorPart part = EditorUtility.openInEditor(type, true);
					EditorUtility.revealInEditor(part, type);
				} catch (CoreException x) {
					String title= JavaUIMessages.OpenTypeAction_errorTitle; //$NON-NLS-1$
					String message= JavaUIMessages.OpenTypeAction_errorMessage; //$NON-NLS-1$ //$NON-NLS-1$
					ExceptionHandler.handle(x, title, message);
				}
			}
			
		}
	}

	public void run(IAction action) {
		run();
	}

}
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
import org.eclipse.jdt.internal.ui.JavaUIMessages;
import org.eclipse.jdt.internal.ui.actions.OpenTypeAction;
import org.eclipse.jdt.internal.ui.dialogs.OpenTypeSelectionDialog2;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.help.WorkbenchHelp;
public class SelectionClassAction extends OpenTypeAction {
	private OpenTypeSelectionDialog2 dialog;

	private Shell parent;

	private Text classValue;

	public SelectionClassAction() {
		super();
		setText(JavaUIMessages.OpenTypeAction_label); //$NON-NLS-1$
		setDescription(JavaUIMessages.OpenTypeAction_description); //$NON-NLS-1$
		setToolTipText(JavaUIMessages.OpenTypeAction_tooltip); //$NON-NLS-1$
		setImageDescriptor(JavaPluginImages.DESC_TOOL_OPENTYPE);
		WorkbenchHelp.setHelp(this, IJavaHelpContextIds.OPEN_TYPE_ACTION);
		parent = JavaPlugin.getActiveWorkbenchShell();
		try {
			dialog = new OpenTypeSelectionDialog2(parent, true, PlatformUI
					.getWorkbench().getProgressService(), SearchEngine
					.createWorkspaceScope(), IJavaSearchConstants.TYPE);
		} catch (OperationCanceledException e) {
			return;
		}
	}

	public OpenTypeSelectionDialog2 getDialog() {
		return dialog;
	}

	public void run() {
		// dialog.setMatchEmptyString(true);
		dialog.setTitle(JavaUIMessages.OpenTypeAction_dialogTitle); //$NON-NLS-1$
		dialog.setMessage(JavaUIMessages.OpenTypeAction_dialogMessage); //$NON-NLS-1$//$NON-NLS-1$		
		int result = dialog.open();
		if (result != IDialogConstants.OK_ID)
			return;

		Object[] types = dialog.getResult();
		if (types != null && types.length > 0) {
			IType type = (IType) types[0];
			type.getPackageFragment().getElementName();
			classValue.setText(type.getPackageFragment().getElementName() + "."
					+ type.getElementName());
		}
	}

	public void run(IAction action) {
		run();
	}

	public void run(Text classValue) {
		this.classValue = classValue;
		run();
	}
}
Flaoderに対して:
    :            
IJavaProject currProject = ActionUtil.findSelectedJavaProject(this.selection);
        ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), currProject.getProject().getWorkspace().getRoot(), false,"Select Mapping Folder");
        if (dialog.open() == ContainerSelectionDialog.OK) {
            Object[] result = dialog.getResult();
            if (result.length == 1) {javascript:






                mappingPath.setText(((Path) result[0]).toString());
            }
        }


  
public static IJavaProject findSelectedJavaProject(ISelection selection) {
        IJavaProject currentProject = null;
        if (selection != null) {
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection ss = (IStructuredSelection)selection;
                Object obj = ss.getFirstElement();
                if (obj instanceof IJavaProject) {
                    currentProject = (IJavaProject)obj;
                }
            }
        }
        return currentProject;
    }

  :
ContainerSelectionDialog= new ContainerSelectionDialog(...);
	if(dialog.open == ContainerSelectionDialog.OK){
		Object[] result = dialog.getResult();
		String containerFullName  = ((Path)reslut[0]).toString();
		createFile();
	}
	public createFile(){
		....
	}
 TypeSelectionDialog
    TypeSelectionDialog JDT      UI    ,       ,        ,       ,  :)
    TypeSelectionDialog              Java Type      。       Class   Super Class   。           Eclipse       Java Type   :IType。
          ,        :
    1、  SearchEngine     
    2、       Class  Interface       
    3、  Dialog:
  try{
        TypeSelectionDialog2 dialog = new TypeSelectionDialog2(...);
        dialog.setFilter(...);
        dialog.setTitle(...);
        dialog.setMessage(...);
        
        if (dialog.open() == IDialogConstants.CANCEL_ID) 
          return;

        Object[] types= dialog.getResult();
        if (types == null || types.length == 0) 
          return;
        
        IType type = (IType)types[0];
        IResource res = type.getResource();
    }catch(Exception e){
        ...
    }




 
ElementTreeSelectionDialog
   ElementTreeSelectionDialog   JDT  UI,          validator filter  ,ElementTreeSelectionDialog          Java         , Eclipse JDT     ,Java       Package  IPackageFragment,    Java       IPackageFragmentRoot。
       :
     ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(...);
     dialog.setValidator(validator);//            
    dialog.setSorter(new JavaElementSorter());
     dialog.setTitle("Select Java Source Container");
     dialog.setMessage("Select one of java source containers from workspace.");
     dialog.addFilter(filter);//         
     dialog.setInput(IJavaModel)//     Java    
     dialog.setInitialSelection(fWorkspaceRoot.getProject());//    
  ... ...


ElementListSelectionDialog
  ElementListSelectionDialog   JDT  UI,          Dialog      ,       Java    Package       。
  ElementListSelectionDialog dialog= new ElementListSelectionDialog(...));
  dialog.setIgnoreCase(false);
  dialog.setTitle("Select Packages From Java Project ");
  dialog.setMessage("Select packages from java project which you pre-selected.");
  dialog.setEmptyListMessage("There is no package in selected project.");
  dialog.setElements(packages);//