Search in sources :

Example 21 with IEditorInput

use of org.eclipse.ui.IEditorInput in project tesb-studio-se by Talend.

the class OpenOnSelectionHelper method openEditor.

@Override
protected void openEditor(String resource, String spec) {
    //$NON-NLS-1$
    String pattern = "platform:/resource";
    IWorkbenchPage workbenchPage = WSDLEditorPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart editorPart = workbenchPage.getActiveEditor();
    String currentEditorId = editorPart.getEditorSite().getId();
    if (resource != null && resource.startsWith(pattern)) {
        Path path = new Path(resource.substring(pattern.length()));
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        if (editorPart.getEditorInput() instanceof IFileEditorInput && ((IFileEditorInput) editorPart.getEditorInput()).getFile().equals(file)) {
            workbenchPage.getNavigationHistory().markLocation(editorPart);
        } else {
            try {
                Item item = ((ServiceEditorInput) editorPart.getEditorInput()).getItem();
                // TODO: Use content type as below
                if (resource.endsWith("xsd")) {
                    //$NON-NLS-1$
                    editorPart = workbenchPage.openEditor(new ServiceEditorInput(file, item), WSDLEditorPlugin.XSD_EDITOR_ID);
                } else {
                    // Since we are already in the wsdleditor
                    editorPart = workbenchPage.openEditor(new ServiceEditorInput(file, item), editorPart.getEditorSite().getId());
                }
            } catch (PartInitException initEx) {
                ExceptionHandler.process(initEx);
            }
        }
        try {
            Class<? extends IEditorPart> theClass = editorPart.getClass();
            Class<?>[] methodArgs = { String.class };
            //$NON-NLS-1$
            Method method = theClass.getMethod("openOnSelection", methodArgs);
            Object[] args = { spec };
            method.invoke(editorPart, args);
            workbenchPage.getNavigationHistory().markLocation(editorPart);
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    } else if (resource != null && resource.startsWith("http")) {
        IEditorPart newEditorPart = null;
        boolean doOpenWsdlEditor = true;
        if (//$NON-NLS-1$
        resource.endsWith("xsd")) {
            doOpenWsdlEditor = false;
        }
        try {
            IEditorReference[] refs = workbenchPage.getEditorReferences();
            int length = refs.length;
            // Need to find if an editor on that schema has already been opened
            for (int i = 0; i < length; i++) {
                IEditorInput input = refs[i].getEditorInput();
                if (input instanceof ADTReadOnlyFileEditorInput) {
                    ADTReadOnlyFileEditorInput readOnlyEditorInput = (ADTReadOnlyFileEditorInput) input;
                    if (readOnlyEditorInput.getUrlString().equals(resource) && (!doOpenWsdlEditor && readOnlyEditorInput.getEditorID().equals(WSDLEditorPlugin.XSD_EDITOR_ID) || doOpenWsdlEditor && readOnlyEditorInput.getEditorID().equals(WSDLEditorPlugin.WSDL_EDITOR_ID))) {
                        newEditorPart = refs[i].getEditor(true);
                        workbenchPage.activate(refs[i].getPart(true));
                        break;
                    }
                }
            }
            if (newEditorPart == null) {
                ADTReadOnlyFileEditorInput readOnlyStorageEditorInput = new ADTReadOnlyFileEditorInput(resource);
                IContentType contentType = null;
                try (InputStream iStream = readOnlyStorageEditorInput.getStorage().getContents()) {
                    contentType = Platform.getContentTypeManager().findContentTypeFor(iStream, resource);
                }
                // content type more reliable check
                if (//$NON-NLS-1$
                contentType != null && contentType.equals(XSDEditorPlugin.XSD_CONTENT_TYPE_ID) || resource.endsWith("xsd")) {
                    readOnlyStorageEditorInput.setEditorID(WSDLEditorPlugin.XSD_EDITOR_ID);
                    //$NON-NLS-1$
                    workbenchPage.openEditor(readOnlyStorageEditorInput, WSDLEditorPlugin.XSD_EDITOR_ID, true, 0);
                } else {
                    readOnlyStorageEditorInput.setEditorID(currentEditorId);
                    //$NON-NLS-1$
                    workbenchPage.openEditor(readOnlyStorageEditorInput, currentEditorId, true, 0);
                }
            }
        } catch (IOException | CoreException e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ADTReadOnlyFileEditorInput(org.eclipse.wst.xsd.ui.internal.adt.editor.ADTReadOnlyFileEditorInput) InputStream(java.io.InputStream) IContentType(org.eclipse.core.runtime.content.IContentType) IEditorPart(org.eclipse.ui.IEditorPart) Method(java.lang.reflect.Method) ServiceEditorInput(org.talend.repository.services.action.ServiceEditorInput) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) Item(org.talend.core.model.properties.Item) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 22 with IEditorInput

use of org.eclipse.ui.IEditorInput 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)

Example 23 with IEditorInput

use of org.eclipse.ui.IEditorInput in project cubrid-manager by CUBRID.

the class BrokerConfOpenFileDialog method buttonPressed.

/**
	 * When press button,call it
	 * 
	 * @param buttonId the button id
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OK_ID) {
        if (!validate()) {
            CommonUITool.openErrorBox(Messages.cubridBrokerConfOpenFileDialogErrMsg);
            return;
        }
    }
    try {
        IEditorInput input = new BrokerConfigEditorInput(filePath.getText(), fileCharsetCombo.getText());
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, BrokerConfigEditorPart.ID);
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
    }
    setReturnCode(buttonId);
    close();
}
Also used : BrokerConfigEditorInput(com.cubrid.common.ui.common.control.BrokerConfigEditorInput) IEditorInput(org.eclipse.ui.IEditorInput)

Example 24 with IEditorInput

use of org.eclipse.ui.IEditorInput in project cubrid-manager by CUBRID.

the class QueryOpenAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null || window.getActivePage() == null) {
        return;
    }
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor != null && editor.isDirty()) {
        int confirm = CommonUITool.openMsgBox(editor.getSite().getShell(), MessageDialog.WARNING, Messages.saveResource, Messages.bind(Messages.saveConfirm, editor.getTitle()), new String[] { Messages.btnYes, Messages.btnNo, Messages.cancel });
        switch(confirm) {
            case 0:
                editor.doSave(null);
                break;
            case 1:
                break;
            default:
                return;
        }
    }
    try {
        if (editor == null) {
            IEditorInput input = new QueryUnit();
            editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
        }
    } catch (PartInitException e) {
        CommonUITool.openErrorBox(e.getMessage());
    }
    if (editor == null) {
        return;
    }
    try {
        QueryEditorPart queryEditor = (QueryEditorPart) editor;
        SQLEditorComposite editorComp = queryEditor.getCombinedQueryComposite().getSqlEditorComp();
        String encoding = editorComp.getDocument().getEncoding();
        SetFileEncodingDialog dialog = new SetFileEncodingDialog(getShell(), encoding, true);
        if (IDialogConstants.OK_ID == dialog.open()) {
            editorComp.open(dialog.getFilePath(), dialog.getEncoding());
        }
    } catch (IOException e) {
        CommonUITool.openErrorBox(e.getMessage());
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SQLEditorComposite(com.cubrid.common.ui.query.control.SQLEditorComposite) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) SetFileEncodingDialog(com.cubrid.common.ui.query.dialog.SetFileEncodingDialog) IEditorInput(org.eclipse.ui.IEditorInput)

Example 25 with IEditorInput

use of org.eclipse.ui.IEditorInput in project cubrid-manager by CUBRID.

the class QueryNewCustomAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    Object[] selected = getSelectedObj();
    LoginQueryEditDialog dialog = new LoginQueryEditDialog(getShell());
    if (selected != null && selected.length == 1 && selected[0] instanceof ISchemaNode) {
        dialog.setSelServerName(((ISchemaNode) selected[0]).getServer().getServerName());
        dialog.setSelDatabaseName(((ISchemaNode) selected[0]).getDatabase().getName());
    } else if (selected != null && selected.length == 1 && selected[0] instanceof CubridServer) {
        dialog.setSelServerName(((CubridServer) selected[0]).getName());
    } else {
        dialog.setSelServerName(DatabaseNavigatorMenu.SELF_DATABASE_SELECTED_LABEL);
    }
    if (dialog.open() == IDialogConstants.OK_ID) {
        try {
            IEditorInput input = new QueryUnit();
            IEditorPart editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
            ((QueryEditorPart) editor).connect(DatabaseNavigatorMenu.SELF_DATABASE);
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage());
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) LoginQueryEditDialog(com.cubrid.cubridmanager.ui.common.dialog.LoginQueryEditDialog) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

IEditorInput (org.eclipse.ui.IEditorInput)71 IFile (org.eclipse.core.resources.IFile)26 PartInitException (org.eclipse.ui.PartInitException)21 IEditorPart (org.eclipse.ui.IEditorPart)19 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)17 IEditorReference (org.eclipse.ui.IEditorReference)14 CoreException (org.eclipse.core.runtime.CoreException)13 ArrayList (java.util.ArrayList)11 IViewPart (org.eclipse.ui.IViewPart)11 FileEditorInput (org.eclipse.ui.part.FileEditorInput)10 Shell (org.eclipse.swt.widgets.Shell)9 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)8 IFileEditorInput (org.eclipse.ui.IFileEditorInput)8 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)8 File (java.io.File)7 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)7 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)7 Item (org.talend.core.model.properties.Item)7 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)6 IProject (org.eclipse.core.resources.IProject)6