]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Expanded drop area for empty chart panels and chart panels with all minimized charts...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 16 Jan 2012 14:19:06 +0000 (14:19 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 16 Jan 2012 14:19:06 +0000 (14:19 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23990 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartDropTarget.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelElement.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelSeparator.java

index f641a3c788aa1337a45094004703d2fdee386a9f..a1b8cd469a92f111883cbc7c9a8d6a27b002a469 100644 (file)
@@ -15,6 +15,7 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.dnd.DND;\r
 import org.eclipse.swt.dnd.DropTargetAdapter;\r
 import org.eclipse.swt.dnd.DropTargetEvent;\r
+import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Display;\r
 import org.simantics.db.Resource;\r
 import org.simantics.ui.utils.AdaptionUtils;\r
@@ -26,12 +27,12 @@ import org.simantics.ui.utils.AdaptionUtils;
  */\r
 public class ChartDropTarget extends DropTargetAdapter {\r
     \r
-    private ChartPanelSeparator separator;\r
+    private Composite separator;\r
     private ChartPanelElement element;\r
     private Display display;\r
     private ChartPanel panel;\r
     \r
-    public ChartDropTarget(ChartPanelSeparator separator, ChartPanelElement element, ChartPanel panel) {\r
+    public ChartDropTarget(Composite separator, ChartPanelElement element, ChartPanel panel) {\r
         this.separator = separator;\r
         this.display = separator.getDisplay();\r
         this.element = element;\r
index a82b6c29526a67478c6b464a4771338fb4d02d61..180212780c9bc92297166084d0d3265c51de74de 100644 (file)
@@ -157,7 +157,6 @@ public class ChartPanel extends ViewPart {
         sc.setExpandVertical(true);\r
         sc.getVerticalBar().setIncrement(sc.getVerticalBar().getIncrement()*3);\r
         sc.getHorizontalBar().setIncrement(sc.getHorizontalBar().getIncrement()*3);\r
-        setupDropTarget();\r
 \r
         body = new Composite(sc, SWT.NONE);\r
         GridLayoutFactory.fillDefaults().margins(3, 0).spacing(0, 0).applyTo(body);\r
@@ -165,6 +164,9 @@ public class ChartPanel extends ViewPart {
 \r
         sc.setContent(body);\r
         createContents();\r
+        \r
+        setupDropTarget();\r
+\r
     }\r
     \r
     /**\r
@@ -342,6 +344,10 @@ public class ChartPanel extends ViewPart {
             }\r
 \r
         });\r
+        \r
+        DropTarget target2 = new DropTarget(body, DND.DROP_COPY | DND.DROP_MOVE);\r
+        target2.setTransfer(new Transfer[] {  LocalObjectTransfer.getTransfer() });\r
+        target2.addDropListener(new ChartDropTarget(body, null, this));\r
 \r
     }\r
 \r
@@ -369,6 +375,8 @@ public class ChartPanel extends ViewPart {
      * @param layout refresh layout. use with vertical layout. \r
      */\r
     public void addChart(Resource chartResource, ChartPanelElement element, boolean layout) {\r
+        if(element == null)\r
+            element = chartElements.get(chartElements.size() - 1);\r
         int index = chartElements.indexOf(element);\r
         if(index >= 0) {\r
             ChartPanelElement e = chartElements.get(index);\r
@@ -457,4 +465,7 @@ public class ChartPanel extends ViewPart {
         });\r
     }\r
 \r
+    public ArrayList<ChartPanelElement> getElements() {\r
+        return chartElements;\r
+    }\r
 }\r
index 5c830dc5750e0b01b792e7af1cfbf188de1569aa..405294a94f76ef759ba2477bdffd1706c0c27541 100644 (file)
@@ -52,10 +52,13 @@ public class ChartPanelElement extends Composite {
             oldData = GridDataFactory.fillDefaults().create();\r
         }\r
 \r
+        int size = panel.getElements().size();\r
         GridData data = (GridData) oldData;\r
         // Horizontal data\r
         data.widthHint = CHART_MINIMUM_WIDTH;\r
-        if(chartResource == null && !panel.isVertical()){\r
+        if(getResource() == null && size == 1) {\r
+            data.grabExcessHorizontalSpace = true;\r
+        } else if(getResource() == null && !panel.isVertical()){\r
             data.grabExcessHorizontalSpace = false;\r
             data.widthHint = SWT.DEFAULT;\r
         } else if(minimized && !panel.isVertical()) {\r
@@ -66,7 +69,9 @@ public class ChartPanelElement extends Composite {
         }\r
 \r
         // Vertical data\r
-        if(!minimized && getResource() != null) {\r
+        if(getResource() == null && size == 1) {\r
+            data.grabExcessVerticalSpace = true;\r
+        } else if(!minimized && getResource() != null) {\r
             data.grabExcessVerticalSpace = true;\r
             data.heightHint = CHART_MINIMUM_HEIGHT;\r
         } else if(!panel.isVertical()){\r
@@ -99,7 +104,7 @@ public class ChartPanelElement extends Composite {
      * @param style The Style of the created chart element\r
      */\r
     public ChartPanelElement(Composite parent, ChartPanel panel, Resource chartResource, boolean minimized, int style) {\r
-        super(parent, style | SWT.NONE);\r
+        super(parent, style | SWT.NONE );\r
         \r
         this.panel = panel;\r
         this.chartResource = chartResource;\r
index d529a8650fc251066889cc5dc52c31c5489b22d2..e0bde1e288899c6de939d298d243420b0d86d999 100644 (file)
@@ -37,13 +37,20 @@ public class ChartPanelSeparator extends Composite {
             oldData = GridDataFactory.fillDefaults().create();\r
         }\r
         GridData data = (GridData) oldData;\r
-        if(panel.isVertical()) { \r
+        // Empty panel -> drop area the size of the whole panel\r
+        if(panel.getElements().size() == 1 && panel.getElements().get(0).getResource() == null) {\r
             data.grabExcessHorizontalSpace = true;\r
-            data.grabExcessVerticalSpace = false;\r
-        } else {\r
-            data.grabExcessHorizontalSpace = false;\r
             data.grabExcessVerticalSpace = true;\r
         }\r
+        else {\r
+            if(panel.isVertical()) { \r
+                data.grabExcessHorizontalSpace = true;\r
+                data.grabExcessVerticalSpace = false;\r
+            } else {\r
+                data.grabExcessHorizontalSpace = false;\r
+                data.grabExcessVerticalSpace = true;\r
+            }\r
+        }\r
         return data;\r
     }\r
 \r