Search in sources :

Example 1 with UndefinedParagraphFormatException

use of org.jabref.logic.openoffice.UndefinedParagraphFormatException in project jabref by JabRef.

the class OpenOfficePanel method pushEntries.

private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addPageInfo) {
    if (!ooBase.isConnectedToDocument()) {
        JOptionPane.showMessageDialog(frame, Localization.lang("Not connected to any Writer document. Please" + " make sure a document is open, and use the 'Select Writer document' button to connect to it."), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    Boolean inParenthesis = inParenthesisIn;
    String pageInfo = null;
    if (addPageInfo) {
        AdvancedCiteDialog citeDialog = new AdvancedCiteDialog(frame);
        citeDialog.showDialog();
        if (citeDialog.canceled()) {
            return;
        }
        if (!citeDialog.getPageInfo().isEmpty()) {
            pageInfo = citeDialog.getPageInfo();
        }
        inParenthesis = citeDialog.isInParenthesisCite();
    }
    BasePanel panel = frame.getCurrentBasePanel();
    if (panel != null) {
        final BibDatabase database = panel.getDatabase();
        List<BibEntry> entries = panel.getSelectedEntries();
        if (!entries.isEmpty() && checkThatEntriesHaveKeys(entries)) {
            try {
                if (style == null) {
                    style = loader.getUsedStyle();
                }
                ooBase.insertEntry(entries, database, getBaseList(), style, inParenthesis, withText, pageInfo, preferences.syncWhenCiting());
            } catch (FileNotFoundException ex) {
                JOptionPane.showMessageDialog(frame, Localization.lang("You must select either a valid style file, or use one of the default styles."), Localization.lang("No valid style file defined"), JOptionPane.ERROR_MESSAGE);
                LOGGER.warn("Problem with style file", ex);
            } catch (ConnectionLostException ex) {
                showConnectionLostErrorMessage();
            } catch (UndefinedCharacterFormatException ex) {
                reportUndefinedCharacterFormat(ex);
            } catch (UndefinedParagraphFormatException ex) {
                reportUndefinedParagraphFormat(ex);
            } catch (com.sun.star.lang.IllegalArgumentException | UnknownPropertyException | PropertyVetoException | CreationException | NoSuchElementException | WrappedTargetException | IOException | BibEntryNotFoundException | IllegalTypeException | PropertyExistException | NotRemoveableException ex) {
                LOGGER.warn("Could not insert entry", ex);
            }
        }
    }
}
Also used : BasePanel(org.jabref.gui.BasePanel) WrappedTargetException(com.sun.star.lang.WrappedTargetException) IllegalTypeException(com.sun.star.beans.IllegalTypeException) NotRemoveableException(com.sun.star.beans.NotRemoveableException) FileNotFoundException(java.io.FileNotFoundException) PropertyExistException(com.sun.star.beans.PropertyExistException) BibEntry(org.jabref.model.entry.BibEntry) IOException(java.io.IOException) UnknownPropertyException(com.sun.star.beans.UnknownPropertyException) PropertyVetoException(com.sun.star.beans.PropertyVetoException) BibDatabase(org.jabref.model.database.BibDatabase) UndefinedParagraphFormatException(org.jabref.logic.openoffice.UndefinedParagraphFormatException) NoSuchElementException(com.sun.star.container.NoSuchElementException)

Example 2 with UndefinedParagraphFormatException

use of org.jabref.logic.openoffice.UndefinedParagraphFormatException in project jabref by JabRef.

the class OpenOfficePanel method initPanel.

private void initPanel() {
    connect.addActionListener(e -> connect(true));
    manualConnect.addActionListener(e -> connect(false));
    selectDocument.setToolTipText(Localization.lang("Select which open Writer document to work on"));
    selectDocument.addActionListener(e -> {
        try {
            ooBase.selectDocument();
            frame.output(Localization.lang("Connected to document") + ": " + ooBase.getCurrentDocumentTitle().orElse(""));
        } catch (UnknownPropertyException | WrappedTargetException | IndexOutOfBoundsException | NoSuchElementException | NoDocumentException ex) {
            JOptionPane.showMessageDialog(frame, ex.getMessage(), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
            LOGGER.warn("Problem connecting", ex);
        }
    });
    setStyleFile.addActionListener(event -> {
        if (styleDialog == null) {
            styleDialog = new StyleSelectDialog(frame, preferences, loader);
        }
        styleDialog.setVisible(true);
        styleDialog.getStyle().ifPresent(selectedStyle -> {
            style = selectedStyle;
            try {
                style.ensureUpToDate();
            } catch (IOException e) {
                LOGGER.warn("Unable to reload style file '" + style.getPath() + "'", e);
            }
            frame.setStatus(Localization.lang("Current style is '%0'", style.getName()));
        });
    });
    pushEntries.setToolTipText(Localization.lang("Cite selected entries between parenthesis"));
    pushEntries.addActionListener(e -> pushEntries(true, true, false));
    pushEntriesInt.setToolTipText(Localization.lang("Cite selected entries with in-text citation"));
    pushEntriesInt.addActionListener(e -> pushEntries(false, true, false));
    pushEntriesEmpty.setToolTipText(Localization.lang("Insert a citation without text (the entry will appear in the reference list)"));
    pushEntriesEmpty.addActionListener(e -> pushEntries(false, false, false));
    pushEntriesAdvanced.setToolTipText(Localization.lang("Cite selected entries with extra information"));
    pushEntriesAdvanced.addActionListener(e -> pushEntries(false, true, true));
    update.setToolTipText(Localization.lang("Ensure that the bibliography is up-to-date"));
    Action updateAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                if (style == null) {
                    style = loader.getUsedStyle();
                } else {
                    style.ensureUpToDate();
                }
                ooBase.updateSortedReferenceMarks();
                List<BibDatabase> databases = getBaseList();
                List<String> unresolvedKeys = ooBase.refreshCiteMarkers(databases, style);
                ooBase.rebuildBibTextSection(databases, style);
                if (!unresolvedKeys.isEmpty()) {
                    JOptionPane.showMessageDialog(frame, Localization.lang("Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current library.", unresolvedKeys.get(0)), Localization.lang("Unable to synchronize bibliography"), JOptionPane.ERROR_MESSAGE);
                }
            } catch (UndefinedCharacterFormatException ex) {
                reportUndefinedCharacterFormat(ex);
            } catch (UndefinedParagraphFormatException ex) {
                reportUndefinedParagraphFormat(ex);
            } catch (ConnectionLostException ex) {
                showConnectionLostErrorMessage();
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(frame, Localization.lang("You must select either a valid style file, or use one of the default styles."), Localization.lang("No valid style file defined"), JOptionPane.ERROR_MESSAGE);
                LOGGER.warn("Problem with style file", ex);
            } catch (BibEntryNotFoundException ex) {
                JOptionPane.showMessageDialog(frame, Localization.lang("Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current library.", ex.getBibtexKey()), Localization.lang("Unable to synchronize bibliography"), JOptionPane.ERROR_MESSAGE);
                LOGGER.debug("BibEntry not found", ex);
            } catch (com.sun.star.lang.IllegalArgumentException | PropertyVetoException | UnknownPropertyException | WrappedTargetException | NoSuchElementException | CreationException ex) {
                LOGGER.warn("Could not update bibliography", ex);
            }
        }
    };
    update.addActionListener(updateAction);
    merge.setToolTipText(Localization.lang("Combine pairs of citations that are separated by spaces only"));
    merge.addActionListener(e -> {
        try {
            ooBase.combineCiteMarkers(getBaseList(), style);
        } catch (UndefinedCharacterFormatException ex) {
            reportUndefinedCharacterFormat(ex);
        } catch (com.sun.star.lang.IllegalArgumentException | UnknownPropertyException | PropertyVetoException | CreationException | NoSuchElementException | WrappedTargetException | IOException | BibEntryNotFoundException ex) {
            LOGGER.warn("Problem combining cite markers", ex);
        }
    });
    settingsB.addActionListener(e -> showSettingsPopup());
    manageCitations.addActionListener(e -> {
        try {
            CitationManager cm = new CitationManager(frame, ooBase);
            cm.showDialog();
        } catch (NoSuchElementException | WrappedTargetException | UnknownPropertyException ex) {
            LOGGER.warn("Problem showing citation manager", ex);
        }
    });
    exportCitations.addActionListener(event -> exportEntries());
    selectDocument.setEnabled(false);
    pushEntries.setEnabled(false);
    pushEntriesInt.setEnabled(false);
    pushEntriesEmpty.setEnabled(false);
    pushEntriesAdvanced.setEnabled(false);
    update.setEnabled(false);
    merge.setEnabled(false);
    manageCitations.setEnabled(false);
    exportCitations.setEnabled(false);
    diag = new JDialog((JFrame) null, "OpenOffice/LibreOffice panel", false);
    FormBuilder mainBuilder = FormBuilder.create().layout(new FormLayout("fill:pref:grow", "p,p,p,p,p,p,p,p,p,p,p"));
    FormBuilder topRowBuilder = FormBuilder.create().layout(new FormLayout("fill:pref:grow, 1dlu, fill:pref:grow, 1dlu, fill:pref:grow, 1dlu, fill:pref:grow, 1dlu, fill:pref", "pref"));
    topRowBuilder.add(connect).xy(1, 1);
    topRowBuilder.add(manualConnect).xy(3, 1);
    topRowBuilder.add(selectDocument).xy(5, 1);
    topRowBuilder.add(update).xy(7, 1);
    topRowBuilder.add(help).xy(9, 1);
    mainBuilder.add(topRowBuilder.getPanel()).xy(1, 1);
    mainBuilder.add(setStyleFile).xy(1, 2);
    mainBuilder.add(pushEntries).xy(1, 3);
    mainBuilder.add(pushEntriesInt).xy(1, 4);
    mainBuilder.add(pushEntriesAdvanced).xy(1, 5);
    mainBuilder.add(pushEntriesEmpty).xy(1, 6);
    mainBuilder.add(merge).xy(1, 7);
    mainBuilder.add(manageCitations).xy(1, 8);
    mainBuilder.add(exportCitations).xy(1, 9);
    mainBuilder.add(settingsB).xy(1, 10);
    JPanel content = new JPanel();
    sidePane.setContentContainer(content);
    content.setLayout(new BorderLayout());
    content.add(mainBuilder.getPanel(), BorderLayout.CENTER);
    frame.getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(Globals.getKeyPrefs().getKey(KeyBinding.REFRESH_OO), "Refresh OO");
    frame.getTabbedPane().getActionMap().put("Refresh OO", updateAction);
}
Also used : JPanel(javax.swing.JPanel) AbstractAction(javax.swing.AbstractAction) HelpAction(org.jabref.gui.help.HelpAction) Action(javax.swing.Action) WrappedTargetException(com.sun.star.lang.WrappedTargetException) ActionEvent(java.awt.event.ActionEvent) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) AbstractAction(javax.swing.AbstractAction) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) IOException(java.io.IOException) UnknownPropertyException(com.sun.star.beans.UnknownPropertyException) PropertyVetoException(com.sun.star.beans.PropertyVetoException) BibDatabase(org.jabref.model.database.BibDatabase) NoSuchElementException(com.sun.star.container.NoSuchElementException) UndefinedParagraphFormatException(org.jabref.logic.openoffice.UndefinedParagraphFormatException) JDialog(javax.swing.JDialog)

Aggregations

PropertyVetoException (com.sun.star.beans.PropertyVetoException)2 UnknownPropertyException (com.sun.star.beans.UnknownPropertyException)2 NoSuchElementException (com.sun.star.container.NoSuchElementException)2 WrappedTargetException (com.sun.star.lang.WrappedTargetException)2 IOException (java.io.IOException)2 UndefinedParagraphFormatException (org.jabref.logic.openoffice.UndefinedParagraphFormatException)2 BibDatabase (org.jabref.model.database.BibDatabase)2 FormBuilder (com.jgoodies.forms.builder.FormBuilder)1 FormLayout (com.jgoodies.forms.layout.FormLayout)1 IllegalTypeException (com.sun.star.beans.IllegalTypeException)1 NotRemoveableException (com.sun.star.beans.NotRemoveableException)1 PropertyExistException (com.sun.star.beans.PropertyExistException)1 BorderLayout (java.awt.BorderLayout)1 ActionEvent (java.awt.event.ActionEvent)1 FileNotFoundException (java.io.FileNotFoundException)1 AbstractAction (javax.swing.AbstractAction)1 Action (javax.swing.Action)1 JDialog (javax.swing.JDialog)1 JFrame (javax.swing.JFrame)1 JPanel (javax.swing.JPanel)1