use of org.eclipse.ui.IEditorPart in project translationstudio8 by heartsome.
the class NextSplitPointHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
final Shell shell = window.getShell();
XLIFFEditorImplWithNatTable xliffEditor = null;
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
if (activePart instanceof IEditorPart) {
if (XLIFF_EDITOR_ID.equals(activePart.getSite().getId())) {
xliffEditor = (XLIFFEditorImplWithNatTable) activePart;
List<String> splitPointList = xliffEditor.getSplitXliffPoints();
if (splitPointList.size() <= 0) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.info"), Messages.getString("NextSplitPointHandler.msg.nullSplitPoint"));
return null;
}
final XLFHandler xlfHander = xliffEditor.getXLFHandler();
// 先对 splitPointList 进行排序
Collections.sort(splitPointList, new Comparator<String>() {
public int compare(String rowId1, String rowId2) {
int rowIndex1 = xlfHander.getRowIndex(rowId1);
int rowIndex2 = xlfHander.getRowIndex(rowId2);
return rowIndex1 > rowIndex2 ? 1 : -1;
}
});
List<String> selectionRowIdList = xliffEditor.getSelectedRowIds();
if (selectionRowIdList != null && selectionRowIdList.size() > 0) {
curSelectionRowId = selectionRowIdList.get(0);
}
// 开始定位,定位之前让 nattable 恢复默认布局
xliffEditor.resetOrder();
if (curSelectionRowId == null) {
curSelectionRowId = splitPointList.get(0);
} else {
int curSelectionRowIndex = xlfHander.getRowIndex(curSelectionRowId);
for (String curRowId : splitPointList) {
int pointRowIndex = xlfHander.getRowIndex(curRowId);
if (pointRowIndex > curSelectionRowIndex) {
curSelectionRowId = curRowId;
xliffEditor.jumpToRow(curSelectionRowId);
break;
}
}
}
}
}
return null;
}
use of org.eclipse.ui.IEditorPart 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.IEditorPart in project translationstudio8 by heartsome.
the class ImportProjectWizardPage2 method getAllOpenedIFile.
/**
* 获取所有已经被打开的文件
* @return
*/
private Map<IFile, IEditorPart> getAllOpenedIFile() {
Map<IFile, IEditorPart> openedIfileMap = new HashMap<IFile, IEditorPart>();
IEditorReference[] referenceArray = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
for (IEditorReference reference : referenceArray) {
IEditorPart editor = reference.getEditor(true);
// 如果这是一个 nattable 编辑器
if (XLIFF_EDITOR_ID.equals(editor.getSite().getId())) {
IXliffEditor xlfEditor = (IXliffEditor) editor;
if (xlfEditor.isMultiFile()) {
for (File file : xlfEditor.getMultiFileList()) {
openedIfileMap.put(ResourceUtils.fileToIFile(file.getAbsolutePath()), editor);
}
} else {
openedIfileMap.put(((FileEditorInput) editor.getEditorInput()).getFile(), editor);
}
} else {
// 其他情况,直接将文件丢进去就行了
openedIfileMap.put(((FileEditorInput) editor.getEditorInput()).getFile(), editor);
}
}
return openedIfileMap;
}
use of org.eclipse.ui.IEditorPart 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.IEditorPart in project tdi-studio-se by Talend.
the class OpenExistVersionProcessAction method doRun.
@Override
protected void doRun() {
ISelection selection = getSelection();
Object obj = ((IStructuredSelection) selection).getFirstElement();
RepositoryNode node = (RepositoryNode) obj;
IPath path = RepositoryNodeUtilities.getPath(node);
String originalName = node.getObject().getLabel();
RepositoryObject repositoryObj = new RepositoryObject(node.getObject().getProperty());
repositoryObj.setRepositoryNode(node.getObject().getRepositoryNode());
OpenExistVersionProcessWizard wizard = new OpenExistVersionProcessWizard(repositoryObj);
WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
dialog.setPageSize(300, 250);
//$NON-NLS-1$
dialog.setTitle(Messages.getString("OpenExistVersionProcess.open.dialog"));
if (dialog.open() == Dialog.OK) {
refresh(node);
// refresh the corresponding editor's name
IEditorPart part = getCorrespondingEditor(node);
if (part != null && part instanceof IUIRefresher) {
((IUIRefresher) part).refreshName();
} else {
processRoutineRenameOperation(originalName, node, path);
}
}
}
Aggregations