use of org.eclipse.ui.IEditorReference in project tdi-studio-se by Talend.
the class MavenVersionManagementProjectSettingPage method updateItemsVersion.
protected void updateItemsVersion() {
List<ItemVersionObject> JobsOpenedInEditor = new ArrayList<ItemVersionObject>();
List<ItemVersionObject> closedJobs = new ArrayList<ItemVersionObject>();
boolean hasJobOpenedInEditor = false;
StringBuilder builder = new StringBuilder();
for (ItemVersionObject object : checkedObjects) {
if (RepositoryManager.isOpenedItemInEditor(object.getRepositoryNode().getObject())) {
hasJobOpenedInEditor = true;
JobsOpenedInEditor.add(object);
//$NON-NLS-1$
builder.append(object.getRepositoryNode().getObject().getLabel() + ", ");
} else {
closedJobs.add(object);
}
}
if (builder.length() > 0) {
builder.delete(builder.length() - 2, builder.length());
}
if (hasJobOpenedInEditor) {
MessageDialog.openWarning(Display.getCurrent().getActiveShell(), //$NON-NLS-1$
Messages.getString("VersionManagementDialog.WarningTitle2"), //$NON-NLS-1$
Messages.getString("VersionManagementDialog.openedInEditorMessage", builder.toString()));
IWorkbenchWindow workBench = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (workBench != null) {
IWorkbenchPage page = workBench.getActivePage();
IEditorReference[] editorRefs = page.getEditorReferences();
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
IDesignerCoreUIService service = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
if (service != null) {
for (IEditorReference editorRef : editorRefs) {
IEditorPart editor = editorRef.getEditor(false);
if (editor instanceof IMultiPageTalendEditor) {
IProcess2 process = ((IMultiPageTalendEditor) editor).getProcess();
String version = null;
for (ItemVersionObject object : JobsOpenedInEditor) {
if (object.getItem().getProperty().getId().equals(process.getId())) {
version = object.getNewVersion();
break;
}
}
if (version != null) {
String jobDefaultVersion = MavenVersionUtils.getDefaultVersion(process.getProperty().getVersion());
if (version.equals(jobDefaultVersion)) {
// if default, set null to remove key from property.
version = null;
}
Command command = service.crateMavenDeploymentValueChangeCommand(process, MavenConstants.NAME_USER_VERSION, version);
if (process instanceof IGEFProcess) {
service.executeCommand((IGEFProcess) process, command);
}
}
}
}
}
}
}
}
final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(final IProgressMonitor monitor) throws CoreException {
RepositoryWorkUnit<Object> rwu = new //$NON-NLS-1$
RepositoryWorkUnit<Object>(//$NON-NLS-1$
project, //$NON-NLS-1$
"Update items Maven version") {
@Override
protected void run() throws LoginException, PersistenceException {
//$NON-NLS-1$
monitor.beginTask("Update items Maven version", closedJobs.size());
for (ItemVersionObject object : closedJobs) {
final Item item = object.getItem();
Property itemProperty = item.getProperty();
MavenVersionUtils.setItemMavenVersion(itemProperty, object.getNewVersion());
monitor.subTask(itemProperty.getLabel());
FACTORY.save(project, itemProperty);
monitor.worked(1);
}
try {
FACTORY.saveProject(project);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
};
rwu.setAvoidUnloadResources(true);
rwu.executeRun();
monitor.done();
}
};
IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace runnable to avoid all notification
// of changes before the end of the modifications.
workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
};
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
try {
dialog.run(false, false, iRunnableWithProgress);
} catch (InvocationTargetException | InterruptedException e) {
ExceptionHandler.process(e);
}
}
use of org.eclipse.ui.IEditorReference in project tdi-studio-se by Talend.
the class SaveJobBeforeRunAction method run.
public void run() {
boolean saveMyself = false;
List<? extends INode> nodes = filterTRunJobNode();
if (nodes.isEmpty()) {
return;
}
IEditorReference[] references = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
for (int i = 0; i < references.length; i++) {
IEditorPart part = references[i].getEditor(false);
if (!(part instanceof MultiPageTalendEditor)) {
continue;
}
MultiPageTalendEditor editor = (MultiPageTalendEditor) part;
saveJob(nodes, editor);
}
}
use of org.eclipse.ui.IEditorReference in project tdi-studio-se by Talend.
the class OpenExistVersionProcessAction method getCorrespondingEditor.
@Override
protected IEditorPart getCorrespondingEditor(IRepositoryNode node) {
IEditorReference[] eidtors = getActivePage().getEditorReferences();
for (IEditorReference eidtor : eidtors) {
try {
IEditorInput input = eidtor.getEditorInput();
if (!(input instanceof JobEditorInput)) {
continue;
}
JobEditorInput repositoryInput = (JobEditorInput) input;
checkUnLoadedNodeForProcess(repositoryInput);
if (repositoryInput.getItem().equals(node.getObject().getProperty().getItem())) {
IPath path = repositoryInput.getFile().getLocation();
return eidtor.getEditor(false);
}
} catch (PartInitException e) {
continue;
}
}
return null;
}
use of org.eclipse.ui.IEditorReference in project tesb-studio-se by Talend.
the class RunContainerPreferencePage method performOk.
/*
* (non-Javadoc)
*
* @see org.talend.designer.esb.runcontainer.preferences.FieldLayoutPreferencePage#performOk()
*/
@Override
public boolean performOk() {
boolean performOk = super.performOk();
if (runtimeEnable != getPreferenceStore().getBoolean(RunContainerPreferenceInitializer.P_ESB_IN_OSGI)) {
IRunProcessService service = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
if (service != null) {
service.refreshView();
}
List<IEditorReference> editorRefs = new ArrayList();
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorReference[] reference = page.getEditorReferences();
for (IEditorReference editorRef : reference) {
IEditorPart part = editorRef.getEditor(false);
if (part.getEditorInput() instanceof JobEditorInput) {
editorRefs.add(editorRef);
}
}
if (editorRefs.size() > 0 && MessageDialog.openConfirm(getShell(), "Running Container Changed", "All editors need to be closed to apply the changes, do you want to close all opening editors now?")) {
page.closeEditors(editorRefs.toArray(new IEditorReference[editorRefs.size()]), true);
}
}
return performOk;
}
use of org.eclipse.ui.IEditorReference in project tdi-studio-se by Talend.
the class SQLPatternComposite method resourceChanged.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent
* )
*/
@Override
public void resourceChanged(IResourceChangeEvent event) {
boolean needRefresh = false;
boolean modifySQL = true;
if (event.getSource() instanceof SQLPatternItem && event.getType() == IResourceChangeEvent.PRE_CLOSE) {
needRefresh = true;
modifySQL = false;
// if still have sql template editor to be opened.
if (getCurrentOpenedEditors() != null) {
for (IEditorReference editor : getCurrentOpenedEditors()) {
ERepositoryObjectType type = null;
try {
type = getCurrentOpenEditorType(editor);
} catch (PartInitException e) {
e.printStackTrace();
}
if (type != null && ERepositoryObjectType.SQLPATTERNS.equals(type)) {
modifySQL = true;
}
}
}
}
if (event.getSource() instanceof SQLPatternItem && event.getType() == IResourceChangeEvent.POST_CHANGE) {
needRefresh = true;
}
if (needRefresh) {
refreshComboContent(this.tableViewer, modifySQL);
refresh();
}
}
Aggregations