From: lempinen Date: Mon, 16 Jan 2012 14:19:06 +0000 (+0000) Subject: Expanded drop area for empty chart panels and chart panels with all minimized charts... X-Git-Tag: simantics-1.6~50 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=787b2b479ccb66308406af88c0d54fa8f9e4387c;p=simantics%2Fsysdyn.git Expanded drop area for empty chart panels and chart panels with all minimized charts ( refs #3082 ) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23990 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartDropTarget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartDropTarget.java index f641a3c7..a1b8cd46 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartDropTarget.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartDropTarget.java @@ -15,6 +15,7 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.dnd.DND; import org.eclipse.swt.dnd.DropTargetAdapter; import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.simantics.db.Resource; import org.simantics.ui.utils.AdaptionUtils; @@ -26,12 +27,12 @@ import org.simantics.ui.utils.AdaptionUtils; */ public class ChartDropTarget extends DropTargetAdapter { - private ChartPanelSeparator separator; + private Composite separator; private ChartPanelElement element; private Display display; private ChartPanel panel; - public ChartDropTarget(ChartPanelSeparator separator, ChartPanelElement element, ChartPanel panel) { + public ChartDropTarget(Composite separator, ChartPanelElement element, ChartPanel panel) { this.separator = separator; this.display = separator.getDisplay(); this.element = element; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java index a82b6c29..18021278 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java @@ -157,7 +157,6 @@ public class ChartPanel extends ViewPart { sc.setExpandVertical(true); sc.getVerticalBar().setIncrement(sc.getVerticalBar().getIncrement()*3); sc.getHorizontalBar().setIncrement(sc.getHorizontalBar().getIncrement()*3); - setupDropTarget(); body = new Composite(sc, SWT.NONE); GridLayoutFactory.fillDefaults().margins(3, 0).spacing(0, 0).applyTo(body); @@ -165,6 +164,9 @@ public class ChartPanel extends ViewPart { sc.setContent(body); createContents(); + + setupDropTarget(); + } /** @@ -342,6 +344,10 @@ public class ChartPanel extends ViewPart { } }); + + DropTarget target2 = new DropTarget(body, DND.DROP_COPY | DND.DROP_MOVE); + target2.setTransfer(new Transfer[] { LocalObjectTransfer.getTransfer() }); + target2.addDropListener(new ChartDropTarget(body, null, this)); } @@ -369,6 +375,8 @@ public class ChartPanel extends ViewPart { * @param layout refresh layout. use with vertical layout. */ public void addChart(Resource chartResource, ChartPanelElement element, boolean layout) { + if(element == null) + element = chartElements.get(chartElements.size() - 1); int index = chartElements.indexOf(element); if(index >= 0) { ChartPanelElement e = chartElements.get(index); @@ -457,4 +465,7 @@ public class ChartPanel extends ViewPart { }); } + public ArrayList getElements() { + return chartElements; + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelElement.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelElement.java index 5c830dc5..405294a9 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelElement.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelElement.java @@ -52,10 +52,13 @@ public class ChartPanelElement extends Composite { oldData = GridDataFactory.fillDefaults().create(); } + int size = panel.getElements().size(); GridData data = (GridData) oldData; // Horizontal data data.widthHint = CHART_MINIMUM_WIDTH; - if(chartResource == null && !panel.isVertical()){ + if(getResource() == null && size == 1) { + data.grabExcessHorizontalSpace = true; + } else if(getResource() == null && !panel.isVertical()){ data.grabExcessHorizontalSpace = false; data.widthHint = SWT.DEFAULT; } else if(minimized && !panel.isVertical()) { @@ -66,7 +69,9 @@ public class ChartPanelElement extends Composite { } // Vertical data - if(!minimized && getResource() != null) { + if(getResource() == null && size == 1) { + data.grabExcessVerticalSpace = true; + } else if(!minimized && getResource() != null) { data.grabExcessVerticalSpace = true; data.heightHint = CHART_MINIMUM_HEIGHT; } else if(!panel.isVertical()){ @@ -99,7 +104,7 @@ public class ChartPanelElement extends Composite { * @param style The Style of the created chart element */ public ChartPanelElement(Composite parent, ChartPanel panel, Resource chartResource, boolean minimized, int style) { - super(parent, style | SWT.NONE); + super(parent, style | SWT.NONE ); this.panel = panel; this.chartResource = chartResource; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelSeparator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelSeparator.java index d529a865..e0bde1e2 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelSeparator.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelSeparator.java @@ -37,13 +37,20 @@ public class ChartPanelSeparator extends Composite { oldData = GridDataFactory.fillDefaults().create(); } GridData data = (GridData) oldData; - if(panel.isVertical()) { + // Empty panel -> drop area the size of the whole panel + if(panel.getElements().size() == 1 && panel.getElements().get(0).getResource() == null) { data.grabExcessHorizontalSpace = true; - data.grabExcessVerticalSpace = false; - } else { - data.grabExcessHorizontalSpace = false; data.grabExcessVerticalSpace = true; } + else { + if(panel.isVertical()) { + data.grabExcessHorizontalSpace = true; + data.grabExcessVerticalSpace = false; + } else { + data.grabExcessHorizontalSpace = false; + data.grabExcessVerticalSpace = true; + } + } return data; }