Search in sources :

Example 1 with SpecfilePackage

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage in project linuxtools by eclipse.

the class SpecStructureCreator method parseSpecfile.

private void parseSpecfile(DocumentRangeNode root, IDocument doc, IFile file) {
    SpecfileParser parser = new SpecfileParser();
    // FIXME: error markers do not show
    if (file != null) {
        FileEditorInput fei = new FileEditorInput(file);
        // without it, the compare editor is blank
        try {
            SpecfileEditor.getSpecfileDocumentProvider().disconnect(fei);
            SpecfileEditor.getSpecfileDocumentProvider().connect(fei);
        } catch (CoreException e) {
            SpecfileLog.logError(e);
        }
        parser.setErrorHandler(new SpecfileErrorHandler(fei, doc));
        parser.setTaskHandler(new SpecfileTaskHandler(fei, doc));
        Specfile specfile = parser.parse(doc);
        String id = specfile.getName();
        // Be a child under parent node of specfileSectionRoot (would be
        // rootNode)
        SpecNode fileNode = new SpecNode((DocumentRangeNode) root.getParentNode(), 1, id, doc, 0, doc.getLength());
        for (SpecfileSection sec : specfile.getSections()) {
            try {
                addNode(root, doc, sec.getName(), doc.getLineOffset(sec.getLineNumber()), doc.getLineOffset(sec.getSectionEndLine()) - doc.getLineOffset(sec.getLineNumber()), 2);
            } catch (BadLocationException e) {
                SpecfileLog.logError(e);
            }
        }
        // Be a child under the parent file node
        for (SpecfilePackage sPackage : specfile.getPackages().getPackages()) {
            try {
                SpecNode pNode = addNode(fileNode, doc, sPackage.getPackageName(), doc.getLineOffset(sPackage.getLineNumber()), doc.getLineOffset(sPackage.getSectionEndLine()) - doc.getLineOffset(sPackage.getLineNumber()), 3);
                for (SpecfileSection section : sPackage.getSections()) {
                    addNode(pNode, doc, section.getName(), doc.getLineOffset(section.getLineNumber()), doc.getLineOffset(section.getSectionEndLine()) - doc.getLineOffset(section.getLineNumber()), 4);
                }
            } catch (BadLocationException e) {
                SpecfileLog.logError(e);
            }
        }
    }
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) SpecfileSection(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection) SpecfileTaskHandler(org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileTaskHandler) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) SpecfileErrorHandler(org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileErrorHandler) SpecfileParser(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser) SpecfilePackage(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with SpecfilePackage

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage in project linuxtools by eclipse.

the class MainPackagePage method createFormContent.

@Override
protected void createFormContent(IManagedForm managedForm) {
    super.createFormContent(managedForm);
    FormToolkit toolkit = managedForm.getToolkit();
    ScrolledForm form = managedForm.getForm();
    form.setText(Messages.MainPackagePage_2);
    GridLayout layout = new GridLayout();
    layout.marginWidth = layout.marginHeight = 5;
    layout.numColumns = 2;
    RowLayout rowLayout = new RowLayout();
    rowLayout.type = SWT.VERTICAL;
    rowLayout.justify = true;
    rowLayout.fill = true;
    form.getBody().setLayout(rowLayout);
    form.getBody().setLayoutData(rowLayout);
    layout.numColumns = 2;
    GridData gd = new GridData();
    gd.horizontalSpan = 2;
    gd.horizontalAlignment = SWT.FILL;
    final Section mainPackageSection = toolkit.createSection(form.getBody(), ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
    mainPackageSection.setText(Messages.MainPackagePage_3);
    mainPackageSection.setLayout(new GridLayout());
    Composite mainPackageClient = toolkit.createComposite(mainPackageSection);
    GridLayout gridLayout = new GridLayout();
    gridLayout.marginWidth = gridLayout.marginHeight = 5;
    gridLayout.numColumns = 2;
    mainPackageClient.setLayout(gridLayout);
    new RpmTagText(mainPackageClient, RpmTags.NAME, specfile);
    new RpmTagText(mainPackageClient, RpmTags.VERSION, specfile);
    new RpmTagText(mainPackageClient, RpmTags.RELEASE, specfile);
    new RpmTagText(mainPackageClient, RpmTags.URL, specfile);
    new RpmTagText(mainPackageClient, RpmTags.LICENSE, specfile);
    new RpmTagText(mainPackageClient, RpmTags.GROUP, specfile);
    new RpmTagText(mainPackageClient, RpmTags.EPOCH, specfile);
    new RpmTagText(mainPackageClient, RpmTags.BUILD_ROOT, specfile);
    new RpmTagText(mainPackageClient, RpmTags.BUILD_ARCH, specfile);
    new RpmTagText(mainPackageClient, RpmTags.SUMMARY, specfile, SWT.MULTI);
    // BuildRequires
    final Section buildRequiresSection = toolkit.createSection(mainPackageClient, ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
    buildRequiresSection.setText(Messages.MainPackagePage_4);
    buildRequiresSection.setLayout(rowLayout);
    buildRequiresSection.setExpanded(false);
    Composite buildRequiresClient = toolkit.createComposite(buildRequiresSection);
    buildRequiresClient.setLayout(gridLayout);
    for (SpecfileTag buildRequire : specfile.getBuildRequires()) {
        new RpmTagText(buildRequiresClient, buildRequire, specfile);
    }
    buildRequiresSection.setClient(buildRequiresClient);
    toolkit.paintBordersFor(buildRequiresClient);
    toolkit.paintBordersFor(buildRequiresSection);
    // Requires
    final Section requiresSection = toolkit.createSection(mainPackageClient, ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
    requiresSection.setText(Messages.MainPackagePage_5);
    requiresSection.setLayout(rowLayout);
    requiresSection.setExpanded(false);
    Composite requiresClient = toolkit.createComposite(requiresSection);
    requiresClient.setLayout(gridLayout);
    requiresClient.setLayoutData(gd);
    for (SpecfileTag require : specfile.getRequires()) {
        new RpmTagText(requiresClient, require, specfile);
    }
    requiresSection.setClient(requiresClient);
    toolkit.paintBordersFor(requiresClient);
    toolkit.paintBordersFor(requiresSection);
    mainPackageSection.setClient(mainPackageClient);
    toolkit.paintBordersFor(mainPackageClient);
    toolkit.paintBordersFor(mainPackageSection);
    // subpackages
    final Section packagesSection = toolkit.createSection(form.getBody(), ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
    packagesSection.setText(Messages.MainPackagePage_6);
    packagesSection.setLayout(gridLayout);
    Composite packagesClient = toolkit.createComposite(packagesSection);
    packagesClient.setLayout(gridLayout);
    packagesClient.setLayoutData(gd);
    for (SpecfilePackage specfilePackage : specfile.getPackages().getPackages()) {
        if (specfilePackage.isMainPackage()) {
            continue;
        }
        final Section packageSection = toolkit.createSection(packagesClient, ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
        packageSection.setText(specfilePackage.getFullPackageName());
        packageSection.setExpanded(false);
        packageSection.setLayout(rowLayout);
        Composite packageClient = toolkit.createComposite(packageSection);
        packageClient.setLayout(gridLayout);
        packageClient.setLayoutData(gd);
        new RpmTagText(packageClient, RpmTags.SUMMARY, specfile, specfilePackage, SWT.MULTI);
        new RpmTagText(packageClient, RpmTags.GROUP, specfile, specfilePackage, SWT.MULTI);
        final Section packageRequiresSection = toolkit.createSection(packageClient, ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
        packageRequiresSection.setText(Messages.MainPackagePage_7);
        packageRequiresSection.setLayout(rowLayout);
        packageRequiresSection.setLayoutData(gd);
        Composite packageRequiresClient = toolkit.createComposite(packageRequiresSection);
        packageRequiresClient.setLayout(gridLayout);
        packageRequiresClient.setLayoutData(gd);
        for (SpecfileTag require : specfilePackage.getRequires()) {
            new RpmTagText(packageRequiresClient, require, specfile);
        }
        packageRequiresSection.setClient(packageRequiresClient);
        toolkit.paintBordersFor(packageRequiresClient);
        toolkit.paintBordersFor(packageRequiresSection);
        packageSection.setClient(packageClient);
        toolkit.paintBordersFor(packageClient);
        toolkit.paintBordersFor(packageSection);
    }
    packagesSection.setClient(packagesClient);
    toolkit.paintBordersFor(packagesClient);
    toolkit.paintBordersFor(packagesSection);
    managedForm.refresh();
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) SpecfileTag(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileTag) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) Section(org.eclipse.ui.forms.widgets.Section) SpecfilePackage(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage)

Example 3 with SpecfilePackage

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage in project linuxtools by eclipse.

the class SpecfileLabelProvider method getText.

@Override
public String getText(Object element) {
    // $NON-NLS-1$
    String str = "";
    if (element instanceof SpecfileSection) {
        SpecfileSection specfileSection = (SpecfileSection) element;
        str = specfileSection.toString();
    } else if (element instanceof Specfile) {
        str = ((Specfile) element).getName();
    } else if (element instanceof SpecfilePackageContainer) {
        str = Messages.SpecfileLabelProvider_0;
    } else if (element instanceof SpecfilePreamble) {
        str = Messages.SpecfileLabelProvider_1;
    } else if (element instanceof SpecfileElement) {
        SpecfileElement specfileElement = (SpecfileElement) element;
        str = specfileElement.getName();
    } else if (element instanceof String) {
        str = (String) element;
    } else if (element instanceof SpecfilePackage) {
        str = ((SpecfilePackage) element).getName();
    }
    return filterMacros(str.trim());
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) SpecfileSection(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection) SpecfileElement(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement) SpecfilePreamble(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfilePreamble) SpecfilePackage(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage) SpecfilePackageContainer(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackageContainer)

Aggregations

SpecfilePackage (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage)3 Specfile (org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile)2 SpecfileSection (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection)2 CoreException (org.eclipse.core.runtime.CoreException)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 SpecfilePreamble (org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfilePreamble)1 SpecfileTag (org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileTag)1 SpecfileErrorHandler (org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileErrorHandler)1 SpecfileTaskHandler (org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileTaskHandler)1 SpecfileElement (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement)1 SpecfilePackageContainer (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackageContainer)1 SpecfileParser (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)1 FormToolkit (org.eclipse.ui.forms.widgets.FormToolkit)1 ScrolledForm (org.eclipse.ui.forms.widgets.ScrolledForm)1 Section (org.eclipse.ui.forms.widgets.Section)1