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
*/\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
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
\r
sc.setContent(body);\r
createContents();\r
+ \r
+ setupDropTarget();\r
+\r
}\r
\r
/**\r
}\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
* @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
});\r
}\r
\r
+ public ArrayList<ChartPanelElement> getElements() {\r
+ return chartElements;\r
+ }\r
}\r
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
}\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
* @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
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