Search in sources :

Example 1 with DocumentationItem

use of org.talend.core.model.properties.DocumentationItem in project tdi-studio-se by Talend.

the class OpenDocumentationAction method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
protected void doRun() {
    RepositoryNode node = (RepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement();
    Item item = node.getObject().getProperty().getItem();
    if (item == null) {
        return;
    }
    URL url = null;
    // String extension = null;
    if (item instanceof DocumentationItem) {
        DocumentationItem documentationItem = (DocumentationItem) item;
        // if (documentationItem.getExtension() != null) {
        // extension = documentationItem.getExtension();
        // }
        IFile file = LinkDocumentationHelper.getTempFile(documentationItem.getName(), documentationItem.getExtension());
        try {
            documentationItem.getContent().setInnerContentToFile(file.getLocation().toFile());
            url = file.getLocationURI().toURL();
        } catch (Exception e) {
            showErrorMessage();
            return;
        }
    } else if (item instanceof LinkDocumentationItem) {
        // link documenation
        LinkDocumentationItem linkDocItem = (LinkDocumentationItem) item;
        if (!LinkUtils.validateLink(linkDocItem.getLink())) {
            showErrorMessage();
            return;
        }
        // if (linkDocItem.getExtension() != null) {
        // extension = linkDocItem.getExtension();
        // }
        String uri = linkDocItem.getLink().getURI();
        if (LinkUtils.isRemoteFile(uri)) {
            try {
                url = new URL(uri);
            } catch (MalformedURLException e) {
            //
            }
        } else if (LinkUtils.existedFile(uri)) {
            try {
                url = new File(uri).toURL();
            } catch (MalformedURLException e) {
            //
            }
        }
    }
    openedByBrowser(item, url);
// progress(item, extension);
}
Also used : Item(org.talend.core.model.properties.Item) DocumentationItem(org.talend.core.model.properties.DocumentationItem) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) MalformedURLException(java.net.MalformedURLException) IFile(org.eclipse.core.resources.IFile) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) RepositoryNode(org.talend.repository.model.RepositoryNode) BinRepositoryNode(org.talend.repository.model.BinRepositoryNode) DocumentationItem(org.talend.core.model.properties.DocumentationItem) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) IFile(org.eclipse.core.resources.IFile) File(java.io.File) URL(java.net.URL) PartInitException(org.eclipse.ui.PartInitException) MalformedURLException(java.net.MalformedURLException)

Example 2 with DocumentationItem

use of org.talend.core.model.properties.DocumentationItem in project tdi-studio-se by Talend.

the class ExtractDocumentationAction method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
protected void doRun() {
    RepositoryNode node = (RepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement();
    final Item item = node.getObject().getProperty().getItem();
    if (item == null) {
        return;
    }
    String initialFileName = null;
    String initialExtension = null;
    if (item instanceof DocumentationItem) {
        DocumentationItem documentationItem = (DocumentationItem) item;
        initialFileName = documentationItem.getName();
        if (documentationItem.getExtension() != null) {
            initialExtension = documentationItem.getExtension();
        }
    } else if (item instanceof LinkDocumentationItem) {
        // link documenation
        LinkDocumentationItem linkDocItem = (LinkDocumentationItem) item;
        if (!LinkUtils.validateLink(linkDocItem.getLink())) {
            MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.getString(//$NON-NLS-1$
            "ExtractDocumentationAction.fileErrorTitle"), //$NON-NLS-1$
            Messages.getString("ExtractDocumentationAction.fileErrorMessages"));
            return;
        }
        initialFileName = linkDocItem.getName();
        if (linkDocItem.getExtension() != null) {
            initialExtension = linkDocItem.getExtension();
        }
    }
    if (initialFileName != null) {
        FileDialog fileDlg = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
        if (initialExtension != null) {
            //$NON-NLS-1$
            initialFileName = initialFileName + LinkUtils.DOT + initialExtension;
            //$NON-NLS-1$ //$NON-NLS-2$
            fileDlg.setFilterExtensions(new String[] { "*." + initialExtension, "*.*" });
        }
        fileDlg.setFileName(initialFileName);
        String filename = fileDlg.open();
        if (filename != null) {
            final File file = new File(filename);
            ProgressDialog progressDialog = new ProgressDialog(Display.getCurrent().getActiveShell()) {

                @Override
                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    try {
                        if (item instanceof DocumentationItem) {
                            DocumentationItem documentationItem = (DocumentationItem) item;
                            documentationItem.getContent().setInnerContentToFile(file);
                        } else if (item instanceof LinkDocumentationItem) {
                            // link documenation
                            LinkDocumentationItem linkDocItem = (LinkDocumentationItem) item;
                            ByteArray byteArray = LinkDocumentationHelper.getLinkItemContent(linkDocItem);
                            if (byteArray != null) {
                                byteArray.setInnerContentToFile(file);
                            }
                        }
                    } catch (IOException ioe) {
                        MessageBoxExceptionHandler.process(ioe);
                    }
                }
            };
            try {
                progressDialog.executeProcess();
            } catch (InvocationTargetException e) {
                ExceptionHandler.process(e);
            } catch (InterruptedException e) {
            // Nothing to do
            }
        }
    }
}
Also used : LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) IOException(java.io.IOException) RepositoryNode(org.talend.repository.model.RepositoryNode) BinRepositoryNode(org.talend.repository.model.BinRepositoryNode) DocumentationItem(org.talend.core.model.properties.DocumentationItem) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) Item(org.talend.core.model.properties.Item) DocumentationItem(org.talend.core.model.properties.DocumentationItem) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ByteArray(org.talend.core.model.properties.ByteArray) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Aggregations

File (java.io.File)2 DocumentationItem (org.talend.core.model.properties.DocumentationItem)2 Item (org.talend.core.model.properties.Item)2 LinkDocumentationItem (org.talend.core.model.properties.LinkDocumentationItem)2 BinRepositoryNode (org.talend.repository.model.BinRepositoryNode)2 RepositoryNode (org.talend.repository.model.RepositoryNode)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 IFile (org.eclipse.core.resources.IFile)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 PartInitException (org.eclipse.ui.PartInitException)1 ProgressDialog (org.talend.commons.ui.swt.dialogs.ProgressDialog)1 ByteArray (org.talend.core.model.properties.ByteArray)1