added "interactive" option for line chart dashboard element
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 30 Jun 2016 23:53:40 +0000 (02:53 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 30 Jun 2016 23:53:40 +0000 (02:53 +0300)
src/java/netxms-eclipse/Dashboard/src/org/netxms/ui/eclipse/dashboard/propertypages/AbstractChart.java
src/java/netxms-eclipse/Dashboard/src/org/netxms/ui/eclipse/dashboard/widgets/LineChartElement.java
src/java/netxms-eclipse/Dashboard/src/org/netxms/ui/eclipse/dashboard/widgets/internal/LineChartConfig.java
src/java/netxms-eclipse/PerfView/META-INF/MANIFEST.MF
src/java/netxms-eclipse/PerfView/src/org/netxms/ui/eclipse/perfview/views/HistoricalGraphView.java
webui/webapp/Dashboard/src/org/netxms/ui/eclipse/dashboard/propertypages/AbstractChart.java
webui/webapp/Dashboard/src/org/netxms/ui/eclipse/dashboard/widgets/LineChartElement.java
webui/webapp/Dashboard/src/org/netxms/ui/eclipse/dashboard/widgets/internal/LineChartConfig.java
webui/webapp/PerfView/META-INF/MANIFEST.MF
webui/webapp/PerfView/src/org/netxms/ui/eclipse/perfview/views/HistoricalGraphView.java

index 91d9f6f..075bf9c 100644 (file)
@@ -62,6 +62,7 @@ public class AbstractChart extends PropertyPage
    private Button checkLogScale;
    private Button checkStacked;
    private Button checkAreaChart;
+   private Button checkInteractive;
    private LabeledSpinner lineWidth;
    private YAxisRangeEditor yAxisRange;   
 
@@ -193,6 +194,13 @@ public class AbstractChart extends PropertyPage
                        gd.horizontalAlignment = SWT.FILL;
                        gd.grabExcessHorizontalSpace = true;
                        checkShowGrid.setLayoutData(gd);
+         
+         checkInteractive = new Button(optionsGroup, SWT.CHECK);
+         checkInteractive.setText("&Interactive");
+         checkInteractive.setSelection(((LineChartConfig)config).isInteractive());
+         gd = new GridData();
+         gd.horizontalSpan = layout.numColumns;
+         checkInteractive.setLayoutData(gd);
                        
                        Composite timeRangeArea = new Composite(dialogArea, SWT.NONE);
                        layout = new GridLayout();
@@ -326,6 +334,7 @@ public class AbstractChart extends PropertyPage
          ((LineChartConfig)config).setLogScaleEnabled(checkLogScale.getSelection());
          ((LineChartConfig)config).setStacked(checkStacked.getSelection());
          ((LineChartConfig)config).setArea(checkAreaChart.getSelection());
+         ((LineChartConfig)config).setInteractive(checkInteractive.getSelection());
          ((LineChartConfig)config).setLineWidth(lineWidth.getSelection());
                }
                return true;
index 4c85c53..9c19752 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * NetXMS - open source network management system
- * Copyright (C) 2003-2015 Victor Kirhenshtein
+ * Copyright (C) 2003-2016 Victor Kirhenshtein
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -24,11 +24,19 @@ import java.util.List;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.DisposeEvent;
 import org.eclipse.swt.events.DisposeListener;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.Widget;
 import org.eclipse.ui.IViewPart;
 import org.netxms.client.NXCSession;
@@ -36,6 +44,7 @@ import org.netxms.client.dashboards.DashboardElement;
 import org.netxms.client.datacollection.DciData;
 import org.netxms.client.datacollection.GraphItem;
 import org.netxms.client.datacollection.GraphItemStyle;
+import org.netxms.ui.eclipse.actions.RefreshAction;
 import org.netxms.ui.eclipse.charts.api.ChartColor;
 import org.netxms.ui.eclipse.charts.api.ChartDciConfig;
 import org.netxms.ui.eclipse.charts.api.ChartFactory;
@@ -44,6 +53,8 @@ import org.netxms.ui.eclipse.dashboard.Activator;
 import org.netxms.ui.eclipse.dashboard.Messages;
 import org.netxms.ui.eclipse.dashboard.widgets.internal.LineChartConfig;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.perfview.views.HistoricalGraphView;
+import org.netxms.ui.eclipse.perfview.views.HistoricalGraphView.ActionType;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 import org.netxms.ui.eclipse.tools.ViewRefreshController;
 
@@ -58,6 +69,11 @@ public class LineChartElement extends ElementWidget
        private boolean updateInProgress = false;
        private NXCSession session;
        private List<DataCacheElement> dataCache = new ArrayList<DataCacheElement>(16);
+   private Action actionRefresh;
+   private Action actionAdjustX;
+   private Action actionAdjustY;
+   private Action actionAdjustBoth;
+   private Action[] presetActions;
 
        /**
         * @param parent
@@ -81,7 +97,7 @@ public class LineChartElement extends ElementWidget
                setLayout(new FillLayout());
                
                chart = ChartFactory.createLineChart(this, SWT.NONE);
-               chart.setZoomEnabled(false);
+               chart.setZoomEnabled(config.isInteractive());
                chart.setTitleVisible(config.isShowTitle());
                chart.setChartTitle(config.getTitle());
                chart.setLegendVisible(config.isShowLegend());
@@ -127,6 +143,82 @@ public class LineChartElement extends ElementWidget
             refreshController.dispose();
          }
       });
+               
+               if (config.isInteractive())
+               {
+                  createActions();
+                  createChartContextMenu();
+               }
+       }
+
+   /**
+    * Create actions
+    */
+   private void createActions()
+   {
+      actionRefresh = new RefreshAction() {
+         @Override
+         public void run()
+         {
+            refreshData();
+         }
+      };
+
+      actionAdjustX = HistoricalGraphView.createAction(ActionType.ADJUST_X, chart);
+      actionAdjustY = HistoricalGraphView.createAction(ActionType.ADJUST_Y, chart);
+      actionAdjustBoth = HistoricalGraphView.createAction(ActionType.ADJUST_BOTH, chart);
+
+      presetActions = HistoricalGraphView.createPresetActions(new HistoricalGraphView.PresetHandler() {
+         @Override
+         public void onPresetSelected(int units, int range)
+         {
+            config.setTimeUnits(units);
+            config.setTimeRange(range);
+            refreshData();
+         }
+      });
+   }
+
+       /**
+        * Create chart's context menu
+        */
+       private void createChartContextMenu()
+       {
+          final MenuManager manager = new MenuManager();
+          manager.setRemoveAllWhenShown(true);
+          manager.addMenuListener(new IMenuListener() {
+         public void menuAboutToShow(IMenuManager mgr)
+         {
+            fillContextMenu(manager);
+         }
+      });
+          
+      Menu menu = manager.createContextMenu((Control)chart);
+      ((Control)chart).setMenu(menu);
+      for(Control ch : ((Composite)chart).getChildren())
+      {
+         ch.setMenu(menu);
+      }
+       }
+       
+       /**
+        * Fill context menu
+        * 
+        * @param manager
+        */
+       private void fillContextMenu(IMenuManager manager)
+       {
+      MenuManager presets = new MenuManager("&Presets");
+      for(int i = 0; i < presetActions.length; i++)
+         presets.add(presetActions[i]);
+      
+      manager.add(presets);
+      manager.add(new Separator());
+      manager.add(actionAdjustBoth);
+      manager.add(actionAdjustX);
+      manager.add(actionAdjustY);
+      manager.add(new Separator());
+      manager.add(actionRefresh);
        }
 
    /**
index 986fa91..ab4f41e 100644 (file)
@@ -51,6 +51,9 @@ public class LineChartConfig extends AbstractChartConfig
    
    @Element(required = false)
    private boolean area = false;
+   
+   @Element(required = false)
+   private boolean interactive = false;
 
    /**
     * Default constructor
@@ -220,4 +223,20 @@ public class LineChartConfig extends AbstractChartConfig
    {
       this.area = area;
    }
+
+   /**
+    * @return the interactive
+    */
+   public boolean isInteractive()
+   {
+      return interactive;
+   }
+
+   /**
+    * @param interactive the interactive to set
+    */
+   public void setInteractive(boolean interactive)
+   {
+      this.interactive = interactive;
+   }
 }
index 65617d0..1d054ab 100644 (file)
@@ -15,5 +15,6 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.8.2",
  org.netxms.ui.eclipse.usermanager;bundle-version="2.0.8"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
-Export-Package: org.netxms.ui.eclipse.perfview.views.helpers,
+Export-Package: org.netxms.ui.eclipse.perfview.views,
+ org.netxms.ui.eclipse.perfview.views.helpers,
  org.netxms.ui.eclipse.perfview.widgets
index 8b29f54..b504c99 100644 (file)
@@ -403,7 +403,7 @@ public class HistoricalGraphView extends ViewPart implements GraphSettingsChange
          }
       });
 
-      // Create menu.
+      // Create menu
       Menu menu = menuMgr.createContextMenu((Control)chart);
       ((Control)chart).setMenu(menu);
       for(Control ch : ((Composite)chart).getChildren())
@@ -579,36 +579,9 @@ public class HistoricalGraphView extends ViewPart implements GraphSettingsChange
       };
       actionZoomOut.setImageDescriptor(SharedIcons.ZOOM_OUT);
 
-      actionAdjustX = new Action() {
-         @Override
-         public void run()
-         {
-            chart.adjustXAxis(true);
-         }
-      };
-      actionAdjustX.setText(Messages.get().HistoricalGraphView_AdjustX);
-      actionAdjustX.setImageDescriptor(Activator.getImageDescriptor("icons/adjust_x.png")); //$NON-NLS-1$
-
-      actionAdjustY = new Action() {
-         @Override
-         public void run()
-         {
-            chart.adjustYAxis(true);
-         }
-      };
-      actionAdjustY.setText(Messages.get().HistoricalGraphView_AdjustY);
-      actionAdjustY.setImageDescriptor(Activator.getImageDescriptor("icons/adjust_y.png")); //$NON-NLS-1$
-
-      actionAdjustBoth = new Action() {
-         @Override
-         public void run()
-         {
-            chart.adjustXAxis(false);
-            chart.adjustYAxis(true);
-         }
-      };
-      actionAdjustBoth.setText(Messages.get().HistoricalGraphView_Adjust);
-      actionAdjustBoth.setImageDescriptor(Activator.getImageDescriptor("icons/adjust.png")); //$NON-NLS-1$
+      actionAdjustX = createAction(ActionType.ADJUST_X, chart);
+      actionAdjustY = createAction(ActionType.ADJUST_Y, chart);
+      actionAdjustBoth = createAction(ActionType.ADJUST_BOTH, chart);
 
       actionShowLegend = new Action(Messages.get().HistoricalGraphView_ShowLegend) {
          @Override
@@ -709,20 +682,15 @@ public class HistoricalGraphView extends ViewPart implements GraphSettingsChange
       };
       actionAreaChart.setChecked(config.isArea());
 
-      presetActions = new Action[presetRanges.length];
-      for(int i = 0; i < presetRanges.length; i++)
-      {
-         final Integer presetIndex = i;
-         presetActions[i] = new Action(String.format(Messages.get().HistoricalGraphView_Last, presetNames[i])) {
-            @Override
-            public void run()
-            {
-               config.setTimeUnits(presetUnits[presetIndex]);
-               config.setTimeRange(presetRanges[presetIndex]);
-               updateChart();
-            }
-         };
-      }
+      presetActions = createPresetActions(new PresetHandler() {
+         @Override
+         public void onPresetSelected(int units, int range)
+         {
+            config.setTimeUnits(units);
+            config.setTimeRange(range);
+            updateChart();
+         }
+      });
       
       actionCopyImage = new Action(Messages.get().HistoricalGraphView_CopyToClipboard, SharedIcons.COPY) {
           @Override
@@ -735,7 +703,7 @@ public class HistoricalGraphView extends ViewPart implements GraphSettingsChange
           }
        };
    }
-
+   
    /**
     * 
     */
@@ -1012,4 +980,99 @@ public class HistoricalGraphView extends ViewPart implements GraphSettingsChange
       }
       updateChart();
    }
+
+   /**
+    * Create preset actions
+    * 
+    * @param handler
+    * @return
+    */
+   public static Action[] createPresetActions(final PresetHandler handler)
+   {
+      Action[] actions = new Action[presetRanges.length];
+      for(int i = 0; i < presetRanges.length; i++)
+      {
+         final Integer presetIndex = i;
+         actions[i] = new Action(String.format(Messages.get().HistoricalGraphView_Last, presetNames[i])) {
+            @Override
+            public void run()
+            {
+               handler.onPresetSelected(presetUnits[presetIndex], presetRanges[presetIndex]);
+            }
+         };
+      }
+      return actions;
+   }
+   
+   /**
+    * Create action for chart
+    * 
+    * @param type
+    * @param chart
+    * @return
+    */
+   public static Action createAction(ActionType type, final HistoricalDataChart chart)
+   {
+      Action action = null;
+      switch(type)
+      {
+         case ADJUST_BOTH:
+            action = new Action() {
+               @Override
+               public void run()
+               {
+                  chart.adjustXAxis(false);
+                  chart.adjustYAxis(true);
+               }
+            };
+            action.setText(Messages.get().HistoricalGraphView_Adjust);
+            action.setImageDescriptor(Activator.getImageDescriptor("icons/adjust.png")); //$NON-NLS-1$
+            break;
+         case ADJUST_X:
+            action = new Action() {
+               @Override
+               public void run()
+               {
+                  chart.adjustXAxis(true);
+               }
+            };
+            action.setText(Messages.get().HistoricalGraphView_AdjustX);
+            action.setImageDescriptor(Activator.getImageDescriptor("icons/adjust_x.png")); //$NON-NLS-1$
+            break;
+         case ADJUST_Y:
+            action = new Action() {
+               @Override
+               public void run()
+               {
+                  chart.adjustYAxis(true);
+               }
+            };
+            action.setText(Messages.get().HistoricalGraphView_AdjustY);
+            action.setImageDescriptor(Activator.getImageDescriptor("icons/adjust_y.png")); //$NON-NLS-1$
+            break;
+      }
+      return action;
+   }
+   
+   /**
+    * Action types
+    */
+   public enum ActionType
+   {
+      ADJUST_X, ADJUST_Y, ADJUST_BOTH
+   }
+   
+   /**
+    * Preset handler
+    */
+   public interface PresetHandler
+   {
+      /**
+       * Called when new preset selected
+       * 
+       * @param units
+       * @param range
+       */
+      public void onPresetSelected(int units, int range);
+   }
 }
index 91d9f6f..075bf9c 100644 (file)
@@ -62,6 +62,7 @@ public class AbstractChart extends PropertyPage
    private Button checkLogScale;
    private Button checkStacked;
    private Button checkAreaChart;
+   private Button checkInteractive;
    private LabeledSpinner lineWidth;
    private YAxisRangeEditor yAxisRange;   
 
@@ -193,6 +194,13 @@ public class AbstractChart extends PropertyPage
                        gd.horizontalAlignment = SWT.FILL;
                        gd.grabExcessHorizontalSpace = true;
                        checkShowGrid.setLayoutData(gd);
+         
+         checkInteractive = new Button(optionsGroup, SWT.CHECK);
+         checkInteractive.setText("&Interactive");
+         checkInteractive.setSelection(((LineChartConfig)config).isInteractive());
+         gd = new GridData();
+         gd.horizontalSpan = layout.numColumns;
+         checkInteractive.setLayoutData(gd);
                        
                        Composite timeRangeArea = new Composite(dialogArea, SWT.NONE);
                        layout = new GridLayout();
@@ -326,6 +334,7 @@ public class AbstractChart extends PropertyPage
          ((LineChartConfig)config).setLogScaleEnabled(checkLogScale.getSelection());
          ((LineChartConfig)config).setStacked(checkStacked.getSelection());
          ((LineChartConfig)config).setArea(checkAreaChart.getSelection());
+         ((LineChartConfig)config).setInteractive(checkInteractive.getSelection());
          ((LineChartConfig)config).setLineWidth(lineWidth.getSelection());
                }
                return true;
index 4c85c53..9c19752 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * NetXMS - open source network management system
- * Copyright (C) 2003-2015 Victor Kirhenshtein
+ * Copyright (C) 2003-2016 Victor Kirhenshtein
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -24,11 +24,19 @@ import java.util.List;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.DisposeEvent;
 import org.eclipse.swt.events.DisposeListener;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.Widget;
 import org.eclipse.ui.IViewPart;
 import org.netxms.client.NXCSession;
@@ -36,6 +44,7 @@ import org.netxms.client.dashboards.DashboardElement;
 import org.netxms.client.datacollection.DciData;
 import org.netxms.client.datacollection.GraphItem;
 import org.netxms.client.datacollection.GraphItemStyle;
+import org.netxms.ui.eclipse.actions.RefreshAction;
 import org.netxms.ui.eclipse.charts.api.ChartColor;
 import org.netxms.ui.eclipse.charts.api.ChartDciConfig;
 import org.netxms.ui.eclipse.charts.api.ChartFactory;
@@ -44,6 +53,8 @@ import org.netxms.ui.eclipse.dashboard.Activator;
 import org.netxms.ui.eclipse.dashboard.Messages;
 import org.netxms.ui.eclipse.dashboard.widgets.internal.LineChartConfig;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.perfview.views.HistoricalGraphView;
+import org.netxms.ui.eclipse.perfview.views.HistoricalGraphView.ActionType;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 import org.netxms.ui.eclipse.tools.ViewRefreshController;
 
@@ -58,6 +69,11 @@ public class LineChartElement extends ElementWidget
        private boolean updateInProgress = false;
        private NXCSession session;
        private List<DataCacheElement> dataCache = new ArrayList<DataCacheElement>(16);
+   private Action actionRefresh;
+   private Action actionAdjustX;
+   private Action actionAdjustY;
+   private Action actionAdjustBoth;
+   private Action[] presetActions;
 
        /**
         * @param parent
@@ -81,7 +97,7 @@ public class LineChartElement extends ElementWidget
                setLayout(new FillLayout());
                
                chart = ChartFactory.createLineChart(this, SWT.NONE);
-               chart.setZoomEnabled(false);
+               chart.setZoomEnabled(config.isInteractive());
                chart.setTitleVisible(config.isShowTitle());
                chart.setChartTitle(config.getTitle());
                chart.setLegendVisible(config.isShowLegend());
@@ -127,6 +143,82 @@ public class LineChartElement extends ElementWidget
             refreshController.dispose();
          }
       });
+               
+               if (config.isInteractive())
+               {
+                  createActions();
+                  createChartContextMenu();
+               }
+       }
+
+   /**
+    * Create actions
+    */
+   private void createActions()
+   {
+      actionRefresh = new RefreshAction() {
+         @Override
+         public void run()
+         {
+            refreshData();
+         }
+      };
+
+      actionAdjustX = HistoricalGraphView.createAction(ActionType.ADJUST_X, chart);
+      actionAdjustY = HistoricalGraphView.createAction(ActionType.ADJUST_Y, chart);
+      actionAdjustBoth = HistoricalGraphView.createAction(ActionType.ADJUST_BOTH, chart);
+
+      presetActions = HistoricalGraphView.createPresetActions(new HistoricalGraphView.PresetHandler() {
+         @Override
+         public void onPresetSelected(int units, int range)
+         {
+            config.setTimeUnits(units);
+            config.setTimeRange(range);
+            refreshData();
+         }
+      });
+   }
+
+       /**
+        * Create chart's context menu
+        */
+       private void createChartContextMenu()
+       {
+          final MenuManager manager = new MenuManager();
+          manager.setRemoveAllWhenShown(true);
+          manager.addMenuListener(new IMenuListener() {
+         public void menuAboutToShow(IMenuManager mgr)
+         {
+            fillContextMenu(manager);
+         }
+      });
+          
+      Menu menu = manager.createContextMenu((Control)chart);
+      ((Control)chart).setMenu(menu);
+      for(Control ch : ((Composite)chart).getChildren())
+      {
+         ch.setMenu(menu);
+      }
+       }
+       
+       /**
+        * Fill context menu
+        * 
+        * @param manager
+        */
+       private void fillContextMenu(IMenuManager manager)
+       {
+      MenuManager presets = new MenuManager("&Presets");
+      for(int i = 0; i < presetActions.length; i++)
+         presets.add(presetActions[i]);
+      
+      manager.add(presets);
+      manager.add(new Separator());
+      manager.add(actionAdjustBoth);
+      manager.add(actionAdjustX);
+      manager.add(actionAdjustY);
+      manager.add(new Separator());
+      manager.add(actionRefresh);
        }
 
    /**
index 986fa91..ab4f41e 100644 (file)
@@ -51,6 +51,9 @@ public class LineChartConfig extends AbstractChartConfig
    
    @Element(required = false)
    private boolean area = false;
+   
+   @Element(required = false)
+   private boolean interactive = false;
 
    /**
     * Default constructor
@@ -220,4 +223,20 @@ public class LineChartConfig extends AbstractChartConfig
    {
       this.area = area;
    }
+
+   /**
+    * @return the interactive
+    */
+   public boolean isInteractive()
+   {
+      return interactive;
+   }
+
+   /**
+    * @param interactive the interactive to set
+    */
+   public void setInteractive(boolean interactive)
+   {
+      this.interactive = interactive;
+   }
 }
index e4a298b..f5bfe47 100644 (file)
@@ -15,5 +15,6 @@ Require-Bundle: org.eclipse.rap.ui;bundle-version="2.3.2",
  org.netxms.ui.eclipse.usermanager;bundle-version="2.0.8"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
-Export-Package: org.netxms.ui.eclipse.perfview.views.helpers,
+Export-Package: org.netxms.ui.eclipse.perfview.views,
+ org.netxms.ui.eclipse.perfview.views.helpers,
  org.netxms.ui.eclipse.perfview.widgets
index d2dc132..9a03cbe 100644 (file)
@@ -398,7 +398,7 @@ public class HistoricalGraphView extends ViewPart implements GraphSettingsChange
          }
       });
 
-      // Create menu.
+      // Create menu
       Menu menu = menuMgr.createContextMenu((Control)chart);
       ((Control)chart).setMenu(menu);
       for(Control ch : ((Composite)chart).getChildren())
@@ -574,36 +574,9 @@ public class HistoricalGraphView extends ViewPart implements GraphSettingsChange
       };
       actionZoomOut.setImageDescriptor(SharedIcons.ZOOM_OUT);
 
-      actionAdjustX = new Action() {
-         @Override
-         public void run()
-         {
-            chart.adjustXAxis(true);
-         }
-      };
-      actionAdjustX.setText(Messages.get().HistoricalGraphView_AdjustX);
-      actionAdjustX.setImageDescriptor(Activator.getImageDescriptor("icons/adjust_x.png")); //$NON-NLS-1$
-
-      actionAdjustY = new Action() {
-         @Override
-         public void run()
-         {
-            chart.adjustYAxis(true);
-         }
-      };
-      actionAdjustY.setText(Messages.get().HistoricalGraphView_AdjustY);
-      actionAdjustY.setImageDescriptor(Activator.getImageDescriptor("icons/adjust_y.png")); //$NON-NLS-1$
-
-      actionAdjustBoth = new Action() {
-         @Override
-         public void run()
-         {
-            chart.adjustXAxis(false);
-            chart.adjustYAxis(true);
-         }
-      };
-      actionAdjustBoth.setText(Messages.get().HistoricalGraphView_Adjust);
-      actionAdjustBoth.setImageDescriptor(Activator.getImageDescriptor("icons/adjust.png")); //$NON-NLS-1$
+      actionAdjustX = createAction(ActionType.ADJUST_X, chart);
+      actionAdjustY = createAction(ActionType.ADJUST_Y, chart);
+      actionAdjustBoth = createAction(ActionType.ADJUST_BOTH, chart);
 
       actionShowLegend = new Action(Messages.get().HistoricalGraphView_ShowLegend) {
          @Override
@@ -704,22 +677,17 @@ public class HistoricalGraphView extends ViewPart implements GraphSettingsChange
       };
       actionAreaChart.setChecked(config.isArea());
 
-      presetActions = new Action[presetRanges.length];
-      for(int i = 0; i < presetRanges.length; i++)
-      {
-         final Integer presetIndex = i;
-         presetActions[i] = new Action(String.format(Messages.get().HistoricalGraphView_Last, presetNames[i])) {
-            @Override
-            public void run()
-            {
-               config.setTimeUnits(presetUnits[presetIndex]);
-               config.setTimeRange(presetRanges[presetIndex]);
-               updateChart();
-            }
-         };
-      }
+      presetActions = createPresetActions(new PresetHandler() {
+         @Override
+         public void onPresetSelected(int units, int range)
+         {
+            config.setTimeUnits(units);
+            config.setTimeRange(range);
+            updateChart();
+         }
+      });
    }
-
+   
    /**
     * 
     */
@@ -995,4 +963,99 @@ public class HistoricalGraphView extends ViewPart implements GraphSettingsChange
       }
       updateChart();
    }
+
+   /**
+    * Create preset actions
+    * 
+    * @param handler
+    * @return
+    */
+   public static Action[] createPresetActions(final PresetHandler handler)
+   {
+      Action[] actions = new Action[presetRanges.length];
+      for(int i = 0; i < presetRanges.length; i++)
+      {
+         final Integer presetIndex = i;
+         actions[i] = new Action(String.format(Messages.get().HistoricalGraphView_Last, presetNames[i])) {
+            @Override
+            public void run()
+            {
+               handler.onPresetSelected(presetUnits[presetIndex], presetRanges[presetIndex]);
+            }
+         };
+      }
+      return actions;
+   }
+   
+   /**
+    * Create action for chart
+    * 
+    * @param type
+    * @param chart
+    * @return
+    */
+   public static Action createAction(ActionType type, final HistoricalDataChart chart)
+   {
+      Action action = null;
+      switch(type)
+      {
+         case ADJUST_BOTH:
+            action = new Action() {
+               @Override
+               public void run()
+               {
+                  chart.adjustXAxis(false);
+                  chart.adjustYAxis(true);
+               }
+            };
+            action.setText(Messages.get().HistoricalGraphView_Adjust);
+            action.setImageDescriptor(Activator.getImageDescriptor("icons/adjust.png")); //$NON-NLS-1$
+            break;
+         case ADJUST_X:
+            action = new Action() {
+               @Override
+               public void run()
+               {
+                  chart.adjustXAxis(true);
+               }
+            };
+            action.setText(Messages.get().HistoricalGraphView_AdjustX);
+            action.setImageDescriptor(Activator.getImageDescriptor("icons/adjust_x.png")); //$NON-NLS-1$
+            break;
+         case ADJUST_Y:
+            action = new Action() {
+               @Override
+               public void run()
+               {
+                  chart.adjustYAxis(true);
+               }
+            };
+            action.setText(Messages.get().HistoricalGraphView_AdjustY);
+            action.setImageDescriptor(Activator.getImageDescriptor("icons/adjust_y.png")); //$NON-NLS-1$
+            break;
+      }
+      return action;
+   }
+   
+   /**
+    * Action types
+    */
+   public enum ActionType
+   {
+      ADJUST_X, ADJUST_Y, ADJUST_BOTH
+   }
+   
+   /**
+    * Preset handler
+    */
+   public interface PresetHandler
+   {
+      /**
+       * Called when new preset selected
+       * 
+       * @param units
+       * @param range
+       */
+      public void onPresetSelected(int units, int range);
+   }
 }