import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
-import java.util.Vector;
-
import javax.swing.JMenu;
import javax.swing.JMenuItem;
return us;
}
- List<ServiceWithParameters> ourServices = new ArrayList();
+ List<ServiceWithParameters> ourServices = new ArrayList<>();
/**
* forget about any known services
}
public void populateWSMenuEntry(List<ServiceWithParameters> services,
- PropertyChangeSupport changeSupport,
- JMenu jws2al, final AlignFrame alignFrame, String typeFilter)
+ PreferredServiceChangeListener changeListener, JMenu menu,
+ final AlignFrame alignFrame, String typeFilter)
{
/**
* eventually, JWS2 services will appear under the same align/etc submenus.
* for moment we keep them separate.
*/
+ ourServices.addAll(services);
JMenu atpoint;
- List<ServiceWithParameters> enumerableServices = new ArrayList<>();
- // jws2al.removeAll();
+
+ List<ServiceWithParameters> oneshotServices = new ArrayList<>();
+ List<ServiceWithParameters> interactiveServices = new ArrayList<>();
Map<String, ServiceWithParameters> preferredHosts = new HashMap<>();
Map<String, List<ServiceWithParameters>> alternates = new HashMap<>();
- for (ServiceWithParameters service : services)
+
+ for (var service : services)
+ {
+ if (service.isInteractiveUpdate())
+ interactiveServices.add(service);
+ else
+ oneshotServices.add(service);
+ }
+ for (var service : interactiveServices)
{
- ourServices.add(service);
- // TODO: check this behaves with refactored serviceType to getName
- if (!service.isInteractiveUpdate())
+ if (!preferredHosts.containsKey(service.getName()))
{
- // add 'one shot' services to be displayed using the classic menu
- // structure
- enumerableServices.add(service);
+ var preferred = getPreferredServiceFor(alignFrame, service.getName());
+ preferredHosts.put(service.getName(), (preferred != null) ? preferred : service);
}
- else
+ var ph = alternates.getOrDefault(service.getName(), new ArrayList<>());
+ if (!preferredHosts.containsValue(service))
{
- if (!preferredHosts.containsKey(service.getName()))
- {
- ServiceWithParameters preferredInstance = getPreferredServiceFor(
- alignFrame, service.getName());
- if (preferredInstance != null)
- {
- preferredHosts.put(service.getName(), preferredInstance);
- }
- else
- {
- preferredHosts.put(service.getName(), service);
- }
- }
- List<ServiceWithParameters> ph = alternates.get(service.getName());
- if (preferredHosts.get(service.getName()) != service)
- {
- if (ph == null)
- {
- ph = new ArrayList<>();
- }
- ph.add(service);
- alternates.put(service.getName(), ph);
- }
+ ph.add(service);
+ alternates.putIfAbsent(service.getName(), ph);
}
-
}
// create GUI element for classic services
- addEnumeratedServices(jws2al, alignFrame, enumerableServices);
+ addEnumeratedServices(menu, alignFrame, oneshotServices);
// and the instantaneous services
for (final ServiceWithParameters service : preferredHosts.values())
{
- atpoint = JvSwingUtils.findOrCreateMenu(jws2al,
+ atpoint = JvSwingUtils.findOrCreateMenu(menu,
service.getServiceType());
- JMenuItem hitm;
if (atpoint.getItemCount() > 1)
{
// previous service of this type already present
atpoint.addSeparator();
}
+ JMenuItem hitm;
atpoint.add(hitm = new JMenuItem(service.getHostURL()));
hitm.setForeground(Color.blue);
- hitm.addActionListener(new ActionListener()
- {
-
- @Override
- public void actionPerformed(ActionEvent e)
- {
- Desktop.showUrl(service.getHostURL());
- }
- });
+ hitm.addActionListener(e -> Desktop.showUrl(service.getHostURL()));
hitm.setToolTipText(JvSwingUtils.wrapTooltip(false,
MessageManager.getString("label.open_jabaws_web_page")));
JMenuItem itm;
hitm.add(itm = new JMenuItem(sv.getHostURL()));
itm.setForeground(Color.blue);
- itm.addActionListener(new ActionListener()
- {
-
- @Override
- public void actionPerformed(ActionEvent arg0)
- {
- new Thread(new Runnable()
- {
- @Override
- public void run()
- {
- setPreferredServiceFor(alignFrame, sv.getName(),
- sv.getServiceType(), sv);
- changeSupport.firePropertyChange("services",
- new Vector<ServiceWithParameters>(), services);
- };
- }).start();
-
- }
+ itm.addActionListener(e -> {
+ setPreferredServiceFor(alignFrame, sv.getName(), sv.getServiceType(), sv);
+ changeListener.preferredServiceChanged(sv);
});
}
}