List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress
IRunnableWithProgress
From source file:com.liferay.ide.project.ui.wizard.BinaryProjectsImportWizardPage.java
License:Open Source License
@Override public void updateProjectsList(String path) { // on an empty path empty selectedProjects if (path == null || path.length() == 0) { setMessage(StringPool.EMPTY);//from w w w .j a va 2s . c o m selectedProjects = new BinaryProjectRecord[0]; projectsList.refresh(true); projectsList.setCheckedElements(selectedProjects); setPageComplete(projectsList.getCheckedElements().length > 0); lastPath = path; return; } // Check if the direcotry is the Plugins SDK folder String sdkLocationPath = sdkLocation.getText(); if (sdkLocationPath != null && sdkLocationPath.equals(path)) { path = sdkLocationPath + "/dist"; //$NON-NLS-1$ } final File directory = new File(path); long modified = directory.lastModified(); if (path.equals(lastPath) && lastModified == modified) { // since the file/folder was not modified and the path did not // change, no refreshing is required if (selectedProjects.length == 0) { setMessage(StringPool.EMPTY, WARNING); } return; } lastPath = path; lastModified = modified; final boolean dirSelected = true; try { getContainer().run(true, true, new IRunnableWithProgress() { /* * (non-Javadoc) * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org * .eclipse.core.runtime.IProgressMonitor) */ public void run(IProgressMonitor monitor) { monitor.beginTask(StringPool.EMPTY, 100); selectedProjects = new BinaryProjectRecord[0]; Collection<File> projectBinaries = new ArrayList<File>(); monitor.worked(10); if (dirSelected && directory.isDirectory()) { if (!ProjectImportUtil.collectBinariesFromDirectory(projectBinaries, directory, true, monitor)) { return; } selectedProjects = new BinaryProjectRecord[projectBinaries.size()]; int index = 0; monitor.worked(50); monitor.subTask(StringPool.EMPTY); for (File binaryFile : projectBinaries) { selectedProjects[index++] = new BinaryProjectRecord(binaryFile); } // for ( File liferayProjectDir : liferayProjectDirs ) { // selectedProjects[index++] = new ProjectRecord( liferayProjectDir ); // } } else { monitor.worked(60); } monitor.done(); } }); } catch (InvocationTargetException e) { ProjectUI.logError(e); } catch (InterruptedException e) { // Nothing to do if the user interrupts. } projectsList.refresh(true); setPageComplete(projectsList.getCheckedElements().length > 0); if (selectedProjects.length == 0) { setMessage(StringPool.EMPTY, WARNING); } Object[] checkedBinaries = projectsList.getCheckedElements(); if (checkedBinaries != null && checkedBinaries.length > 0) { selectedProjects = new BinaryProjectRecord[checkedBinaries.length]; for (int i = 0; i < checkedBinaries.length; i++) { selectedProjects[i] = (BinaryProjectRecord) checkedBinaries[i]; } getDataModel().setProperty(SELECTED_PROJECTS, selectedProjects); } }
From source file:com.liferay.ide.project.ui.wizard.NewPluginProjectWizard.java
License:Open Source License
protected void postPerformFinish(final boolean pluginFragmentEnabled) throws InvocationTargetException { try {//from ww w .ja v a 2 s . c o m PlatformUI.getWorkbench().getProgressService().run(true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { postProjectCreated(monitor, pluginFragmentEnabled); UIUtil.sync(new Runnable() { public void run() { try { NewPluginProjectWizard.super.postPerformFinish(); } catch (InvocationTargetException e) { ProjectUIPlugin.logError(e); } } }); } catch (ExecutionException e) { e.printStackTrace(); } } }); } catch (InterruptedException e1) { throw new InvocationTargetException(e1); } }
From source file:com.liferay.ide.project.ui.wizard.SDKProjectConvertWizardPage.java
License:Open Source License
public void updateProjectsList(final String path) { // on an empty path empty selectedProjects if (path == null || path.length() == 0) { setMessage(Msgs.importProjectsDescription); selectedProjects = new ProjectRecord[0]; projectsList.refresh(true);/*from w w w. j a va 2s. c o m*/ projectsList.setCheckedElements(selectedProjects); setPageComplete(projectsList.getCheckedElements().length > 0); lastPath = path; return; } final File directory = new File(path); long modified = directory.lastModified(); if (path.equals(lastPath) && lastModified == modified) { // since the file/folder was not modified and the path did not // change, no refreshing is required return; } lastPath = path; lastModified = modified; final boolean dirSelected = true; try { getContainer().run(true, true, new IRunnableWithProgress() { /* * (non-Javadoc) * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org * .eclipse.core.runtime.IProgressMonitor) */ public void run(IProgressMonitor monitor) { monitor.beginTask(Msgs.searchingMessage, 100); monitor.worked(10); if (dirSelected && directory.isDirectory()) { ProjectRecord[] projectToConvert = (ProjectRecord[]) getDataModel() .getProperty(SELECTED_PROJECTS); IPath dir = new Path(directory.getPath()); if (dir.isPrefixOf(projectToConvert[0].getProjectLocation())) { selectedProjects = projectToConvert; } else { selectedProjects = new ProjectRecord[0]; } } else { monitor.worked(60); } monitor.done(); } }); } catch (InvocationTargetException e) { IDEWorkbenchPlugin.log(e.getMessage(), e); } catch (InterruptedException e) { // Nothing to do if the user interrupts. } projectsList.refresh(true); // ProjectRecord[] projects = getProjectRecords(); // boolean displayWarning = false; // for (int i = 0; i < projects.length; i++) { // if(projects[i].hasConflicts()) { // displayWarning = true; // projectsList.setGrayed(projects[i], true); // }else { // projectsList.setChecked(projects[i], true); // } // } // if (displayWarning) { // setMessage( // DataTransferMessages.WizardProjectsImportPage_projectsInWorkspace, // WARNING); // } else { // setMessage(DataTransferMessages.WizardProjectsImportPage_ImportProjectsDescription); // } if (!CoreUtil.isNullOrEmpty(selectedProjects)) { projectsList.setChecked(selectedProjects[0], true); } setPageComplete(projectsList.getCheckedElements().length > 0); if (selectedProjects.length == 0) { setMessage(Msgs.noProjectsToImport, WARNING); } Object[] checkedProjects = projectsList.getCheckedElements(); if (checkedProjects != null && checkedProjects.length > 0) { selectedProjects = new ProjectRecord[checkedProjects.length]; for (int i = 0; i < checkedProjects.length; i++) { selectedProjects[i] = (ProjectRecord) checkedProjects[i]; } getDataModel().setProperty(SELECTED_PROJECTS, selectedProjects); } }
From source file:com.liferay.ide.project.ui.wizard.SDKProjectsImportWizardPage.java
License:Open Source License
public void updateProjectsList(final String path) { // on an empty path empty selectedProjects if (path == null || path.length() == 0) { setMessage(Msgs.importProjectsDescription); selectedProjects = new ProjectRecord[0]; projectsList.refresh(true);//from ww w . j av a2s . co m projectsList.setCheckedElements(selectedProjects); setPageComplete(projectsList.getCheckedElements().length > 0); lastPath = path; return; } final File directory = new File(path); long modified = directory.lastModified(); if (path.equals(lastPath) && lastModified == modified) { // since the file/folder was not modified and the path did not // change, no refreshing is required return; } lastPath = path; lastModified = modified; final boolean dirSelected = true; try { getContainer().run(true, true, new IRunnableWithProgress() { /* * (non-Javadoc) * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org * .eclipse.core.runtime.IProgressMonitor) */ public void run(IProgressMonitor monitor) { monitor.beginTask(Msgs.searchingMessage, 100); selectedProjects = new ProjectRecord[0]; Collection<File> eclipseProjectFiles = new ArrayList<File>(); Collection<File> liferayProjectDirs = new ArrayList<File>(); monitor.worked(10); if (dirSelected && directory.isDirectory()) { if (!ProjectUtil.collectSDKProjectsFromDirectory(eclipseProjectFiles, liferayProjectDirs, directory, null, true, monitor)) { return; } selectedProjects = new ProjectRecord[eclipseProjectFiles.size() + liferayProjectDirs.size()]; int index = 0; monitor.worked(50); monitor.subTask(Msgs.processingMessage); for (File eclipseProjectFile : eclipseProjectFiles) { selectedProjects[index++] = new ProjectRecord(eclipseProjectFile); } for (File liferayProjectDir : liferayProjectDirs) { selectedProjects[index++] = new ProjectRecord(liferayProjectDir); } } else { monitor.worked(60); } monitor.done(); } }); } catch (InvocationTargetException e) { ProjectUI.logError(e); } catch (InterruptedException e) { // Nothing to do if the user interrupts. } projectsList.refresh(true); Object[] projects = getProjectRecords(); boolean displayWarning = false; for (int i = 0; i < projects.length; i++) { ProjectRecord projectRecord = (ProjectRecord) projects[i]; if (projectRecord.hasConflicts()) { displayWarning = true; projectsList.setGrayed(projects[i], true); } // else { // projectsList.setChecked(projects[i], true); // } } if (displayWarning) { setMessage(Msgs.projectsInWorkspace, WARNING); } else { setMessage(Msgs.importProjectsDescription); } setPageComplete(projectsList.getCheckedElements().length > 0); if (selectedProjects.length == 0) { setMessage(Msgs.noProjectsToImport, WARNING); } // else { // if (!sdkLocation.isDisposed()) { // ProjectUIPlugin.getDefault().getPreferenceStore().setValue( // ProjectUIPlugin.LAST_SDK_IMPORT_LOCATION_PREF, sdkLocation.getText()); // } // } Object[] checkedProjects = projectsList.getCheckedElements(); if (checkedProjects != null && checkedProjects.length > 0) { selectedProjects = new ProjectRecord[checkedProjects.length]; for (int i = 0; i < checkedProjects.length; i++) { selectedProjects[i] = (ProjectRecord) checkedProjects[i]; } getDataModel().setProperty(SELECTED_PROJECTS, selectedProjects); } }
From source file:com.liferay.ide.server.ui.RemoteSettingsEditorSection.java
License:Open Source License
protected IStatus validateSection() { final IStatus[] status = new IStatus[1]; try {/*from w w w. j av a 2 s . co m*/ PlatformUI.getWorkbench().getProgressService().run(true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { status[0] = remoteServer.validate(monitor); } }); } catch (Exception e) { } return status[0]; }
From source file:com.liferay.ide.server.ui.wizard.RemoteServerComposite.java
License:Open Source License
protected void validate() { if (disableValidation) { return;// w w w . j av a2 s .c om } if (serverWC == null) { wizard.setMessage(StringPool.EMPTY, IMessageProvider.ERROR); return; } try { IRunnableWithProgress validateRunnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { final IStatus updateStatus = validateServer(monitor); if (updateStatus.isOK()) { String contextPath = RemoteUtil.detectServerManagerContextPath(getRemoteServer(), monitor); remoteServerWC.setServerManagerContextPath(contextPath); } RemoteServerComposite.this.getDisplay().syncExec(new Runnable() { public void run() { if (updateStatus == null || updateStatus.isOK()) { wizard.setMessage(null, IMessageProvider.NONE); } else if (updateStatus.getSeverity() == IStatus.WARNING || updateStatus.getSeverity() == IStatus.ERROR) { if (updateStatus.getMessage().contains("Your license key has expired") || updateStatus.getMessage() .contains("Register Your Server or Application")) { wizard.setMessage("Server is not registered or license key has expired ", IMessageProvider.WARNING); } else { wizard.setMessage(updateStatus.getMessage(), IMessageProvider.WARNING); } } wizard.update(); } }); } }; wizard.run(true, true, validateRunnable); wizard.update(); if (fragment.lastServerStatus != null && fragment.lastServerStatus.isOK()) { ignoreModifyEvents = true; textServerManagerContextPath.setText(this.remoteServerWC.getServerManagerContextPath()); textLiferayPortalContextPath.setText(this.remoteServerWC.getLiferayPortalContextPath()); ignoreModifyEvents = false; } } catch (final Exception e) { RemoteServerComposite.this.getDisplay().syncExec(new Runnable() { public void run() { wizard.setMessage(e.getMessage(), IMessageProvider.WARNING); wizard.update(); } }); } }
From source file:com.liferay.ide.server.ui.wizard.RemoteServerWizardFragment.java
License:Open Source License
@Override public void performFinish(IProgressMonitor monitor) throws CoreException { try {// w ww . j a va 2s. c om this.wizard.run(false, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (lastServerStatus == null || (!lastServerStatus.isOK())) { lastServerStatus = getRemoteServerWC().validate(monitor); if (!lastServerStatus.isOK()) { throw new InterruptedException(lastServerStatus.getMessage()); } } } }); } catch (Exception e) { } ServerCore.addServerLifecycleListener(new IServerLifecycleListener() { String id = getServerWorkingCopy().getId(); public void serverAdded(final IServer server) { if (server.getId().equals(id)) { UIUtil.async(new Runnable() { public void run() { IViewPart serversView = UIUtil.showView("org.eclipse.wst.server.ui.ServersView"); //$NON-NLS-1$ CommonViewer viewer = (CommonViewer) serversView.getAdapter(CommonViewer.class); viewer.setSelection(new StructuredSelection(server)); } }); ServerCore.removeServerLifecycleListener(this); server.addServerListener(new IServerListener() { public void serverChanged(ServerEvent event) { if (event.getServer().getServerState() == IServer.STATE_STARTED) { server.publish(IServer.PUBLISH_INCREMENTAL, null, null, null); server.removeServerListener(this); } } }); } } public void serverChanged(IServer server) { } public void serverRemoved(IServer server) { } }); }
From source file:com.liferay.ide.ui.WorkspaceHelper.java
License:Open Source License
@Override public String openDir(String path) { String retval = null;//from ww w.j av a 2 s .c om final File dir = new File(path); if ((!dir.exists()) || (!dir.isDirectory())) { retval = "Directory doesn't exist or isn't a directory."; } final File dotProject = new File(dir, ".project"); if (dotProject.exists()) { retval = importExistingProject(dir); } else { for (ILiferayProjectImporter importer : LiferayCore.getImporters()) { try { final IStatus importStatus = importer.canImport(dir.getCanonicalPath()); if (importStatus != null && importStatus.isOK()) { UIUtil.async(new Runnable() { @Override public void run() { try { new ProgressMonitorDialog(UIUtil.getActiveShell()).run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { importer.importProjects(path, monitor); } catch (CoreException e) { LiferayUIPlugin.logError("Error opening project", e); } } }); } catch (InvocationTargetException | InterruptedException e) { } } }); return retval; } } catch (Exception e) { } } retval = "Directory must have a .project file to open."; } return retval; }
From source file:com.liferay.ide.ui.WorkspaceHelper.java
License:Open Source License
private String importExistingProject(File dir) { String retval = null;//w ww . j a v a 2s . c o m try { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProjectDescription description = workspace .loadProjectDescription(new Path(dir.getAbsolutePath()).append(".project")); final String name = description.getName(); final IProject project = workspace.getRoot().getProject(name); if (project.exists()) { retval = "Project with name " + name + " already exists"; } else { final IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { project.create(description, monitor); project.open(IResource.BACKGROUND_REFRESH, monitor); try { project.refreshLocal(IResource.DEPTH_INFINITE, monitor); } catch (CoreException e) { // ignore error this is just best effort } final IWorkbench workbench = PlatformUI.getWorkbench(); final Shell shell = workbench.getActiveWorkbenchWindow().getShell(); shell.forceActive(); shell.forceFocus(); PackageExplorerPart view = PackageExplorerPart.openInActivePerspective(); view.selectAndReveal(project); } catch (CoreException e) { LiferayUIPlugin.logError("Unable to import project " + name, e); } } }; UIUtil.async(new Runnable() { @Override public void run() { try { new ProgressMonitorDialog(UIUtil.getActiveShell()).run(true, true, runnable); } catch (InvocationTargetException | InterruptedException e) { } } }); } } catch (CoreException e) { retval = e.getMessage(); } return retval; }
From source file:com.lowcoupling.dono.m2t.dono2msw.ui.popupMenus.AcceleoGenerateDocml2mswAction.java
License:Open Source License
/**{@inheritDoc} * * @see org.eclipse.ui.actions.ActionDelegate#run(org.eclipse.jface.action.IAction) * @generated/*from ww w .j a v a 2 s.c o m*/ */ public void run(IAction action) { if (files != null) { IRunnableWithProgress operation = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { try { Iterator<IFile> filesIt = files.iterator(); while (filesIt.hasNext()) { IFile model = (IFile) filesIt.next(); URI modelURI = URI.createPlatformResourceURI(model.getFullPath().toString(), true); ImgToBase64Encoder.setProject(model.getProject()); try { IContainer target = model.getProject().getFolder("doc-gen"); GenerateAll generator = new GenerateAll(modelURI, target, getArguments()); generator.doGenerate(monitor); } catch (IOException e) { IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); Activator.getDefault().getLog().log(status); } finally { model.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor); } } } catch (CoreException e) { IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); Activator.getDefault().getLog().log(status); } } }; try { PlatformUI.getWorkbench().getProgressService().run(true, true, operation); } catch (InvocationTargetException e) { IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); Activator.getDefault().getLog().log(status); } catch (InterruptedException e) { IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); Activator.getDefault().getLog().log(status); } } }