Dear users, Please note that, from Monday, August 16, 2019, RSA keys shorter than 2048bit will no longer be accepted for security reasons. Please update your keys as needed before this date. If you need assistance with regard to this process, please contact sia@list.lu

Thank you for your understanding.

Commit d696c066 authored by Nico Mack's avatar Nico Mack

Added support for SelectionGroups to SelectorWidget

parent c84c7008
......@@ -8,6 +8,7 @@ import lu.list.itis.dkd.tui.event.conditional.Conditional;
import lu.list.itis.dkd.tui.utility.AngleUtils;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.ValueRange;
import lu.list.itis.dkd.tui.utility.selection.SelectionGroup;
import lu.list.itis.dkd.tui.widget.builder.SelectorWidgetBuilder;
import lu.list.itis.dkd.tui.widget.corona.SelectableCorona;
import lu.list.itis.dkd.tui.widget.state.StateManager;
......@@ -20,8 +21,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
// ***************************************************************************
// * Class Definition and Members *
......@@ -38,6 +41,9 @@ public class SelectorWidget extends ValueWidget {
private double segmentSpan;
private List<ValueRange<Double>> segmentSpans;
private Map<String, SelectionGroup> selectionGroups;
private List<SelectableCorona> selectableCoronas;
// ***************************************************************************
......@@ -49,7 +55,7 @@ public class SelectorWidget extends ValueWidget {
private static final Logger LOGGER = LoggerFactory.getLogger(SelectorWidget.class.getSimpleName());
// ***************************************************************************
// * Inner Classs *
// * Inner Class *
// ***************************************************************************
private class IndexCondition extends Condition<Integer> {
......@@ -86,6 +92,7 @@ public class SelectorWidget extends ValueWidget {
this.numberOfPositions = (builder.numberOfPositions > 0) ? builder.numberOfPositions : this.getNumberOfPositions();
this.presetPosition = builder.preselect;
this.selectionGroups = builder.selectionGroups;
this.buildFromProperties();
}
......@@ -106,6 +113,7 @@ public class SelectorWidget extends ValueWidget {
this.numberOfPositions = (original.numberOfPositions > 0) ? original.numberOfPositions : this.getNumberOfPositions();
this.presetPosition = original.presetPosition;
this.selectionGroups = original.cloneSelectionGroups();
this.buildFromProperties();
}
......@@ -125,12 +133,40 @@ public class SelectorWidget extends ValueWidget {
segmentSpans.add(buildSegmentSpan(position));
}
if ((this.selectionGroups != null) && (this.selectableCoronas != null)) {
for (SelectableCorona corona : this.selectableCoronas) {
if (selectionGroups.containsKey(corona.getGroup())) {
SelectionGroup group = selectionGroups.get(corona.getGroup());
group.addToGroup(corona);
}
}
}
if (presetPosition != NONE) {
this.initialValue = presetPosition;
this.selectPosition(presetPosition);
}
}
// ---------------------------------------------------------------------------
/**
* returns a multimap containing copies of every single corona associated with this widget. The map
* uses the widgets' potential handle IDs a keys and the corresponding coronas as values.
*
* @return a map containing a copy of all coronas handled by this widget.
*/
// ---------------------------------------------------------------------------
public Map<String, SelectionGroup> cloneSelectionGroups() {
Map<String, SelectionGroup> clonedGroups = new HashMap<>();
for (Entry<String, SelectionGroup> entry : selectionGroups.entrySet()) {
SelectionGroup cloned = entry.getValue().clone();
clonedGroups.put(entry.getKey(), cloned);
}
return clonedGroups;
}
// ---------------------------------------------------------------------------
private ValueRange<Double> buildSegmentSpan(int position) {
......
......@@ -7,10 +7,15 @@ import lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.CpsNamespace;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.utility.selection.SelectionGroup;
import lu.list.itis.dkd.tui.widget.SelectorWidget;
import org.jdom2.Element;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author nmack
* @date 13 Jan 2016
......@@ -27,15 +32,25 @@ public class SelectorWidgetBuilder<B extends SelectorWidgetBuilder<B>> extends B
public Integer numberOfPositions;
public Integer preselect;
public Map<String, SelectionGroup> selectionGroups;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Simple no-arg constructor initializing all fields.
*/
// ---------------------------------------------------------------------------
public SelectorWidgetBuilder() {
super();
preselect = SelectorWidget.NONE;
}
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all the
* information on fields to initialize.
......@@ -47,11 +62,14 @@ public class SelectorWidgetBuilder<B extends SelectorWidgetBuilder<B>> extends B
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
// ---------------------------------------------------------------------------
public SelectorWidgetBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all the
* information on fields to initialize.
......@@ -63,11 +81,18 @@ public class SelectorWidgetBuilder<B extends SelectorWidgetBuilder<B>> extends B
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
// ---------------------------------------------------------------------------
public SelectorWidgetBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
this.buildFromBootstrap(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitive(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
* @param rootElement
......@@ -75,17 +100,37 @@ public class SelectorWidgetBuilder<B extends SelectorWidgetBuilder<B>> extends B
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
numberOfPositions = BootstrappingUtils.getContentAsInteger(rootElement, CpsNamespace.POSITIONS_NODE, BootstrappingUtils.OPTIONAL, SelectorWidget.NONE, context);
preselect = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.PRESELECT_NODE, BootstrappingUtils.OPTIONAL, SelectorWidget.NONE, context);
selectionGroups = new HashMap<>();
Element selectionGroupsElement = rootElement.getChild(Externalization.SELECTION_GROUPS_NODE);
if (selectionGroupsElement != null) {
List<Element> selectionGroupElements = selectionGroupsElement.getChildren(Externalization.SELECTION_GROUP_NODE);
for (Element selectionGroupElement : selectionGroupElements) {
SelectionGroup group = new SelectionGroup(selectionGroupElement);
selectionGroups.put(group.getName(), group);
}
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public B withPreselect(Integer index) {
this.preselect = index;
return (B) this;
}
// ---------------------------------------------------------------------------
@Override
public SelectorWidget build() {
return new SelectorWidget(this);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment