Search in sources :

Example 81 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.

the class ImageBuildPage method createControl.

@Override
public void createControl(Composite parent) {
    final Composite container = new Composite(parent, SWT.NULL);
    FormLayout layout = new FormLayout();
    layout.marginHeight = 5;
    layout.marginWidth = 5;
    container.setLayout(layout);
    Label label = new Label(container, SWT.NULL);
    Label nameLabel = new Label(container, SWT.NULL);
    nameLabel.setText(WizardMessages.getString(NAME_LABEL));
    nameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    nameText.addModifyListener(Listener);
    nameText.setToolTipText(WizardMessages.getString(NAME_TOOLTIP));
    Label dirLabel = new Label(container, SWT.NULL);
    dirLabel.setText(WizardMessages.getString(DIRECTORY_LABEL));
    directoryText = new Text(container, SWT.BORDER | SWT.SINGLE);
    directoryText.addModifyListener(Listener);
    directoryText.setToolTipText(WizardMessages.getString(DIRECTORY_TOOLTIP));
    Button browse = new Button(container, SWT.NULL);
    browse.setText(WizardMessages.getString(BROWSE_LABEL));
    browse.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        DirectoryDialog d = new DirectoryDialog(container.getShell());
        String k = d.open();
        if (k != null)
            directoryText.setText(k);
    }));
    editButton = new Button(container, SWT.NULL);
    editButton.setText(WizardMessages.getString(EDIT_LABEL));
    editButton.setEnabled(false);
    editButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        String dir = directoryText.getText();
        IFileStore fileStore = EFS.getLocalFileSystem().getStore(// $NON-NLS-1$
        new Path(dir).append("Dockerfile"));
        // $NON-NLS-1$
        java.nio.file.Path filePath = Paths.get(dir, "Dockerfile");
        if (!Files.exists(filePath)) {
            try {
                Files.createFile(filePath);
            } catch (IOException e1) {
            // File won't exist, and directory should be
            // writable
            }
        }
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        try {
            IEditorPart dockerFileEditor = IDE.openEditorOnFileStore(page, fileStore);
            IWorkbenchPartSite site = page.getActivePart().getSite();
            EModelService s = site.getService(EModelService.class);
            MPartSashContainerElement p = site.getService(MPart.class);
            s.detach(p, 100, 100, 500, 375);
            dockerFileEditor.getEditorSite().getShell().setText(WizardMessages.getString(// $NON-NLS-1$
            "ImageBuild.editor.name"));
            editors.add(dockerFileEditor);
        } catch (PartInitException e1) {
            Activator.log(e1);
        }
        validate();
    }));
    Point p1 = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Point p2 = directoryText.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Point p3 = browse.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    int centering = (p2.y - p1.y + 1) / 2;
    int centering2 = (p3.y - p2.y + 1) / 2;
    FormData f = new FormData();
    f.top = new FormAttachment(0);
    label.setLayoutData(f);
    f = new FormData();
    f.top = new FormAttachment(label, 11 + centering + centering2);
    f.left = new FormAttachment(0, 0);
    nameLabel.setLayoutData(f);
    f = new FormData();
    f.top = new FormAttachment(label, 11 + centering2);
    f.left = new FormAttachment(nameLabel, 5);
    f.right = new FormAttachment(browse, -10);
    nameText.setLayoutData(f);
    f = new FormData();
    f.top = new FormAttachment(nameLabel, 11 + centering + centering2);
    f.left = new FormAttachment(0, 0);
    dirLabel.setLayoutData(f);
    f = new FormData();
    f.top = new FormAttachment(nameLabel, 11);
    f.right = new FormAttachment(100);
    editButton.setLayoutData(f);
    f = new FormData();
    f.top = new FormAttachment(nameLabel, 11);
    f.right = new FormAttachment(editButton, -10);
    browse.setLayoutData(f);
    f = new FormData();
    f.top = new FormAttachment(nameLabel, 11 + centering2);
    f.left = new FormAttachment(nameLabel, 5);
    f.right = new FormAttachment(browse, -10);
    directoryText.setLayoutData(f);
    if (lastDirectoryPath != null) {
        directoryText.setText(lastDirectoryPath);
    }
    setControl(container);
    setPageComplete(false);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) IDE(org.eclipse.ui.ide.IDE) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) Activator(org.eclipse.linuxtools.docker.ui.Activator) Point(org.eclipse.swt.graphics.Point) HashSet(java.util.HashSet) IMessageProvider(org.eclipse.jface.dialogs.IMessageProvider) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) WizardPage(org.eclipse.jface.wizard.WizardPage) EFS(org.eclipse.core.filesystem.EFS) IEditorPart(org.eclipse.ui.IEditorPart) IFileStore(org.eclipse.core.filesystem.IFileStore) Text(org.eclipse.swt.widgets.Text) Button(org.eclipse.swt.widgets.Button) Files(java.nio.file.Files) FormLayout(org.eclipse.swt.layout.FormLayout) PlatformUI(org.eclipse.ui.PlatformUI) IFileInfo(org.eclipse.core.filesystem.IFileInfo) FormData(org.eclipse.swt.layout.FormData) MPartSashContainerElement(org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainerElement) Set(java.util.Set) IOException(java.io.IOException) FormAttachment(org.eclipse.swt.layout.FormAttachment) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) EModelService(org.eclipse.e4.ui.workbench.modeling.EModelService) SWTImagesFactory(org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory) Paths(java.nio.file.Paths) ModifyListener(org.eclipse.swt.events.ModifyListener) Path(org.eclipse.core.runtime.Path) SWT(org.eclipse.swt.SWT) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) Label(org.eclipse.swt.widgets.Label) SelectionListener(org.eclipse.swt.events.SelectionListener) Path(org.eclipse.core.runtime.Path) FormData(org.eclipse.swt.layout.FormData) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) Composite(org.eclipse.swt.widgets.Composite) EModelService(org.eclipse.e4.ui.workbench.modeling.EModelService) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) IOException(java.io.IOException) IEditorPart(org.eclipse.ui.IEditorPart) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) Button(org.eclipse.swt.widgets.Button) MPartSashContainerElement(org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainerElement) IFileStore(org.eclipse.core.filesystem.IFileStore) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) FormAttachment(org.eclipse.swt.layout.FormAttachment) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 82 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.

the class JavaDocToc method getTopics.

@Override
public ITopic[] getTopics() {
    try {
        // Finds the path to the javadoc directory from the preference
        // store, and gets all children directories.
        ArrayList<ITopic> topics = new ArrayList<>();
        IPreferenceStore ps = JavaDocPlugin.getDefault().getPreferenceStore();
        IPath javadocLocation = new Path(ps.getString(PreferenceConstants.JAVADOCS_DIRECTORY));
        IFileSystem fs = EFS.getLocalFileSystem();
        IFileStore htmlDir = fs.getStore(javadocLocation);
        IFileStore[] files = htmlDir.childStores(EFS.NONE, null);
        Arrays.sort(files, new Comparator<IFileStore>() {

            @Override
            public int compare(IFileStore arg0, IFileStore arg1) {
                return (arg0.getName().compareToIgnoreCase(arg1.getName()));
            }
        });
        // directory and generates topics for them.
        for (IFileStore file : files) {
            String name = file.fetchInfo().getName();
            if (fs.getStore(// $NON-NLS-1$
            javadocLocation.append(name)).fetchInfo().exists() && fs.getStore(// $NON-NLS-1$
            javadocLocation.append(name + "/index.html")).fetchInfo().exists()) {
                ITopic topic = new JavaDocTopic(name);
                topics.add(topic);
            }
        }
        // Returns an array of the generated topics
        ITopic[] retval = new ITopic[topics.size()];
        return topics.toArray(retval);
    } catch (CoreException e) {
    }
    // child directories present.
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ITopic(org.eclipse.help.ITopic) IPath(org.eclipse.core.runtime.IPath) IFileSystem(org.eclipse.core.filesystem.IFileSystem) ArrayList(java.util.ArrayList) CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 83 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.

the class RemoteProxyCMainTab method checkProgram.

private boolean checkProgram(IProject project) {
    String name = fProgText.getText().trim();
    if (name.length() == 0) {
        setErrorMessage(ProxyLaunchMessages.executable_is_not_specified);
        return false;
    }
    // changed (binary or project name). See bug 277663.
    if (name.equals(fPreviouslyCheckedProgram)) {
        if (fPreviouslyCheckedProgramErrorMsg != null) {
            setErrorMessage(fPreviouslyCheckedProgramErrorMsg);
        }
        return fPreviouslyCheckedProgramIsValid;
    }
    fPreviouslyCheckedProgram = name;
    // we'll flip this below if
    fPreviouslyCheckedProgramIsValid = true;
    // not true
    // we'll set this below if
    fPreviouslyCheckedProgramErrorMsg = null;
    // there's an error
    IPath exePath;
    URI exeURI = null;
    boolean passed = false;
    try {
        exeURI = new URI(name);
        String exePathStr = exeURI.getPath();
        if (exePathStr == null) {
            setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.uri_of_executable_is_invalid);
            fPreviouslyCheckedProgramIsValid = false;
            return false;
        }
        exePath = Path.fromOSString(exeURI.getPath());
        if (!exePath.isAbsolute() && exeURI != null && !exeURI.isAbsolute()) {
            URI projectURI = project.getLocationURI();
            exeURI = new URI(projectURI.getScheme(), projectURI.getAuthority(), projectURI.getRawPath() + '/' + exePath.toString(), EMPTY_STRING);
        }
        if (exeURI != null) {
            passed = true;
        }
    } catch (URISyntaxException e) {
        setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.uri_of_executable_is_invalid);
        fPreviouslyCheckedProgramIsValid = false;
        return false;
    }
    if (!passed) {
        setErrorMessage(fPreviouslyCheckedProgramErrorMsg = LaunchMessages.CMainTab_Program_does_not_exist);
        fPreviouslyCheckedProgramIsValid = false;
        return false;
    }
    passed = false;
    try {
        IRemoteFileProxy exeFileProxy;
        exeFileProxy = RemoteProxyManager.getInstance().getFileProxy(exeURI);
        if (exeFileProxy != null) {
            String exeFilePath = exeURI.getPath();
            IFileStore exeFS = exeFileProxy.getResource(exeFilePath);
            if (exeFS != null) {
                IFileInfo exeFI = exeFS.fetchInfo();
                if (exeFI != null) {
                    if (dontCheckProgram || enableCopyFromExeButton.getSelection()) {
                        // The program may not exist yet if we are copying it.
                        passed = true;
                    } else {
                        if (exeFI.exists()) {
                            if (exeFI.getAttribute(EFS.ATTRIBUTE_EXECUTABLE) && !exeFI.isDirectory()) {
                                passed = true;
                            } else {
                                setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.executable_does_not_have_execution_rights);
                            }
                        } else {
                            setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.executable_does_not_exist);
                        }
                    }
                } else {
                    setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.error_accessing_executable);
                }
            } else {
                setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.error_accessing_executable);
            }
        } else {
            setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.scheme_error_in_executable);
        }
    } catch (CoreException e) {
        setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.connection_of_executable_cannot_be_opened);
    }
    if (!passed) {
        fPreviouslyCheckedProgramIsValid = false;
        return false;
    }
    setErrorMessage(null);
    return true;
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 84 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.

the class AbstractRemoteTest method deleteResource.

protected void deleteResource(String directory) {
    IRemoteServicesManager sm = getServicesManager();
    IRemoteConnection conn = sm.getConnectionType("ssh").getConnection(CONNECTION_NAME);
    assertNotNull(conn);
    IRemoteFileService fileManager = conn.getService(IRemoteFileService.class);
    assertNotNull(fileManager);
    final IFileStore dstFileStore = fileManager.getResource(directory);
    try {
        dstFileStore.delete(EFS.NONE, null);
    } catch (CoreException e) {
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IRemoteConnection(org.eclipse.remote.core.IRemoteConnection) IRemoteServicesManager(org.eclipse.remote.core.IRemoteServicesManager) IFileStore(org.eclipse.core.filesystem.IFileStore) IRemoteFileService(org.eclipse.remote.core.IRemoteFileService)

Example 85 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.

the class AbstractTest method createConfiguration.

protected ILaunchConfiguration createConfiguration(IProject proj) throws CoreException {
    String projectName = proj.getName();
    String binPath = "";
    ILaunchConfigurationType configType = getLaunchConfigType();
    ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(projectName));
    if (proj.getLocation() == null) {
        IFileStore fileStore = null;
        try {
            fileStore = EFS.getStore(new URI(proj.getLocationURI() + BIN_DIR + IPath.SEPARATOR + projectName));
        } catch (URISyntaxException e) {
            fail(NLS.bind(Messages.getString("AbstractTest.No_binary"), // $NON-NLS-1$
            projectName));
        }
        if ((fileStore instanceof LocalFile)) {
            fail(NLS.bind(Messages.getString("AbstractTest.No_binary"), // $NON-NLS-1$
            projectName));
        }
        binPath = EFSExtensionManager.getDefault().getPathFromURI(proj.getLocationURI()) + BIN_DIR + IPath.SEPARATOR + proj.getName();
    } else {
        IResource bin = proj.findMember(new Path(BIN_DIR).append(projectName));
        if (bin == null) {
            fail(NLS.bind(Messages.getString("AbstractTest.No_binary"), // $NON-NLS-1$
            projectName));
        }
        binPath = bin.getProjectRelativePath().toString();
        wc.setMappedResources(new IResource[] { bin, proj });
    }
    wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, binPath);
    wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
    wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
    // Make launch run in foreground
    wc.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, false);
    setProfileAttributes(wc);
    return wc.doSave();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) IFileStore(org.eclipse.core.filesystem.IFileStore) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) IResource(org.eclipse.core.resources.IResource)

Aggregations

IFileStore (org.eclipse.core.filesystem.IFileStore)105 CoreException (org.eclipse.core.runtime.CoreException)49 IPath (org.eclipse.core.runtime.IPath)29 IOException (java.io.IOException)26 IFileInfo (org.eclipse.core.filesystem.IFileInfo)25 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)18 URI (java.net.URI)16 InputStream (java.io.InputStream)14 Path (org.eclipse.core.runtime.Path)14 IFile (org.eclipse.core.resources.IFile)12 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)12 InputStreamReader (java.io.InputStreamReader)11 PartInitException (org.eclipse.ui.PartInitException)11 BufferedReader (java.io.BufferedReader)10 URISyntaxException (java.net.URISyntaxException)10 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)10 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)10 Test (org.junit.Test)10 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)9 IStatus (org.eclipse.core.runtime.IStatus)9