Search in sources :

Example 56 with IStorage

use of org.eclipse.core.resources.IStorage in project erlide_eclipse by erlang.

the class ErlModelUtils method getPathForInput.

private static String getPathForInput(final IEditorInput editorInput) {
    if (editorInput instanceof IStorageEditorInput) {
        final IStorageEditorInput sei = (IStorageEditorInput) editorInput;
        try {
            final IStorage storage = sei.getStorage();
            final IPath p = storage.getFullPath();
            return p.toPortableString();
        } catch (final CoreException e) {
        }
    }
    if (editorInput instanceof IURIEditorInput) {
        final IURIEditorInput ue = (IURIEditorInput) editorInput;
        return ue.getURI().getPath();
    }
    return null;
}
Also used : IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IStorage(org.eclipse.core.resources.IStorage)

Example 57 with IStorage

use of org.eclipse.core.resources.IStorage in project webtools.sourceediting by eclipse.

the class StorageModelProvider method calculateID.

String calculateID(IStorageEditorInput input) {
    /**
     * Typically CVS will return a path of "filename.ext" and the input's
     * name will be "filename.ext version". The path must be used to load
     * the model so that the suffix will be available to compute the
     * contentType properly. The editor input name can then be set as the
     * base location for display on the editor title bar.
     */
    String path = null;
    if (input instanceof ILocationProvider) {
        IPath ipath = ((ILocationProvider) input).getPath(input);
        if (ipath != null) {
            path = ipath.toString();
        }
    }
    if (path == null) {
        try {
            IStorage storage = input.getStorage();
            if (storage != null) {
                IPath storagePath = storage.getFullPath();
                String name = storage.getName();
                if (storagePath != null) {
                    // Favor the name.
                    if (!storagePath.lastSegment().equals(name)) {
                        IPath workingPath = storagePath.addTrailingSeparator();
                        path = workingPath.append(name).toString();
                    } else {
                        path = storagePath.makeAbsolute().toString();
                    }
                }
                if (path == null)
                    path = name;
            }
        } catch (CoreException e) {
            Logger.logException(e);
        } finally {
            if (path == null)
                // $NON-NLS-1$
                path = input.getName();
        }
    }
    /*
		 * Prepend the hash to the path value so that we have a 1:1:1 match
		 * between editor inputs, element info, and models. The editor manager
		 * should help prevent needlessly duplicated models as long as two
		 * editor inputs from the same storage indicate they're equals().
		 */
    // $NON-NLS-1$
    path = input.hashCode() + "#" + path;
    return path;
}
Also used : IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) ILocationProvider(org.eclipse.ui.editors.text.ILocationProvider) IStorage(org.eclipse.core.resources.IStorage)

Example 58 with IStorage

use of org.eclipse.core.resources.IStorage in project n4js by eclipse.

the class BuildInstruction method shouldGenerate.

private boolean shouldGenerate(Resource resource, IProject aProject) {
    try {
        Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(resource.getURI());
        for (Pair<IStorage, IProject> pair : storages) {
            if (pair.getFirst() instanceof IFile && pair.getSecond().equals(aProject)) {
                IFile file = (IFile) pair.getFirst();
                int findMaxProblemSeverity = file.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
                // Easiest way here is to remove that error marker-type and look for other severe errors once more:
                if (findMaxProblemSeverity == IMarker.SEVERITY_ERROR) {
                    // clean
                    GeneratorMarkerSupport generatorMarkerSupport = injector.getInstance(GeneratorMarkerSupport.class);
                    generatorMarkerSupport.deleteMarker(resource);
                    // and recompute:
                    findMaxProblemSeverity = file.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
                }
                // the final decision to build:
                return findMaxProblemSeverity != IMarker.SEVERITY_ERROR;
            }
        }
        return false;
    } catch (CoreException exc) {
        throw new WrappedException(exc);
    }
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) GeneratorMarkerSupport(org.eclipse.n4js.ui.generator.GeneratorMarkerSupport) IStorage(org.eclipse.core.resources.IStorage) IProject(org.eclipse.core.resources.IProject) Pair(org.eclipse.xtext.util.Pair)

Example 59 with IStorage

use of org.eclipse.core.resources.IStorage in project mdw-designer by CenturyLinkCloud.

the class ProcessInstanceListView method createContextMenu.

private Menu createContextMenu(Shell shell) {
    Menu menu = new Menu(shell, SWT.POP_UP);
    final StructuredSelection selection = (StructuredSelection) getTableViewer().getSelection();
    if (selection.size() == 1 && selection.getFirstElement() instanceof ProcessInstanceVO) {
        final ProcessInstanceVO processInstanceInfo = (ProcessInstanceVO) selection.getFirstElement();
        // open instance
        MenuItem openItem = new MenuItem(menu, SWT.PUSH);
        openItem.setText("Open");
        ImageDescriptor openImageDesc = MdwPlugin.getImageDescriptor("icons/process.gif");
        openItem.setImage(openImageDesc.createImage());
        openItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                handleOpen(processInstanceInfo);
            }
        });
        // owning document
        if (OwnerType.DOCUMENT.equals(processInstanceInfo.getOwner()) || OwnerType.TESTER.equals(processInstanceInfo.getOwner())) {
            MenuItem docItem = new MenuItem(menu, SWT.PUSH);
            docItem.setText("View Owning Document");
            ImageDescriptor docImageDesc = MdwPlugin.getImageDescriptor("icons/doc.gif");
            docItem.setImage(docImageDesc.createImage());
            docItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    IStorage storage = new DocumentStorage(workflowProject, new DocumentReference(processInstanceInfo.getOwnerId(), null));
                    final IStorageEditorInput input = new StorageEditorInput(storage);
                    final IWorkbenchPage page = MdwPlugin.getActivePage();
                    if (page != null) {
                        BusyIndicator.showWhile(getSite().getShell().getDisplay(), new Runnable() {

                            public void run() {
                                try {
                                    page.openEditor(input, "org.eclipse.ui.DefaultTextEditor");
                                } catch (PartInitException ex) {
                                    PluginMessages.uiError(ex, "View Document", workflowProject);
                                }
                            }
                        });
                    }
                }
            });
        }
        // instance hierarchy
        MenuItem hierarchyItem = new MenuItem(menu, SWT.PUSH);
        hierarchyItem.setText("Instance Hierarchy");
        ImageDescriptor hierarchyImageDesc = MdwPlugin.getImageDescriptor("icons/hierarchy.gif");
        hierarchyItem.setImage(hierarchyImageDesc.createImage());
        hierarchyItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                WorkflowProcess pv = new WorkflowProcess(processVersion);
                pv.setProcessVO(processVersion.getProcessVO());
                pv.setProcessInstance(processInstanceInfo);
                new WorkflowElementActionHandler().showHierarchy(pv);
            }
        });
    }
    // delete
    if (!selection.isEmpty() && !processVersion.getProject().isProduction() && processVersion.isUserAuthorized(UserRoleVO.PROCESS_EXECUTION)) {
        MenuItem deleteItem = new MenuItem(menu, SWT.PUSH);
        deleteItem.setText("Delete...");
        ImageDescriptor deleteImageDesc = MdwPlugin.getImageDescriptor("icons/delete.gif");
        deleteItem.setImage(deleteImageDesc.createImage());
        deleteItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (selection.size() == 1 && selection.getFirstElement() instanceof ProcessInstanceVO) {
                    ProcessInstanceVO pii = (ProcessInstanceVO) selection.getFirstElement();
                    if (MessageDialog.openConfirm(getSite().getShell(), "Confirm Delete", "Delete process instance ID: " + pii.getId() + " for workflow project '" + processVersion.getProject().getName() + "'?")) {
                        List<ProcessInstanceVO> instances = new ArrayList<>();
                        instances.add((ProcessInstanceVO) selection.getFirstElement());
                        handleDelete(instances);
                    }
                } else {
                    if (MessageDialog.openConfirm(getSite().getShell(), "Confirm Delete", "Delete selected process instances for workflow project '" + processVersion.getProject().getName() + "'?")) {
                        List<ProcessInstanceVO> instances = new ArrayList<>();
                        for (Object instance : selection.toArray()) {
                            if (instance instanceof ProcessInstanceVO)
                                instances.add((ProcessInstanceVO) instance);
                        }
                        handleDelete(instances);
                    }
                }
            }
        });
    }
    return menu;
}
Also used : DocumentStorage(com.centurylink.mdw.plugin.designer.storage.DocumentStorage) IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) MenuItem(org.eclipse.swt.widgets.MenuItem) IStorage(org.eclipse.core.resources.IStorage) WorkflowElementActionHandler(com.centurylink.mdw.plugin.actions.WorkflowElementActionHandler) StorageEditorInput(com.centurylink.mdw.plugin.designer.storage.StorageEditorInput) IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) List(java.util.List) ArrayList(java.util.ArrayList) Menu(org.eclipse.swt.widgets.Menu) PartInitException(org.eclipse.ui.PartInitException) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO) DocumentReference(com.centurylink.mdw.model.value.variable.DocumentReference)

Example 60 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-xtend by eclipse.

the class XtendNatureAddingEditorCallback method canBuild.

private boolean canBuild(XtextEditor editor) {
    IResource resource = editor.getResource();
    if (!(resource instanceof IStorage)) {
        return false;
    }
    IStorage storage = (IStorage) resource;
    URI uri = mapper.getUri(storage);
    return uriValidator.canBuild(uri, storage);
}
Also used : IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IResource(org.eclipse.core.resources.IResource)

Aggregations

IStorage (org.eclipse.core.resources.IStorage)96 URI (org.eclipse.emf.common.util.URI)32 IFile (org.eclipse.core.resources.IFile)31 IProject (org.eclipse.core.resources.IProject)27 CoreException (org.eclipse.core.runtime.CoreException)25 IResource (org.eclipse.core.resources.IResource)20 Pair (org.eclipse.xtext.util.Pair)16 Test (org.junit.Test)15 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 IStorageEditorInput (org.eclipse.ui.IStorageEditorInput)12 IPath (org.eclipse.core.runtime.IPath)11 IJavaProject (org.eclipse.jdt.core.IJavaProject)10 IOException (java.io.IOException)7 WrappedException (org.eclipse.emf.common.util.WrappedException)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)6 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)6 Storage2UriMapperJavaImpl (org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl)6