Search in sources :

Example 6 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project liferay-ide by liferay.

the class AbstractLiferayTableViewCustomPart method _handleUpgradeEvent.

private void _handleUpgradeEvent() {
    try {
        IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
        progressService.run(true, false, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
                int count = _tableViewElements != null ? _tableViewElements.length : 0;
                if (count == 0) {
                    UIUtil.async(new Runnable() {

                        @Override
                        public void run() {
                            String message = "No files that need to be upgraded were found.";
                            PageValidateEvent pe = new PageValidateEvent();
                            pe.setMessage(message);
                            pe.setType(PageValidateEvent.warning);
                            triggerValidationEvent(pe);
                        }
                    });
                    return;
                }
                int unit = 100 / count;
                monitor.beginTask("Start to upgrade files.....", 100);
                for (int i = 0; i < count; i++) {
                    monitor.worked(i + 1 * unit);
                    if (i == (count - 1)) {
                        monitor.worked(100);
                    }
                    LiferayUpgradeElement tableViewElement = _tableViewElements[i];
                    monitor.setTaskName("Upgrading files for " + tableViewElement.getProjectName());
                    if (tableViewElement.getUpgradeStatus() == true) {
                        continue;
                    }
                    try {
                        IProject project = tableViewElement.getProject();
                        doUpgrade(tableViewElement.getFile(), project);
                        if (project != null) {
                            project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
                        }
                        final int loopNum = i;
                        UIUtil.async(new Runnable() {

                            @Override
                            public void run() {
                                tableViewElement.setUpgradeStatus(true);
                                _tableViewElements[loopNum] = tableViewElement;
                                tableViewer.setInput(_tableViewElements);
                                Stream.of(tableViewer.getTable().getColumns()).forEach(obj -> obj.pack());
                                tableViewer.refresh();
                            }
                        });
                    } catch (Exception e) {
                        ProjectCore.logError("Error upgrade files...... ", e);
                    }
                }
            }
        });
    } catch (Exception e) {
        ProjectUI.logError(e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProgressService(org.eclipse.ui.progress.IProgressService) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 7 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project liferay-ide by liferay.

the class InitConfigureProjectPage method importProject.

protected void importProject() throws CoreException {
    String layout = dataModel.getLayout().content();
    IPath location = PathBridge.create(dataModel.getSdkLocation().content());
    if (_isAlreadyImported(location)) {
        Stream.of(CoreUtil.getAllProjects()).forEach(this::_checkProjectType);
        dataModel.setImportFinished(true);
        return;
    }
    try {
        IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
        progressService.run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
                try {
                    String newPath = "";
                    _backup(monitor);
                    _clearExistingProjects(location, monitor);
                    _deleteEclipseConfigFiles(location.toFile());
                    if (_isMavenProject(location.toPortableString())) {
                        ILiferayProjectImporter importer = LiferayCore.getImporter("maven");
                        List<IProject> projects = importer.importProjects(location.toPortableString(), monitor);
                        for (IProject project : projects) {
                            _checkProjectType(project);
                        }
                    } else {
                        if (layout.equals("Upgrade to Liferay Workspace")) {
                            _createLiferayWorkspace(location, monitor);
                            _removeIvyPrivateSetting(location.append("plugins-sdk"));
                            newPath = _renameProjectFolder(location);
                            IPath sdkLocation = new Path(newPath).append("plugins-sdk");
                            _deleteSDKLegacyProjects(sdkLocation);
                            ILiferayProjectImporter importer = LiferayCore.getImporter("gradle");
                            importer.importProjects(newPath, monitor);
                            if (dataModel.getDownloadBundle().content()) {
                                _createInitBundle(monitor);
                            }
                            _importSDKProject(sdkLocation, monitor);
                            dataModel.setConvertLiferayWorkspace(true);
                        } else {
                            _deleteEclipseConfigFiles(location.toFile());
                            _copyNewSDK(location, monitor);
                            _removeIvyPrivateSetting(location);
                            _deleteSDKLegacyProjects(location);
                            String serverName = dataModel.getLiferay70ServerName().content();
                            IServer server = ServerUtil.getServer(serverName);
                            newPath = _renameProjectFolder(location);
                            SDK sdk = SDKUtil.createSDKFromLocation(new Path(newPath));
                            sdk.addOrUpdateServerProperties(ServerUtil.getLiferayRuntime(server).getLiferayHome());
                            SDKUtil.openAsProject(sdk, monitor);
                            _importSDKProject(sdk.getLocation(), monitor);
                        }
                    }
                    dataModel.setImportFinished(true);
                } catch (Exception e) {
                    ProjectUI.logError(e);
                    throw new InvocationTargetException(e, e.getMessage());
                }
            }
        });
    } catch (Exception e) {
        ProjectUI.logError(e);
        throw new CoreException(StatusBridge.create(Status.createErrorStatus(e.getMessage(), e)));
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IServer(org.eclipse.wst.server.core.IServer) IPath(org.eclipse.core.runtime.IPath) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) BladeCLIException(com.liferay.ide.project.core.modules.BladeCLIException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ILiferayProjectImporter(com.liferay.ide.core.ILiferayProjectImporter) CoreException(org.eclipse.core.runtime.CoreException) IProgressService(org.eclipse.ui.progress.IProgressService) ArrayList(java.util.ArrayList) List(java.util.List) SDK(com.liferay.ide.sdk.core.SDK)

Example 8 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project liferay-ide by liferay.

the class CustomJspConverter method doExecute.

public void doExecute(String[] projectPaths, String[] projectNames, String targetPath, boolean liferayWorkspace) {
    Job job = new WorkspaceJob("Converting Jsp hook to fragments...") {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            IStatus retval = Status.OK_STATUS;
            try {
                convertJspHookProject(projectPaths, projectNames, targetPath, monitor, liferayWorkspace);
                String[] projectPaths = getConvertResult(resultPrefix);
                if (ListUtil.isNotEmpty(projectPaths)) {
                    for (String path : projectPaths) {
                        ImportLiferayModuleProjectOp importOp = ImportLiferayModuleProjectOp.TYPE.instantiate();
                        importOp.setLocation(path);
                        if (importOp.validation().severity() != org.eclipse.sapphire.modeling.Status.Severity.ERROR) {
                            ImportLiferayModuleProjectOpMethods.execute(importOp, ProgressMonitorBridge.create(monitor));
                        }
                    }
                    refreshUI();
                }
            } catch (Exception e) {
                retval = ProjectUI.createErrorStatus("Error in convert jsp", e);
            }
            return retval;
        }
    };
    try {
        IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
        progressService.showInDialog(Display.getDefault().getActiveShell(), job);
        job.schedule();
    } catch (Exception e) {
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) ImportLiferayModuleProjectOp(com.liferay.ide.project.core.modules.ImportLiferayModuleProjectOp) IProgressService(org.eclipse.ui.progress.IProgressService) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Job(org.eclipse.core.runtime.jobs.Job) CoreException(org.eclipse.core.runtime.CoreException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException)

Example 9 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project jbosstools-hibernate by jbosstools.

the class HibernatePersistenceUnitClassesComposite method chooseType.

/**
 * Prompts the user the Open Type dialog.
 *
 * @return Either the selected type or <code>null</code> if the user
 * canceled the dialog
 */
private IType chooseType() {
    IJavaProject javaProject = getJavaProject();
    IJavaElement[] elements = new IJavaElement[] { javaProject };
    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements);
    IProgressService service = PlatformUI.getWorkbench().getProgressService();
    SelectionDialog typeSelectionDialog;
    try {
        typeSelectionDialog = JavaUI.createTypeDialog(getShell(), service, scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, // $NON-NLS-1$
        "");
    } catch (JavaModelException e) {
        HibernateJptUIPlugin.logException(e);
        return null;
    }
    typeSelectionDialog.setTitle(JptCommonUiMessages.CLASS_CHOOSER_PANE__DIALOG_TITLE);
    typeSelectionDialog.setMessage(JptCommonUiMessages.CLASS_CHOOSER_PANE__DIALOG_MESSAGE);
    if (typeSelectionDialog.open() == Window.OK) {
        return (IType) typeSelectionDialog.getResult()[0];
    }
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) IProgressService(org.eclipse.ui.progress.IProgressService) SelectionDialog(org.eclipse.ui.dialogs.SelectionDialog) IType(org.eclipse.jdt.core.IType)

Example 10 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project netxms by netxms.

the class ConsoleJob method runInForeground.

/**
 * Run job in foreground using IProgressService.busyCursorWhile
 *
 * @return true if job was successful
 */
public boolean runInForeground() {
    passException = true;
    IProgressService service = PlatformUI.getWorkbench().getProgressService();
    boolean success = true;
    try {
        service.run(true, false, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                IStatus status = ConsoleJob.this.run(monitor);
                if (!status.isOK()) {
                    throw new InvocationTargetException(status.getException());
                }
            }
        });
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause == null)
            cause = e;
        // $NON-NLS-1$
        MessageDialog.openError(null, Messages.get().ConsoleJob_ErrorDialogTitle, getErrorMessage() + ": " + cause.getLocalizedMessage());
    } catch (InterruptedException e) {
    }
    return success;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IProgressService(org.eclipse.ui.progress.IProgressService) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

IProgressService (org.eclipse.ui.progress.IProgressService)38 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)17 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)15 IStatus (org.eclipse.core.runtime.IStatus)11 IOException (java.io.IOException)7 Status (org.eclipse.core.runtime.Status)6 IWorkbench (org.eclipse.ui.IWorkbench)6 File (java.io.File)5 CoreException (org.eclipse.core.runtime.CoreException)5 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)4 IContext (org.talend.core.model.process.IContext)4 ProcessorException (org.talend.designer.runprocess.ProcessorException)4 MessageFormat (java.text.MessageFormat)3 Date (java.util.Date)3 IProject (org.eclipse.core.resources.IProject)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)3 IProcessor (org.talend.designer.runprocess.IProcessor)3 ClearPerformanceAction (org.talend.designer.runprocess.ui.actions.ClearPerformanceAction)3