use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project tdi-studio-se by Talend.
the class LoginProjectPage method refreshLicenseIfNeeded.
/**
*
* @return if false: user cancel login
*/
private boolean refreshLicenseIfNeeded() {
ConnectionBean conn = loginHelper.getCurrentSelectedConnBean();
Project proj = getProject();
if (LoginHelper.isRemoteConnection(conn)) {
String url = getAdminURL();
String projLabel = proj.getLabel();
String userId = conn.getUser();
try {
String key = loginHelper.getLicenseMapKey(url, projLabel, userId);
String license = loginHelper.getLicense(key);
if (license == null || license.isEmpty()) {
Job fetchJob = fetchLicenseJobMap.get(proj);
if (fetchJob == null || fetchJob.getResult() != null) {
// if result is not null, means fetchJob has already finished but no license fetched
fetchJob = fetchLicense(proj);
}
final Job fJob = fetchJob;
if (fJob != null) {
final AtomicBoolean isInterupted = new AtomicBoolean(false);
ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
dialog.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.setTaskName(fJob.getName());
while (true) {
if (monitor.isCanceled()) {
/**
* If network is slow, maybe just wait the fetch job finish, but still can click
* the Refresh button to cancel all fetch jobs
*/
// fJob.cancel();
isInterupted.set(true);
break;
}
IStatus result = fJob.getResult();
if (result != null) {
break;
}
try {
Thread.sleep(250);
} catch (Exception e) {
// nothing to do
}
}
}
});
if (isInterupted.get()) {
return false;
}
}
license = loginHelper.getLicense(key);
}
if (license == null || license.isEmpty()) {
//$NON-NLS-1$
throw new Exception(Messages.getString("LoginProjectPage.fetchLicense.error.failed"));
}
// will do save in CoreTisService if needed
// ICoreTisService tisService = (ICoreTisService) GlobalServiceRegister.getDefault()
// .getService(ICoreTisService.class);
// File remoteLicense = tisService.getRemoteLicenseFile();
// tisService.storeLicenseFile(remoteLicense, license);
} catch (Exception e) {
//$NON-NLS-1$
ExceptionMessageDialog.openError(//$NON-NLS-1$
getShell(), //$NON-NLS-1$
Messages.getString("LoginProjectPage.fetchLicense.error.title"), Messages.getString("LoginProjectPage.fetchLicense.error.msg"), //$NON-NLS-1$
e);
return false;
}
}
return true;
}
use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project tdi-studio-se by Talend.
the class ComponentsPreferencePage method performOk.
@Override
public boolean performOk() {
boolean flag = super.performOk();
String newPath = CodeGeneratorActivator.getDefault().getPreferenceStore().getString(IComponentPreferenceConstant.USER_COMPONENTS_FOLDER);
if ("".equals(oldPath)) {
//$NON-NLS-1$
oldPath = null;
}
if ("".equals(newPath)) {
//$NON-NLS-1$
newPath = null;
}
DesignerPlugin.getDefault().getPreferenceStore().setValue(TalendDesignerPrefConstants.COMPONENT_ASSIST, enableComponentAssistCheckBoxField.getBooleanValue());
TalendEditorComponentCreationUtil.updateAssistListener();
if (this.oldPath != newPath) {
final IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
//$NON-NLS-1$
monitor.beginTask("Loading user component ......", 100);
Display display = Display.getCurrent();
if (display == null) {
display = Display.getDefault();
}
if (display != null) {
display.syncExec(new Runnable() {
@Override
public void run() {
// install the new components via P2
ComponentsInstallComponent component = LocalComponentInstallHelper.getComponent();
if (component != null) {
String newPath = CodeGeneratorActivator.getDefault().getPreferenceStore().getString(IComponentPreferenceConstant.USER_COMPONENTS_FOLDER);
if (newPath != null && StringUtils.isNotEmpty(newPath.trim())) {
File componentFolder = new File(newPath.trim());
if (componentFolder.exists()) {
try {
component.setComponentFolder(componentFolder);
if (component.install()) {
String installedMessages = component.getInstalledMessages();
//$NON-NLS-1$
String title = Messages.getString("ComponentsPreferencePage_SuccessTitle");
if (component.needRelaunch()) {
String warningMessage = Messages.getString(//$NON-NLS-1$
"ComponentsPreferencePage_SuccessMessage1") + //$NON-NLS-1$
Messages.getString("ComponentsPreferencePage_SuccessMessage2");
boolean confirm = MessageDialog.openConfirm(getShell(), title, installedMessages + '\n' + '\n' + warningMessage);
if (confirm) {
PlatformUI.getWorkbench().restart();
}
} else {
MessageDialog.openInformation(getShell(), title, installedMessages);
}
}
} finally {
// after install, clear the setting for service.
component.setComponentFolder(null);
}
}
}
}
// components will be reloaded when refreshTemplates;
// IComponentsFactory components = ComponentsFactoryProvider.getInstance();
// components.loadUserComponentsFromComponentsProviderExtension();
CorePlugin.getDefault().getLibrariesService().resetModulesNeeded();
monitor.worked(50);
// ComponentUtilities.updatePalette();
ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
service.refreshTemplates();
}
});
}
}
};
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
try {
dialog.run(true, true, runnable);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
this.oldPath = newPath;
}
return flag;
}
use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project tdi-studio-se by Talend.
the class ImportExchangeDialog method okPressed.
@Override
protected void okPressed() {
//$NON-NLS-1$ //$NON-NLS-2$
IPath tempPath = new Path(System.getProperty("user.dir")).append("temp");
File pathFile = tempPath.toFile();
if (downloadproperty.getFileName() == null || downloadproperty.getFileName() == null) {
MessageBox box = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_WARNING | SWT.OK);
//$NON-NLS-1$
box.setText(Messages.getString("ImportExchangeDialog.WARNING"));
//$NON-NLS-1$
box.setMessage(Messages.getString("ImportExchangeDialog.NOTSELECTWARNING"));
box.open();
return;
}
tempFile = new File(pathFile, downloadproperty.getFileName());
try {
url = new URL(downloadproperty.getDownloadUrl());
} catch (MalformedURLException e1) {
ExceptionHandler.process(e1);
}
if (!pathFile.exists()) {
pathFile.mkdirs();
}
ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell().getShell());
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) {
//$NON-NLS-1$
monitor.beginTask(Messages.getString("ImportExchangeDialog.downloadProgressBar"), IProgressMonitor.UNKNOWN);
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
try {
new DownloadHelper().download(url, tempFile);
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
});
monitor.done();
}
};
try {
progressDialog.run(true, true, runnable);
} catch (InvocationTargetException e1) {
ExceptionHandler.process(e1);
} catch (InterruptedException e1) {
ExceptionHandler.process(e1);
}
selectFile = tempFile.toString();
super.okPressed();
}
use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project tdi-studio-se by Talend.
the class ImportCompatibleEcoComponentsComposite method findChoiceExchange.
/**
*
* This is a progressBar.when this progressBar run it will download some jobs/templates/routines from net.
*/
public void findChoiceExchange() {
ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell().getShell());
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) {
monitor.beginTask(progressBarMessage, IProgressMonitor.UNKNOWN);
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
compatible = ComponentSearcher.getImportComponentExtensions(version, ExchangeUtils.getCurrentLanguage(), categoryCombo.getSelectionIndex() >= 0 ? fCategorys.get(categoryCombo.getSelectionIndex()).getCategoryId() : "");
updateTable(compatible);
}
});
monitor.done();
if (monitor.isCanceled()) {
try {
//$NON-NLS-1$
throw new InterruptedException(Messages.getString("ImportExchangeDialog.OPERATION_CANCELLED"));
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
}
};
try {
progressDialog.run(true, true, runnable);
} catch (InvocationTargetException e1) {
ExceptionHandler.process(e1);
} catch (InterruptedException e1) {
ExceptionHandler.process(e1);
}
}
use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project bndtools by bndtools.
the class GitHubRepoDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
setTitle(title);
Composite area = (Composite) super.createDialogArea(parent);
Composite container = new Composite(area, SWT.NONE);
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
container.setLayout(new GridLayout(2, false));
Label lblRepo = new Label(container, SWT.NONE);
lblRepo.setText("Repository Name:");
txtRepository = new Text(container, SWT.BORDER);
txtRepository.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
txtRepository.setMessage("username/repository");
if (repository != null)
txtRepository.setText(repository);
new Label(container, SWT.NONE).setText("Branch:");
txtBranch = new Text(container, SWT.BORDER);
txtBranch.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
txtBranch.setMessage("default branch");
if (branch != null)
txtBranch.setText(branch);
ControlDecoration branchDecor = new ControlDecoration(txtBranch, SWT.LEFT, container);
branchDecor.setDescriptionText("Specify the branch, tag or commit ID you would like to clone from the\nrepository. We use the default branch specified in GitHub settings.");
branchDecor.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
branchDecor.setShowHover(true);
final Button btnValidate = new Button(container, SWT.PUSH);
btnValidate.setText("Validate");
btnValidate.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 2, 1));
ModifyListener modifyListener = new ModifyListener() {
@Override
public void modifyText(ModifyEvent ev) {
if (!txtRepository.getText().trim().equals(repository)) {
isValidated = false;
repository = txtRepository.getText().trim();
}
branch = txtBranch.getText().trim();
updateButtons();
}
};
txtRepository.addModifyListener(modifyListener);
txtBranch.addModifyListener(modifyListener);
btnValidate.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setMessage(null, IMessageProvider.INFORMATION);
try {
if (repository == null || repository.isEmpty())
throw new GitHubValidationException("No repository name specified");
if (repository.contains(":/"))
throw new GitHubValidationException("Specify GitHub repositories as username/repository");
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
final GithubRepoDetailsDTO dto = new GitHub(cache, executor).loadRepoDetails(repository).getValue();
final URI cloneUri = URI.create(dto.clone_url);
btnValidate.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
setMessage(String.format("Validated! Clone URL is '%s'. Default branch 'origin/%s'", cloneUri, dto.default_branch), IMessageProvider.INFORMATION);
isValidated = true;
updateButtons();
}
});
} catch (InvocationTargetException e) {
throw e;
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
};
ProgressRunner.execute(false, runnable, new ProgressMonitorDialog(getParentShell()), btnValidate.getDisplay());
setErrorMessage(null);
} catch (InvocationTargetException ex) {
Throwable t = ex.getCause();
if (t instanceof FileNotFoundException)
setErrorMessage("Could not find the requested repository");
else
setErrorMessage(t.getClass().getSimpleName() + ": " + t.getMessage());
} catch (GitHubValidationException ex) {
setErrorMessage(ex.getMessage());
} catch (Exception ex) {
setErrorMessage(ex.getClass().getSimpleName() + ": " + ex.getMessage());
}
}
});
return area;
}
Aggregations