use of org.eclipse.ui.IWorkbenchWindow in project translationstudio8 by heartsome.
the class SplitXliffHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
final String navegatorID = "net.heartsome.cat.common.ui.navigator.view";
final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
final Shell shell = window.getShell();
IFile selectFile = null;
XLIFFEditorImplWithNatTable xliffEditor = null;
List<Integer> splitXlfPointsIndex = new LinkedList<Integer>();
List<String> splitXlfPointsRowId = new LinkedList<String>();
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
// 如果是导航视图,那么就获取导航视图中选中的文件
if (activePart instanceof IViewPart) {
if (navegatorID.equals(activePart.getSite().getId())) {
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(navegatorID);
ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
Object object = structuredSelection.getFirstElement();
if (object instanceof IFile) {
selectFile = (IFile) object;
String fileExtension = selectFile.getFileExtension();
// 如果后缀名不是xlf,那么就退出操作
if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg1"));
return null;
}
FileEditorInput fileInput = new FileEditorInput(selectFile);
IEditorReference[] editorRefer = window.getActivePage().findEditors(fileInput, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
IEditorPart editorPart = null;
if (editorRefer.length >= 1) {
editorPart = editorRefer[0].getEditor(true);
xliffEditor = (XLIFFEditorImplWithNatTable) editorPart;
if (window.getActivePage().getActiveEditor() != editorPart) {
window.getActivePage().activate(editorPart);
}
} else {
try {
xliffEditor = (XLIFFEditorImplWithNatTable) window.getActivePage().openEditor(fileInput, XLIFF_EDITOR_ID, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
} catch (PartInitException e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
} else {
MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg1"));
return null;
}
}
}
} else if (activePart instanceof IEditorPart) {
if (XLIFF_EDITOR_ID.equals(activePart.getSite().getId())) {
xliffEditor = (XLIFFEditorImplWithNatTable) activePart;
selectFile = ((FileEditorInput) xliffEditor.getEditorInput()).getFile();
}
}
// 根据每个tu节点的rowId获取其具体的位置,才好进行排序
Map<Integer, String> pointIndexRowIdMap = new HashMap<Integer, String>();
for (String rowId : xliffEditor.getSplitXliffPoints()) {
// 获取指定tu节点所处其他结点的序列号
int tuPostion = xliffEditor.getXLFHandler().getTUPositionByRowId(rowId);
if (tuPostion >= 1) {
splitXlfPointsIndex.add(tuPostion);
pointIndexRowIdMap.put(tuPostion, rowId);
}
}
if (splitXlfPointsIndex.size() <= 0) {
MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg2"));
return null;
}
// 对切割点集合进行排序
for (int i = 0; i < splitXlfPointsIndex.size(); i++) {
int point1 = splitXlfPointsIndex.get(i);
for (int j = i + 1; j < splitXlfPointsIndex.size(); j++) {
int point2 = splitXlfPointsIndex.get(j);
if (point1 > point2) {
splitXlfPointsIndex.set(i, point2);
splitXlfPointsIndex.set(j, point1);
point1 = point2;
}
}
}
// 向存储rowId的list存放数据,这样的话,所存储的rowId就是经过排序了的。
for (int i = 0; i < splitXlfPointsIndex.size(); i++) {
splitXlfPointsRowId.add(pointIndexRowIdMap.get(splitXlfPointsIndex.get(i)));
}
SplitOrMergeXlfModel model = new SplitOrMergeXlfModel();
model.setSplitFile(selectFile);
model.setSplitXlfPointsIndex(splitXlfPointsIndex);
model.setSplitXlfPointsRowId(splitXlfPointsRowId);
model.setXliffEditor(xliffEditor);
model.setShell(shell);
SplitXliffWizard wizard = new SplitXliffWizard(model);
final TSWizardDialog dialog = new NattableWizardDialog(shell, wizard);
dialog.open();
return null;
}
use of org.eclipse.ui.IWorkbenchWindow in project flux by eclipse.
the class LiveEditConnector method dispose.
public void dispose() {
this.liveEditCoordinator.removeLiveEditConnector(liveEditConnector);
this.repository.removeRepositoryListener(repositoryListener);
FileBuffers.getTextFileBufferManager().removeFileBufferListener(fileBufferListener);
ResourcesPlugin.getWorkspace().removeResourceChangeListener(workspaceListener);
WorkbenchJob jw = new WorkbenchJob("Removing listener") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
window.getActivePage().removePartListener(partListener);
}
return Status.OK_STATUS;
}
};
jw.setSystem(true);
jw.schedule();
for (IDocument document : documentMappings.values()) {
if (document != null) {
document.removeDocumentListener(documentListener);
}
}
resourceMappings.clear();
documentMappings.clear();
}
use of org.eclipse.ui.IWorkbenchWindow in project tdi-studio-se by Talend.
the class AbstractJvmPropertySection method isFocused.
/**
* Gets the state indicating if property sheet containing this property section is focused.
*
* @return True of property sheet is focused.
*/
private boolean isFocused() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return false;
}
IWorkbenchPage page = window.getActivePage();
if (page == null) {
return false;
}
IWorkbenchPart part = page.getActivePart();
if (part != null) {
return part.equals(propertySheet);
}
return false;
}
use of org.eclipse.ui.IWorkbenchWindow 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.IWorkbenchWindow in project tdi-studio-se by Talend.
the class OpenExistVersionProcessAction method checkUnLoadedNodeForProcess.
private void checkUnLoadedNodeForProcess(JobEditorInput fileEditorInput) {
if (fileEditorInput == null || fileEditorInput.getLoadedProcess() == null) {
return;
}
IProcess2 loadedProcess = fileEditorInput.getLoadedProcess();
List<NodeType> unloadedNode = loadedProcess.getUnloadedNode();
if (unloadedNode != null && !unloadedNode.isEmpty()) {
String message = "Some Component are not loaded:\n";
for (int i = 0; i < unloadedNode.size(); i++) {
message = message + unloadedNode.get(i).getComponentName() + "\n";
}
if (!CommonsPlugin.isHeadless() && PlatformUI.isWorkbenchRunning()) {
Display display = Display.getCurrent();
if (display == null) {
display = Display.getDefault();
}
if (display != null) {
final Display tmpDis = display;
final String tmpMess = message;
display.syncExec(new Runnable() {
@Override
public void run() {
Shell shell = null;
final IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow != null) {
shell = activeWorkbenchWindow.getShell();
} else {
if (tmpDis != null) {
shell = tmpDis.getActiveShell();
} else {
shell = new Shell();
}
}
MessageDialog.openWarning(shell, "Warning", tmpMess);
}
});
}
}
}
}
Aggregations