Search in sources :

Example 1 with RouteResourceItem

use of org.talend.camel.core.model.camelProperties.RouteResourceItem in project tesb-studio-se by Talend.

the class OpenAnotherVersionResrouceWizard method openAnotherVersion.

private void openAnotherVersion(final IRepositoryNode node) /*, final boolean readonly*/
{
    if (node.getObject() != null) {
        Item item = node.getObject().getProperty().getItem();
        IWorkbenchPage page = getActivePage();
        if (item instanceof RouteResourceItem) {
            RouteResourceEditorUtil.openEditor(page, node, (RouteResourceItem) item);
        }
    }
}
Also used : RouteResourceItem(org.talend.camel.core.model.camelProperties.RouteResourceItem) Item(org.talend.core.model.properties.Item) RouteResourceItem(org.talend.camel.core.model.camelProperties.RouteResourceItem) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 2 with RouteResourceItem

use of org.talend.camel.core.model.camelProperties.RouteResourceItem in project tesb-studio-se by Talend.

the class RouteResourceUtil method copyResources.

/**
     * Copy route resource
     * 
     * @param model
     * @throws CoreException
     */
private static IFile copyResources(final IFolder folder, final ResourceDependencyModel model) {
    final RouteResourceItem item = model.getItem();
    EList<?> referenceResources = item.getReferenceResources();
    if (referenceResources.isEmpty()) {
        return null;
    }
    final IFile classpathFile = folder.getFile(new Path(model.getClassPathUrl()));
    final ReferenceFileItem refFile = (ReferenceFileItem) referenceResources.get(0);
    try (final InputStream inputStream = new ByteArrayInputStream(refFile.getContent().getInnerContent())) {
        if (classpathFile.exists()) {
            classpathFile.setContents(inputStream, 0, null);
        } else {
            if (!classpathFile.getParent().exists()) {
                prepareFolder((IFolder) classpathFile.getParent());
            }
            classpathFile.create(inputStream, true, null);
        }
    } catch (CoreException | IOException e) {
        ExceptionHandler.process(e);
    }
    return classpathFile;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) IFile(org.eclipse.core.resources.IFile) RouteResourceItem(org.talend.camel.core.model.camelProperties.RouteResourceItem) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 3 with RouteResourceItem

use of org.talend.camel.core.model.camelProperties.RouteResourceItem in project tesb-studio-se by Talend.

the class OpenDefaultEditorAction method opendTextEditor.

/**
	 * Open or bind RouteResourceEditor
	 * 
	 * @param node
	 */
private void opendTextEditor(RepositoryNode node) {
    Property property = (Property) node.getObject().getProperty();
    RouteResourceItem item = null;
    if (property != null) {
        Assert.isTrue(property.getItem() instanceof RouteResourceItem);
        item = (RouteResourceItem) property.getItem();
        IWorkbenchPage page = getActivePage();
        RouteResourceEditorUtil.openDefaultEditor(page, node, item);
    }
}
Also used : RouteResourceItem(org.talend.camel.core.model.camelProperties.RouteResourceItem) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) Property(org.talend.core.model.properties.Property)

Example 4 with RouteResourceItem

use of org.talend.camel.core.model.camelProperties.RouteResourceItem in project tesb-studio-se by Talend.

the class RouteResourceEditor method saveContentsToItem.

/**
	 * Save the file content to EMF item.
	 * 
	 * @param rrInput
	 */
public static void saveContentsToItem(RouteResourceInput rrInput) {
    try {
        RouteResourceItem item = (RouteResourceItem) rrInput.getItem();
        ReferenceFileItem refFile = (ReferenceFileItem) item.getReferenceResources().get(0);
        InputStream inputstream = rrInput.getFile().getContents();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputstream));
        String line = bufferedReader.readLine();
        StringBuffer sb = new StringBuffer();
        String lineSeparator = System.getProperty("line.separator");
        while (line != null) {
            sb.append(line).append(lineSeparator);
            line = bufferedReader.readLine();
        }
        bufferedReader.close();
        inputstream.close();
        ByteArray content = refFile.getContent();
        content.setInnerContent(sb.toString().getBytes());
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) RouteResourceItem(org.talend.camel.core.model.camelProperties.RouteResourceItem) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) ByteArray(org.talend.core.model.properties.ByteArray) PartInitException(org.eclipse.ui.PartInitException)

Example 5 with RouteResourceItem

use of org.talend.camel.core.model.camelProperties.RouteResourceItem in project tesb-studio-se by Talend.

the class CreateRouteResourceAction method doRun.

@Override
protected void doRun() {
    IRepositoryNode node = null;
    NewRouteResourceWizard wizard = null;
    ISelection selection = getSelection();
    if (selection == null) {
        return;
    }
    Object obj = ((IStructuredSelection) selection).getFirstElement();
    node = (IRepositoryNode) obj;
    IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
    IPath path = service.getRepositoryPath(node);
    if (RepositoryConstants.isSystemFolder(path.toString())) {
        // Not allowed to create in system folder.
        return;
    }
    wizard = new NewRouteResourceWizard(path);
    WizardDialog dlg = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
    int open = dlg.open();
    if (open == Window.OK) {
        RouteResourceItem item = wizard.getItem();
        IWorkbenchPage page = getActivePage();
        RouteResourceEditorUtil.openEditor(page, null, item);
    }
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) IPath(org.eclipse.core.runtime.IPath) RouteResourceItem(org.talend.camel.core.model.camelProperties.RouteResourceItem) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) NewRouteResourceWizard(org.talend.designer.camel.resource.ui.wizards.NewRouteResourceWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IRepositoryService(org.talend.repository.model.IRepositoryService)

Aggregations

RouteResourceItem (org.talend.camel.core.model.camelProperties.RouteResourceItem)7 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 InputStream (java.io.InputStream)2 IPath (org.eclipse.core.runtime.IPath)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Item (org.talend.core.model.properties.Item)2 Property (org.talend.core.model.properties.Property)2 ReferenceFileItem (org.talend.core.model.properties.ReferenceFileItem)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 Path (org.eclipse.core.runtime.Path)1 ISelection (org.eclipse.jface.viewers.ISelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 ToolItem (org.eclipse.swt.widgets.ToolItem)1 PartInitException (org.eclipse.ui.PartInitException)1