Search in sources :

Example 1 with SettingModel

use of com.gitblit.models.SettingModel in project gitblit by gitblit.

the class RuntimeManager method getSettingsModel.

@Override
public ServerSettings getSettingsModel() {
    // ensure that the current values are updated in the setting models
    for (String key : settings.getAllKeys(null)) {
        SettingModel setting = settingsModel.get(key);
        if (setting == null) {
            // unreferenced setting, create a setting model
            setting = new SettingModel();
            setting.name = key;
            settingsModel.add(setting);
        }
        setting.currentValue = settings.getString(key, "");
    }
    // settingsModel.pushScripts = getAllScripts();
    return settingsModel;
}
Also used : SettingModel(com.gitblit.models.SettingModel)

Example 2 with SettingModel

use of com.gitblit.models.SettingModel in project gitblit by gitblit.

the class SettingsTableModel method getValueAt.

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    String key = keys.get(rowIndex);
    SettingModel setting = settings.get(key);
    Columns col = Columns.values()[columnIndex];
    switch(col) {
        case Name:
            return key;
        case Value:
            return setting;
        case Since:
            return setting.since;
    }
    return null;
}
Also used : SettingModel(com.gitblit.models.SettingModel)

Example 3 with SettingModel

use of com.gitblit.models.SettingModel in project gitblit by gitblit.

the class SettingsPanel method initialize.

private void initialize() {
    JButton refreshSettings = new JButton(Translation.get("gb.refresh"));
    refreshSettings.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refreshSettings();
        }
    });
    final JButton editSetting = new JButton(Translation.get("gb.edit"));
    editSetting.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int viewRow = table.getSelectedRow();
            int modelRow = table.convertRowIndexToModel(viewRow);
            String key = tableModel.keys.get(modelRow);
            SettingModel setting = tableModel.settings.get(key);
            editSetting(setting);
        }
    });
    NameRenderer nameRenderer = new NameRenderer();
    final SettingPanel settingPanel = new SettingPanel();
    tableModel = new SettingsTableModel();
    defaultSorter = new TableRowSorter<SettingsTableModel>(tableModel);
    table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
    table.setDefaultRenderer(SettingModel.class, new SettingCellRenderer());
    String name = table.getColumnName(UsersTableModel.Columns.Name.ordinal());
    table.getColumn(name).setCellRenderer(nameRenderer);
    table.setRowSorter(defaultSorter);
    table.getRowSorter().toggleSortOrder(SettingsTableModel.Columns.Name.ordinal());
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            boolean singleSelection = table.getSelectedRows().length == 1;
            editSetting.setEnabled(singleSelection);
            if (singleSelection) {
                int viewRow = table.getSelectedRow();
                int modelRow = table.convertRowIndexToModel(viewRow);
                SettingModel setting = tableModel.get(modelRow);
                settingPanel.setSetting(setting);
            } else {
                settingPanel.clear();
            }
        }
    });
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                int viewRow = table.getSelectedRow();
                int modelRow = table.convertRowIndexToModel(viewRow);
                SettingModel setting = tableModel.get(modelRow);
                editSetting(setting);
            }
        }
    });
    filterTextfield = new JTextField();
    filterTextfield.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            filterSettings(filterTextfield.getText());
        }
    });
    filterTextfield.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            filterSettings(filterTextfield.getText());
        }
    });
    JPanel settingFilterPanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    settingFilterPanel.add(new JLabel(Translation.get("gb.filter")), BorderLayout.WEST);
    settingFilterPanel.add(filterTextfield, BorderLayout.CENTER);
    JPanel settingsTablePanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    settingsTablePanel.add(settingFilterPanel, BorderLayout.NORTH);
    settingsTablePanel.add(new JScrollPane(table), BorderLayout.CENTER);
    settingsTablePanel.add(settingPanel, BorderLayout.SOUTH);
    JPanel settingsControls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
    settingsControls.add(refreshSettings);
    settingsControls.add(editSetting);
    setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    header = new HeaderPanel(Translation.get("gb.settings"), "settings_16x16.png");
    add(header, BorderLayout.NORTH);
    add(settingsTablePanel, BorderLayout.CENTER);
    add(settingsControls, BorderLayout.SOUTH);
}
Also used : SettingModel(com.gitblit.models.SettingModel) JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) ListSelectionListener(javax.swing.event.ListSelectionListener) KeyEvent(java.awt.event.KeyEvent) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout)

Example 4 with SettingModel

use of com.gitblit.models.SettingModel in project gitblit by gitblit.

the class GitblitManager method loadSettingModels.

/**
 * Parse the properties file and aggregate all the comments by the setting
 * key. A setting model tracks the current value, the default value, the
 * description of the setting and and directives about the setting.
 *
 * @return Map<String, SettingModel>
 */
private void loadSettingModels(ServerSettings settingsModel) {
    try {
        // Read bundled Gitblit properties to extract setting descriptions.
        // This copy is pristine and only used for populating the setting
        // models map.
        InputStream is = GitblitManager.class.getResourceAsStream("/defaults.properties");
        BufferedReader propertiesReader = new BufferedReader(new InputStreamReader(is));
        StringBuilder description = new StringBuilder();
        SettingModel setting = new SettingModel();
        String line = null;
        while ((line = propertiesReader.readLine()) != null) {
            if (line.length() == 0) {
                description.setLength(0);
                setting = new SettingModel();
            } else {
                if (line.charAt(0) == '#') {
                    if (line.length() > 1) {
                        String text = line.substring(1).trim();
                        if (SettingModel.CASE_SENSITIVE.equals(text)) {
                            setting.caseSensitive = true;
                        } else if (SettingModel.RESTART_REQUIRED.equals(text)) {
                            setting.restartRequired = true;
                        } else if (SettingModel.SPACE_DELIMITED.equals(text)) {
                            setting.spaceDelimited = true;
                        } else if (text.startsWith(SettingModel.SINCE)) {
                            try {
                                setting.since = text.split(" ")[1];
                            } catch (Exception e) {
                                setting.since = text;
                            }
                        } else {
                            description.append(text);
                            description.append('\n');
                        }
                    }
                } else {
                    String[] kvp = line.split("=", 2);
                    String key = kvp[0].trim();
                    setting.name = key;
                    setting.defaultValue = kvp[1].trim();
                    setting.currentValue = setting.defaultValue;
                    setting.description = description.toString().trim();
                    settingsModel.add(setting);
                    description.setLength(0);
                    setting = new SettingModel();
                }
            }
        }
        propertiesReader.close();
    } catch (NullPointerException e) {
        logger.error("Failed to find classpath resource 'defaults.properties'");
    } catch (IOException e) {
        logger.error("Failed to load classpath resource 'defaults.properties'");
    }
}
Also used : SettingModel(com.gitblit.models.SettingModel) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) JsonIOException(com.google.gson.JsonIOException) IOException(java.io.IOException) JsonIOException(com.google.gson.JsonIOException) GitBlitException(com.gitblit.GitBlitException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException)

Example 5 with SettingModel

use of com.gitblit.models.SettingModel in project gitblit by gitblit.

the class SettingCellRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    if (value instanceof SettingModel) {
        SettingModel setting = (SettingModel) value;
        if (setting.isDefaultValue()) {
            this.setFont(defaultFont);
            if (!isSelected) {
                this.setForeground(Color.BLACK);
            }
        } else {
            this.setFont(modifiedFont);
            if (!isSelected) {
                this.setForeground(Color.BLUE);
            }
        }
        this.setText(setting.getString(""));
    }
    return this;
}
Also used : SettingModel(com.gitblit.models.SettingModel)

Aggregations

SettingModel (com.gitblit.models.SettingModel)6 GitBlitException (com.gitblit.GitBlitException)1 JsonIOException (com.google.gson.JsonIOException)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 BorderLayout (java.awt.BorderLayout)1 FlowLayout (java.awt.FlowLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 JButton (javax.swing.JButton)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1