Skip to content

Commit

Permalink
#52: keep required fields after clicking 'check only visible' button
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeFcosta committed Feb 13, 2023
1 parent 74216c1 commit 31dae56
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public List<String> getSelectedProperties() {
return selectedProperties;
}

protected void enableOnlySelectedProperties(List<String> props) {
protected void checkOnlySelectedProperties(List<String> props) {
for (Map.Entry<String, CheckBoxState> hmEntry : allCheckBoxesState.entrySet()) {
String nonLocalizedKey = LocalizedProperties.getNonLocalizedField(hmEntry.getKey());
if (props.contains(nonLocalizedKey)) {
Expand All @@ -442,11 +442,11 @@ protected void enableOnlySelectedProperties(List<String> props) {
}
}

protected void enableAllProperties() {
protected void checkAllProperties() {
allCheckBoxesState.replaceAll((name, state) -> state = new CheckBoxState(true));
}

protected void disableAllProperties() {
protected void uncheckAllProperties() {
allCheckBoxesState.replaceAll((name, state) -> state = new CheckBoxState(false));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,23 @@ protected ColumnsSelectReportUI() {

loadedSelectedProperties = ColumnsManager.loadSelectedFields(saveFileName);
if (loadedSelectedProperties != null) {
columnsManager.enableOnlySelectedProperties(loadedSelectedProperties);
columnsManager.checkOnlySelectedProperties(loadedSelectedProperties);
} else {
columnsManager.enableOnlySelectedProperties(Arrays.asList(basicReportProps));
columnsManager.checkOnlySelectedProperties(Arrays.asList(basicReportProps));
}
disableRequiredProperties();
disableRequiredPropertiesCheckBoxes();
updatePanelList();
}

@Override
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
if (e.getSource().equals(clearButton)) {
columnsManager.disableAllProperties();
disableRequiredProperties();
if (e.getSource().equals(selectVisibleButton)) {
disableRequiredPropertiesCheckBoxes();
updatePanelList();
} else if (e.getSource().equals(clearButton)) {
columnsManager.uncheckAllProperties();
disableRequiredPropertiesCheckBoxes();
updatePanelList();
} else if (e.getSource() instanceof JCheckBox || e.getSource().equals(selectVisibleButton)) {
if (columnsManager.getSelectedProperties().size() > PROPERTIES_LIMIT_NUM) {
Expand All @@ -98,15 +101,15 @@ public void actionPerformed(ActionEvent e) {
} else {
JOptionPane.showMessageDialog(dialog, Messages.getString("ColumnsManager.LimitReachedVisibleMessage", PROPERTIES_LIMIT_NUM),
Messages.getString("ColumnsManager.LimitReachedTitle"), JOptionPane.ERROR_MESSAGE);
columnsManager.enableOnlySelectedProperties(
columnsManager.checkOnlySelectedProperties(
columnsManager.colState.visibleFields.stream().limit(PROPERTIES_LIMIT_NUM).collect(Collectors.toList()));
}
updatePanelList();
}
}
}

public void disableRequiredProperties() {
public void disableRequiredPropertiesCheckBoxes() {
columnsManager.allCheckBoxesState.put(IndexItem.ID_IN_SOURCE, new CheckBoxState(true, false));
columnsManager.allCheckBoxesState.put(BasicProps.PATH, new CheckBoxState(true, false));
}
Expand Down
13 changes: 6 additions & 7 deletions iped-app/src/main/java/iped/app/ui/columns/ColumnsSelectUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,23 @@ public void windowClosing(WindowEvent e) {

loadedSelectedProperties = ColumnsManager.loadSelectedFields(saveFileName);
if (loadedSelectedProperties != null) {
columnsManager.enableOnlySelectedProperties(loadedSelectedProperties);
columnsManager.checkOnlySelectedProperties(loadedSelectedProperties);
} else {
columnsManager.enableOnlySelectedProperties(new ArrayList<String>(Arrays.asList(ResultTableModel.fields)));
columnsManager.checkOnlySelectedProperties(new ArrayList<String>(Arrays.asList(ResultTableModel.fields)));
}
updatePanelList();
}

@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(selectVisibleButton)) {
columnsManager.enableOnlySelectedProperties(columnsManager.colState.visibleFields);
columnsManager.checkOnlySelectedProperties(columnsManager.colState.visibleFields);
updatePanelList();
} else if (e.getSource().equals(toggleSelectUnselectAllCheckBox)) {
if (toggleSelectUnselectAllCheckBox.isSelected()) {
columnsManager.enableAllProperties();
columnsManager.checkAllProperties();
} else {
columnsManager.disableAllProperties();
columnsManager.uncheckAllProperties();
}
updatePanelList();
} else if (e.getSource().equals(combo)) {
Expand Down Expand Up @@ -151,8 +151,7 @@ protected void updatePanelList() {
JCheckBox check = new JCheckBox();
check.setText(fieldName);
CheckBoxState checkBoxState = columnsManager.allCheckBoxesState.get(LocalizedProperties.getNonLocalizedField(fieldName));
if (checkBoxState.isSelected)
check.setSelected(checkBoxState.isSelected);
check.setSelected(checkBoxState.isSelected);
check.setEnabled(checkBoxState.isEnabled);
check.addActionListener(this);
listPanel.add(check);
Expand Down

0 comments on commit 31dae56

Please sign in to comment.