/** * The contents of this file are subject to the OpenMRS Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://license.openmrs.org * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * Copyright (C) OpenMRS, LLC. All Rights Reserved. */ package org.eclipse.datatools.connectivity.oda.openmrs.ui.impl; import java.util.Map; import java.util.logging.Logger; import org.eclipse.datatools.connectivity.oda.openmrs.impl.QueryBuilder; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.List; /** * The Class AggregateRow. */ public class AggregateRow { private static final String TOKENS = "TOKENS"; private static Logger log = Logger.getLogger(AggregateRow.class.getName()); private String token; private List list; private Combo aggregateCombo; private Combo valueCombo; /** * Instantiates a new aggregate row. * * @param token the token * @param list the list that will hold the token * @param aggregateCombo the aggregate name combo for this token * @param valueCombo the aggregate value combo for this token * @param aggregateRows all of the aggregrate rows * @param modifierPage the pointer to the modifier page */ public AggregateRow(final String token, final List list, final Combo aggregateCombo, final Combo valueCombo, final Map aggregateRows, final ModifierPage modifierPage) { this.token = token; this.list = list; this.aggregateCombo = aggregateCombo; this.valueCombo = valueCombo; aggregateCombo.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String aggregate = aggregateCombo.getText(); log.info(InformationHolder.getPropertyValue(TOKENS)); log.info("Aggregate changed for " + token + " to " + aggregate); InformationHolder.setPropertyValue(TOKENS, Utils .replaceAggregateNameForToken(token, aggregate, InformationHolder.getPropertyValue(TOKENS))); log.info(InformationHolder.getPropertyValue(TOKENS)); } }); valueCombo.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String value = valueCombo.getText(); log.info(InformationHolder.getPropertyValue(TOKENS)); log.info("Value changed for " + token + " to " + value); InformationHolder.setPropertyValue(TOKENS, Utils .replaceAggregateValueForToken(token, value, InformationHolder.getPropertyValue(TOKENS))); log.info(InformationHolder.getPropertyValue(TOKENS)); } }); list.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (list.isSelected(0)) { String tokenSelected = list.getSelection()[0]; log.info(tokenSelected + " selected"); java.util.List tokens = QueryBuilder .getTokenNamesFromStorage(InformationHolder .getPropertyValue(TOKENS)); for (String token : tokens) { log.info("Looking at : " + token); if (!aggregateRows.get(token).getToken().equals( tokenSelected)) { aggregateRows.get(token).getList().deselectAll(); } if (aggregateRows.get(token).getToken().equals( tokenSelected)) { modifierPage.loadModifierTable(token); } } } } }); } /** * Gets the list that contains the token. * * @return the list */ public List getList() { return list; } /** * Gets the token name. * * @return the token */ public String getToken() { return token; } /** * Gets the aggregate combo for this token. * * @return the aggregate combo */ public Combo getAggregateCombo() { return aggregateCombo; } /** * Gets the value combo for this token. * * @return the value combo */ public Combo getValueCombo() { return valueCombo; } }