Search in sources :

Example 1 with DBMSType

use of org.jabref.shared.DBMSType in project jabref by JabRef.

the class ConnectToSharedDatabaseDialog method setupActions.

/**
     * Defines and sets the different actions up.
     */
private void setupActions() {
    Action openAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                checkFields();
                connectionProperties = new DBMSConnectionProperties();
                connectionProperties.setType((DBMSType) dbmsTypeDropDown.getSelectedItem());
                connectionProperties.setHost(hostField.getText());
                connectionProperties.setPort(Integer.parseInt(portField.getText()));
                connectionProperties.setDatabase(databaseField.getText());
                connectionProperties.setUser(userField.getText());
                //JPasswordField.getPassword() does not return a String, but a char array.
                connectionProperties.setPassword(new String(passwordField.getPassword()));
                openSharedDatabase();
            } catch (JabRefException exception) {
                JOptionPane.showMessageDialog(ConnectToSharedDatabaseDialog.this, exception.getMessage(), Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);
            }
        }
    };
    connectButton.addActionListener(openAction);
    cancelButton.addActionListener(e -> dispose());
    /**
         * Set up a listener which updates the default port number once the selection in dbmsTypeDropDown has changed.
         */
    Action dbmsTypeDropDownAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            portField.setText(Integer.toString(((DBMSType) dbmsTypeDropDown.getSelectedItem()).getDefaultPort()));
        }
    };
    dbmsTypeDropDown.addActionListener(dbmsTypeDropDownAction);
    // Add enter button action listener
    connectButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter_pressed");
    connectButton.getActionMap().put("Enter_pressed", openAction);
    browseButton.addActionListener(e -> showFileChooser());
    autosaveFile.addActionListener(e -> updateEnableState());
}
Also used : SaveDatabaseAction(org.jabref.gui.exporter.SaveDatabaseAction) AbstractAction(javax.swing.AbstractAction) HelpAction(org.jabref.gui.help.HelpAction) Action(javax.swing.Action) JabRefException(org.jabref.JabRefException) ActionEvent(java.awt.event.ActionEvent) DBMSType(org.jabref.shared.DBMSType) AbstractAction(javax.swing.AbstractAction) DBMSConnectionProperties(org.jabref.shared.DBMSConnectionProperties)

Example 2 with DBMSType

use of org.jabref.shared.DBMSType in project jabref by JabRef.

the class ConnectToSharedDatabaseDialog method initLayout.

/**
     * Set up the layout and position the control units in their right place.
     */
private void initLayout() {
    setResizable(false);
    Insets defautInsets = new Insets(4, 15, 4, 4);
    connectionPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), Localization.lang("Connection")));
    connectionPanel.setLayout(gridBagLayout);
    Set<DBMSType> availableDBMSTypes = DBMSConnection.getAvailableDBMSTypes();
    DefaultComboBoxModel<DBMSType> comboBoxModel = new DefaultComboBoxModel<>(availableDBMSTypes.toArray(new DBMSType[availableDBMSTypes.size()]));
    dbmsTypeDropDown.setModel(comboBoxModel);
    gridBagConstraints.insets = defautInsets;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagLayout.setConstraints(connectionPanel, gridBagConstraints);
    //1. column
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    connectionPanel.add(databaseTypeLabel, gridBagConstraints);
    gridBagConstraints.gridy = 1;
    connectionPanel.add(hostPortLabel, gridBagConstraints);
    gridBagConstraints.gridy = 2;
    connectionPanel.add(databaseLabel, gridBagConstraints);
    gridBagConstraints.gridy = 3;
    connectionPanel.add(userLabel, gridBagConstraints);
    gridBagConstraints.gridy = 4;
    connectionPanel.add(passwordLabel, gridBagConstraints);
    // 2. column
    gridBagConstraints.gridwidth = 2;
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    connectionPanel.add(dbmsTypeDropDown, gridBagConstraints);
    gridBagConstraints.gridy = 1;
    // the hostField is smaller than the others.
    gridBagConstraints.gridwidth = 1;
    gridBagConstraints.insets = new Insets(4, 15, 4, 0);
    connectionPanel.add(hostField, gridBagConstraints);
    gridBagConstraints.gridy = 2;
    gridBagConstraints.gridwidth = 2;
    gridBagConstraints.insets = defautInsets;
    connectionPanel.add(databaseField, gridBagConstraints);
    gridBagConstraints.gridy = 3;
    connectionPanel.add(userField, gridBagConstraints);
    gridBagConstraints.gridy = 4;
    connectionPanel.add(passwordField, gridBagConstraints);
    gridBagConstraints.gridy = 5;
    connectionPanel.add(rememberPassword, gridBagConstraints);
    // 3. column
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.gridwidth = 1;
    gridBagConstraints.insets = new Insets(4, 0, 4, 4);
    connectionPanel.add(portField, gridBagConstraints);
    // help button
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 6;
    gridBagConstraints.insets = new Insets(10, 10, 0, 0);
    JPanel helpPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    helpPanel.add(helpButton);
    // add panel
    getContentPane().setLayout(gridBagLayout);
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = 1;
    gridBagConstraints.insets = new Insets(5, 5, 5, 5);
    gridBagLayout.setConstraints(connectionPanel, gridBagConstraints);
    getContentPane().add(connectionPanel);
    // filePanel
    filePanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), Localization.lang("File")));
    filePanel.setLayout(gridBagLayout);
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = 2;
    filePanel.add(autosaveFile, gridBagConstraints);
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.gridwidth = 1;
    filePanel.add(fileLocationField, gridBagConstraints);
    gridBagConstraints.gridx = 2;
    filePanel.add(browseButton, gridBagConstraints);
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.insets = new Insets(5, 5, 5, 5);
    gridBagLayout.setConstraints(filePanel, gridBagConstraints);
    getContentPane().add(filePanel);
    // buttonPanel
    buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
    buttonPanel.add(connectButton);
    buttonPanel.add(cancelButton);
    buttonPanel.add(helpPanel);
    gridBagConstraints.gridy = 2;
    gridBagConstraints.insets = new Insets(5, 5, 5, 5);
    gridBagLayout.setConstraints(buttonPanel, gridBagConstraints);
    getContentPane().add(buttonPanel);
    // Owner window should be disabled while this dialog is opened.
    setModal(true);
}
Also used : JPanel(javax.swing.JPanel) Insets(java.awt.Insets) FlowLayout(java.awt.FlowLayout) DBMSType(org.jabref.shared.DBMSType) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Aggregations

DBMSType (org.jabref.shared.DBMSType)2 FlowLayout (java.awt.FlowLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 AbstractAction (javax.swing.AbstractAction)1 Action (javax.swing.Action)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 JPanel (javax.swing.JPanel)1 JabRefException (org.jabref.JabRefException)1 SaveDatabaseAction (org.jabref.gui.exporter.SaveDatabaseAction)1 HelpAction (org.jabref.gui.help.HelpAction)1 DBMSConnectionProperties (org.jabref.shared.DBMSConnectionProperties)1