Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i_943 Fix Group tab on Edit Problem #944

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 26 additions & 36 deletions src/edu/csus/ecs/pc2/ui/ProblemGroupPane.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 1989-2019 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
// Copyright (C) 1989-2024 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
package edu.csus.ecs.pc2.ui;

import java.awt.Color;
Expand All @@ -12,7 +12,6 @@
import javax.swing.DefaultListModel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.ListModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

Expand All @@ -21,13 +20,13 @@

/**
* Edit groups that can view this Problem.
*
*
* @author Douglas A. Lane, PC^2 Team, [email protected]
*/
public class ProblemGroupPane extends JPanePlugin {

/**
*
*
*/
private static final long serialVersionUID = 6334530401574768488L;

Expand All @@ -39,18 +38,18 @@ public class ProblemGroupPane extends JPanePlugin {
* Model containing checkboxes
*/
private DefaultListModel<WrapperJCheckBox> groupListModel = new DefaultListModel<WrapperJCheckBox>();

private JCheckBoxJList groupListBox = null;

private JScrollPane groupsScrollPane = null;

private ButtonGroup groupsSelectedButtonGroup = null;

private EditProblemPane parentPane;
private EditProblemPane parentPane;

/**
* This method initializes groupListBox
*
*
* @return javax.swing.JList
*/
public JCheckBoxJList getGroupListBox() {
Expand All @@ -76,6 +75,7 @@ public ProblemGroupPane() {

allGroupsRadioButton = new JRadioButton("Show to all groups");
allGroupsRadioButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
parentPane.enableUpdateButton();
enableGroupCheckBoxes(false);
Expand All @@ -87,6 +87,7 @@ public void actionPerformed(ActionEvent e) {

selectGroupsRadioButton = new JRadioButton("Show to only these groups");
selectGroupsRadioButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
parentPane.enableUpdateButton();
enableGroupCheckBoxes(true);
Expand All @@ -101,29 +102,17 @@ public void actionPerformed(ActionEvent e) {


/**
* Enable or disable Group Checkboxes
* Enable or disable Group Checkboxs by enabling/disabling the JCheckboxJList
*/
protected void enableGroupCheckBoxes(boolean enable) {

ListModel<Object> list = getGroupListBox().getModel();

if (!enable) {
getGroupListBox().clearSelection();
getGroupListBox().setForeground(Color.GRAY);
} else {
getGroupListBox().setForeground(Color.BLACK);
}

for (int i = 0; i < list.getSize(); i++) {
Object ele = list.getElementAt(i);
if (ele instanceof WrapperJCheckBox) {
WrapperJCheckBox box = (WrapperJCheckBox) ele;

box.setEnabled(enable);

}

}
getGroupListBox().setEnabled(enable);
}

@Override
Expand All @@ -132,15 +121,15 @@ public String getPluginTitle() {
}

public void setProblem(Problem problem) {

groupListModel.removeAllElements(); // clear checkbox

populateProblemGroups(problem);

}

private void populateProblemGroups(Problem problem) {

boolean allGroupsSelected = true;
if (problem != null) {
allGroupsSelected = problem.isAllView();
Expand All @@ -151,24 +140,25 @@ private void populateProblemGroups(Problem problem) {
} else {
selectGroupsRadioButton.setSelected(true);
}

enableGroupCheckBoxes(true);


// Enable/Disable the checkbox list box depending on whether "all groups" can view the problem
enableGroupCheckBoxes(!allGroupsSelected);

Group[] groups = getContest().getGroups();
for (Group group : groups) {

WrapperJCheckBox wrapperJCheckBox = new WrapperJCheckBox(group);
wrapperJCheckBox.setSelected(allGroupsSelected || problem.canView(group));
wrapperJCheckBox.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
parentPane.enableUpdateButton();
}
});

groupListModel.addElement(wrapperJCheckBox);
}

enableGroupCheckBoxes(! allGroupsSelected);
}

public List<Group> getGroups() {
Expand All @@ -179,14 +169,14 @@ public List<Group> getGroups() {

Enumeration<WrapperJCheckBox> enumeration = groupListModel.elements();
while (enumeration.hasMoreElements()) {
WrapperJCheckBox element = (WrapperJCheckBox) enumeration.nextElement();
WrapperJCheckBox element = enumeration.nextElement();
if (element.isSelected()) {
Group group = (Group) element.getContents();
groups.add(group);
}
}
}

return groups;
}

Expand All @@ -199,11 +189,11 @@ private ButtonGroup getValidatorChoiceButtonGroup() {
return groupsSelectedButtonGroup;
}



public void setParentPane(EditProblemPane editProblemPane) {
parentPane = editProblemPane;


}
}
Loading