diff --git a/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/GroupingComp.java b/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/GroupingComp.java index f3033d655b..61bb2f5ae4 100644 --- a/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/GroupingComp.java +++ b/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/GroupingComp.java @@ -20,7 +20,7 @@ package com.raytheon.uf.viz.stats.ui; /** - * TODO Add Description + * Grouping Composite for the Stats Graph. * *
  *
@@ -35,10 +35,14 @@ package com.raytheon.uf.viz.stats.ui;
  * @author mpduff
  * @version 1.0
  */
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.regex.Pattern;
 
 import org.eclipse.swt.SWT;
@@ -108,6 +112,8 @@ public class GroupingComp extends Composite implements IGroupSelection {
     /** Grouping callback */
     private final IStatsGroup callback;
 
+    private final List selectionEntries = new ArrayList();
+
     /**
      * Constructor.
      * 
@@ -193,12 +199,26 @@ public class GroupingComp extends Composite implements IGroupSelection {
      */
     private void createControls() {
         List keyArray = graphData.getKeysWithData();
+        Map> grpNameMap = graphData.getGroupAndNamesMap();
 
+        // Create the Selection Entry objects
         for (String key : keyArray) {
+            SelectionEntry se = new SelectionEntry();
+            String[] parts = colonPattern.split(key);
+
+            Set grpNames = grpNameMap.keySet();
+            Iterator iter = grpNames.iterator();
+            for (int i = 0; i < grpNames.size(); i++) {
+                se.addPair(iter.next(), parts[i]);
+            }
+            this.selectionEntries.add(se);
+        }
+
+        for (SelectionEntry se : selectionEntries) {
             GridData gd = new GridData(20, 10);
             Label lbl = new Label(controlComp, SWT.BORDER);
             lbl.setLayoutData(gd);
-            lbl.setData(key);
+            lbl.setData(se);
             lbl.addMouseListener(new MouseAdapter() {
                 @Override
                 public void mouseDown(MouseEvent e) {
@@ -208,8 +228,9 @@ public class GroupingComp extends Composite implements IGroupSelection {
             });
 
             Button btn = new Button(controlComp, SWT.CHECK);
-            btn.setText(key);
+            btn.setText(se.toString());
             btn.setSelection(true);
+            btn.setData(se);
             btn.addSelectionListener(new SelectionAdapter() {
                 @Override
                 public void widgetSelected(SelectionEvent e) {
@@ -218,8 +239,8 @@ public class GroupingComp extends Composite implements IGroupSelection {
                 }
             });
 
-            labelMap.put(key, lbl);
-            checkBtnMap.put(key, btn);
+            labelMap.put(se.toString(), lbl);
+            checkBtnMap.put(se.toString(), btn);
         }
     }
 
@@ -286,7 +307,7 @@ public class GroupingComp extends Composite implements IGroupSelection {
      */
     private void handleLabelClickEvent(Label lbl) {
         RGB rgb = lbl.getBackground().getRGB();
-        String key = (String) lbl.getData();
+        String key = ((SelectionEntry) lbl.getData()).toString();
 
         ColorDialog colorDlg = new ColorDialog(this.getShell());
         colorDlg.setRGB(rgb);
@@ -364,8 +385,6 @@ public class GroupingComp extends Composite implements IGroupSelection {
      */
     @Override
     public void setSelections(Map> selectionMap) {
-        List keySequence = graphData.getKeySequence();
-
         Multimap offMap = ArrayListMultimap.create();
         for (String key : selectionMap.keySet()) {
             for (String selection : selectionMap.get(key).keySet()) {
@@ -383,21 +402,18 @@ public class GroupingComp extends Composite implements IGroupSelection {
             }
         } else {
             for (String btnKey : checkBtnMap.keySet()) {
-                String[] parts = colonPattern.split(btnKey);
+                Button b = checkBtnMap.get(btnKey);
+                SelectionEntry se = (SelectionEntry) b.getData();
 
-                for (String group : offMap.keySet()) {
-                    for (String part : parts) {
-                        int idx = keySequence.indexOf(part);
-                        if (idx >= 0
-                                && offMap.get(group).contains(
-                                        keySequence.get(idx))) {
-                            checkBtnMap.get(btnKey).setSelection(false);
-                            keyRgbMap.remove(btnKey);
-                        } else {
-                            checkBtnMap.get(btnKey).setSelection(true);
-                            keyRgbMap.put(btnKey, labelMap.get(btnKey)
-                                    .getBackground().getRGB());
-                        }
+                for (String key : offMap.keySet()) {
+                    Collection valueList = offMap.get(key);
+                    if (valueList.contains(se.getValue(key))) {
+                        checkBtnMap.get(btnKey).setSelection(false);
+                        keyRgbMap.remove(btnKey);
+                    } else {
+                        checkBtnMap.get(btnKey).setSelection(true);
+                        keyRgbMap.put(btnKey, labelMap.get(btnKey)
+                                .getBackground().getRGB());
                     }
                 }
             }
diff --git a/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/SelectionEntry.java b/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/SelectionEntry.java
new file mode 100644
index 0000000000..b8b4620c8e
--- /dev/null
+++ b/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/SelectionEntry.java
@@ -0,0 +1,87 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ * 
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ * 
+ * Contractor Name:        Raytheon Company
+ * Contractor Address:     6825 Pine Street, Suite 340
+ *                         Mail Stop B8
+ *                         Omaha, NE 68106
+ *                         402.291.0100
+ * 
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package com.raytheon.uf.viz.stats.ui;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * Stats Graph Item.
+ * 
+ * 
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 24, 2013            mpduff     Initial creation
+ * 
+ * 
+ * + * @author mpduff + * @version 1.0 + */ +public class SelectionEntry { + private final Map values = new LinkedHashMap(); + + private boolean checked = true; + + public SelectionEntry() { + + } + + public void addPair(String key, String value) { + values.put(key, value); + } + + public String getValue(String key) { + return values.get(key); + } + + /** + * @return the checked + */ + public boolean isChecked() { + return checked; + } + + /** + * @param checked + * the checked to set + */ + public void setChecked(boolean checked) { + this.checked = checked; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + for (Iterator iter = values.values().iterator(); iter.hasNext();) { + sb.append(iter.next()); + if (iter.hasNext()) { + sb.append(":"); + } + } + + return sb.toString(); + } +} diff --git a/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/SelectionManagerDlg.java b/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/SelectionManagerDlg.java index 2b46907b56..d12231d3c5 100644 --- a/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/SelectionManagerDlg.java +++ b/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/SelectionManagerDlg.java @@ -79,7 +79,7 @@ public class SelectionManagerDlg extends CaveSWTDialogBase { * Constructor. * * @param parentShell - * @param graphData + * @param selectionEntries * @param callback */ public SelectionManagerDlg(Shell parentShell, GraphData graphData, @@ -89,8 +89,8 @@ public class SelectionManagerDlg extends CaveSWTDialogBase { | CAVE.INDEPENDENT_SHELL); setText("Selection Manager"); - this.graphData = graphData; this.callback = callback; + this.graphData = graphData; } /** @@ -254,7 +254,6 @@ public class SelectionManagerDlg extends CaveSWTDialogBase { private void populateTree() { Map> grpMemberMap = graphData .getGroupAndNamesMap(); - Map stateMap = callback.getStates(); for (String key : grpMemberMap.keySet()) { TreeItem treeItem = new TreeItem(selectionTree, SWT.NONE); @@ -265,8 +264,7 @@ public class SelectionManagerDlg extends CaveSWTDialogBase { for (String subKey : array) { TreeItem subTreeItem = new TreeItem(treeItem, SWT.NONE); subTreeItem.setText(subKey); - - subTreeItem.setChecked(stateMap.get(subKey)); + subTreeItem.setChecked(true); } } diff --git a/edexOsgi/com.raytheon.uf.edex.stats/src/com/raytheon/uf/edex/stats/util/Archiver.java b/edexOsgi/com.raytheon.uf.edex.stats/src/com/raytheon/uf/edex/stats/util/Archiver.java index 9150f940a2..59dd45cd2e 100644 --- a/edexOsgi/com.raytheon.uf.edex.stats/src/com/raytheon/uf/edex/stats/util/Archiver.java +++ b/edexOsgi/com.raytheon.uf.edex.stats/src/com/raytheon/uf/edex/stats/util/Archiver.java @@ -54,6 +54,7 @@ import com.raytheon.uf.common.time.TimeRange; * ------------ ---------- ----------- -------------------------- * Aug 21, 2012 jsanchez Initial creation. * Nov 09, 2012 dhladky Changed to CSV output + * Jan 24, 2013 1357 mpduff Fix comma output and paths. * *
* @@ -91,6 +92,8 @@ public class Archiver { private static final String COMMA = ","; + private static final Pattern NLPattern = Pattern.compile("[\\n\\r]+"); + private static final IUFStatusHandler statusHandler = UFStatus .getHandler(Archiver.class); @@ -116,15 +119,13 @@ public class Archiver { * @param items * @return */ - private String createFilename(TimeRange tr, String eventType, String group) { + private String createFilename(TimeRange tr, String eventType) { SimpleDateFormat fileDateFormatter = new SimpleDateFormat( FILE_DATE_FORMAT); StringBuilder sb = new StringBuilder("stats/aggregates"); String[] chunks = PERIOD_PATTERN.split(eventType); sb.append("/"); - sb.append(group); - sb.append("/"); sb.append(chunks[chunks.length - 1]); sb.append("."); sb.append(fileDateFormatter.format(tr.getStart())); @@ -156,24 +157,29 @@ public class Archiver { double count = agrec.getCount(); if (eventType != null) { - sb.append(eventType).append(COMMA); + sb.append(eventType); } + sb.append(COMMA); if (startDate != null) { - sb.append(dateFormat.format(startDate.getTime())) - .append(COMMA); + sb.append(dateFormat.format(startDate.getTime())); } + sb.append(COMMA); if (endDate != null) { - sb.append(dateFormat.format(endDate.getTime())).append( - COMMA); + sb.append(dateFormat.format(endDate.getTime())); } + sb.append(COMMA); + if (grouping != null) { - sb.append(grouping).append(COMMA); + sb.append(NLPattern.matcher(grouping).replaceAll("")); } + sb.append(COMMA); + if (field != null) { - sb.append(field).append(COMMA); + sb.append(field); } + sb.append(COMMA); sb.append(max).append(COMMA); sb.append(min).append(COMMA); @@ -212,10 +218,9 @@ public class Archiver { for (StatisticsKey key : statisticsMap.keySet()) { String eventType = key.eventType; - String grouping = key.grouping; List records = statisticsMap.get(key); - String filename = createFilename(key.timeRange, eventType, grouping); + String filename = createFilename(key.timeRange, eventType); try { writeToFile(filename, records); } catch (JAXBException e) { @@ -243,8 +248,7 @@ public class Archiver { siteLocalization.getFile().getParentFile().mkdirs(); // Write this to output CSV try { - bw = new BufferedWriter(new FileWriter( - outputFilePath)); + bw = new BufferedWriter(new FileWriter(outputFilePath)); if (bw != null) { for (AggregateRecord agrec : records) { bw.write(getCSVOutput(agrec, dateFormatter)); diff --git a/tests/.classpath b/tests/.classpath index f3924ee656..a139e358aa 100644 --- a/tests/.classpath +++ b/tests/.classpath @@ -70,5 +70,6 @@ + diff --git a/tests/unit/com/raytheon/uf/viz/stats/ui/SelectionEntryTest.java b/tests/unit/com/raytheon/uf/viz/stats/ui/SelectionEntryTest.java new file mode 100644 index 0000000000..d728231f3e --- /dev/null +++ b/tests/unit/com/raytheon/uf/viz/stats/ui/SelectionEntryTest.java @@ -0,0 +1,54 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.stats.ui; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * SelectionEntry test class. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 24, 2013            mpduff     Initial creation
+ * 
+ * 
+ * + * @author mpduff + * @version 1.0 + */ + +public class SelectionEntryTest { + + @Test + public void testCreateSelectionEntryClassAndAddKeys() { + SelectionEntry se = new SelectionEntry(); + se.addPair("Key", "Value"); + se.addPair("Key2", "Value2"); + se.addPair("Key3", "Value3"); + assertTrue("Keys are wrong", se.toString() + .equals("Value:Value2:Value3")); + } +}