| | |
| | | import java.awt.Insets;
|
| | | import java.awt.event.ActionEvent;
|
| | | import java.awt.event.ActionListener;
|
| | | import java.awt.event.ItemEvent;
|
| | | import java.awt.event.ItemListener;
|
| | | import java.awt.event.KeyEvent;
|
| | | import java.text.MessageFormat;
|
| | | import java.util.ArrayList;
|
| | |
| | | import java.util.Set;
|
| | |
|
| | | import javax.swing.BoxLayout;
|
| | | import javax.swing.ButtonGroup;
|
| | | import javax.swing.DefaultComboBoxModel;
|
| | | import javax.swing.DefaultListCellRenderer;
|
| | | import javax.swing.ImageIcon;
|
| | | import javax.swing.JButton;
|
| | | import javax.swing.JCheckBox;
|
| | |
| | | import javax.swing.JList;
|
| | | import javax.swing.JOptionPane;
|
| | | import javax.swing.JPanel;
|
| | | import javax.swing.JRadioButton;
|
| | | import javax.swing.JRootPane;
|
| | | import javax.swing.JScrollPane;
|
| | | import javax.swing.JTabbedPane;
|
| | |
| | | import javax.swing.ScrollPaneConstants;
|
| | |
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.Constants.AuthorizationControl;
|
| | | import com.gitblit.Constants.FederationStrategy;
|
| | | import com.gitblit.Constants.RegistrantType;
|
| | | import com.gitblit.models.RegistrantAccessPermission;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.utils.ArrayUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | |
| | | private JTextField mailingListsField;
|
| | |
|
| | | private JComboBox accessRestriction;
|
| | | |
| | | private JRadioButton allowAuthenticated;
|
| | | |
| | | private JRadioButton allowNamed;
|
| | | |
| | | private JCheckBox allowForks;
|
| | |
|
| | | private JCheckBox verifyCommitter;
|
| | |
|
| | | private JComboBox federationStrategy;
|
| | |
|
| | | private JComboBox ownerField;
|
| | |
|
| | | private JComboBox headRefField;
|
| | | |
| | | private JComboBox gcPeriod;
|
| | | |
| | | private JTextField gcThreshold;
|
| | |
|
| | | private JPalette<String> usersPalette;
|
| | | private RegistrantPermissionsPanel usersPalette;
|
| | |
|
| | | private JPalette<String> setsPalette;
|
| | |
|
| | | private JPalette<String> teamsPalette;
|
| | | private RegistrantPermissionsPanel teamsPalette;
|
| | |
|
| | | private JPalette<String> indexedBranchesPalette;
|
| | |
|
| | |
| | | anRepository.availableRefs.toArray());
|
| | | headRefField.setSelectedItem(anRepository.HEAD);
|
| | | }
|
| | | |
| | | Integer [] gcPeriods = { 1, 2, 3, 4, 5, 7, 10, 14 };
|
| | | gcPeriod = new JComboBox(gcPeriods);
|
| | | gcPeriod.setSelectedItem(anRepository.gcPeriod);
|
| | | |
| | | gcThreshold = new JTextField(8);
|
| | | gcThreshold.setText(anRepository.gcThreshold);
|
| | |
|
| | | ownerField = new JComboBox();
|
| | |
|
| | |
| | | accessRestriction = new JComboBox(AccessRestrictionType.values());
|
| | | accessRestriction.setRenderer(new AccessRestrictionRenderer());
|
| | | accessRestriction.setSelectedItem(anRepository.accessRestriction);
|
| | | accessRestriction.addItemListener(new ItemListener() {
|
| | | @Override
|
| | | public void itemStateChanged(ItemEvent e) {
|
| | | if (e.getStateChange() == ItemEvent.SELECTED) {
|
| | | AccessRestrictionType art = (AccessRestrictionType) accessRestriction.getSelectedItem();
|
| | | EditRepositoryDialog.this.setupAccessPermissions(art);
|
| | | }
|
| | | }
|
| | | });
|
| | | |
| | | boolean authenticated = anRepository.authorizationControl != null |
| | | && AuthorizationControl.AUTHENTICATED.equals(anRepository.authorizationControl);
|
| | | allowAuthenticated = new JRadioButton(Translation.get("gb.allowAuthenticatedDescription"));
|
| | | allowAuthenticated.setSelected(authenticated);
|
| | | allowAuthenticated.addItemListener(new ItemListener() {
|
| | | @Override
|
| | | public void itemStateChanged(ItemEvent e) {
|
| | | if (e.getStateChange() == ItemEvent.SELECTED) {
|
| | | usersPalette.setEnabled(false);
|
| | | teamsPalette.setEnabled(false);
|
| | | }
|
| | | }
|
| | | });
|
| | | |
| | | allowNamed = new JRadioButton(Translation.get("gb.allowNamedDescription"));
|
| | | allowNamed.setSelected(!authenticated);
|
| | | allowNamed.addItemListener(new ItemListener() {
|
| | | @Override
|
| | | public void itemStateChanged(ItemEvent e) {
|
| | | if (e.getStateChange() == ItemEvent.SELECTED) {
|
| | | usersPalette.setEnabled(true);
|
| | | teamsPalette.setEnabled(true);
|
| | | }
|
| | | }
|
| | | });
|
| | | |
| | | ButtonGroup group = new ButtonGroup();
|
| | | group.add(allowAuthenticated);
|
| | | group.add(allowNamed);
|
| | | |
| | | JPanel authorizationPanel = new JPanel(new GridLayout(0, 1));
|
| | | authorizationPanel.add(allowAuthenticated);
|
| | | authorizationPanel.add(allowNamed);
|
| | | |
| | | allowForks = new JCheckBox(Translation.get("gb.allowForksDescription"), anRepository.allowForks);
|
| | | verifyCommitter = new JCheckBox(Translation.get("gb.verifyCommitterDescription"), anRepository.verifyCommitter);
|
| | |
|
| | | // federation strategies - remove ORIGIN choice if this repository has
|
| | | // no origin.
|
| | |
| | | fieldsPanel
|
| | | .add(newFieldPanel(Translation.get("gb.origin"), originField));
|
| | | fieldsPanel.add(newFieldPanel(Translation.get("gb.headRef"), headRefField));
|
| | | fieldsPanel.add(newFieldPanel(Translation.get("gb.owner"), ownerField));
|
| | | fieldsPanel.add(newFieldPanel(Translation.get("gb.gcPeriod"), gcPeriod));
|
| | | fieldsPanel.add(newFieldPanel(Translation.get("gb.gcThreshold"), gcThreshold));
|
| | |
|
| | | fieldsPanel.add(newFieldPanel(Translation.get("gb.enableTickets"),
|
| | | useTickets));
|
| | |
| | | skipSizeCalculation));
|
| | | fieldsPanel.add(newFieldPanel(Translation.get("gb.skipSummaryMetrics"),
|
| | | skipSummaryMetrics));
|
| | | fieldsPanel
|
| | | .add(newFieldPanel(Translation.get("gb.isFrozen"), isFrozen));
|
| | | fieldsPanel.add(newFieldPanel(Translation.get("gb.mailingLists"),
|
| | | mailingListsField));
|
| | |
|
| | | usersPalette = new JPalette<String>();
|
| | | JPanel clonePushPanel = new JPanel(new GridLayout(0, 1));
|
| | | clonePushPanel
|
| | | .add(newFieldPanel(Translation.get("gb.isFrozen"), isFrozen));
|
| | | clonePushPanel
|
| | | .add(newFieldPanel(Translation.get("gb.allowForks"), allowForks));
|
| | | clonePushPanel
|
| | | .add(newFieldPanel(Translation.get("gb.verifyCommitter"), verifyCommitter));
|
| | |
|
| | | usersPalette = new RegistrantPermissionsPanel(RegistrantType.USER);
|
| | |
|
| | | JPanel northFieldsPanel = new JPanel(new GridLayout(0, 1, 0, 5));
|
| | | northFieldsPanel.add(newFieldPanel(Translation.get("gb.owner"), ownerField));
|
| | | northFieldsPanel.add(newFieldPanel(Translation.get("gb.accessRestriction"),
|
| | | accessRestriction), BorderLayout.NORTH);
|
| | |
|
| | | JPanel northAccessPanel = new JPanel(new BorderLayout(5, 5));
|
| | | northAccessPanel.add(northFieldsPanel, BorderLayout.NORTH);
|
| | | northAccessPanel.add(newFieldPanel(Translation.get("gb.authorizationControl"),
|
| | | authorizationPanel), BorderLayout.CENTER);
|
| | | northAccessPanel.add(clonePushPanel, BorderLayout.SOUTH);
|
| | |
|
| | | JPanel accessPanel = new JPanel(new BorderLayout(5, 5));
|
| | | accessPanel.add(
|
| | | newFieldPanel(Translation.get("gb.accessRestriction"),
|
| | | accessRestriction), BorderLayout.NORTH);
|
| | | accessPanel.add(
|
| | | newFieldPanel(Translation.get("gb.permittedUsers"),
|
| | | accessPanel.add(northAccessPanel, BorderLayout.NORTH);
|
| | | accessPanel.add(newFieldPanel(Translation.get("gb.userPermissions"),
|
| | | usersPalette), BorderLayout.CENTER);
|
| | |
|
| | | teamsPalette = new JPalette<String>();
|
| | | teamsPalette = new RegistrantPermissionsPanel(RegistrantType.TEAM);
|
| | | JPanel teamsPanel = new JPanel(new BorderLayout(5, 5));
|
| | | teamsPanel.add(
|
| | | newFieldPanel(Translation.get("gb.permittedTeams"),
|
| | | newFieldPanel(Translation.get("gb.teamPermissions"),
|
| | | teamsPalette), BorderLayout.CENTER);
|
| | |
|
| | | setsPalette = new JPalette<String>();
|
| | |
| | |
|
| | | panel.addTab(Translation.get("gb.customFields"), customFieldsScrollPane);
|
| | |
|
| | |
|
| | | setupAccessPermissions(anRepository.accessRestriction);
|
| | |
|
| | | JButton createButton = new JButton(Translation.get("gb.save"));
|
| | | createButton.addActionListener(new ActionListener() {
|
| | |
| | | panel.add(fieldLabel);
|
| | | panel.add(comp);
|
| | | return panel;
|
| | | }
|
| | | |
| | | private void setupAccessPermissions(AccessRestrictionType art) {
|
| | | if (AccessRestrictionType.NONE.equals(art)) {
|
| | | usersPalette.setEnabled(false);
|
| | | teamsPalette.setEnabled(false);
|
| | | |
| | | allowAuthenticated.setEnabled(false);
|
| | | allowNamed.setEnabled(false);
|
| | | } else {
|
| | | allowAuthenticated.setEnabled(true);
|
| | | allowNamed.setEnabled(true);
|
| | | |
| | | if (allowNamed.isSelected()) {
|
| | | usersPalette.setEnabled(true);
|
| | | teamsPalette.setEnabled(true);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | private boolean validateFields() {
|
| | |
| | | : ownerField.getSelectedItem().toString();
|
| | | repository.HEAD = headRefField.getSelectedItem() == null ? null
|
| | | : headRefField.getSelectedItem().toString();
|
| | | repository.gcPeriod = (Integer) gcPeriod.getSelectedItem();
|
| | | repository.gcThreshold = gcThreshold.getText();
|
| | | repository.useTickets = useTickets.isSelected();
|
| | | repository.useDocs = useDocs.isSelected();
|
| | | repository.showRemoteBranches = showRemoteBranches.isSelected();
|
| | | repository.showReadme = showReadme.isSelected();
|
| | | repository.skipSizeCalculation = skipSizeCalculation.isSelected();
|
| | | repository.skipSummaryMetrics = skipSummaryMetrics.isSelected();
|
| | | |
| | | repository.isFrozen = isFrozen.isSelected();
|
| | | repository.allowForks = allowForks.isSelected();
|
| | | repository.verifyCommitter = verifyCommitter.isSelected();
|
| | |
|
| | | String ml = mailingListsField.getText();
|
| | | if (!StringUtils.isEmpty(ml)) {
|
| | |
| | |
|
| | | repository.accessRestriction = (AccessRestrictionType) accessRestriction
|
| | | .getSelectedItem();
|
| | | repository.authorizationControl = allowAuthenticated.isSelected() ? |
| | | AuthorizationControl.AUTHENTICATED : AuthorizationControl.NAMED;
|
| | | repository.federationStrategy = (FederationStrategy) federationStrategy
|
| | | .getSelectedItem();
|
| | |
|
| | |
| | |
|
| | | public void setAccessRestriction(AccessRestrictionType restriction) {
|
| | | this.accessRestriction.setSelectedItem(restriction);
|
| | | setupAccessPermissions(restriction);
|
| | | }
|
| | |
|
| | | public void setUsers(String owner, List<String> all, List<String> selected) {
|
| | | public void setAuthorizationControl(AuthorizationControl authorization) {
|
| | | boolean authenticated = authorization != null && AuthorizationControl.AUTHENTICATED.equals(authorization);
|
| | | this.allowAuthenticated.setSelected(authenticated);
|
| | | this.allowNamed.setSelected(!authenticated);
|
| | | }
|
| | |
|
| | | public void setUsers(String owner, List<String> all, List<RegistrantAccessPermission> permissions) {
|
| | | ownerField.setModel(new DefaultComboBoxModel(all.toArray()));
|
| | | if (!StringUtils.isEmpty(owner)) {
|
| | | ownerField.setSelectedItem(owner);
|
| | | }
|
| | | usersPalette.setObjects(all, selected);
|
| | | usersPalette.setObjects(all, permissions);
|
| | | }
|
| | |
|
| | | public void setTeams(List<String> all, List<String> selected) {
|
| | | teamsPalette.setObjects(all, selected);
|
| | | public void setTeams(List<String> all, List<RegistrantAccessPermission> permissions) {
|
| | | teamsPalette.setObjects(all, permissions);
|
| | | }
|
| | |
|
| | | public void setRepositories(List<RepositoryModel> repositories) {
|
| | |
| | | return repository;
|
| | | }
|
| | |
|
| | | public List<String> getPermittedUsers() {
|
| | | return usersPalette.getSelections();
|
| | | public List<RegistrantAccessPermission> getUserAccessPermissions() {
|
| | | return usersPalette.getPermissions();
|
| | | }
|
| | |
|
| | | public List<String> getPermittedTeams() {
|
| | | return teamsPalette.getSelections();
|
| | | public List<RegistrantAccessPermission> getTeamAccessPermissions() {
|
| | | return teamsPalette.getPermissions();
|
| | | }
|
| | |
|
| | | public void setCustomFields(RepositoryModel repository, Map<String, String> customFields) {
|
| | |
| | | * restriction.
|
| | | *
|
| | | */
|
| | | private class AccessRestrictionRenderer extends JLabel implements
|
| | | ListCellRenderer {
|
| | | private class AccessRestrictionRenderer extends DefaultListCellRenderer {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | @Override
|
| | | public Component getListCellRendererComponent(JList list, Object value,
|
| | | int index, boolean isSelected, boolean cellHasFocus) {
|
| | | super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
| | | |
| | | if (value instanceof AccessRestrictionType) {
|
| | | AccessRestrictionType restriction = (AccessRestrictionType) value;
|
| | | switch (restriction) {
|