Search in sources :

Example 6 with ByteArray

use of org.talend.core.model.properties.ByteArray 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)

Example 7 with ByteArray

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

the class AddCopyBookXc2jFileMigrationTask method updateXc2jFilePath.

private boolean updateXc2jFilePath(Item item) throws PersistenceException, IOException {
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean update = false;
    if (item instanceof ConnectionItem) {
        ConnectionItem connectionItem = (ConnectionItem) item;
        Connection con = connectionItem.getConnection();
        if (con instanceof EbcdicConnection) {
            ReferenceFileItem createReferenceFileItem = null;
            // the old copybook version depands MidFile
            String midFile = ((EbcdicConnection) con).getMidFile();
            if (midFile != null) {
                File xc2jMidFile = new File(midFile);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                if (xc2jMidFile.exists()) {
                    readXc2jFile(xc2jMidFile, baos);
                }
                // create a referenceItem first,maybe it has content,maybe is empty,decide by the midFile
                if (connectionItem.getReferenceResources().isEmpty()) {
                    createReferenceFileItem = PropertiesFactory.eINSTANCE.createReferenceFileItem();
                    ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
                    createReferenceFileItem.setContent(byteArray);
                    createReferenceFileItem.setExtension("xc2j");
                    connectionItem.getReferenceResources().add(createReferenceFileItem);
                } else {
                    createReferenceFileItem = (ReferenceFileItem) connectionItem.getReferenceResources().get(0);
                }
                createReferenceFileItem.getContent().setInnerContent(baos.toByteArray());
                // create the phyhical x2cj file and set referenceFileItem content for it
                String xc2jFilePath = getReferenceXc2jFile(connectionItem).getLocation().makeAbsolute().toFile().getAbsolutePath();
                getXc2jFileFromBytes(createReferenceFileItem.getContent().getInnerContent(), xc2jFilePath);
                update = true;
            }
        }
        if (update) {
            factory.save(connectionItem, true);
        }
    }
    return update;
}
Also used : EbcdicConnection(org.talend.core.model.metadata.builder.connection.EbcdicConnection) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Connection(org.talend.core.model.metadata.builder.connection.Connection) EbcdicConnection(org.talend.core.model.metadata.builder.connection.EbcdicConnection) ByteArray(org.talend.core.model.properties.ByteArray) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 8 with ByteArray

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

the class NewRoutineWizard method updateRoutineContent.

private void updateRoutineContent() {
    if (routineItem == null) {
        return;
    }
    ByteArray content = routineItem.getContent();
    if (content != null) {
        String routineContent = new String(content.getInnerContent());
        String label = routineItem.getProperty().getLabel();
        if (routineContent != null && !label.equals(ITalendSynchronizer.TEMPLATE)) {
            routineContent = routineContent.replaceAll(ITalendSynchronizer.TEMPLATE, label);
            content.setInnerContent(routineContent.getBytes());
        }
    }
}
Also used : ByteArray(org.talend.core.model.properties.ByteArray)

Example 9 with ByteArray

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

the class SaveAsSQLPatternWizard method performFinish.

public boolean performFinish() {
    boolean ok = false;
    try {
        isUpdate = isUpdate();
        if (isUpdate) {
            assginVlaues(oldProperty, property);
            repositoryFactory.save(oldSqlpatternItem);
            // assign value
            sqlpatternItem = oldSqlpatternItem;
        } else {
            property.setId(repositoryFactory.getNextId());
            // copy the byte[] content, the new routineItem get the old saved content, it is not the newest.
            SQLPatternItem oldItem = (SQLPatternItem) repositoryEditorInput.getItem();
            ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
            byteArray.setInnerContent(oldItem.getContent().getInnerContent());
            sqlpatternItem.setContent(byteArray);
            // don't need to add depended routines.
            repositoryFactory.create(sqlpatternItem, mainPage.getDestinationPath());
        }
        ok = true;
    } catch (Exception e) {
        MessageDialog.openError(getShell(), "Error", "SQLTemplate could not be saved" + " : " + e.getMessage());
        ExceptionHandler.process(e);
    }
    return ok;
}
Also used : ByteArray(org.talend.core.model.properties.ByteArray) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem)

Example 10 with ByteArray

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

the class EditPropertiesAction method processRename.

protected void processRename(IRepositoryNode node, String originalName) {
    try {
        IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
        ITalendProcessJavaProject talendProcessJavaProject = runProcessService.getTalendProcessJavaProject();
        if (talendProcessJavaProject == null) {
            return;
        }
        IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
        IPackageFragmentRoot root = talendProcessJavaProject.getJavaProject().getPackageFragmentRoot(srcFolder);
        // add for bug TDI-24379 on August 23, 2013.
        IFolder srcInterFolder = srcFolder.getFolder(JavaUtils.JAVA_INTERNAL_DIRECTORY);
        if (srcInterFolder.exists()) {
            File file = new File(srcInterFolder.getLocationURI());
            for (File f : file.listFiles()) {
                if (f.isFile()) {
                    f.delete();
                }
            }
        }
        // qli modified to fix the bug 5400 and 6185.
        // update for fix [TESB-6784]
        IPackageFragment routinesPkg = getPackageFragment(root, node);
        // ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName +
        // SuffixConstants.SUFFIX_STRING_java);
        //$NON-NLS-1$
        ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName + ".java");
        if (unit == null) {
            return;
        }
        String newName = node.getObject().getProperty().getLabel();
        JavaRenameProcessor processor = new RenameCompilationUnitProcessor(unit);
        // processor.setNewElementName(newName + SuffixConstants.SUFFIX_STRING_java);
        //$NON-NLS-1$
        processor.setNewElementName(newName + ".java");
        RenameRefactoring ref = new RenameRefactoring(processor);
        final PerformRefactoringOperation operation = new PerformRefactoringOperation(ref, CheckConditionsOperation.ALL_CONDITIONS);
        IRunnableWithProgress r = new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            operation.run(monitor);
                        } catch (CoreException e) {
                            ExceptionHandler.process(e);
                        }
                    }
                });
            }
        };
        PlatformUI.getWorkbench().getProgressService().run(true, true, r);
        RefactoringStatus conditionStatus = operation.getConditionStatus();
        if (conditionStatus.hasError()) {
            //$NON-NLS-1$
            String errorMessage = Messages.getString("EditPropertiesAction.renameError", unit.getElementName(), newName);
            RefactoringStatusEntry[] entries = conditionStatus.getEntries();
            for (RefactoringStatusEntry entry : entries) {
                //$NON-NLS-1$
                errorMessage += "\n>>>" + entry.getMessage();
            }
            Shell shell = null;
            IRepositoryView viewPart = getViewPart();
            if (viewPart != null) {
                shell = viewPart.getViewSite().getShell();
            } else {
                shell = Display.getCurrent().getActiveShell();
            }
            //$NON-NLS-1$
            MessageDialog.openError(shell, Messages.getString("EditPropertiesAction.warning"), errorMessage);
            return;
        }
        // ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + SuffixConstants.SUFFIX_STRING_java);
        //$NON-NLS-1$
        ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + ".java");
        if (newUnit == null) {
            return;
        }
        RoutineItem item = (RoutineItem) node.getObject().getProperty().getItem();
        IFile javaFile = (IFile) newUnit.getAdapter(IResource.class);
        try {
            ByteArray byteArray = item.getContent();
            byteArray.setInnerContentFromFile(javaFile);
            IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
            IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
            repFactory.save(item);
        } catch (Exception e) {
            // e.printStackTrace();
            ExceptionHandler.process(e);
        }
    } catch (Exception e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) PerformRefactoringOperation(org.eclipse.ltk.core.refactoring.PerformRefactoringOperation) IRepositoryView(org.talend.repository.ui.views.IRepositoryView) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IRepositoryService(org.talend.repository.model.IRepositoryService) Shell(org.eclipse.swt.widgets.Shell) ByteArray(org.talend.core.model.properties.ByteArray) JavaRenameProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) RoutineItem(org.talend.core.model.properties.RoutineItem) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RenameCompilationUnitProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameCompilationUnitProcessor) CoreException(org.eclipse.core.runtime.CoreException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

ByteArray (org.talend.core.model.properties.ByteArray)19 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)8 File (java.io.File)7 IOException (java.io.IOException)7 RoutineItem (org.talend.core.model.properties.RoutineItem)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 IFile (org.eclipse.core.resources.IFile)4 PersistenceException (org.talend.commons.exception.PersistenceException)4 Message (ca.uhn.hl7v2.model.Message)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 PartInitException (org.eclipse.ui.PartInitException)3 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)2 Property (org.talend.core.model.properties.Property)2 ReferenceFileItem (org.talend.core.model.properties.ReferenceFileItem)2 SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)2