| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.gui; |
| 22 |
|
|
| 23 |
|
import jalview.jbgui.GRestInputParamEditDialog; |
| 24 |
|
import jalview.ws.params.InvalidArgumentException; |
| 25 |
|
import jalview.ws.params.OptionI; |
| 26 |
|
import jalview.ws.params.ParameterI; |
| 27 |
|
import jalview.ws.rest.InputType; |
| 28 |
|
import jalview.ws.rest.RestServiceDescription; |
| 29 |
|
|
| 30 |
|
import java.util.ArrayList; |
| 31 |
|
import java.util.Hashtable; |
| 32 |
|
|
| 33 |
|
import javax.swing.JOptionPane; |
| 34 |
|
import javax.swing.JPanel; |
| 35 |
|
import javax.swing.event.ListSelectionEvent; |
| 36 |
|
|
| 37 |
|
import net.miginfocom.swing.MigLayout; |
| 38 |
|
|
| |
|
| 0% |
Uncovered Elements: 119 (119) |
Complexity: 29 |
Complexity Density: 0.35 |
|
| 39 |
|
public class RestInputParamEditDialog extends GRestInputParamEditDialog |
| 40 |
|
implements OptsParametersContainerI |
| 41 |
|
{ |
| 42 |
|
Hashtable<String, Class> typeclass = new Hashtable<String, Class>(); |
| 43 |
|
|
| 44 |
|
Hashtable<String, ArrayList<JPanel>> typeopts = new Hashtable<String, ArrayList<JPanel>>(); |
| 45 |
|
|
| 46 |
|
Hashtable<String, OptsAndParamsPage> opanps = new Hashtable<String, OptsAndParamsPage>(); |
| 47 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 48 |
0 |
private InputType getTypeFor(String name)... |
| 49 |
|
{ |
| 50 |
0 |
try |
| 51 |
|
{ |
| 52 |
0 |
return (InputType) (typeclass.get(name).getConstructor() |
| 53 |
|
.newInstance()); |
| 54 |
|
} catch (Throwable x) |
| 55 |
|
{ |
| 56 |
0 |
jalview.bin.Console.errPrintln( |
| 57 |
|
"Unexpected exception when instantiating rest input type."); |
| 58 |
0 |
x.printStackTrace(); |
| 59 |
|
} |
| 60 |
0 |
return null; |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
int reply; |
| 64 |
|
|
| 65 |
|
JalviewDialog frame = new JalviewDialog() |
| 66 |
|
{ |
| 67 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 68 |
0 |
@Override... |
| 69 |
|
protected void raiseClosed() |
| 70 |
|
{ |
| 71 |
|
|
| 72 |
|
} |
| 73 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 74 |
0 |
@Override... |
| 75 |
|
protected void okPressed() |
| 76 |
|
{ |
| 77 |
0 |
reply = JvOptionPane.OK_OPTION; |
| 78 |
|
} |
| 79 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 80 |
0 |
@Override... |
| 81 |
|
protected void cancelPressed() |
| 82 |
|
{ |
| 83 |
0 |
reply = JvOptionPane.CANCEL_OPTION; |
| 84 |
|
|
| 85 |
|
} |
| 86 |
|
}; |
| 87 |
|
|
| 88 |
|
InputType old, current; |
| 89 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 90 |
0 |
public RestInputParamEditDialog(... |
| 91 |
|
RestServiceEditorPane restServiceEditorPane, |
| 92 |
|
RestServiceDescription currentservice, InputType toedit) |
| 93 |
|
{ |
| 94 |
0 |
initFor(restServiceEditorPane, currentservice, toedit); |
| 95 |
0 |
frame.waitForInput(); |
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
} |
| 100 |
|
|
| |
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
|
| 101 |
0 |
private void initFor(RestServiceEditorPane restServiceEditorPane,... |
| 102 |
|
RestServiceDescription currentservice, InputType toedit) |
| 103 |
|
{ |
| 104 |
0 |
okcancel.add(frame.cancel); |
| 105 |
0 |
okcancel.add(frame.ok); |
| 106 |
0 |
frame.initDialogFrame(dpane, true, true, |
| 107 |
|
"Edit parameter for service " + currentservice.getName(), 600, |
| 108 |
|
800); |
| 109 |
|
|
| 110 |
0 |
initTypeLists(); |
| 111 |
0 |
reply = JvOptionPane.CANCEL_OPTION; |
| 112 |
0 |
old = toedit; |
| 113 |
0 |
current = null; |
| 114 |
0 |
if (old != null) |
| 115 |
|
{ |
| 116 |
0 |
setStateFor(old); |
| 117 |
|
} |
| 118 |
0 |
updated = updated && reply == JvOptionPane.OK_OPTION; |
| 119 |
0 |
frame.validate(); |
| 120 |
|
} |
| 121 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 122 |
0 |
public RestInputParamEditDialog(... |
| 123 |
|
RestServiceEditorPane restServiceEditorPane, |
| 124 |
|
RestServiceDescription currentservice, String string) |
| 125 |
|
{ |
| 126 |
0 |
initFor(restServiceEditorPane, currentservice, null); |
| 127 |
0 |
tok.setText(string); |
| 128 |
0 |
frame.waitForInput(); |
| 129 |
|
} |
| 130 |
|
|
| |
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 131 |
0 |
private void setStateFor(InputType current)... |
| 132 |
|
{ |
| 133 |
0 |
tok.setText(current.token); |
| 134 |
0 |
OptsAndParamsPage opanp = opanps.get(current.getURLtokenPrefix()); |
| 135 |
0 |
for (OptionI ops : current.getOptions()) |
| 136 |
|
{ |
| 137 |
0 |
if (ops instanceof ParameterI) |
| 138 |
|
{ |
| 139 |
0 |
opanp.setParameter((ParameterI) ops); |
| 140 |
|
} |
| 141 |
|
else |
| 142 |
|
{ |
| 143 |
0 |
if (ops.getValue() != null && ops.getValue().length() > 0) |
| 144 |
|
{ |
| 145 |
0 |
opanp.selectOption(ops, ops.getValue()); |
| 146 |
|
} |
| 147 |
|
} |
| 148 |
|
} |
| 149 |
0 |
typeList.setSelectedValue(current.getURLtokenPrefix(), true); |
| 150 |
0 |
type_SelectionChangedActionPerformed(null); |
| 151 |
|
} |
| 152 |
|
|
| |
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
| 153 |
0 |
private void updateCurrentType()... |
| 154 |
|
{ |
| 155 |
0 |
if (typeList.getSelectedValue() != null) |
| 156 |
|
{ |
| 157 |
0 |
InputType newType = getTypeFor((String) typeList.getSelectedValue()); |
| 158 |
0 |
if (newType != null) |
| 159 |
|
{ |
| 160 |
0 |
newType.token = tok.getText().trim(); |
| 161 |
0 |
try |
| 162 |
|
{ |
| 163 |
0 |
newType.configureFromArgumentI(opanps |
| 164 |
|
.get(newType.getURLtokenPrefix()).getCurrentSettings()); |
| 165 |
0 |
current = newType; |
| 166 |
0 |
updated = true; |
| 167 |
|
} catch (InvalidArgumentException ex) |
| 168 |
|
{ |
| 169 |
0 |
jalview.bin.Console.errPrintln( |
| 170 |
|
"IMPLEMENTATION ERROR: Invalid argument for type : " |
| 171 |
|
+ typeList.getSelectedValue() + "\n"); |
| 172 |
0 |
ex.printStackTrace(); |
| 173 |
|
} |
| 174 |
|
} |
| 175 |
|
} |
| 176 |
|
|
| 177 |
|
} |
| 178 |
|
|
| |
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 3 |
Complexity Density: 0.14 |
|
| 179 |
0 |
private void initTypeLists()... |
| 180 |
|
{ |
| 181 |
0 |
ArrayList<String> types = new ArrayList<String>(); |
| 182 |
|
|
| 183 |
0 |
for (Class type : RestServiceDescription.getInputTypes()) |
| 184 |
|
{ |
| 185 |
|
|
| 186 |
0 |
InputType jtype = null; |
| 187 |
0 |
try |
| 188 |
|
{ |
| 189 |
0 |
JPanel inopts = new JPanel(new MigLayout()); |
| 190 |
0 |
ArrayList<JPanel> opts = new ArrayList<JPanel>(), |
| 191 |
|
prms = new ArrayList<JPanel>(); |
| 192 |
0 |
jtype = (InputType) (type.getConstructor().newInstance()); |
| 193 |
0 |
typeclass.put(jtype.getURLtokenPrefix(), type); |
| 194 |
|
|
| 195 |
0 |
OptsAndParamsPage opanp = new OptsAndParamsPage(this, true); |
| 196 |
0 |
opanps.put(jtype.getURLtokenPrefix(), opanp); |
| 197 |
0 |
for (OptionI opt : jtype.getOptions()) |
| 198 |
|
{ |
| 199 |
|
|
| 200 |
0 |
if (opt instanceof ParameterI) |
| 201 |
|
{ |
| 202 |
0 |
prms.add(opanp.addParameter((ParameterI) opt)); |
| 203 |
|
} |
| 204 |
|
else |
| 205 |
|
{ |
| 206 |
0 |
opts.add(opanp.addOption(opt)); |
| 207 |
|
} |
| 208 |
|
} |
| 209 |
|
|
| 210 |
0 |
for (JPanel pnl : prms) |
| 211 |
|
{ |
| 212 |
0 |
opts.add(pnl); |
| 213 |
|
} |
| 214 |
0 |
typeopts.put(jtype.getURLtokenPrefix(), opts); |
| 215 |
0 |
types.add(jtype.getURLtokenPrefix()); |
| 216 |
|
} catch (Throwable x) |
| 217 |
|
{ |
| 218 |
0 |
jalview.bin.Console.errPrintln( |
| 219 |
|
"Unexpected exception when instantiating rest input type."); |
| 220 |
0 |
x.printStackTrace(); |
| 221 |
|
} |
| 222 |
|
} |
| 223 |
0 |
typeList.setListData(types.toArray()); |
| 224 |
|
|
| 225 |
|
} |
| 226 |
|
|
| |
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
|
| 227 |
0 |
@Override... |
| 228 |
|
protected void type_SelectionChangedActionPerformed(ListSelectionEvent e) |
| 229 |
|
{ |
| 230 |
0 |
options.removeAll(); |
| 231 |
0 |
String typen = (String) typeList.getSelectedValue(); |
| 232 |
0 |
if (typeopts.get(typen) != null) |
| 233 |
|
{ |
| 234 |
0 |
for (JPanel opt : typeopts.get(typen)) |
| 235 |
|
{ |
| 236 |
0 |
opt.setOpaque(true); |
| 237 |
0 |
options.add(opt, "wrap"); |
| 238 |
|
} |
| 239 |
0 |
options.invalidate(); |
| 240 |
0 |
optionsPanel.setVisible(true); |
| 241 |
|
} |
| 242 |
|
else |
| 243 |
|
{ |
| 244 |
0 |
optionsPanel.setVisible(false); |
| 245 |
|
} |
| 246 |
0 |
dpane.revalidate(); |
| 247 |
0 |
updateCurrentType(); |
| 248 |
|
} |
| 249 |
|
|
| 250 |
|
boolean updated = false; |
| 251 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 252 |
0 |
public boolean wasUpdated()... |
| 253 |
|
{ |
| 254 |
0 |
return updated; |
| 255 |
|
} |
| 256 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 257 |
0 |
@Override... |
| 258 |
|
public void refreshParamLayout() |
| 259 |
|
{ |
| 260 |
0 |
options.invalidate(); |
| 261 |
0 |
dpane.revalidate(); |
| 262 |
|
} |
| 263 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 264 |
0 |
@Override... |
| 265 |
|
protected void tokChanged_actionPerformed() |
| 266 |
|
{ |
| 267 |
0 |
if (tok.getText().trim().length() > 0) |
| 268 |
|
{ |
| 269 |
0 |
if (current != null) |
| 270 |
|
{ |
| 271 |
0 |
current.token = tok.getText().trim(); |
| 272 |
0 |
updated = true; |
| 273 |
|
} |
| 274 |
|
} |
| 275 |
|
} |
| 276 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 277 |
0 |
@Override... |
| 278 |
|
public void argSetModified(Object modifiedElement, boolean b) |
| 279 |
|
{ |
| 280 |
0 |
updated = updated | b; |
| 281 |
0 |
if (updated) |
| 282 |
|
{ |
| 283 |
0 |
updateCurrentType(); |
| 284 |
|
} |
| 285 |
|
} |
| 286 |
|
|
| 287 |
|
} |