Replies: 3 comments 4 replies
|
Yes, you are right, currently GLSP writes only a UUID into the real system clipboard and keeps the payload in But I believe even if that were to work, the selected element ids put into the clipboard may not work as they will not match the proper element ids anyways. So ideally, what we need for that to work is:
For the payload part, the default GModel-based handlers may be a good reference: For the shared storage part, you have two options today: a) Share the clipboard on the client. Rebind b) Let the server own the clipboard. This is what the Eclipse integration does: If you only care about editor-to-editor within the same application, (b) is the least amount of fighting with browser clipboard restrictions. (a) is closer to where we'd want to take #148. So if you build something there, feedback or a contribution on that issue would be very welcome. Of course, this is just theory and I have not actively tested this so I'm happy to see what you report ;-) |
|
Hi @martin-fleck-at once again I need your help. I am still struggeling with the over all concept you are talking about. To me it looks like my server side ClipboardDataActionHandler is fine : public class BPMNClipboardDataActionHandler extends AbstractActionHandler<RequestClipboardDataAction> {
@Override
protected List<Action> executeAction(final RequestClipboardDataAction actualAction) {
EditorContext ctx = actualAction.getEditorContext();
List<String> selectedElements = ctx.getSelectedElementIds();
logger.debug("... copy " + selectedElements.size() + " elements...");
..........
}
}It simply copy somehow the diagram information on store it somehow in my server. The problem seems to be only the client side Clipboard-Paste-Handler. As you pointed out the LocalClipboardService is not sending each paste event to the server. So my shared server side clipboard is not working. As far as I understand GLSP I need to implement my own bind(TYPES.IAsyncClipboardService).to(BPMNClipboardService);Is this approach correct? Or do I oversee something? |
|
Ok, I think I found the correct way to solve the problem based on solution b) server side clipboard: Client: A custom BPMNCopyPasteHandler (extends ServerCopyPasteHandler) overrides handlePaste() to always dispatch the PasteOperation to the server, regardless of whether the client-side IAsyncClipboardService has matching data. @injectable()
export class BPMNCopyPasteHandler extends ServerCopyPasteHandler {
override handlePaste(event: ClipboardEvent): void {
if (event.clipboardData && this.shouldPaste(event)) {
// Always dispatch the PasteOperation - the server holds the actual
// clipboard data itself and knows what to paste.
this.actionDispatcher.dispatch(
PasteOperation.create({ clipboardData: {}, editorContext: this.editorContext.get() })
);
event.preventDefault();
}
}
}The default handler otherwise aborts if no local data is found for the clipboard id - which is always the case across two independently opened diagram editors, since that service is scoped per diagram injector. I rebind the handler in my BPMNDiagramModule: Server: A new BPMNClipboardService holds the copied element ids. The key point is that it's not bound in the DiagramModule (per-diagram injector), but in a dedicated BPMNServerModule (extending ServerModule) as a Singleton. This way it's shared across all diagrams opened within the same client connection. So in my java server I have a new class: public class BPMNClipboardService {
private Map<String, String> data;
public void put(final Map<String, String> data) {
this.data = data;
}
public Map<String, String> get() {
return data;
}
public void clear() {
data = null;
}
}and I overwrite the default server module public class BPMNServerModule extends ServerModule {
@Override
protected void configure() {
super.configure();
// Bind the clipboard service as a session-wide singleton so it is shared
// across all diagram editors within the same client connection.
bind(BPMNClipboardService.class).in(Singleton.class);
}
}...which I call in my ServerLauncher instead of the GLSP Default server public final class BPMNServerLauncher {
private BPMNServerLauncher() {
}
public static void main(final String[] args) {
// setup custom logging format
LoggingHelper.setupLogging();
String processName = "OpenBPMNServer";
try {
DefaultCLIParser parser = new DefaultCLIParser(args, processName);
LaunchUtil.configure(parser);
int port = parser.parsePort();
String host = parser.parseHostname();
ServerModule bpmnServerModule = new BPMNServerModule()
.configureDiagramModule(new BPMNDiagramModule());
GLSPServerLauncher launcher = new SocketGLSPServerLauncher(bpmnServerModule);
launcher.start(host, port, parser);
} catch (ParseException ex) {
ex.printStackTrace();
LaunchUtil.printHelp(processName, DefaultCLIParser.getDefaultOptions());
}
}
}The Handler: Finally my As a result copy in editor A → paste in editor B now works :-) |
Uh oh!
There was an error while loading. Please reload this page.
I whant to copy/paste elements from one editor window into another.
Currently this works only in one opened Editor window. I have implemented a
RequestClipboardDataActionto react on a 'Copy' command from the UII understand that in this way I have the data only in my current ModelState and I can only 'paste' the data into the same model.
I have currently already implemented a
PasteOperation:My plan was to store the data into a general memory or a temp file to allow Paste Actions between two different model files.
But I now regonized, that the PasteOperation in a second opened Model File will never be triggered.
I register my OpeationHandler in my DiagramModule:
What is the correct way to handel the Paste Action when I whant to copy elements from one editor into another?
Thanks for help
===
Ralph
All reactions