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;
}
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;
}
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);
}
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'");
}
}
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;
}
Aggregations