Search in sources :

Example 1 with NativeDesktop

use of org.jabref.gui.desktop.os.NativeDesktop in project jabref by JabRef.

the class OpenOfficePanel method showManualConnectionDialog.

private void showManualConnectionDialog() {
    dialogOkPressed = false;
    final JDialog cDiag = new JDialog(frame, Localization.lang("Set connection parameters"), true);
    final NativeDesktop nativeDesktop = JabRefDesktop.getNativeDesktop();
    final DialogService dirDialog = new FXDialogService();
    DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder().withInitialDirectory(nativeDesktop.getApplicationDirectory()).build();
    FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(nativeDesktop.getApplicationDirectory()).build();
    DialogService fileDialog = new FXDialogService();
    // Path fields
    final JTextField ooPath = new JTextField(30);
    JButton browseOOPath = new JButton(Localization.lang("Browse"));
    ooPath.setText(preferences.getInstallationPath());
    browseOOPath.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> dirDialog.showDirectorySelectionDialog(dirDialogConfiguration)).ifPresent(f -> ooPath.setText(f.toAbsolutePath().toString())));
    final JTextField ooExec = new JTextField(30);
    JButton browseOOExec = new JButton(Localization.lang("Browse"));
    ooExec.setText(preferences.getExecutablePath());
    browseOOExec.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> fileDialog.showFileOpenDialog(fileDialogConfiguration)).ifPresent(f -> ooExec.setText(f.toAbsolutePath().toString())));
    final JTextField ooJars = new JTextField(30);
    ooJars.setText(preferences.getJarsPath());
    JButton browseOOJars = new JButton(Localization.lang("Browse"));
    browseOOJars.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> dirDialog.showDirectorySelectionDialog(dirDialogConfiguration)).ifPresent(f -> ooJars.setText(f.toAbsolutePath().toString())));
    FormBuilder builder = FormBuilder.create().layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "pref"));
    if (OS.WINDOWS || OS.OS_X) {
        builder.add(Localization.lang("Path to OpenOffice/LibreOffice directory")).xy(1, 1);
        builder.add(ooPath).xy(3, 1);
        builder.add(browseOOPath).xy(5, 1);
    } else {
        builder.add(Localization.lang("Path to OpenOffice/LibreOffice executable")).xy(1, 1);
        builder.add(ooExec).xy(3, 1);
        builder.add(browseOOExec).xy(5, 1);
        builder.appendRows("4dlu, pref");
        builder.add(Localization.lang("Path to OpenOffice/LibreOffice library dir")).xy(1, 3);
        builder.add(ooJars).xy(3, 3);
        builder.add(browseOOJars).xy(5, 3);
    }
    builder.padding("5dlu, 5dlu, 5dlu, 5dlu");
    cDiag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    // Buttons
    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    ok.addActionListener(e -> {
        if (OS.WINDOWS || OS.OS_X) {
            preferences.updateConnectionParams(ooPath.getText(), ooPath.getText(), ooPath.getText());
        } else {
            preferences.updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText());
        }
        dialogOkPressed = true;
        cDiag.dispose();
    });
    cancel.addActionListener(e -> cDiag.dispose());
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addRelatedGap();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    bb.padding("5dlu, 5dlu, 5dlu, 5dlu");
    cDiag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    // Finish and show dirDialog
    cDiag.pack();
    cDiag.setLocationRelativeTo(frame);
    cDiag.setVisible(true);
}
Also used : JDialog(javax.swing.JDialog) OpenOfficePreferences(org.jabref.logic.openoffice.OpenOfficePreferences) URL(java.net.URL) BibDatabase(org.jabref.model.database.BibDatabase) AbstractWorker(org.jabref.gui.worker.AbstractWorker) IconTheme(org.jabref.gui.IconTheme) NativeDesktop(org.jabref.gui.desktop.os.NativeDesktop) BasePanel(org.jabref.gui.BasePanel) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) URLClassLoader(java.net.URLClassLoader) JabRefFrame(org.jabref.gui.JabRefFrame) SidePaneManager(org.jabref.gui.SidePaneManager) UnknownPropertyException(com.sun.star.beans.UnknownPropertyException) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) Method(java.lang.reflect.Method) Path(java.nio.file.Path) HelpFile(org.jabref.logic.help.HelpFile) PropertyVetoException(com.sun.star.beans.PropertyVetoException) BibEntry(org.jabref.model.entry.BibEntry) IllegalTypeException(com.sun.star.beans.IllegalTypeException) Icon(javax.swing.Icon) FXDialogService(org.jabref.gui.FXDialogService) StyleLoader(org.jabref.logic.openoffice.StyleLoader) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DefaultTaskExecutor(org.jabref.gui.util.DefaultTaskExecutor) Dimension(java.awt.Dimension) List(java.util.List) WrappedTargetException(com.sun.star.lang.WrappedTargetException) AbstractAction(javax.swing.AbstractAction) BibtexKeyPatternUtil(org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil) FormLayout(com.jgoodies.forms.layout.FormLayout) OS(org.jabref.logic.util.OS) Optional(java.util.Optional) BootstrapException(com.sun.star.comp.helper.BootstrapException) LogFactory(org.apache.commons.logging.LogFactory) UndoableKeyChange(org.jabref.gui.undo.UndoableKeyChange) JPanel(javax.swing.JPanel) KeyBinding(org.jabref.gui.keyboard.KeyBinding) HelpAction(org.jabref.gui.help.HelpAction) NamedCompound(org.jabref.gui.undo.NamedCompound) JTextField(javax.swing.JTextField) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) JabRefDesktop(org.jabref.gui.desktop.JabRefDesktop) DialogService(org.jabref.gui.DialogService) Action(javax.swing.Action) SidePaneComponent(org.jabref.gui.SidePaneComponent) ArrayList(java.util.ArrayList) JMenuItem(javax.swing.JMenuItem) OOBibStyle(org.jabref.logic.openoffice.OOBibStyle) DirectoryDialogConfiguration(org.jabref.gui.util.DirectoryDialogConfiguration) Localization(org.jabref.logic.l10n.Localization) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) JComponent(javax.swing.JComponent) FormBuilder(com.jgoodies.forms.builder.FormBuilder) FileUtil(org.jabref.logic.util.io.FileUtil) JButton(javax.swing.JButton) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) NoSuchElementException(com.sun.star.container.NoSuchElementException) ButtonGroup(javax.swing.ButtonGroup) JPopupMenu(javax.swing.JPopupMenu) UndefinedParagraphFormatException(org.jabref.logic.openoffice.UndefinedParagraphFormatException) IOException(java.io.IOException) JOptionPane(javax.swing.JOptionPane) NotRemoveableException(com.sun.star.beans.NotRemoveableException) ActionEvent(java.awt.event.ActionEvent) Globals(org.jabref.Globals) Paths(java.nio.file.Paths) PropertyExistException(com.sun.star.beans.PropertyExistException) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) Log(org.apache.commons.logging.Log) Defaults(org.jabref.model.Defaults) BibtexKeyPatternPreferences(org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) FXDialogService(org.jabref.gui.FXDialogService) DialogService(org.jabref.gui.DialogService) NativeDesktop(org.jabref.gui.desktop.os.NativeDesktop) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) FormBuilder(com.jgoodies.forms.builder.FormBuilder) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) FXDialogService(org.jabref.gui.FXDialogService) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) DirectoryDialogConfiguration(org.jabref.gui.util.DirectoryDialogConfiguration) JDialog(javax.swing.JDialog)

Example 2 with NativeDesktop

use of org.jabref.gui.desktop.os.NativeDesktop in project jabref by JabRef.

the class DetectOpenOfficeInstallation method selectInstallationPath.

private Optional<Path> selectInstallationPath() {
    final NativeDesktop nativeDesktop = JabRefDesktop.getNativeDesktop();
    JOptionPane.showMessageDialog(parent, Localization.lang("Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually."), Localization.lang("Could not find OpenOffice/LibreOffice installation"), JOptionPane.INFORMATION_MESSAGE);
    DialogService ds = new FXDialogService();
    DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder().withInitialDirectory(nativeDesktop.getApplicationDirectory()).build();
    Optional<Path> path = DefaultTaskExecutor.runInJavaFXThread(() -> ds.showDirectorySelectionDialog(dirDialogConfiguration));
    if (path.isPresent()) {
        return path;
    }
    return Optional.empty();
}
Also used : FXDialogService(org.jabref.gui.FXDialogService) Path(java.nio.file.Path) DialogService(org.jabref.gui.DialogService) FXDialogService(org.jabref.gui.FXDialogService) NativeDesktop(org.jabref.gui.desktop.os.NativeDesktop) DirectoryDialogConfiguration(org.jabref.gui.util.DirectoryDialogConfiguration) FormBuilder(com.jgoodies.forms.builder.FormBuilder)

Aggregations

FormBuilder (com.jgoodies.forms.builder.FormBuilder)2 Path (java.nio.file.Path)2 DialogService (org.jabref.gui.DialogService)2 FXDialogService (org.jabref.gui.FXDialogService)2 NativeDesktop (org.jabref.gui.desktop.os.NativeDesktop)2 DirectoryDialogConfiguration (org.jabref.gui.util.DirectoryDialogConfiguration)2 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)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 PropertyVetoException (com.sun.star.beans.PropertyVetoException)1 UnknownPropertyException (com.sun.star.beans.UnknownPropertyException)1 BootstrapException (com.sun.star.comp.helper.BootstrapException)1 NoSuchElementException (com.sun.star.container.NoSuchElementException)1 WrappedTargetException (com.sun.star.lang.WrappedTargetException)1 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 FileNotFoundException (java.io.FileNotFoundException)1