Search in sources :

Example 96 with IEditorPart

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;
                    }
                }
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorReference(org.eclipse.ui.IEditorReference) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) AbstractTalendEditor(org.talend.designer.core.ui.editor.AbstractTalendEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart)

Example 97 with IEditorPart

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;
}
Also used : Control(org.eclipse.swt.widgets.Control) ITextOperationTarget(org.eclipse.jface.text.ITextOperationTarget) IEditorPart(org.eclipse.ui.IEditorPart) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) JsonEditor(com.reprezen.swagedit.core.editor.JsonEditor)

Example 98 with IEditorPart

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;
}
Also used : PasteViewRequest(org.eclipse.gmf.runtime.diagram.ui.requests.PasteViewRequest) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) BusinessProcessEditPart(org.talend.designer.business.model.business.diagram.edit.parts.BusinessProcessEditPart) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ICommand(org.eclipse.gmf.runtime.common.core.command.ICommand) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(org.eclipse.core.commands.ExecutionException) GmfPastCommand(org.talend.designer.business.diagram.custom.commands.GmfPastCommand) DiagramCommandStack(org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack) CommandStack(org.eclipse.gef.commands.CommandStack) IDiagramWorkbenchPart(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart) AbstractEditPart(org.eclipse.gef.editparts.AbstractEditPart) DiagramEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart) BusinessProcessEditPart(org.talend.designer.business.model.business.diagram.edit.parts.BusinessProcessEditPart) EditPart(org.eclipse.gef.EditPart) IEditorPart(org.eclipse.ui.IEditorPart) Diagram(org.eclipse.gmf.runtime.notation.Diagram) DiagramEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart) ICommand(org.eclipse.gmf.runtime.common.core.command.ICommand) GmfPastCommand(org.talend.designer.business.diagram.custom.commands.GmfPastCommand) Command(org.eclipse.gef.commands.Command) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) BusinessItem(org.talend.designer.business.model.business.BusinessItem) BusinessProcess(org.talend.designer.business.model.business.BusinessProcess)

Example 99 with IEditorPart

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;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 100 with IEditorPart

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) ConverterViewModel(net.heartsome.cat.convert.ui.model.ConverterViewModel) ArrayList(java.util.ArrayList) List(java.util.List) IEditorPart(org.eclipse.ui.IEditorPart) IEditorInput(org.eclipse.ui.IEditorInput) CoreException(org.eclipse.core.runtime.CoreException) ConverterException(net.heartsome.cat.converter.ConverterException) PartInitException(org.eclipse.ui.PartInitException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Aggregations

IEditorPart (org.eclipse.ui.IEditorPart)401 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)137 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)127 PartInitException (org.eclipse.ui.PartInitException)73 IFile (org.eclipse.core.resources.IFile)58 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)53 IEditorReference (org.eclipse.ui.IEditorReference)52 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)45 ArrayList (java.util.ArrayList)43 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)41 IEditorInput (org.eclipse.ui.IEditorInput)37 IViewPart (org.eclipse.ui.IViewPart)34 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)33 Test (org.junit.Test)31 ISelection (org.eclipse.jface.viewers.ISelection)30 FileEditorInput (org.eclipse.ui.part.FileEditorInput)29 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)27 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)26 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)26 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)24