Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Scout/HowTo/4.0/Drag and drop support"
(Created page with "{{ScoutPage|cat=HowTo 4.0}} This how-to describes how to add support for drag and drop to your tables. = Steps = *Select the table<br> *In the Scout Object Properties un...") |
(→Steps) |
||
Line 24: | Line 24: | ||
*Add code to '''execDrag()''' to create an appropriate TransferObject<br> | *Add code to '''execDrag()''' to create an appropriate TransferObject<br> | ||
<pre> @Override | <pre> @Override | ||
− | protected TransferObject execDrag(ITableRow | + | protected TransferObject execDrag(List<ITableRow> rows) throws ProcessingException { |
StringBuilder result = new StringBuilder(); | StringBuilder result = new StringBuilder(); | ||
Line 39: | Line 39: | ||
<pre> @Override | <pre> @Override | ||
protected void execDrop(ITableRow row, TransferObject t) throws ProcessingException { | protected void execDrop(ITableRow row, TransferObject t) throws ProcessingException { | ||
− | if (t.isText() & | + | if (t.isText() && (t instanceof TextTransferObject)) { |
String text = ((TextTransferObject) t).getPlainText(); | String text = ((TextTransferObject) t).getPlainText(); | ||
// split text at "; " to get seperate lines | // split text at "; " to get seperate lines | ||
Line 46: | Line 46: | ||
} | } | ||
else if (t.isFileList()) { | else if (t.isFileList()) { | ||
− | File | + | List<File> o = ((FileListTransferObject) t).getFiles(); |
− | for (int i = 0; i | + | for (int i = 0; i < o.size(); ++i) { |
// handle content of o[i] | // handle content of o[i] | ||
− | System.out.println("Dropped file: " + o | + | System.out.println("Dropped file: " + o.get(i).getName()); |
} | } | ||
} | } | ||
Line 65: | Line 65: | ||
*If you added '''execCopy()''', the easiest way to implement this is probably to just forward it to execDrag() | *If you added '''execCopy()''', the easiest way to implement this is probably to just forward it to execDrag() | ||
<pre> @Override | <pre> @Override | ||
− | protected TransferObject execCopy(ITableRow | + | protected TransferObject execCopy(List<? extends ITableRow> rows) throws ProcessingException { |
− | return execDrag(rows); | + | return execDrag((List<ITableRow>) rows); |
} | } | ||
</pre> | </pre> | ||
<br> | <br> |
Revision as of 09:45, 9 May 2014
The Scout documentation has been moved to https://eclipsescout.github.io/.
This how-to describes how to add support for drag and drop to your tables.
Steps
- Select the table
- In the Scout Object Properties under Advanced Operations add the following methods:
execDrag()
execDrop()
If you want to also add support for copying using Ctrl-C, you can also add execCopy() - Click on one of the newly added methods to open the source code at the correct position.
- Add two new methods
getConfiguredDropType()
getConfiguredDragType()
to define what type of objects your drag and drop handlers support.
@Override protected int getConfiguredDragType() { return TYPE_TEXT_TRANSFER; } @Override @ConfigProperty("DRAG_AND_DROP_TYPE") @Order(190.0) @ConfigPropertyValue("0") protected int getConfiguredDropType() { return TYPE_TEXT_TRANSFER | TYPE_FILE_TRANSFER | TYPE_IMAGE_TRANSFER | TYPE_JAVA_ELEMENT_TRANSFER; }
- Add code to execDrag() to create an appropriate TransferObject
@Override protected TransferObject execDrag(List<ITableRow> rows) throws ProcessingException { StringBuilder result = new StringBuilder(); for (ITableRow row : rows) { if (!result.toString().equals("")) { result.append("; "); } result.append(getTable().getShortNameColumn().getValue(row) + " " + getTable().getNameColumn().getValue(row)); } return new TextTransferObject(result.toString()); }
- Add code to execDrop() to handle the appropriate TransferObjects. You need to treat each TransferObject type that getConfiguredDropType() returns
@Override protected void execDrop(ITableRow row, TransferObject t) throws ProcessingException { if (t.isText() && (t instanceof TextTransferObject)) { String text = ((TextTransferObject) t).getPlainText(); // split text at "; " to get seperate lines // treat each line according to business logic System.out.println("Dropped text: " + text); } else if (t.isFileList()) { List<File> o = ((FileListTransferObject) t).getFiles(); for (int i = 0; i < o.size(); ++i) { // handle content of o[i] System.out.println("Dropped file: " + o.get(i).getName()); } } else if (t.isImage()) { System.out.println("Dropped image"); } else if (t.isLocalObject()) { System.out.println("Dropped local object"); } else { System.out.println("Dropped other stuff"); } }
- If you added execCopy(), the easiest way to implement this is probably to just forward it to execDrag()
@Override protected TransferObject execCopy(List<? extends ITableRow> rows) throws ProcessingException { return execDrag((List<ITableRow>) rows); }