Search in sources :

Example 1 with IDocumentWrapper

use of bndtools.editor.model.IDocumentWrapper in project bndtools by bndtools.

the class BlueprintXmlFileWizard method updateBundleBlueprintAndIncludeResource.

private void updateBundleBlueprintAndIncludeResource(IFile blueprintFile, IFile bndFile) throws Exception {
    BndEditModel editModel;
    IEditorPart editor = ResourceUtil.findEditor(workbench.getActiveWorkbenchWindow().getActivePage(), bndFile);
    IDocument doc = null;
    if (editor instanceof BndEditor) {
        editModel = ((BndEditor) editor).getEditModel();
    } else {
        editModel = new BndEditModel(Central.getWorkspace());
        doc = FileUtils.readFully(bndFile);
        editModel.loadFrom(new IDocumentWrapper(doc));
    }
    String blueprintrelativePath = blueprintFile.getProjectRelativePath().toString();
    updateBundleBlueprintIfNecessary(editModel, blueprintrelativePath);
    updateIncludeResourceIfNecessary(editModel, blueprintrelativePath, blueprintFile);
    if (editor == null) {
        editModel.saveChangesTo(new IDocumentWrapper(doc));
        FileUtils.writeFully(doc, bndFile, false);
    }
}
Also used : BndEditor(bndtools.editor.BndEditor) IEditorPart(org.eclipse.ui.IEditorPart) BndEditModel(aQute.bnd.build.model.BndEditModel) IDocumentWrapper(bndtools.editor.model.IDocumentWrapper) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with IDocumentWrapper

use of bndtools.editor.model.IDocumentWrapper in project bndtools by bndtools.

the class BndEditor method loadEditModel.

private void loadEditModel() throws Exception {
    // Create the bnd edit model and workspace
    Workspace ws = Central.getWorkspaceIfPresent();
    Project bndProject = Run.createRun(ws, inputFile);
    model.setWorkspace(bndProject.getWorkspace());
    model.setProject(bndProject);
    // Load content into the edit model
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            final IDocumentProvider docProvider = sourcePage.getDocumentProvider();
            // #1625: Ensure the IDocumentProvider is not null.
            if (docProvider != null) {
                IDocument document = docProvider.getDocument(getEditorInput());
                try {
                    model.loadFrom(new IDocumentWrapper(document));
                    model.setBndResource(inputFile);
                } catch (IOException e) {
                    logger.logError("Unable to load edit model", e);
                }
                for (int i = 0; i < getPageCount(); i++) {
                    Control control = getControl(i);
                    if (control instanceof ScrolledForm) {
                        ScrolledForm form = (ScrolledForm) control;
                        if (SYNC_MESSAGE.equals(form.getMessage())) {
                            form.setMessage(null, IMessageProvider.NONE);
                        }
                    }
                }
            }
        }
    });
}
Also used : Project(aQute.bnd.build.Project) Control(org.eclipse.swt.widgets.Control) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) IOException(java.io.IOException) IDocumentWrapper(bndtools.editor.model.IDocumentWrapper) IDocument(org.eclipse.jface.text.IDocument) Workspace(aQute.bnd.build.Workspace)

Example 3 with IDocumentWrapper

use of bndtools.editor.model.IDocumentWrapper in project bndtools by bndtools.

the class BndSourceEditorPage method getDocument.

private IDocument getDocument() {
    IDocumentProvider docProvider = getDocumentProvider();
    IEditorInput input = getEditorInput();
    return new IDocumentWrapper(docProvider.getDocument(input));
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IDocumentWrapper(bndtools.editor.model.IDocumentWrapper) IEditorInput(org.eclipse.ui.IEditorInput)

Example 4 with IDocumentWrapper

use of bndtools.editor.model.IDocumentWrapper in project bndtools by bndtools.

the class BndEditor method resourceChanged.

@Override
public void resourceChanged(IResourceChangeEvent event) {
    IResource myResource = ResourceUtil.getResource(getEditorInput());
    IResourceDelta delta = event.getDelta();
    if (delta == null)
        return;
    IPath fullPath = myResource.getFullPath();
    delta = delta.findMember(fullPath);
    if (delta == null)
        return;
    // Delegate to any interested pages
    for (Object page : pages) {
        if (page instanceof IResourceChangeListener) {
            ((IResourceChangeListener) page).resourceChanged(event);
        }
    }
    // Close editor if file removed or switch to new location if file moved
    if (delta.getKind() == IResourceDelta.REMOVED) {
        if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
            IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(delta.getMovedToPath());
            final FileEditorInput newInput = new FileEditorInput(file);
            setInput(newInput);
            Display display = getEditorSite().getShell().getDisplay();
            if (display != null) {
                SWTConcurrencyUtil.execForDisplay(display, true, new Runnable() {

                    @Override
                    public void run() {
                        setPartNameForInput(newInput);
                        sourcePage.setInput(newInput);
                    }
                });
            }
        } else {
            close(false);
        }
    } else // File content updated externally => reload all pages
    if ((delta.getKind() & IResourceDelta.CHANGED) > 0 && (delta.getFlags() & IResourceDelta.CONTENT) > 0) {
        if (!saving.get()) {
            final IDocumentProvider docProvider = sourcePage.getDocumentProvider();
            // #1625: Ensure the IDocumentProvider is not null.
            if (docProvider != null) {
                final IDocument document = docProvider.getDocument(getEditorInput());
                SWTConcurrencyUtil.execForControl(getEditorSite().getShell(), true, new Runnable() {

                    @Override
                    public void run() {
                        try {
                            model.loadFrom(new IDocumentWrapper(document));
                            updateIncludedPages();
                        } catch (IOException e) {
                            logger.logError("Failed to reload document", e);
                        }
                    }
                });
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) IOException(java.io.IOException) IDocumentWrapper(bndtools.editor.model.IDocumentWrapper) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IResource(org.eclipse.core.resources.IResource) IDocument(org.eclipse.jface.text.IDocument) IResourceDelta(org.eclipse.core.resources.IResourceDelta) Display(org.eclipse.swt.widgets.Display)

Aggregations

IDocumentWrapper (bndtools.editor.model.IDocumentWrapper)4 IDocument (org.eclipse.jface.text.IDocument)3 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)3 IOException (java.io.IOException)2 Project (aQute.bnd.build.Project)1 Workspace (aQute.bnd.build.Workspace)1 BndEditModel (aQute.bnd.build.model.BndEditModel)1 BndEditor (bndtools.editor.BndEditor)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)1 IResourceDelta (org.eclipse.core.resources.IResourceDelta)1 IPath (org.eclipse.core.runtime.IPath)1 Control (org.eclipse.swt.widgets.Control)1 Display (org.eclipse.swt.widgets.Display)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IFileEditorInput (org.eclipse.ui.IFileEditorInput)1 ScrolledForm (org.eclipse.ui.forms.widgets.ScrolledForm)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1