Example usage for org.eclipse.jgit.transport CredentialItem isValueSecure

List of usage examples for org.eclipse.jgit.transport CredentialItem isValueSecure

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport CredentialItem isValueSecure.

Prototype

public boolean isValueSecure() 

Source Link

Document

Whether the value should be masked when entered.

Usage

From source file:org.eclipse.egit.ui.internal.dialogs.CustomPromptDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    editingControls = new ArrayList<Control>(credentialItems.length);

    Composite main = (Composite) super.createDialogArea(parent);
    GridLayout mainLayout = (GridLayout) main.getLayout();
    mainLayout.numColumns = 2;/*from w w  w  .ja va 2s. com*/

    Label infoLabel = new Label(main, SWT.NONE);
    GridDataFactory.defaultsFor(infoLabel).span(2, 1).applyTo(infoLabel);
    String tempInfoText = hasEditingItems() ? UIText.CustomPromptDialog_provide_information_for
            : UIText.CustomPromptDialog_information_about;
    infoLabel.setText(NLS.bind(tempInfoText, uri.toString()));

    for (CredentialItem item : credentialItems) {
        Label label = new Label(main, SWT.NONE);
        label.setText(item.getPromptText());
        GridDataFactory.defaultsFor(label).applyTo(label);

        if (item instanceof CharArrayType || item instanceof StringType) {
            Text text = new Text(main, SWT.BORDER | (item.isValueSecure() ? SWT.PASSWORD : SWT.NONE));
            GridDataFactory.defaultsFor(text).applyTo(text);
            text.setData(KEY_ITEM, item);
            editingControls.add(text);
        } else if (item instanceof YesNoType) {
            Button checkBox = new Button(main, SWT.CHECK);
            GridDataFactory.defaultsFor(checkBox).applyTo(checkBox);
            editingControls.add(checkBox);
        } else {
            // unknown type, not editable
            Label dummy = new Label(main, SWT.NONE);
            GridDataFactory.fillDefaults().applyTo(dummy);
        }
    }

    return main;
}

From source file:serendipitytranslator.mainWindow.MainFrame.java

License:Open Source License

private void initApplication() {
    try {/*from w ww . j  a  v a 2s .c  om*/
        l.addHandler(new FileHandler("error.log"));
    } catch (IOException ex) {
        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    }

    executorService = Executors.newSingleThreadExecutor();
    PluginList.setSettings(settingsDialog);
    language = settingsDialog.getLanguage();
    settingsDialog.setMainWindowSizeAndPosition(this);
    translateFrame.setLocation(this.getX() + this.getWidth(), 0);
    progressBar.setVisible(false);
    cancelButton.setVisible(false);

    settingsDialog.addPropertyChangeListener(this);

    pluginTable.setModel(new PluginTableModel(plugins));
    pluginTable.setColumnModel(new PluginColumnModel());

    pluginTable.setDefaultRenderer(PluginStatus.class, new PluginTableRenderer());
    pluginTable.setDefaultRenderer(DocumentationStatus.class, new PluginTableRenderer());

    TableRowSorter sorter = new TableRowSorter<PluginTableModel>((PluginTableModel) pluginTable.getModel());
    sorter.setRowFilter(new RowFilter<PluginTableModel, Integer>() {
        @Override
        public boolean include(Entry<? extends PluginTableModel, ? extends Integer> entry) {
            PluginTableModel tableModel = entry.getModel();
            PluginStatus status = (PluginStatus) tableModel.getValueAt(entry.getIdentifier(), 5);
            DocumentationStatus docStatus = (DocumentationStatus) tableModel.getValueAt(entry.getIdentifier(),
                    7);
            return !(settingsDialog.isShowEmptyPlugins() && status.equals(PluginStatus.problem)
                    && docStatus.equals(DocumentationStatus.problem));
        }

    });
    pluginTable.setRowSorter(sorter);

    translateFrame.addPropertyChangeListener(this);

    try {
        updateApplication();
    } catch (MalformedURLException ex) {
        Logger.getLogger(MainFrame.class.getName()).log(Level.INFO, ex.getMessage());
    } catch (IOException ex) {
        Logger.getLogger(MainFrame.class.getName()).log(Level.INFO, ex.getMessage());
    }

    JschConfigSessionFactory sessionFactory = new JschConfigSessionFactory() {
        @Override
        protected void configure(OpenSshConfig.Host hc, Session session) {
            CredentialsProvider provider = new CredentialsProvider() {
                @Override
                public boolean isInteractive() {
                    System.out.println("CredentialProvider: check if interactive");
                    return false;
                }

                @Override
                public boolean supports(CredentialItem... items) {
                    System.out.println("CredentialProvider: request if next items are supported");
                    for (CredentialItem ci : items) {
                        System.out.println("\t\t" + ci.getClass().getName() + "; " + ci.getPromptText()
                                + "; secured = " + ci.isValueSecure());
                    }
                    return true;
                }

                @Override
                public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem {
                    System.out.println("CredentialProvider: item request for URI: " + uri);
                    for (CredentialItem item : items) {
                        System.out.println("\t\t setting item: class = " + item.getClass().getName()
                                + "; prompt = " + item.getPromptText() + "; string = " + item.toString()
                                + "; secure = " + item.isValueSecure());
                        JPanel userPanel = new JPanel();
                        JLabel passwordLbl = new JLabel(item.getPromptText());
                        JPasswordField pf = new JPasswordField();
                        userPanel.setLayout(new GridLayout(2, 1));
                        userPanel.add(passwordLbl);
                        userPanel.add(pf);
                        int okCxl = JOptionPane.showConfirmDialog(null, userPanel, "Set password",
                                JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

                        if (okCxl == JOptionPane.OK_OPTION) {
                            String password = new String(pf.getPassword());
                            //System.err.println("You entered: " + password);
                            ((CredentialItem.StringType) item).setValue(password);
                        }
                    }
                    return true;
                }
            };
            UserInfo userInfo = new CredentialsProviderUserInfo(session, provider);
            session.setUserInfo(userInfo);
        }
    };
    SshSessionFactory.setInstance(sessionFactory);

    updateLanguage();
}