Search in sources :

Example 86 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class JavaCommandController method createControl.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.AbstractElementPropertySectionController#createControl
     * (org.eclipse.swt.widgets.Composite, org.talend.core.model.process.IElementParameter, int, int, int,
     * org.eclipse.swt.widgets.Control)
     */
@Override
public Control createControl(Composite subComposite, final IElementParameter param, int numInRow, int nbInRow, int top, Control lastControl) {
    Button btnEdit;
    //$NON-NLS-1$
    btnEdit = getWidgetFactory().createButton(subComposite, "", SWT.PUSH);
    btnEdit.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
    FormData data;
    btnEdit.setData(NAME, JAVA_COMMAND);
    btnEdit.setData(PARAMETER_NAME, param.getName());
    btnEdit.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            // execute Java Command
            ElementParameter fullParam = (ElementParameter) param;
            File jar;
            URL url;
            try {
                List<URL> listURL = new ArrayList<URL>();
                ILibraryManagerService libManager = (ILibraryManagerService) GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
                IFolder javaLibFolder = null;
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
                    IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
                    ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendProcessJavaProject();
                    if (talendProcessJavaProject != null) {
                        javaLibFolder = talendProcessJavaProject.getLibFolder();
                    }
                }
                if (javaLibFolder == null) {
                    return;
                }
                for (String jarString : fullParam.getJar().split(";")) {
                    IPath libPath = javaLibFolder.getLocation();
                    libManager.retrieve(jarString, libPath.toPortableString(), new NullProgressMonitor());
                    jar = libPath.append(jarString).toFile();
                    url = jar.toURL();
                    listURL.add(url);
                }
                URLClassLoader urlClassLoader = new URLClassLoader(listURL.toArray(new URL[0]));
                Class<?> classLoaded = Class.forName(fullParam.getJavaClass(), true, urlClassLoader);
                Object object = classLoaded.newInstance();
                List<String> args = new ArrayList<String>();
                for (String arg : fullParam.getArgs()) {
                    args.add(ElementParameterParser.parse(elem, arg));
                }
                for (Method method : classLoaded.getDeclaredMethods()) {
                    if (method.getName().equals(fullParam.getJavaFunction())) {
                        Object[] arglist = new Object[1];
                        arglist[0] = args.toArray(new String[0]);
                        method.invoke(object, arglist);
                    }
                }
            } catch (Exception e1) {
                MessageBoxExceptionHandler.process(e1);
            }
        }
    });
    if (elem instanceof Node) {
        btnEdit.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }
    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName());
    data = new FormData();
    if (lastControl != null) {
        data.left = new FormAttachment(lastControl, 0);
    } else {
        data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    data.top = new FormAttachment(0, top);
    labelLabel.setLayoutData(data);
    if (numInRow != 1) {
        labelLabel.setAlignment(SWT.RIGHT);
    }
    // **************************
    data = new FormData();
    int currentLabelWidth = STANDARD_LABEL_WIDTH;
    GC gc = new GC(labelLabel);
    Point labelSize = gc.stringExtent(param.getDisplayName());
    gc.dispose();
    if ((labelSize.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth) {
        currentLabelWidth = labelSize.x + ITabbedPropertyConstants.HSPACE;
    }
    if (numInRow == 1) {
        if (lastControl != null) {
            data.left = new FormAttachment(lastControl, currentLabelWidth);
            data.right = new FormAttachment(lastControl, currentLabelWidth + STANDARD_BUTTON_WIDTH);
        } else {
            data.left = new FormAttachment(0, currentLabelWidth);
            data.right = new FormAttachment(0, currentLabelWidth + STANDARD_BUTTON_WIDTH);
        }
    } else {
        data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
        data.right = new FormAttachment(labelLabel, STANDARD_BUTTON_WIDTH, SWT.RIGHT);
    }
    data.top = new FormAttachment(0, top);
    btnEdit.setLayoutData(data);
    // **************************
    hashCurControls.put(param.getName(), btnEdit);
    Point initialSize = btnEdit.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return btnEdit;
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) Node(org.talend.designer.core.ui.editor.nodes.Node) URL(java.net.URL) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) ILibraryManagerService(org.talend.core.ILibraryManagerService) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) GC(org.eclipse.swt.graphics.GC) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormData(org.eclipse.swt.layout.FormData) IPath(org.eclipse.core.runtime.IPath) Method(java.lang.reflect.Method) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) URLClassLoader(java.net.URLClassLoader) File(java.io.File) SelectionListener(org.eclipse.swt.events.SelectionListener) IFolder(org.eclipse.core.resources.IFolder)

Example 87 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class ComponentFolderManager method copyFileFromSrc.

private void copyFileFromSrc(String srcURL, String... particularPath) throws FileNotFoundException, CoreException {
    if (srcURL == null || srcURL.equals(PluginConstant.EMPTY_STRING)) {
        return;
    }
    IPath path = new Path(srcURL);
    IFolder folder = project.getFolder(this.componentFolderName);
    if (!folder.exists()) {
        folder.create(false, true, null);
    }
    String projectFolder = this.componentFolderName;
    if (particularPath != null) {
        for (String mParticularPath : particularPath) {
            //$NON-NLS-1$
            projectFolder += "/" + mParticularPath;
            folder = project.getFolder(projectFolder);
            if (!folder.exists()) {
                folder.create(false, true, null);
            }
        }
    } else {
        projectFolder = this.componentFolderName;
    }
    IFile file = folder.getFile(path.lastSegment());
    if (file.exists()) {
        return;
    }
    FileInputStream fileStream = new FileInputStream(srcURL);
    file.create(fileStream, false, null);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) FileInputStream(java.io.FileInputStream) IFolder(org.eclipse.core.resources.IFolder)

Example 88 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class PushToPaletteActionProvider method fillContextMenu.

/**
     * Adds a submenu to the given menu with the name "New Component".
     */
@Override
public void fillContextMenu(IMenuManager menu) {
    //$NON-NLS-1$
    menu.insertBefore("group.edit", copyProjectAction);
    // Object obj = ((TreeSelection) this.getContext().getSelection()).getFirstElement();// need to get all
    // selected.
    Iterator ite = ((TreeSelection) this.getContext().getSelection()).iterator();
    selectedFolderList = new ArrayList<IFolder>();
    while (ite.hasNext()) {
        Object obj = ite.next();
        if (obj instanceof IFolder) {
            selectedFolderList.add((IFolder) obj);
        }
    }
}
Also used : TreeSelection(org.eclipse.jface.viewers.TreeSelection) Iterator(java.util.Iterator) IFolder(org.eclipse.core.resources.IFolder)

Example 89 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class WizardComponentFolderPage method validatePage.

@Override
protected boolean validatePage() {
    if (useJavaLangButton != null) {
        if (!(useJavaLangButton.getSelection())) {
            //$NON-NLS-1$
            setErrorMessage(Messages.getString("WizardComponentFolderPage.ErrMSG1"));
            return false;
        }
    }
    if (this.componentFolderText.isEnabled()) {
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PluginConstant.COMPONENT_PROJECT);
        String componentName = componentFolderText.getText();
        if (componentName.equals(PluginConstant.EMPTY_STRING)) {
            //$NON-NLS-1$
            setErrorMessage(Messages.getString("WizardComponentFolderPage.ErrMSG2"));
            return false;
        }
        IFolder componentFolder = project.getFolder(componentName);
        if (componentFolder.exists()) {
            //$NON-NLS-1$
            setErrorMessage(Messages.getString("WizardComponentFolderPage.ErrMSG3"));
            return false;
        }
    }
    if (this.componentLongName.isEnabled()) {
        String longName = componentLongName.getText();
        if (longName.equals(PluginConstant.EMPTY_STRING)) {
            //$NON-NLS-1$
            setErrorMessage(Messages.getString("WizardComponentFolderPage.ErrMSG4"));
            return false;
        }
    }
    setErrorMessage(null);
    return true;
}
Also used : IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 90 with IFolder

use of org.eclipse.core.resources.IFolder in project AutoRefactor by JnRouvignac.

the class JavaCoreHelper method createFolder.

private static void createFolder(IFolder folder) throws Exception {
    if (!folder.exists()) {
        final IContainer parent = folder.getParent();
        if (parent instanceof IFolder) {
            createFolder((IFolder) parent);
        }
        folder.create(false, true, null);
    }
}
Also used : IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IFolder (org.eclipse.core.resources.IFolder)299 IFile (org.eclipse.core.resources.IFile)129 IPath (org.eclipse.core.runtime.IPath)90 IProject (org.eclipse.core.resources.IProject)77 CoreException (org.eclipse.core.runtime.CoreException)72 IResource (org.eclipse.core.resources.IResource)66 Path (org.eclipse.core.runtime.Path)47 IContainer (org.eclipse.core.resources.IContainer)45 File (java.io.File)43 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)28 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)26 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)23 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)19 InputStream (java.io.InputStream)18 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)17 IRunProcessService (org.talend.designer.runprocess.IRunProcessService)17 PersistenceException (org.talend.commons.exception.PersistenceException)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15