use of org.eclipse.ui.IEditorPart in project tdi-studio-se by Talend.
the class DownloadComponenentsAction method selectPaletteEntry.
private void selectPaletteEntry(String componentName) {
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow != null) {
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
if (activePage != null) {
IEditorReference[] editorReferences = activePage.getEditorReferences();
if (editorReferences != null) {
for (IEditorReference er : editorReferences) {
IEditorPart part = er.getEditor(false);
if (part instanceof AbstractMultiPageTalendEditor) {
AbstractMultiPageTalendEditor editor = (AbstractMultiPageTalendEditor) part;
AbstractTalendEditor talendEditor = editor.getTalendEditor();
try {
ComponentPaletteUtilities.setSkipUpdatePalette(true);
talendEditor.selectPaletteEntry(componentName);
} catch (Exception e) {
ExceptionHandler.process(e);
}
return;
}
}
}
}
}
}
use of org.eclipse.ui.IEditorPart in project KaiZen-OpenAPI-Editor by RepreZen.
the class OpenQuickOutlineHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISourceViewer viewer = null;
//$NON-NLS-1$
Object activeFocusControl = HandlerUtil.getVariable(event, "activeFocusControl");
if (activeFocusControl instanceof Control) {
Control control = (Control) activeFocusControl;
if (!control.isDisposed()) {
viewer = (ISourceViewer) control.getData(ISourceViewer.class.getName());
}
}
if (viewer == null) {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof JsonEditor) {
viewer = ((JsonEditor) editor).getProjectionViewer();
}
}
if (viewer != null) {
ITextOperationTarget operationTarget = viewer.getTextOperationTarget();
if (operationTarget.canDoOperation(QUICK_OUTLINE)) {
operationTarget.doOperation(QUICK_OUTLINE);
}
}
return null;
}
use of org.eclipse.ui.IEditorPart in project tdi-studio-se by Talend.
the class ClipboardActionHandler method getCommand.
@Override
public ICommand getCommand(IGlobalActionContext cntxt) {
IWorkbenchPart part = cntxt.getActivePart();
if (!(part instanceof IDiagramWorkbenchPart)) {
return null;
}
IDiagramWorkbenchPart workbenchPart = (IDiagramWorkbenchPart) part;
DiagramEditPart diagramEditPart = workbenchPart.getDiagramEditPart();
ICommand command = null;
String actionId = cntxt.getActionId();
if (actionId.equals(GlobalActionId.COPY)) {
command = getCopyCommand(cntxt, workbenchPart, false);
transfer(cntxt.getSelection());
isCut = false;
older = workbenchPart;
orginalCopyFrom = workbenchPart;
clonedSourceProcessItemsList = new ArrayList<BusinessItem>(((BusinessProcess) ((Diagram) diagramEditPart.getModel()).getElement()).getBusinessItems());
} else if (actionId.equals(GlobalActionId.CUT) && cntxt.getSelection() != null) {
saveCut(cntxt.getSelection());
command = getCutCommand(cntxt, workbenchPart);
transfer(cntxt.getSelection());
isCut = true;
older = workbenchPart;
clonedSourceProcessItemsList = new ArrayList<BusinessItem>(((BusinessProcess) ((Diagram) diagramEditPart.getModel()).getElement()).getBusinessItems());
} else if (actionId.equals(GlobalActionId.SAVE)) {
if (workbenchPart instanceof IEditorPart) {
IEditorPart editorPart = (IEditorPart) workbenchPart;
if (editorPart.isDirty()) {
IWorkbenchPage page = editorPart.getSite().getPage();
page.saveEditor(editorPart, false);
}
}
}
if (actionId.equals(GlobalActionId.PASTE)) {
// diagramPart.getDiagramGraphicalViewer().setSelection(new
// StructuredSelection(diagramPart.getDiagramEditPart()));
PasteViewRequest pasteReq = createPasteViewRequest();
CommandStack cs = workbenchPart.getDiagramEditDomain().getDiagramCommandStack();
IStructuredSelection selection = (IStructuredSelection) cntxt.getSelection();
if (!(selection.getFirstElement() instanceof BusinessProcessEditPart)) {
selection = new StructuredSelection(workbenchPart.getDiagramEditPart());
}
Object[] objects = selection.toArray();
Collection returnValues = null;
if (objects.length == 1) {
Command paste = ((EditPart) objects[0]).getCommand(pasteReq);
if (paste != null) {
cs.execute(paste);
workbenchPart.getDiagramEditPart().getFigure().invalidate();
workbenchPart.getDiagramEditPart().getFigure().validate();
returnValues = DiagramCommandStack.getReturnValues(paste);
// selectAddedObject(diagramPart.getDiagramGraphicalViewer(), returnValues);
}
}
Object elements = TemplateTransfer.getInstance().getObject();
if (elements instanceof List) {
List<BusinessItem> list = (List<BusinessItem>) elements;
boolean inEditors = false;
if (older != workbenchPart) {
inEditors = true;
} else if (!this.isCut && orginalCopyFrom != workbenchPart) {
// bug 16065 fixed, by xtan. to resolve the copy(A)/parse(B)/parse(B)/parse(B)... problem.
inEditors = true;
}
// always keep the last one as the current selection.
older = workbenchPart;
GmfPastCommand pastBusiness = new GmfPastCommand((BusinessProcess) ((Diagram) diagramEditPart.getModel()).getElement(), list, diagramEditPart, this.cutItemIds, this.isCut | inEditors);
pastBusiness.setClonedSourceProcessItemsList(clonedSourceProcessItemsList);
try {
pastBusiness.execute(null, null);
} catch (ExecutionException e) {
ExceptionHandler.process(e);
}
}
if (returnValues != null) {
selectAddedObject(workbenchPart.getDiagramGraphicalViewer(), returnValues);
}
return null;
}
return command;
}
use of org.eclipse.ui.IEditorPart in project KaiZen-OpenAPI-Editor by RepreZen.
the class TextDocumentMarkerResolution method openTextEditor.
protected ITextEditor openTextEditor(IFile file) throws CoreException {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart part;
try {
part = IDE.openEditor(page, file, true);
} catch (PartInitException e) {
throw new CoreException(createStatus(e, "Cannot open editor"));
}
if (!(part instanceof ITextEditor)) {
throw new CoreException(createStatus(null, "The editor is not TextEditor: " + part));
}
return (ITextEditor) part;
}
use of org.eclipse.ui.IEditorPart in project translationstudio8 by heartsome.
the class PreviewTranslationHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor == null) {
return false;
}
IEditorInput input = editor.getEditorInput();
IFile file = ResourceUtil.getFile(input);
shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
if (file == null) {
MessageDialog.openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), Messages.getString("handler.PreviewTranslationHandler.msg1"));
} else {
String fileExtension = file.getFileExtension();
if (fileExtension != null && CommonFunction.validXlfExtension(fileExtension)) {
ConverterViewModel model = getConverterViewModel(file);
if (model != null) {
// model.convert();
try {
previewFiles(new ArrayList<IFile>(Arrays.asList(new IFile[] { file })));
} catch (Exception e) {
// 修改 当异常没有消息,提示信息为空
MessageDialog.openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), Messages.getString("handler.PreviewTranslationHandler.msg7"));
LOGGER.error("", e);
}
}
} else if (fileExtension != null && "xlp".equalsIgnoreCase(fileExtension)) {
// UNDO 合并打开的预览翻译有问题,是针对合并打开的文件,而不是针对项目所有的文件 robert 2012-07-12
if (file.exists()) {
// IFolder xliffFolder = file.getProject().getFolder(Constant.FOLDER_XLIFF);
// Fixed Bug #2616 预览翻译--合并打开的文件不能进行预览翻译 by Jason
XLFHandler hander = new XLFHandler();
List<String> files = hander.getMultiFiles(file);
List<IFile> ifileList = new ArrayList<IFile>();
for (String tf : files) {
ifileList.add(ResourceUtils.fileToIFile(tf));
}
// if (xliffFolder.exists()) {
// ArrayList<IFile> files = new ArrayList<IFile>();
// try {
// ResourceUtils.getXliffs(xliffFolder, files);
// } catch (CoreException e) {
// throw new ExecutionException(e.getMessage(), e);
// }
previewFiles(ifileList);
// } else {
// MessageDialog
// .openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"),
// Messages.getString("handler.PreviewTranslationHandler.msg2"));
// }
}
} else {
MessageDialog.openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), Messages.getString("handler.PreviewTranslationHandler.msg3"));
}
}
return null;
}
Aggregations