1 package com.proalpha.java.oea.plugins.querygenerator.handlers;
5 import org.eclipse.core.commands.AbstractHandler;
6 import org.eclipse.core.commands.ExecutionEvent;
7 import org.eclipse.core.commands.ExecutionException;
8 import org.eclipse.swt.widgets.Display;
10 import com.openedge.core.runtime.IAVMClient;
11 import com.openedge.core.runtime.IAVMRuntimeListener;
12 import com.openedge.pdt.project.OEProjectPlugin;
13 import com.openedge.pdt.project.sharedavm.SharedAVM;
14 import com.proalpha.java.oea.plugins.querygenerator.EditorTools;
15 import com.proalpha.java.oea.plugins.querygenerator.runtime.HandlerTools;
16 import com.proalpha.java.oea.plugins.querygenerator.runtime.QueryGeneratorPrograms;
36 public Object
execute(ExecutionEvent event)
throws ExecutionException {
41 Display.getDefault().syncExec(
new QueryGeneratorCommand(event.getParameters()));
47 public boolean isEnabled() {
52 public boolean isHandled() {
56 private class QueryGeneratorCommand
implements Runnable {
58 private Map<String,String> parameters =
null;
60 public QueryGeneratorCommand(Map<String, String> parameters) {
62 this.parameters = parameters;
68 String commandParameter = String.format(
69 "EditorInsertRequestId=%s%sSavePluginSettingId=%s%sLoadPluginSettingId=%s",
70 EditorInsertCommandHandler.getRequestId(),
71 HandlerTools.PARAM_SPLITTER,
72 SavePluginSettingHandler.getRequestId(),
73 HandlerTools.PARAM_SPLITTER,
74 LoadPluginSettingHandler.getRequestId());
76 IAVMClient runtime =
null;
78 String menuItemType = parameters.get(
"com.proalpha.java.oea.plugins.querygenerator.avmTypeParameter");
80 if (menuItemType ==
null
81 || menuItemType.isEmpty()
82 || menuItemType.equals(
"DefaultAVM"))
83 runtime = HandlerTools.getInstance().getRuntime();
85 else if (menuItemType.equals(
"ProjectAVM")) {
87 OEProjectPlugin projectPlugin = OEProjectPlugin.getDefault();
88 String avmName = (String) parameters.get(
"com.proalpha.java.oea.plugins.querygenerator.avmNameParameter");
90 if (avmName !=
null && !avmName.isEmpty())
91 runtime = projectPlugin.getOpenEdgeModel().getOpenEdgeProject(avmName).getRuntime();
93 }
else if (menuItemType.equals(
"SharedAVM")) {
95 if (SharedAVM.isRuntimeStarted())
96 runtime = SharedAVM.getSharedAVM();
105 IAVMClient sharedRuntime = SharedAVM.getSharedAVM();
106 sharedRuntime.addAVMRuntimeListener(
new SharedAVMRuntimeListener(commandParameter));
112 if (runtime !=
null) {
114 startQueryGenerator(runtime, commandParameter);
116 String selectionText = EditorTools.getInstance().getSelectionText();
118 if (selectionText !=
null
119 && !selectionText.isEmpty()
120 && selectionText.length() <= 1024)
121 HandlerTools.getInstance().runProgram(
123 QueryGeneratorPrograms.EXECUTE_COMMAND,
124 String.format(
"command=select_table%stable_name=%s",
125 HandlerTools.PARAM_SPLITTER,
135 private void startQueryGenerator(IAVMClient runtime, String commandParameter) {
137 if (runtime !=
null && runtime.isAvailable())
138 HandlerTools.getInstance().runProgram(
140 QueryGeneratorPrograms.START_QUERY_GENERATOR,
146 private class SharedAVMRuntimeListener
implements IAVMRuntimeListener {
148 private String commandParameter =
"";
150 public SharedAVMRuntimeListener(String commandParameter) {
152 this.commandParameter = commandParameter;
156 public void runtimeAvailable(IAVMClient runtime) { }
159 public void runtimeInitialized(IAVMClient runtime) { }
162 public void runtimeShutdown(IAVMClient runtime) { }
165 public void runtimeStarted(IAVMClient runtime) {
166 runtime.removeAVMRuntimeListener(
this);
167 startQueryGenerator(runtime, commandParameter);
171 public void runtimeStopped(IAVMClient runtime) { }
Object execute(ExecutionEvent event)