use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.
the class NewJvmConnectionWizard method addActiveJvm.
/**
* Adds the active JVM.
*
* @return The active JVM
*/
private IActiveJvm addActiveJvm() {
final boolean isHostAndPortSelected = page.isHostAndPortSelected();
final String hostName = page.getRemoteHost();
final int port = page.getPort();
final String userName = page.getUserName();
final String password = page.getPassword();
final String jmxUrl = page.getJmxUrl();
try {
final IActiveJvm[] result = new IActiveJvm[1];
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
int period = Activator.getDefault().getPreferenceStore().getInt(IConstants.UPDATE_PERIOD);
if (isHostAndPortSelected) {
IHost host = JvmModel.getInstance().addHost(hostName);
result[0] = host.addRemoteActiveJvm(port, userName, password, period);
} else {
result[0] = JvmModel.getInstance().addHostAndJvm(jmxUrl, userName, password, period);
}
} catch (JvmCoreException e) {
throw new InvocationTargetException(e);
}
}
};
new ProgressMonitorDialog(getShell()).run(true, true, op);
return result[0];
} catch (InvocationTargetException e) {
openErrorDialog(e);
return null;
} catch (InterruptedException e) {
return null;
}
}
use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.
the class ExchangeLoginTask method run.
/* (non-Javadoc)
* @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (!PluginChecker.isExchangeSystemLoaded() || TalendPropertiesUtil.isHideExchange()) {
return;
}
Job job = new //$NON-NLS-1$
Job(//$NON-NLS-1$
"Check Exchange") {
@Override
protected IStatus run(IProgressMonitor monitor) {
// check for Talendforge
IPreferenceStore prefStore = PlatformUI.getPreferenceStore();
boolean checkTisVersion = prefStore.getBoolean(ITalendCorePrefConstants.EXCHANGE_CHECK_TIS_VERSION);
IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
if (!checkTisVersion && brandingService.isPoweredbyTalend()) {
int count = prefStore.getInt(TalendForgeDialog.LOGINCOUNT);
if (count < 0) {
count = 1;
}
ExchangeUser exchangeUser = ProjectManager.getInstance().getCurrentProject().getExchangeUser();
//$NON-NLS-1$
boolean isExchangeLogon = exchangeUser.getLogin() != null && !exchangeUser.getLogin().equals("");
boolean isUserPassRight = true;
if (isExchangeLogon) {
IExchangeService service = (IExchangeService) GlobalServiceRegister.getDefault().getService(IExchangeService.class);
if (service.checkUserAndPass(exchangeUser.getUsername(), exchangeUser.getPassword()) != null) {
isUserPassRight = false;
}
}
if (!isExchangeLogon || !isUserPassRight) {
if ((count + 1) % 4 == 0) {
// if (Platform.getOS().equals(Platform.OS_LINUX)) {
// TalendForgeDialog tfDialog = new TalendForgeDialog(this.getShell(), project);
// tfDialog.open();
// } else {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
Project project = ProjectManager.getInstance().getCurrentProject();
String userEmail = null;
if (project.getAuthor() != null) {
userEmail = project.getAuthor().getLogin();
}
TalendForgeDialog tfDialog = new TalendForgeDialog(DisplayUtils.getDefaultShell(), userEmail);
tfDialog.setBlockOnOpen(true);
tfDialog.open();
}
});
}
prefStore.setValue(TalendForgeDialog.LOGINCOUNT, count + 1);
}
}
return org.eclipse.core.runtime.Status.OK_STATUS;
}
};
job.setSystem(true);
job.setUser(false);
job.setPriority(Job.INTERACTIVE);
// start as soon as possible
job.schedule();
}
use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.
the class StandAloneTalendJavaEditor method refreshName.
/*
* (non-Javadoc)
*
* @see org.talend.core.ui.IUIRefresher#refreshName()
*/
@Override
public void refreshName() {
ICompilationUnit unit = (ICompilationUnit) this.getInputJavaElement();
String newName = item.getProperty().getLabel();
try {
boolean noError = true;
// String newName2 = newName + SuffixConstants.SUFFIX_STRING_java;
//$NON-NLS-1$
String newName2 = newName + ".java";
if (item instanceof RoutineItem && !unit.getElementName().equals(newName2)) {
JavaRenameProcessor processor = new RenameCompilationUnitProcessor(unit);
processor.setNewElementName(newName2);
RenameRefactoring ref = new RenameRefactoring(processor);
final PerformRefactoringOperation operation = new PerformRefactoringOperation(ref, CheckConditionsOperation.ALL_CONDITIONS);
IRunnableWithProgress r = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
operation.run(monitor);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
});
}
};
PlatformUI.getWorkbench().getProgressService().run(true, true, r);
RefactoringStatus conditionStatus = operation.getConditionStatus();
if (conditionStatus != null && conditionStatus.hasError()) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String errorMessage = "Rename " + unit.getElementName() + " to " + newName + " has errors!";
RefactoringStatusEntry[] entries = conditionStatus.getEntries();
for (RefactoringStatusEntry entry : entries) {
//$NON-NLS-1$
errorMessage += "\n>>>" + entry.getMessage();
}
//$NON-NLS-1$
MessageDialog.openError(this.getSite().getShell(), "Warning", errorMessage);
noError = false;
}
}
if (noError) {
doSave(null);
}
setName();
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.
the class TalendEditorPaletteFactory method getRelatedComponentNamesFromHelp.
protected static Set<String> getRelatedComponentNamesFromHelp(final String keyword) {
if (keyword == null || keyword.isEmpty()) {
return null;
}
// This method will cost lots of time to complete when it is called the first time
final List<SearchHit> querySearchResult = new ArrayList<SearchHit>();
if (searchInHelpJob != null && searchInHelpJob.getState() != Job.NONE) {
searchInHelpJob.cancel();
}
searchInHelpJob = new Job(SEARCHING_FROM_HELP) {
@SuppressWarnings("restriction")
@Override
protected IStatus run(IProgressMonitor monitor) {
String helpKeyword = keyword;
try {
TalendPaletteSearchIndex searchIndex = TalendPaletteSearchIndex.getInstance();
LocalSearchManager localSearchManager = BaseHelpSystem.getLocalSearchManager();
// if not work or null, maybe should throw a warn to inform user and help us trace
// if (searchIndex != null && localSearchManager != null) {
localSearchManager.ensureIndexUpdated(monitor, searchIndex);
//$NON-NLS-1$
final String WHITESPACE = " ";
//$NON-NLS-1$//$NON-NLS-2$
helpKeyword = helpKeyword + WHITESPACE + "OR" + WHITESPACE + helpKeyword + "*";
ISearchQuery searchQuery = new SearchQuery(helpKeyword, false, new ArrayList<String>(), Platform.getNL());
searchIndex.search(searchQuery, new ISearchHitCollector() {
@Override
public void addQTCException(QueryTooComplexException exception) throws QueryTooComplexException {
// nothing need to do
}
@Override
public void addHits(List<SearchHit> hits, String wordsSearched) {
querySearchResult.addAll(hits);
}
});
// }
} catch (Throwable e) {
CommonExceptionHandler.process(e, Priority.WARN);
}
return Status.OK_STATUS;
}
@Override
public boolean belongsTo(Object family) {
return family.equals(FederatedSearchJob.FAMILY);
}
};
try {
searchInHelpJob.setPriority(Job.INTERACTIVE);
searchInHelpJob.schedule();
searchInHelpJob.join();
} catch (Throwable e) {
CommonExceptionHandler.process(e, Priority.WARN);
}
Set<String> componentNames = new LinkedHashSet<String>();
// the limitation has been moved to it's caller
// int limit = PaletteSettingsPreferencePage.getPaletteSearchResultLimitFromHelp();
// int i = 1;
Iterator<SearchHit> iter = querySearchResult.iterator();
while (iter.hasNext()) {
// if (limit < i) {
// break;
// }
SearchHit result = iter.next();
String label = result.getLabel();
if (label == null || label.trim().length() == 0) {
continue;
}
componentNames.add(label);
// i++;
}
return componentNames;
}
use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.
the class AbstractJobSettingsPage method save.
protected void save() {
List<String> checkedObjects = new ArrayList<String>();
List<IRepositoryViewObject> allProcess = null;
try {
allProcess = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.PROCESS);
} catch (PersistenceException e1) {
ExceptionHandler.process(e1);
}
for (IRepositoryViewObject object : allProcess) {
if (isStatUseProjectSetting(object)) {
if (!checkedObjects.contains(object.getProperty().getId())) {
checkedObjects.add(object.getProperty().getId());
if (!checkedNodeObject.contains(object)) {
checkedNodeObject.add(object);
}
}
}
}
List<IProcess2> allOpenedProcessList = CorePlugin.getDefault().getDesignerCoreService().getOpenedProcess(getEditors());
if (allOpenedProcessList != null) {
for (int i = 0; i < allOpenedProcessList.size(); i++) {
if (checkedObjects.contains(allOpenedProcessList.get(i).getProperty().getId())) {
openedProcessList.add(allOpenedProcessList.get(i));
}
}
}
//
final IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(getTaskMessages(), (checkedNodeObject.size()) * 100);
final Map<String, Set<String>> contextVars = DetectContextVarsUtils.detectByPropertyType(elem, true);
// must init this
addContextModel = false;
if (!contextVars.isEmpty()) {
// boolean showDialog = false;
Set<String> contextSet = new HashSet<String>();
for (String key : contextVars.keySet()) {
contextSet = contextVars.get(key);
break;
}
Connection connection = null;
IElementParameter ptParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
if (ptParam != null) {
IElementParameter propertyElem = ptParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName());
Object proValue = propertyElem.getValue();
if (proValue instanceof String && ((String) proValue).equalsIgnoreCase(EmfComponent.REPOSITORY)) {
IElementParameter repositoryElem = ptParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
String value = (String) repositoryElem.getValue();
ConnectionItem connectionItem = UpdateRepositoryUtils.getConnectionItemByItemId(value);
connection = connectionItem.getConnection();
if (connection != null && connection.isContextMode()) {
addContextModel = true;
// ContextItem contextItem =
// ContextUtils.getContextItemById(connection.getContextId());
// for (IProcess process : openedProcessList) {
// Set<String> addedContext =
// ConnectionContextHelper.checkAndAddContextVariables(contextItem,
// contextSet, process.getContextManager(), false);
// if (addedContext != null && !addedContext.isEmpty()) {
// showDialog = true;
// break;
// }
// }
}
}
}
if (addContextModel) {
// if the context is not existed in job, will add or not.
Display disp = Display.getCurrent();
if (disp == null) {
disp = Display.getDefault();
}
if (disp != null) {
disp.syncExec(new Runnable() {
@Override
public void run() {
showContextAndCheck(contextVars);
}
});
} else {
showContextAndCheck(contextVars);
}
}
}
monitor.worked(10);
IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
for (IRepositoryViewObject object : checkedNodeObject) {
saveProcess(object, addContextModel, contextVars, monitor);
}
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
workspace.run(workspaceRunnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
monitor.done();
}
};
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
try {
dialog.run(true, true, runnable);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
Aggregations