Search in sources :

Example 1 with ImportsCleanUp

use of org.eclipse.jdt.internal.ui.fix.ImportsCleanUp in project liferay-ide by liferay.

the class NewPortletWizard method openJavaClass.

@Override
protected void openJavaClass() {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject project = workspace.getRoot().getProject(getDataModel().getStringProperty(PROJECT_NAME));
    if (getDataModel().getBooleanProperty(USE_DEFAULT_PORTLET_CLASS)) {
        try {
            String jspsFolder = getDataModel().getStringProperty(CREATE_JSPS_FOLDER);
            // IDE-110 IDE-648
            IWebProject webproject = LiferayCore.create(IWebProject.class, project);
            if ((webproject != null) && (webproject.getDefaultDocrootFolder() != null)) {
                IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
                IFile viewFile = defaultDocroot.getFile(new Path(jspsFolder + "/view.jsp"));
                if (viewFile.exists()) {
                    IWorkbench workbench = PlatformUI.getWorkbench();
                    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
                    IDE.openEditor(page, viewFile, true);
                    return;
                }
            }
        } catch (Exception e) {
        // eat this exception this is just best effort
        }
    } else {
        Map<String, String> settings = new Hashtable<>();
        settings.put(CleanUpConstants.ORGANIZE_IMPORTS, CleanUpOptions.TRUE);
        ImportsCleanUp importsCleanUp = new ImportsCleanUp(settings);
        ICleanUp[] cleanUps = { importsCleanUp };
        IJavaProject javaProject = JavaCore.create(project);
        try {
            IType type = javaProject.findType(getDataModel().getStringProperty(INewJavaClassDataModelProperties.QUALIFIED_CLASS_NAME));
            ICompilationUnit cu = (ICompilationUnit) type.getParent();
            ICompilationUnit[] units = { cu };
            RefactoringExecutionStarter.startCleanupRefactoring(units, cleanUps, false, getShell(), false, "organize imports");
        } catch (Exception e) {
        }
        super.openJavaClass();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IFile(org.eclipse.core.resources.IFile) ICleanUp(org.eclipse.jdt.ui.cleanup.ICleanUp) IWebProject(com.liferay.ide.core.IWebProject) Hashtable(java.util.Hashtable) ImportsCleanUp(org.eclipse.jdt.internal.ui.fix.ImportsCleanUp) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IType(org.eclipse.jdt.core.IType) IWorkbench(org.eclipse.ui.IWorkbench) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspace(org.eclipse.core.resources.IWorkspace) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IWebProject (com.liferay.ide.core.IWebProject)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Hashtable (java.util.Hashtable)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 Path (org.eclipse.core.runtime.Path)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IType (org.eclipse.jdt.core.IType)1 ImportsCleanUp (org.eclipse.jdt.internal.ui.fix.ImportsCleanUp)1 ICleanUp (org.eclipse.jdt.ui.cleanup.ICleanUp)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1