Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
b73d1ded
by Tony Chemit at 2022-09-03T08:02:13+02:00
2 changed files:
- client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/config/TreeConfigUIHandler.java
- client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/config/TreeConfigUIModel.java
Changes:
| ... | ... | @@ -49,12 +49,14 @@ import org.nuiton.jaxx.runtime.JAXXObject; |
| 49 | 49 | import org.nuiton.jaxx.runtime.spi.UIHandler;
|
| 50 | 50 | |
| 51 | 51 | import javax.swing.AbstractButton;
|
| 52 | +import javax.swing.Box;
|
|
| 52 | 53 | import javax.swing.Icon;
|
| 53 | 54 | import javax.swing.JComponent;
|
| 54 | 55 | import javax.swing.JPanel;
|
| 55 | 56 | import javax.swing.JPopupMenu;
|
| 56 | 57 | import javax.swing.KeyStroke;
|
| 57 | 58 | import javax.swing.SwingUtilities;
|
| 59 | +import javax.swing.UIManager;
|
|
| 58 | 60 | import javax.swing.event.PopupMenuEvent;
|
| 59 | 61 | import javax.swing.event.PopupMenuListener;
|
| 60 | 62 | import java.awt.Component;
|
| ... | ... | @@ -85,6 +87,11 @@ public class TreeConfigUIHandler implements UIHandler<TreeConfigUI>, PropertyCha |
| 85 | 87 | private final Map<String, AbstractButton> allOptions;
|
| 86 | 88 | private final Multimap<String, AbstractButton> groupByOptions;
|
| 87 | 89 | private final Map<String, AbstractButton> temporalOptions;
|
| 90 | + /**
|
|
| 91 | + * Keep the default height (to add some extra components for missing groupBy count in a module and always have
|
|
| 92 | + * the same groupByChoose height at any cost).
|
|
| 93 | + */
|
|
| 94 | + private final int defaultGroupByComponentHeight;
|
|
| 88 | 95 | private TreeConfigUI ui;
|
| 89 | 96 | |
| 90 | 97 | public static void updateStatistics(ToolkitTreeFlatModelRootRequest request,
|
| ... | ... | @@ -178,6 +185,7 @@ public class TreeConfigUIHandler implements UIHandler<TreeConfigUI>, PropertyCha |
| 178 | 185 | groupByOptions = ArrayListMultimap.create();
|
| 179 | 186 | allOptions = new TreeMap<>();
|
| 180 | 187 | temporalOptions = new TreeMap<>();
|
| 188 | + defaultGroupByComponentHeight = UIManager.getDefaults().getIcon("RadioButton.icon").getIconHeight();
|
|
| 181 | 189 | }
|
| 182 | 190 | |
| 183 | 191 | @Override
|
| ... | ... | @@ -226,7 +234,7 @@ public class TreeConfigUIHandler implements UIHandler<TreeConfigUI>, PropertyCha |
| 226 | 234 | reset(bean);
|
| 227 | 235 | }
|
| 228 | 236 | |
| 229 | - public void updateOptions(){
|
|
| 237 | + public void updateOptions() {
|
|
| 230 | 238 | for (Map.Entry<String, Collection<AbstractButton>> entry : groupByOptions.asMap().entrySet()) {
|
| 231 | 239 | entry.getValue().forEach(c -> {
|
| 232 | 240 | if (Objects.equals(true, c.getClientProperty(DISABLED))) {
|
| ... | ... | @@ -279,6 +287,7 @@ public class TreeConfigUIHandler implements UIHandler<TreeConfigUI>, PropertyCha |
| 279 | 287 | }
|
| 280 | 288 | }
|
| 281 | 289 | }
|
| 290 | + |
|
| 282 | 291 | public void reset(TreeConfig bean) {
|
| 283 | 292 | String moduleName = bean.getModuleName();
|
| 284 | 293 | String groupByName = bean.getGroupByName();
|
| ... | ... | @@ -309,6 +318,15 @@ public class TreeConfigUIHandler implements UIHandler<TreeConfigUI>, PropertyCha |
| 309 | 318 | UseGroupByAction action = (UseGroupByAction) editor.getAction();
|
| 310 | 319 | action.install();
|
| 311 | 320 | }
|
| 321 | + int definitionMaxCount = ui.getModel().getDefinitionMaxCount();
|
|
| 322 | + if (definitionMaxCount > editors.size()) {
|
|
| 323 | + // Fill with extra component to always have the same number of component in the groupByChoose
|
|
| 324 | + // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2340
|
|
| 325 | + for (int i = editors.size(); i < definitionMaxCount; i++) {
|
|
| 326 | + log.info("Add extra dummy component to fix size {} with height {}", i, defaultGroupByComponentHeight);
|
|
| 327 | + groupByChoose.add(Box.createVerticalStrut(defaultGroupByComponentHeight));
|
|
| 328 | + }
|
|
| 329 | + }
|
|
| 312 | 330 | changeGroupByName(newGroupByName);
|
| 313 | 331 | SwingUtilities.invokeLater(ui::revalidate);
|
| 314 | 332 | SwingUtilities.invokeLater(ui::repaint);
|
| ... | ... | @@ -22,8 +22,11 @@ package fr.ird.observe.client.datasource.editor.api.config; |
| 22 | 22 | * #L%
|
| 23 | 23 | */
|
| 24 | 24 | |
| 25 | +import fr.ird.observe.dto.data.DataGroupByDtoDefinition;
|
|
| 25 | 26 | import fr.ird.observe.navigation.tree.GroupByHelper;
|
| 26 | 27 | import fr.ird.observe.navigation.tree.TreeConfig;
|
| 28 | +import fr.ird.observe.spi.module.BusinessModule;
|
|
| 29 | +import fr.ird.observe.spi.module.ObserveBusinessProject;
|
|
| 27 | 30 | import io.ultreia.java4all.bean.AbstractJavaBean;
|
| 28 | 31 | import io.ultreia.java4all.bean.monitor.BeanMonitor;
|
| 29 | 32 | import io.ultreia.java4all.bean.monitor.PropertyDiff;
|
| ... | ... | @@ -78,12 +81,23 @@ public class TreeConfigUIModel extends AbstractJavaBean implements PropertyChang |
| 78 | 81 | * GroupBy helper.
|
| 79 | 82 | */
|
| 80 | 83 | private final GroupByHelper groupByHelper;
|
| 84 | + /**
|
|
| 85 | + * To keep to max count of definitions for a module to fix a minimum size in the ui.
|
|
| 86 | + * <p>
|
|
| 87 | + * See <a href="https://gitlab.com/ultreiaio/ird-observe/-/issues/2340">issue 2340</a>
|
|
| 88 | + */
|
|
| 89 | + private final int definitionMaxCount;
|
|
| 81 | 90 | |
| 82 | 91 | protected TreeConfigUIModel(GroupByHelper groupByHelper, TreeConfig originalBean) {
|
| 83 | 92 | this.groupByHelper = groupByHelper;
|
| 84 | 93 | this.originalBean = originalBean;
|
| 85 | 94 | this.bean = new TreeConfig();
|
| 86 | 95 | this.monitor = new BeanMonitor(MONITORED_PROPERTIES.toArray(new String[0]));
|
| 96 | + this.definitionMaxCount = computeDefinitionMaxCount(ObserveBusinessProject.get().getModules());
|
|
| 97 | + }
|
|
| 98 | + |
|
| 99 | + public int getDefinitionMaxCount() {
|
|
| 100 | + return definitionMaxCount;
|
|
| 87 | 101 | }
|
| 88 | 102 | |
| 89 | 103 | public TreeConfig getOriginalBean() {
|
| ... | ... | @@ -133,15 +147,15 @@ public class TreeConfigUIModel extends AbstractJavaBean implements PropertyChang |
| 133 | 147 | */
|
| 134 | 148 | public boolean isStructureChanged() {
|
| 135 | 149 | List<String> modifiedProperties = List.of(monitor.getModifiedProperties());
|
| 136 | - if( modifiedProperties.contains(TreeConfig.LOAD_DATA)) {
|
|
| 150 | + if (modifiedProperties.contains(TreeConfig.LOAD_DATA)) {
|
|
| 137 | 151 | // loadData is now off
|
| 138 | 152 | return !bean.isLoadData();
|
| 139 | 153 | }
|
| 140 | - if( modifiedProperties.contains(TreeConfig.LOAD_REFERENTIAL)) {
|
|
| 154 | + if (modifiedProperties.contains(TreeConfig.LOAD_REFERENTIAL)) {
|
|
| 141 | 155 | // loadReferential is now off
|
| 142 | 156 | return !bean.isLoadReferential();
|
| 143 | 157 | }
|
| 144 | - if( modifiedProperties.contains(TreeConfig.MODULE_NAME)) {
|
|
| 158 | + if (modifiedProperties.contains(TreeConfig.MODULE_NAME)) {
|
|
| 145 | 159 | // previous module name is off
|
| 146 | 160 | return true;
|
| 147 | 161 | }
|
| ... | ... | @@ -170,4 +184,15 @@ public class TreeConfigUIModel extends AbstractJavaBean implements PropertyChang |
| 170 | 184 | private void fireEmpty() {
|
| 171 | 185 | firePropertyChange(EMPTY, isEmpty());
|
| 172 | 186 | }
|
| 187 | + |
|
| 188 | + |
|
| 189 | + private int computeDefinitionMaxCount(List<BusinessModule> modules) {
|
|
| 190 | + int definitionMaxCount = 0;
|
|
| 191 | + for (BusinessModule module : modules) {
|
|
| 192 | + List<DataGroupByDtoDefinition<?, ?>> definitions = module.getDataGroupByDtoDefinitions();
|
|
| 193 | + definitionMaxCount = Math.max(definitionMaxCount, definitions.size());
|
|
| 194 | + }
|
|
| 195 | + return definitionMaxCount;
|
|
| 196 | + }
|
|
| 197 | + |
|
| 173 | 198 | } |