@Subscribe public void listen(ConnectionLostEvent connectionLostEvent) { jabRefFrame.output(Localization.lang("Connection lost.")); String[] options = { Localization.lang("Reconnect"), Localization.lang("Work offline"), Localization.lang("Close database") }; int answer = JOptionPane.showOptionDialog( jabRefFrame, Localization.lang("The connection to the server has been terminated.") + "\n\n", Localization.lang("Connection lost"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); if (answer == 0) { jabRefFrame.closeCurrentTab(); OpenSharedDatabaseDialog openSharedDatabaseDialog = new OpenSharedDatabaseDialog(jabRefFrame); openSharedDatabaseDialog.setVisible(true); } else if (answer == 1) { connectionLostEvent.getBibDatabaseContext().convertToLocalDatabase(); jabRefFrame.refreshTitleAndTabs(); jabRefFrame.updateEnabledState(); jabRefFrame.output(Localization.lang("Working offline.")); } else { jabRefFrame.closeCurrentTab(); } }
@Override public void actionPerformed(ActionEvent e) { databases = frame.getTabbedPane().getTabCount(); saved = 0; frame.output(Localization.lang("Saving all databases...")); Spin.off(this); run(); frame.output(Localization.lang("Save all finished.")); }
@Override public void action() { try { NamedCompound ce = new NamedCompound(undoText); BibtexEntry[] bes = frame.basePanel().getSelectedEntries(); if (bes == null) { return; } for (BibtexEntry be : bes) { // if (value==null) and then call nullField has been ommited as updatefield also handles // value==null SpecialFieldsUtils.updateField(c, value, be, ce, nullFieldIfValueIsTheSame); } ce.end(); if (ce.hasEdits()) { frame.basePanel().undoManager.addEdit(ce); frame.basePanel().markBaseChanged(); frame.basePanel().updateEntryEditorIfShowing(); String outText; if (nullFieldIfValueIsTheSame) { outText = Localization.lang(doneTextPattern, Integer.toString(bes.length)); } else { outText = Localization.lang(doneTextPattern, value, Integer.toString(bes.length)); } frame.output(outText); } else { // if user does not change anything with his action, we do not do anything either // even no output message } } catch (Throwable ex) { ex.printStackTrace(); } }
@Override public void actionPerformed(ActionEvent e) { boolean success = openLink(); if (!success) { frame.output(Localization.lang("Unable to open link.")); } }
public boolean openLink() { frame.output(Localization.lang("External viewer called") + "."); try { ExternalFileType type = fileType; if (this.fileType == null) { if (this.fieldName == null) { // We don't already know the file type, so we try to deduce it from the extension: File file = new File(link); // We try to check the extension for the file: String name = file.getName(); int pos = name.indexOf('.'); String extension = (pos >= 0) && (pos < (name.length() - 1)) ? name.substring(pos + 1).trim().toLowerCase() : null; // Now we know the extension, check if it is one we know about: type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(extension); fileType = type; } else { JabRefDesktop.openExternalViewer( frame.getCurrentBasePanel().getBibDatabaseContext().getMetaData(), link, fieldName); return true; } } if (type instanceof UnknownExternalFileType) { return JabRefDesktop.openExternalFileUnknown( frame, entry, metaData, link, (UnknownExternalFileType) type); } else { return JabRefDesktop.openExternalFileAnyFormat(metaData, link, type); } } catch (IOException e1) { // See if we should show an error message concerning the application to open the // link with. We check if the file type is set, and if the file type has a non-empty // application link. If that link is referred by the error message, we can assume // that the problem is in the open-with-application setting: if ((fileType != null) && (fileType.getOpenWith() != null) && !fileType.getOpenWith().isEmpty() && e1.getMessage().contains(fileType.getOpenWith())) { JOptionPane.showMessageDialog( frame, Localization.lang( "Unable to open link. " + "The application '%0' associated with the file type '%1' could not be called.", fileType.getOpenWith(), fileType.getName()), Localization.lang("Could not open link"), JOptionPane.ERROR_MESSAGE); return false; } LOGGER.warn("Unable to open link", e1); } return false; }
@Subscribe public void listen(UpdateRefusedEvent updateRefusedEvent) { jabRefFrame.output(Localization.lang("Update refused.")); new MergeSharedEntryDialog( jabRefFrame, dbmsSynchronizer, updateRefusedEvent.getLocalBibEntry(), updateRefusedEvent.getSharedBibEntry(), updateRefusedEvent.getBibDatabaseContext().getMode()) .showMergeDialog(); }
@Override public void update() { if (databases == null) { return; } for (DBImporterResult res : databases) { databaseContext = res.getDatabaseContext(); if (databaseContext != null) { BasePanel pan = frame.addTab(databaseContext, true); pan.getBibDatabaseContext().getMetaData().setDBStrings(dbs); frame.setTabTitle(pan, res.getName() + "(Imported)", "Imported DB"); pan.markBaseChanged(); } } frame.output( Localization.lang( "Imported %0 databases successfully", Integer.toString(databases.size()))); }
/** * Opens a new shared database tab with the given {@link DBMSConnectionProperties}. * * @param dbmsConnectionProperties Connection data * @param raiseTab If <code>true</code> the new tab gets selected. */ private void openNewSharedDatabaseTab( DBMSConnectionProperties dbmsConnectionProperties, boolean raiseTab) throws SQLException, DatabaseNotSupportedException { JabRefFrame frame = JabRefGUI.getMainFrame(); BibDatabaseMode selectedMode = Globals.prefs.getDefaultBibDatabaseMode(); BibDatabaseContext bibDatabaseContext = new BibDatabaseContext( new Defaults(selectedMode), DatabaseLocation.SHARED, Globals.prefs.getKeywordDelimiter()); dbmsSynchronizer = bibDatabaseContext.getDBMSSynchronizer(); dbmsSynchronizer.openSharedDatabase(dbmsConnectionProperties); frame.addTab(bibDatabaseContext, raiseTab); dbmsSynchronizer.registerListener(this); frame.output( Localization.lang( "Connection_to_%0_server_established.", dbmsConnectionProperties.getType().toString())); }
private void performImport() { if (!connectedToDB) { return; } frame.output(Localization.lang("Attempting SQL import...")); DBExporterAndImporterFactory factory = new DBExporterAndImporterFactory(); DatabaseImporter importer = factory.getImporter(dbs.getDbPreferences().getServerType()); try { try (Connection conn = importer.connectToDB(dbs); Statement statement = conn.createStatement(); ResultSet rs = statement.executeQuery(SQLUtil.queryAllFromTable("jabref_database"))) { Vector<Vector<String>> matrix = new Vector<>(); while (rs.next()) { Vector<String> v = new Vector<>(); v.add(rs.getString("database_name")); matrix.add(v); } if (matrix.isEmpty()) { JOptionPane.showMessageDialog( frame, Localization.lang("There are no available databases to be imported"), Localization.lang("Import from SQL database"), JOptionPane.INFORMATION_MESSAGE); } else { DBImportExportDialog dialogo = new DBImportExportDialog(frame, matrix, DBImportExportDialog.DialogType.IMPORTER); if (dialogo.removeAction) { String dbName = dialogo.selectedDB; DatabaseUtil.removeDB(dialogo, dbName, conn, databaseContext); performImport(); } else if (dialogo.moreThanOne) { databases = importer.performImport( dbs, dialogo.listOfDBs, frame.getCurrentBasePanel().getBibDatabaseContext().getMode()); for (DBImporterResult res : databases) { databaseContext = res.getDatabaseContext(); dbs.isConfigValid(true); } frame.output( Localization.lang( "%0 databases will be imported", Integer.toString(databases.size()))); } else { frame.output(Localization.lang("Importing canceled")); } } } } catch (Exception ex) { String preamble = Localization.lang("Could not import from SQL database for the following reason:"); String errorMessage = SQLUtil.getExceptionMessage(ex); dbs.isConfigValid(false); JOptionPane.showMessageDialog( frame, preamble + '\n' + errorMessage, Localization.lang("Import from SQL database"), JOptionPane.ERROR_MESSAGE); frame.output(Localization.lang("Error importing from database")); LOGGER.error("Error importing from database", ex); } }