Search in sources :

Example 1 with ProjectSelectionDialog

use of org.eclipse.jdt.internal.ui.preferences.ProjectSelectionDialog in project liferay-ide by liferay.

the class AddMacroLibrary method run.

public void run(IAction action) {
    ISelectionProvider provider = part.getSite().getSelectionProvider();
    if (null != provider) {
        if (provider.getSelection() instanceof IStructuredSelection) {
            try {
                IStructuredSelection selection = (IStructuredSelection) provider.getSelection();
                Object[] obj = selection.toArray();
                List documents = new ArrayList();
                for (int i = 0; i < obj.length; i++) {
                    if (obj[i] instanceof IFile) {
                        IFile file = (IFile) obj[i];
                        documents.add(file);
                    } else if (obj[i] instanceof JarEntryFile) {
                        JarEntryFile jef = (JarEntryFile) obj[i];
                        documents.add(jef);
                        System.out.println(jef.getFullPath().makeAbsolute());
                        System.out.println(jef.getFullPath().makeRelative());
                        IPath path = jef.getFullPath();
                        System.out.println(path);
                        System.out.println(jef.getName());
                        IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(jef.getFullPath());
                        System.out.println(resource);
                    } else if (obj[i] instanceof IStorage) {
                    }
                }
                IProject project = null;
                if (documents.size() > 0) {
                    // what project?
                    HashSet projects = new HashSet();
                    IProject[] p = ResourcesPlugin.getWorkspace().getRoot().getProjects();
                    for (int i = 0; i < p.length; i++) {
                        projects.add(p[i]);
                    }
                    ProjectSelectionDialog dialog = new ProjectSelectionDialog(Display.getCurrent().getActiveShell(), projects);
                    dialog.setTitle(Messages.AddMacroLibrary_Title);
                    dialog.setMessage(Messages.AddMacroLibrary_Message);
                    int rtn = dialog.open();
                    if (rtn == IDialogConstants.OK_ID) {
                        if (dialog.getFirstResult() instanceof IJavaProject) {
                            project = ((IJavaProject) dialog.getFirstResult()).getProject();
                        } else {
                            MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.AddMacroLibrary_Error, Messages.AddMacroLibrary_ErrorDesc);
                        }
                    }
                }
                if (null != project) {
                    ConfigurationManager.getInstance(project).associateMappingLibraries(documents, Display.getCurrent().getActiveShell());
                }
            } catch (Exception e) {
                Plugin.error(e);
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) ProjectSelectionDialog(org.eclipse.jdt.internal.ui.preferences.ProjectSelectionDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStorage(org.eclipse.core.resources.IStorage) IProject(org.eclipse.core.resources.IProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ArrayList(java.util.ArrayList) List(java.util.List) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IStorage (org.eclipse.core.resources.IStorage)1 IPath (org.eclipse.core.runtime.IPath)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 JarEntryFile (org.eclipse.jdt.internal.core.JarEntryFile)1 ProjectSelectionDialog (org.eclipse.jdt.internal.ui.preferences.ProjectSelectionDialog)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1