Search in sources :

Example 91 with IContainer

use of org.eclipse.core.resources.IContainer in project eclipse-pmd by acanda.

the class AddRuleSetConfigurationController method browseContainer.

private Optional<IResource> browseContainer(final Shell shell, final IContainer container) {
    final FileSelectionDialog dialog = new FileSelectionDialog(shell);
    dialog.setMessage("Choose a PMD rule set configuration:");
    dialog.setValidator(new ISelectionStatusValidator() {

        @Override
        public IStatus validate(final Object[] selection) {
            IStatus result = new Status(IStatus.OK, PMDPlugin.ID, "");
            if (selection.length == 1 && !(selection[0] instanceof IContainer)) {
                final IResource resource = (IResource) selection[0];
                final String configuration = resource.getLocation().toOSString();
                try {
                    new RuleSetFactory().createRuleSet(configuration);
                } catch (final RuleSetNotFoundException | IllegalArgumentException e) {
                    // the rule set location is invalid
                    result = new Status(IStatus.WARNING, PMDPlugin.ID, resource.getName() + " is not a valid PMD rule set configuration");
                }
            } else {
                result = new Status(IStatus.WARNING, PMDPlugin.ID, "");
            }
            return result;
        }
    });
    dialog.setInput(container);
    if (dialog.open() == Window.OK) {
        return Optional.of((IResource) dialog.getFirstResult());
    }
    return Optional.absent();
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) RuleSetFactory(net.sourceforge.pmd.RuleSetFactory) IStatus(org.eclipse.core.runtime.IStatus) FileSelectionDialog(ch.acanda.eclipse.pmd.ui.dialog.FileSelectionDialog) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 92 with IContainer

use of org.eclipse.core.resources.IContainer in project bndtools by bndtools.

the class WorkspaceMainPart method initialize.

@Override
public void initialize(final IManagedForm form) {
    super.initialize(form);
    final Composite container = (Composite) getSection().getClient();
    // create a layout stack and the first visible component will be an empty component with "waiting" message
    // this will be replaced by real composite once workspace completes
    final StackLayout stackLayout = new StackLayout();
    container.setLayout(stackLayout);
    Composite labelParent = new Composite(container, SWT.NONE);
    FillLayout fillLayout = new FillLayout();
    fillLayout.marginHeight = fillLayout.marginWidth = 10;
    labelParent.setLayout(fillLayout);
    if (!Central.isWorkspaceInited()) {
        Label label = new Label(labelParent, SWT.NONE);
        label.setText("Workspace is loading, please wait...");
        label.setBackground(container.getBackground());
        label.setForeground(container.getForeground());
    }
    stackLayout.topControl = labelParent;
    container.layout();
    Central.onWorkspaceInit(new Success<Workspace, Void>() {

        @Override
        public Promise<Void> call(Promise<Workspace> resolved) throws Exception {
            final Deferred<Void> completion = new Deferred<>();
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    try {
                        IFile buildFile = Central.getWorkspaceBuildFile();
                        if (buildFile == null)
                            return;
                        Composite contents = new Composite(container, SWT.NONE);
                        if (!mainFile) {
                            ImageHyperlink link = form.getToolkit().createImageHyperlink(contents, SWT.CENTER);
                            link.setText("Open main build.bnd file.");
                            link.setImage(bndFileImg);
                            link.addHyperlinkListener(new FileOpenLinkListener(buildFile.getFullPath()));
                        } else {
                            IResource[] extFiles;
                            IContainer cnfDir = buildFile.getParent();
                            IFolder extDir = cnfDir.getFolder(new Path("ext"));
                            if (extDir.exists())
                                extFiles = extDir.members();
                            else
                                extFiles = new IResource[0];
                            if (extFiles.length > 0) {
                                for (IResource extFile : extFiles) {
                                    if (extFile.getType() == IResource.FILE && "bnd".equalsIgnoreCase(extFile.getFileExtension())) {
                                        ImageHyperlink link = form.getToolkit().createImageHyperlink(contents, SWT.CENTER);
                                        link.setText("Open " + extFile.getName());
                                        link.setImage(extFileImg);
                                        link.addHyperlinkListener(new FileOpenLinkListener(extFile.getFullPath()));
                                    }
                                }
                            } else {
                                createMissingExtsWarningPanel(contents, form.getToolkit(), extDir.getFullPath());
                            }
                        }
                        stackLayout.topControl = contents;
                        container.layout();
                        completion.resolve(null);
                    } catch (Exception e) {
                        Plugin.error(Collections.singletonList(e.getMessage()));
                        completion.fail(e);
                    }
                }
            });
            return completion.getPromise();
        }
    });
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) ImageHyperlink(org.eclipse.ui.forms.widgets.ImageHyperlink) Deferred(org.osgi.util.promise.Deferred) Label(org.eclipse.swt.widgets.Label) FillLayout(org.eclipse.swt.layout.FillLayout) PartInitException(org.eclipse.ui.PartInitException) Promise(org.osgi.util.promise.Promise) StackLayout(org.eclipse.swt.custom.StackLayout) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) Workspace(aQute.bnd.build.Workspace) IFolder(org.eclipse.core.resources.IFolder)

Example 93 with IContainer

use of org.eclipse.core.resources.IContainer in project bndtools by bndtools.

the class GenerateIndexCommandHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structSel = (IStructuredSelection) selection;
        Object element = structSel.getFirstElement();
        if (element != null && element instanceof IContainer) {
            NewIndexWizard wizard = new NewIndexWizard();
            IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
            wizard.init(workbenchWindow.getWorkbench(), structSel);
            WizardDialog dialog = new WizardDialog(workbenchWindow.getShell(), wizard);
            dialog.open();
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IContainer(org.eclipse.core.resources.IContainer) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 94 with IContainer

use of org.eclipse.core.resources.IContainer in project yamcs-studio by yamcs.

the class ResourceAndContainerGroup method setContainerFullPath.

/**
 * Sets the value of this page's container.
 *
 * @param path
 *            Full path to the container.
 */
public void setContainerFullPath(final IPath path) {
    IResource initial = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
    if (initial != null) {
        if (!(initial instanceof IContainer)) {
            initial = initial.getParent();
        }
        _containerGroup.setSelectedResource(initial);
    }
    validateControls();
}
Also used : IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 95 with IContainer

use of org.eclipse.core.resources.IContainer in project yamcs-studio by yamcs.

the class FileUtil method writeTextFile.

/**
 * Write a text file.
 *
 * @param filePath
 *            path of the file. It can be an absolute path or a relative path to the OPI that contains the specified
 *            widget. If it is an absolute path, it can be either<br>
 *            a workspace path such as <code>/BOY Examples/Scripts/myfile.xml</code><br>
 *            a local file system path such as <code>C:\myfile.xml</code><br>
 *            or an URL path such as <code>http://mysite.com/myfile.xml</code>.
 * @param inWorkspace
 *            true if the file path is a workspace file path. Otherwise, it will be recognized as a local file
 *            system file.
 * @param widget
 *            a widget in the OPI, which is used to provide relative path reference. It can be null if the path is
 *            an absolute path.
 * @param text
 *            the text to be written to the file.
 * @param append
 *            true if the text should be appended to the end of the file.
 * @throws Exception
 *             if error happens.
 */
public static void writeTextFile(String filePath, boolean inWorkspace, AbstractBaseEditPart widget, String text, boolean append) throws Exception {
    IPath path = FileUtil.buildAbsolutePath(filePath, widget);
    if (inWorkspace) {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot root = workspace.getRoot();
        String projectName = path.segment(0);
        IProject project = root.getProject(projectName);
        if (!(project.exists())) {
            project.create(new NullProgressMonitor());
        }
        project.open(new NullProgressMonitor());
        IFolder folder = null;
        for (int i = 1; i < path.segmentCount() - 1; i++) {
            if (i == 1)
                folder = project.getFolder(path.segment(i));
            else
                folder = folder.getFolder(path.segment(i));
            if (!(folder.exists())) {
                folder.create(true, true, null);
            }
        }
        IContainer container;
        if (folder == null)
            container = project;
        else
            container = folder;
        IFile file = container.getFile(ResourceUtil.getPathFromString(path.lastSegment()));
        if (file.exists()) {
            StringBuilder sb = new StringBuilder();
            if (append) {
                sb.append(FileUtil.readTextFile(filePath, widget));
            }
            sb.append(text);
            file.setContents(new ByteArrayInputStream(sb.toString().getBytes("UTF-8")), true, false, // $NON-NLS-1$
            null);
        } else {
            File sysFile = file.getLocation().toFile();
            BufferedWriter writer = new BufferedWriter(// $NON-NLS-1$
            new OutputStreamWriter(new FileOutputStream(sysFile, append), "UTF-8"));
            writer.write(text);
            writer.flush();
            writer.close();
        }
    } else {
        BufferedWriter writer = new BufferedWriter(// $NON-NLS-1$
        new OutputStreamWriter(new FileOutputStream(path.toString(), append), "UTF-8"));
        writer.write(text);
        writer.flush();
        writer.close();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IProject(org.eclipse.core.resources.IProject) BufferedWriter(java.io.BufferedWriter) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ByteArrayInputStream(java.io.ByteArrayInputStream) IWorkspace(org.eclipse.core.resources.IWorkspace) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IContainer(org.eclipse.core.resources.IContainer) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IContainer (org.eclipse.core.resources.IContainer)199 IResource (org.eclipse.core.resources.IResource)89 IFile (org.eclipse.core.resources.IFile)71 IPath (org.eclipse.core.runtime.IPath)47 CoreException (org.eclipse.core.runtime.CoreException)46 IFolder (org.eclipse.core.resources.IFolder)45 Path (org.eclipse.core.runtime.Path)43 IProject (org.eclipse.core.resources.IProject)28 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)26 ArrayList (java.util.ArrayList)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 IOException (java.io.IOException)13 IStatus (org.eclipse.core.runtime.IStatus)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)12 Status (org.eclipse.core.runtime.Status)10 PartInitException (org.eclipse.ui.PartInitException)10 InputStream (java.io.InputStream)9