X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FRestServiceEditorPane.java;h=2e2593b0b8a3fad6904c4b7768231912c0373a38;hb=062ebc02980364930ceb26dd6c06448af971fe20;hp=5174b7aee84551937fc3adb1f29b0576be7a96b1;hpb=ad4c49bfc69cf3f7d844c346aa01fbaceeef0ee0;p=jalview.git
diff --git a/src/jalview/gui/RestServiceEditorPane.java b/src/jalview/gui/RestServiceEditorPane.java
index 5174b7a..2e2593b 100644
--- a/src/jalview/gui/RestServiceEditorPane.java
+++ b/src/jalview/gui/RestServiceEditorPane.java
@@ -1,7 +1,28 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.gui;
import jalview.io.packed.DataProvider.JvDataType;
import jalview.jbgui.GRestServiceEditorPane;
+import jalview.util.MessageManager;
import jalview.ws.rest.InputType;
import jalview.ws.rest.RestServiceDescription;
@@ -51,40 +72,47 @@ public class RestServiceEditorPane extends GRestServiceEditorPane
public void keyTyped(KeyEvent e)
{
}
-
+
@Override
public void keyReleased(KeyEvent e)
{
- refreshCutnPaste(true);
+ refreshCutnPaste(true);
}
-
+
@Override
public void keyPressed(KeyEvent e)
{
-
+
}
});
panels.addChangeListener(new ChangeListener()
{
/**
- * last panel selected - used to decide whether the service or the GUI has the latest info
+ * last panel selected - used to decide whether the service or the GUI has
+ * the latest info
*/
Object lastComp;
+
@Override
public void stateChanged(ChangeEvent e)
{
- if (lastComp!=paste) {
+ if (lastComp != paste)
+ {
updateServiceFromGui();
refreshCutnPaste(false);
- } else {
+ }
+ else
+ {
refreshCutnPaste(true);
}
lastComp = panels.getSelectedComponent();
-
+
}
- });
- currentservice = new RestServiceDescription("Analysis", "service description", "service name", "http://localhost/", "", null, false, false, '-');
+ });
+ currentservice = new RestServiceDescription("Analysis",
+ "service description", "service name", "http://localhost/", "",
+ null, false, false, '-');
initGuiWith(currentservice);
refreshCutnPaste(false);
updateButtons();
@@ -94,10 +122,15 @@ public class RestServiceEditorPane extends GRestServiceEditorPane
{
this();
oldservice = toedit;
- if (oldservice!=null)
- { currentservice = new RestServiceDescription(toedit);
- } else {
- currentservice = new RestServiceDescription("Analysis", "service description", "service name", "http://localhost/", "", null, false, false, '-');
+ if (oldservice != null)
+ {
+ currentservice = new RestServiceDescription(toedit);
+ }
+ else
+ {
+ currentservice = new RestServiceDescription("Analysis",
+ "service description", "service name", "http://localhost/",
+ "", null, false, false, '-');
}
initGuiWith(currentservice);
refreshCutnPaste(false);
@@ -135,7 +168,7 @@ public class RestServiceEditorPane extends GRestServiceEditorPane
gapChar.addItem(".");
gapChar.addItem(" ");
gapChar.addItem("-");
- if (currentservice==null)
+ if (currentservice == null)
{
name.setText("");
descr.setText("");
@@ -143,194 +176,237 @@ public class RestServiceEditorPane extends GRestServiceEditorPane
urlsuff.setText("");
action.setSelectedItem("Analysis");
gapChar.setSelectedItem("-");
- } else {
- name.setText(currentservice.getName());
- descr.setText(currentservice.getDescription());
- url.setText(currentservice.getPostUrl());
- urlsuff.setText(currentservice.getUrlSuffix());
- for (Map.Entry inparam : currentservice
- .getInputParams().entrySet())
- {
- _iparam.add(inparam.getKey() + " "
- + inparam.getValue().getURLtokenPrefix() + ":"
- + inparam.getValue().getURLEncodedParameter().toString());
}
-
- for (JvDataType oparam : currentservice.getResultDataTypes())
+ else
{
- _rparam.add(oparam.name());
- }
- iprms.setListData(_iparam);
- rdata.setListData(_rparam);
+ name.setText(currentservice.getName());
+ descr.setText(currentservice.getDescription());
+ url.setText(currentservice.getPostUrl());
+ urlsuff.setText(currentservice.getUrlSuffix());
+ for (Map.Entry inparam : currentservice
+ .getInputParams().entrySet())
+ {
+ _iparam.add(inparam.getKey() + " "
+ + inparam.getValue().getURLtokenPrefix() + ":"
+ + inparam.getValue().getURLEncodedParameter().toString());
+ }
- action.setSelectedItem(currentservice.getAction());
+ for (JvDataType oparam : currentservice.getResultDataTypes())
+ {
+ _rparam.add(oparam.name());
+ }
+ iprms.setListData(_iparam);
+ rdata.setListData(_rparam);
+
+ action.setSelectedItem(currentservice.getAction());
- gapChar.setSelectedItem(""+currentservice.getGapCharacter());
+ gapChar.setSelectedItem("" + currentservice.getGapCharacter());
}
revalidate();
}
+
private String getSelectedInputToken()
{
- if (iprms.getSelectedIndex()>-1)
+ if (iprms.getSelectedIndex() > -1)
{
- String toktoedit = (String) iprms.getSelectedValue();
- toktoedit=toktoedit.substring(0, toktoedit.indexOf(" "));
- return toktoedit;
+ String toktoedit = (String) iprms.getSelectedValue();
+ toktoedit = toktoedit.substring(0, toktoedit.indexOf(" "));
+ return toktoedit;
}
return null;
}
+
@Override
protected void iprmListSelection_doubleClicked()
{
String toktoedit = getSelectedInputToken();
- if (toktoedit!=null)
+ if (toktoedit != null)
{
InputType toedit = currentservice.getInputParams().get(toktoedit);
- String oldParam=toktoedit;
- RestInputParamEditDialog dialog=new RestInputParamEditDialog(this, currentservice, toedit);
- if (dialog.wasUpdated()) {
+ String oldParam = toktoedit;
+ RestInputParamEditDialog dialog = new RestInputParamEditDialog(this,
+ currentservice, toedit);
+ if (dialog.wasUpdated())
+ {
currentservice.getInputParams().remove(oldParam);
- currentservice.getInputParams().put(dialog.current.token, dialog.current);
+ currentservice.getInputParams().put(dialog.current.token,
+ dialog.current);
initGuiWith(currentservice);
}
-
+
}
}
+
@Override
protected void iprmsAdd_actionPerformed(ActionEvent e)
{
- RestInputParamEditDialog dialog=new RestInputParamEditDialog(this, currentservice, "param"+(1+currentservice.getInputParams().size()));
- if (dialog.wasUpdated()) {
- currentservice.getInputParams().put(dialog.current.token, dialog.current);
+ RestInputParamEditDialog dialog = new RestInputParamEditDialog(this,
+ currentservice,
+ "param" + (1 + currentservice.getInputParams().size()));
+ if (dialog.wasUpdated())
+ {
+ currentservice.getInputParams().put(dialog.current.token,
+ dialog.current);
initGuiWith(currentservice);
}
}
+
@Override
protected void iprmsRem_actionPerformed(ActionEvent e)
{
String toktoedit = getSelectedInputToken();
- if (toktoedit!=null)
+ if (toktoedit != null)
{
currentservice.getInputParams().remove(toktoedit);
initGuiWith(currentservice);
}
}
+
@Override
protected void rdata_rightClicked(MouseEvent mouse)
{
final int rdatasel = rdata.getSelectedIndex();
- if (rdatasel>-1)
+ if (rdatasel > -1)
{
- JPopupMenu popup = new JPopupMenu("Select return type");
- for (final JvDataType type:JvDataType.values()) {
- popup.add(new JMenuItem(type.name())).addActionListener(new ActionListener()
- {
-
- @Override
- public void actionPerformed(ActionEvent e)
- {
- currentservice.getResultDataTypes().set(rdatasel, type);
- initGuiWith(currentservice);
- rdata.setSelectedIndex(rdatasel);
- }
- });
+ JPopupMenu popup = new JPopupMenu(
+ MessageManager.getString("label.select_return_type"));
+ for (final JvDataType type : JvDataType.values())
+ {
+ popup.add(new JMenuItem(type.name()))
+ .addActionListener(new ActionListener()
+ {
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ currentservice.getResultDataTypes().set(rdatasel, type);
+ initGuiWith(currentservice);
+ rdata.setSelectedIndex(rdatasel);
+ }
+ });
}
popup.show(rdata, mouse.getX(), mouse.getY());
}
}
+
@Override
protected void rdataAdd_actionPerformed(ActionEvent e)
{
int p;
- if ((p=rdata.getSelectedIndex())>-1)
+ if ((p = rdata.getSelectedIndex()) > -1)
+ {
+ currentservice.getResultDataTypes().add(p + 1, JvDataType.ANNOTATION);
+ }
+ else
{
- currentservice.getResultDataTypes().add(p+1, JvDataType.ANNOTATION);
- } else {
currentservice.addResultDatatype(JvDataType.ANNOTATION);
}
initGuiWith(currentservice);
- rdata.setSelectedIndex(p==-1 ? currentservice.getResultDataTypes().size()-1 : p+1);
+ rdata.setSelectedIndex(
+ p == -1 ? currentservice.getResultDataTypes().size() - 1
+ : p + 1);
}
+
@Override
protected void rdataNdown_actionPerformed(ActionEvent e)
{
int p;
- if ((p=rdata.getSelectedIndex())>-1 && p<_rparam.size()-1)
+ if ((p = rdata.getSelectedIndex()) > -1 && p < _rparam.size() - 1)
{
List rtypes = currentservice.getResultDataTypes();
- JvDataType below = rtypes.get(p+1);
- rtypes.set(p+1, rtypes.get(p));
+ JvDataType below = rtypes.get(p + 1);
+ rtypes.set(p + 1, rtypes.get(p));
rtypes.set(p, below);
initGuiWith(currentservice);
- rdata.setSelectedIndex(p+1);
+ rdata.setSelectedIndex(p + 1);
}
}
+
@Override
protected void rdataNup_actionPerformed(ActionEvent e)
{
int p;
- if ((p=rdata.getSelectedIndex())>0)
+ if ((p = rdata.getSelectedIndex()) > 0)
{
List rtypes = currentservice.getResultDataTypes();
- JvDataType above = rtypes.get(p-1);
- rtypes.set(p-1, rtypes.get(p));
+ JvDataType above = rtypes.get(p - 1);
+ rtypes.set(p - 1, rtypes.get(p));
rtypes.set(p, above);
initGuiWith(currentservice);
- rdata.setSelectedIndex(p-1);
+ rdata.setSelectedIndex(p - 1);
}
}
+
@Override
protected void rdataRem_actionPerformed(ActionEvent e)
{
- if (rdata.getSelectedIndex()>-1)
+ if (rdata.getSelectedIndex() > -1)
{
currentservice.getResultDataTypes().remove(rdata.getSelectedIndex());
initGuiWith(currentservice);
}
}
- private boolean updateServiceFromGui() {
- MapinputTypes = new HashMap();
- StringBuffer warnings=new StringBuffer();
- for (String its:_iparam)
+ private boolean updateServiceFromGui()
+ {
+ Map inputTypes = new HashMap();
+ StringBuffer warnings = new StringBuffer();
+ for (String its : _iparam)
{
- Matcher mtch = Pattern.compile("(\\S+)\\s(\\S+):\\[(.+)]").matcher(its);
- if (mtch.find()) {
- if (!RestServiceDescription.parseTypeString(mtch.group(2)+":"+mtch.group(3), mtch.group(1), mtch.group(2),mtch.group(3), inputTypes, warnings))
+ Matcher mtch = Pattern.compile("(\\S+)\\s(\\S+):\\[(.+)]")
+ .matcher(its);
+ if (mtch.find())
+ {
+ if (!RestServiceDescription.parseTypeString(
+ mtch.group(2) + ":" + mtch.group(3), mtch.group(1),
+ mtch.group(2), mtch.group(3), inputTypes, warnings))
{
- System.err.println("IMPLEMENTATION PROBLEM: Cannot parse RestService input parameter string '"+its+"'"+"\n"+warnings);
- }
+ System.err.println(
+ "IMPLEMENTATION PROBLEM: Cannot parse RestService input parameter string '"
+ + its + "'" + "\n" + warnings);
+ }
}
}
- char gc = gapChar.getSelectedItem()==null ? ' ' : ((String)gapChar.getSelectedItem()).charAt(0);
- RestServiceDescription newService = new RestServiceDescription((String) action.getSelectedItem(),
- descr.getText().trim(), name.getText().trim(), url.getText().trim(), urlsuff.getText().trim(), inputTypes, hSeparable.isSelected(), vSeparable.isSelected(), gc);
-
+ char gc = gapChar.getSelectedItem() == null ? ' '
+ : ((String) gapChar.getSelectedItem()).charAt(0);
+ RestServiceDescription newService = new RestServiceDescription(
+ (String) action.getSelectedItem(), descr.getText().trim(),
+ name.getText().trim(), url.getText().trim(),
+ urlsuff.getText().trim(), inputTypes, hSeparable.isSelected(),
+ vSeparable.isSelected(), gc);
+
if (newService.isValid())
{
- for (String its:_rparam)
+ for (String its : _rparam)
{
JvDataType dtype;
- try {
+ try
+ {
dtype = JvDataType.valueOf(its);
newService.addResultDatatype(dtype);
- }
- catch (Throwable x)
+ } catch (Throwable x)
{
- System.err.println("IMPLEMENTATION PROBLEM: Cannot parse RestService output parameter string '"+its+"'"+"\n"+warnings);
+ System.err.println(
+ "IMPLEMENTATION PROBLEM: Cannot parse RestService output parameter string '"
+ + its + "'" + "\n" + warnings);
}
}
currentservice = newService;
return true;
- } else {
- System.err.println("IMPLEMENTATION PROBLEM: Restservice generated from GUI is invalid\n"+warnings);
+ }
+ else
+ {
+ System.err.println(
+ "IMPLEMENTATION PROBLEM: Restservice generated from GUI is invalid\n"
+ + warnings);
}
return false;
}
+
protected void refreshCutnPaste(boolean reparse)
{
if (!reparse && currentservice.isValid())
@@ -353,26 +429,30 @@ public class RestServiceEditorPane extends GRestServiceEditorPane
{
parseWarnings.setVisible(false);
parseRes.setText("");
- initGuiWith(currentservice=rsd);
+ initGuiWith(currentservice = rsd);
}
else
{
- parseRes.setText("Parsing failed. Syntax errors shown below\n"
- + rsd.getInvalidMessage());
+ parseRes.setText(MessageManager.formatMessage(
+ "label.parsing_failed_syntax_errors_shown_below_param",
+ new String[]
+ { rsd.getInvalidMessage() }));
parseWarnings.setVisible(true);
}
} catch (Throwable e)
{
e.printStackTrace();
- parseRes.setText("\nParsing failed. An unrecoverable exception was thrown:\n"
- + e.toString());
+ parseRes.setText(MessageManager.formatMessage(
+ "label.parsing_failed_unrecoverable_exception_thrown_param",
+ new String[]
+ { e.toString() }));
parseWarnings.setVisible(true);
}
}
paste.revalidate();
}
}
-
+
}
public static void main(String[] args)
@@ -385,16 +465,16 @@ public class RestServiceEditorPane extends GRestServiceEditorPane
public void run()
{
- boolean nulserv=true;
+ boolean nulserv = true;
while (visible)
{
final Thread runner = Thread.currentThread();
JFrame df = new JFrame();
df.getContentPane().setLayout(new BorderLayout());
- df.getContentPane().add(
- (nulserv=!nulserv) ? new RestServiceEditorPane(jalview.ws.rest.RestClient
- .makeShmmrRestClient().getRestDescription()) : new RestServiceEditorPane(),
- BorderLayout.CENTER);
+ df.getContentPane().add((nulserv = !nulserv)
+ ? new RestServiceEditorPane(jalview.ws.rest.RestClient
+ .makeShmmrRestClient().getRestDescription())
+ : new RestServiceEditorPane(), BorderLayout.CENTER);
df.setBounds(100, 100, 600, 400);
df.addComponentListener(new ComponentListener()
{
@@ -443,42 +523,45 @@ public class RestServiceEditorPane extends GRestServiceEditorPane
}
}
- String finalService=null;
+
+ String finalService = null;
+
public void showDialog(String title)
{
- if (oldservice!=null)
+ if (oldservice != null)
{
finalService = oldservice.toString();
}
JalviewDialog jvd = new JalviewDialog()
{
-
+
@Override
protected void raiseClosed()
{
// TODO Auto-generated method stub
-
+
}
-
+
@Override
protected void okPressed()
{
updateServiceFromGui();
- finalService = currentservice.toString();
+ finalService = currentservice.toString();
}
-
+
@Override
protected void cancelPressed()
{
-
+
}
};
- JPanel pane = new JPanel(new BorderLayout()),okcancel=new JPanel(new FlowLayout());
- pane.add(this,BorderLayout.CENTER);
+ JPanel pane = new JPanel(new BorderLayout()),
+ okcancel = new JPanel(new FlowLayout());
+ pane.add(this, BorderLayout.CENTER);
okcancel.add(jvd.ok);
okcancel.add(jvd.cancel);
pane.add(okcancel, BorderLayout.SOUTH);
- jvd.initDialogFrame(pane, true, true, title, 600,350);
+ jvd.initDialogFrame(pane, true, true, title, 600, 350);
jvd.waitForInput();
}